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

feat(plugin): add configurePages

上级 04833949
......@@ -9,6 +9,7 @@ const Plugin = {
configureEnv: [], // (){},
// 以 H5 为基准的平台特殊配置
configureH5: [], // (h5Options) {},
configurePages: [], // (pagesJson,manifestJson,loader) {},
// 链式修改 webpack config
chainWebpack: [], // (config, vueOptions, api) {},
// 修改 webpack config
......
......@@ -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)
......
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)
})
......
......@@ -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)
......
......@@ -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(',')}]
`
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册