c***@foxmail.com
有,写一个webpack插件
代码我发出来
```
const { getManifestJson, getPagesJson } = require('@dcloudio/uni-cli-shared/lib')
const { getPlatformProject } = require('@dcloudio/uni-cli-shared/lib/platform')
const merge = require('webpack-merge')
const fs = require('fs')
const path = require('path')
class JLWebpackPlugin {
constructor(options) {
this.options = options;
}
apply(compiler) {
if (process.env.UNI_PLATFORM === 'h5') return;
compiler.hooks.afterEmit.tap('JLWebpackPlugin', (compilation, cb) => {
console.log('JLWebpackPlugin compiler.hooks');
const jsonFiles = require('@dcloudio/webpack-uni-pages-loader/lib/platforms/' + process.env.UNI_PLATFORM)(getPagesJson(), getManifestJson(), false);
let project = jsonFiles.filter(item => (item.name + '.json') === getPlatformProject())[0]
if (!project) return
const appid = process.env.VUE_APP_MP_APPID || 'touristappid'
project = merge(project, { content: { appid: appid } })
fs.writeFileSync(path.resolve(process.env.UNI_OUTPUT_DIR, getPlatformProject()), JSON.stringify(project.content, null, 2))
});
}
}
module.exports = JLWebpackPlugin;
```
2022-06-23 13:25
5 个评论
要回复文章请先登录或注册
c***@foxmail.com
c***@foxmail.com
w***@gmail.com
有为啊啊啊啊啊
有为啊啊啊啊啊