提交 a4a36a8a 编写于 作者: fxy060608's avatar fxy060608

feat(plugin): add configurePages

上级 04833949
...@@ -9,6 +9,7 @@ const Plugin = { ...@@ -9,6 +9,7 @@ const Plugin = {
configureEnv: [], // (){}, configureEnv: [], // (){},
// 以 H5 为基准的平台特殊配置 // 以 H5 为基准的平台特殊配置
configureH5: [], // (h5Options) {}, configureH5: [], // (h5Options) {},
configurePages: [], // (pagesJson,manifestJson,loader) {},
// 链式修改 webpack config // 链式修改 webpack config
chainWebpack: [], // (config, vueOptions, api) {}, chainWebpack: [], // (config, vueOptions, api) {},
// 修改 webpack config // 修改 webpack config
......
...@@ -54,7 +54,7 @@ function getAssetsCopyOptions (assetsDir) { ...@@ -54,7 +54,7 @@ function getAssetsCopyOptions (assetsDir) {
function getCopyWebpackPluginOptions (platformOptions, vueOptions) { function getCopyWebpackPluginOptions (platformOptions, vueOptions) {
const copyOptions = getAssetsCopyOptions(assetsDir) const copyOptions = getAssetsCopyOptions(assetsDir)
global.uniPlugin.copyWebpackOptions.forEach(copyWebpackOptions => { global.uniPlugin.copyWebpackOptions.forEach(copyWebpackOptions => {
const platformCopyOptions = copyWebpackOptions(platformOptions, vueOptions) || [] const platformCopyOptions = copyWebpackOptions(platformOptions, vueOptions, copyOptions) || []
platformCopyOptions.forEach(copyOption => { platformCopyOptions.forEach(copyOption => {
if (typeof copyOption === 'string') { if (typeof copyOption === 'string') {
copyOption = getAssetsCopyOption(copyOption) copyOption = getAssetsCopyOption(copyOption)
......
const HtmlWebpackPlugin = require('html-webpack-plugin') const HtmlWebpackPlugin = require('html-webpack-plugin')
class WebpackHtmlAppendPlugin { class WebpackHtmlAppendPlugin {
constructor (content) { constructor(content) {
this.content = content || '' this.content = content || ''
} }
apply (compiler) { apply(compiler) {
compiler.hooks.compilation.tap('WebpackHtmlAppendPlugin', (compilation) => { compiler.hooks.compilation.tap('WebpackHtmlAppendPlugin', (compilation) => {
const beforeEmit = compilation.hooks.htmlWebpackPluginAfterHtmlProcessing || let beforeEmit = compilation.hooks.htmlWebpackPluginAfterHtmlProcessing
HtmlWebpackPlugin.getHooks(compilation).beforeEmit if (!beforeEmit && HtmlWebpackPlugin.getHooks) {
const hooks = HtmlWebpackPlugin.getHooks(compilation)
beforeEmit.tapAsync('WebpackHtmlAppendPlugin', (data, cb) => { if (hooks) {
beforeEmit = hooks.beforeEmit
}
}
beforeEmit && beforeEmit.tapAsync('WebpackHtmlAppendPlugin', (data, cb) => {
data.html += this.content data.html += this.content
cb(null, data) cb(null, data)
}) })
......
...@@ -67,7 +67,7 @@ module.exports = function (content) { ...@@ -67,7 +67,7 @@ module.exports = function (content) {
} }
if (process.env.UNI_PLATFORM === 'h5') { if (process.env.UNI_PLATFORM === 'h5') {
return require('./platforms/h5')(pagesJson, manifestJson) return require('./platforms/h5')(pagesJson, manifestJson, this)
} }
if (process.env.UNI_PLATFORM === 'quickapp-vue') { if (process.env.UNI_PLATFORM === 'quickapp-vue') {
return require('./platforms/quickapp-vue')(pagesJson, manifestJson, this) return require('./platforms/quickapp-vue')(pagesJson, manifestJson, this)
......
...@@ -327,9 +327,13 @@ meta:{ ...@@ -327,9 +327,13 @@ meta:{
] ]
} }
module.exports = function (pagesJson, manifestJson) { module.exports = function (pagesJson, manifestJson, loader) {
const inputDir = process.env.UNI_INPUT_DIR const inputDir = process.env.UNI_INPUT_DIR
global.uniPlugin.configurePages.forEach(configurePages => {
configurePages(pagesJson, manifestJson, loader)
})
const pageComponents = getPageComponents(inputDir, pagesJson) const pageComponents = getPageComponents(inputDir, pagesJson)
pagesJson.globalStyle = process.UNI_H5_PAGES_JSON.globalStyle pagesJson.globalStyle = process.UNI_H5_PAGES_JSON.globalStyle
...@@ -367,4 +371,4 @@ global.__uniConfig.nvue = ${JSON.stringify({ 'flex-direction': getFlexDirection( ...@@ -367,4 +371,4 @@ global.__uniConfig.nvue = ${JSON.stringify({ 'flex-direction': getFlexDirection(
${genRegisterPageVueComponentsCode(pageComponents)} ${genRegisterPageVueComponentsCode(pageComponents)}
global.__uniRoutes=[${genPageRoutes(pageComponents).concat(genSystemRoutes()).join(',')}] global.__uniRoutes=[${genPageRoutes(pageComponents).concat(genSystemRoutes()).join(',')}]
` `
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册