diff --git a/packages/uni-cli-shared/lib/plugin.js b/packages/uni-cli-shared/lib/plugin.js index df4df1b02e72df0180255851e6c7491ce37eb7c8..20a0f336d577c02cf0901fec53b7bd0971f28c09 100644 --- a/packages/uni-cli-shared/lib/plugin.js +++ b/packages/uni-cli-shared/lib/plugin.js @@ -9,6 +9,7 @@ const Plugin = { configureEnv: [], // (){}, // 以 H5 为基准的平台特殊配置 configureH5: [], // (h5Options) {}, + configurePages: [], // (pagesJson,manifestJson,loader) {}, // 链式修改 webpack config chainWebpack: [], // (config, vueOptions, api) {}, // 修改 webpack config diff --git a/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js b/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js index 7e2db2339bda49a4129c2b93f7cdeda2983b9fee..3efe222e7a952df368f77139fb3c806b4fc71ab1 100644 --- a/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js +++ b/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js @@ -54,7 +54,7 @@ function getAssetsCopyOptions (assetsDir) { function getCopyWebpackPluginOptions (platformOptions, vueOptions) { const copyOptions = getAssetsCopyOptions(assetsDir) global.uniPlugin.copyWebpackOptions.forEach(copyWebpackOptions => { - const platformCopyOptions = copyWebpackOptions(platformOptions, vueOptions) || [] + const platformCopyOptions = copyWebpackOptions(platformOptions, vueOptions, copyOptions) || [] platformCopyOptions.forEach(copyOption => { if (typeof copyOption === 'string') { copyOption = getAssetsCopyOption(copyOption) diff --git a/packages/vue-cli-plugin-uni/packages/webpack-html-append-plugin/index.js b/packages/vue-cli-plugin-uni/packages/webpack-html-append-plugin/index.js index 686c7e9f4c5608ae8882e19600d4676593bc234e..32eb00b5f7818a8a4ea4be72420aea969556e0de 100644 --- a/packages/vue-cli-plugin-uni/packages/webpack-html-append-plugin/index.js +++ b/packages/vue-cli-plugin-uni/packages/webpack-html-append-plugin/index.js @@ -1,15 +1,19 @@ const HtmlWebpackPlugin = require('html-webpack-plugin') class WebpackHtmlAppendPlugin { - constructor (content) { + constructor(content) { this.content = content || '' } - apply (compiler) { + apply(compiler) { compiler.hooks.compilation.tap('WebpackHtmlAppendPlugin', (compilation) => { - const beforeEmit = compilation.hooks.htmlWebpackPluginAfterHtmlProcessing || - HtmlWebpackPlugin.getHooks(compilation).beforeEmit - - beforeEmit.tapAsync('WebpackHtmlAppendPlugin', (data, cb) => { + let beforeEmit = compilation.hooks.htmlWebpackPluginAfterHtmlProcessing + if (!beforeEmit && HtmlWebpackPlugin.getHooks) { + const hooks = HtmlWebpackPlugin.getHooks(compilation) + if (hooks) { + beforeEmit = hooks.beforeEmit + } + } + beforeEmit && beforeEmit.tapAsync('WebpackHtmlAppendPlugin', (data, cb) => { data.html += this.content cb(null, data) }) diff --git a/packages/webpack-uni-pages-loader/lib/index-new.js b/packages/webpack-uni-pages-loader/lib/index-new.js index bb776dc994338c32c83f722e24d0c5c2e3bc3885..95be12fd984fca54eeacf2d1f2ef0e08930d4f58 100644 --- a/packages/webpack-uni-pages-loader/lib/index-new.js +++ b/packages/webpack-uni-pages-loader/lib/index-new.js @@ -67,7 +67,7 @@ module.exports = function (content) { } 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') { return require('./platforms/quickapp-vue')(pagesJson, manifestJson, this) diff --git a/packages/webpack-uni-pages-loader/lib/platforms/h5.js b/packages/webpack-uni-pages-loader/lib/platforms/h5.js index 9bf6f08c35c17dc03705df51f63196b1664cbf99..49e884986d68b3e2392b29b4a9ff2031681482af 100644 --- a/packages/webpack-uni-pages-loader/lib/platforms/h5.js +++ b/packages/webpack-uni-pages-loader/lib/platforms/h5.js @@ -327,9 +327,13 @@ meta:{ ] } -module.exports = function (pagesJson, manifestJson) { +module.exports = function (pagesJson, manifestJson, loader) { const inputDir = process.env.UNI_INPUT_DIR + global.uniPlugin.configurePages.forEach(configurePages => { + configurePages(pagesJson, manifestJson, loader) + }) + const pageComponents = getPageComponents(inputDir, pagesJson) pagesJson.globalStyle = process.UNI_H5_PAGES_JSON.globalStyle @@ -367,4 +371,4 @@ global.__uniConfig.nvue = ${JSON.stringify({ 'flex-direction': getFlexDirection( ${genRegisterPageVueComponentsCode(pageComponents)} global.__uniRoutes=[${genPageRoutes(pageComponents).concat(genSystemRoutes()).join(',')}] ` -} +}