疯值幽魂
疯值幽魂
  • 发布:2021-05-27 16:51
  • 更新:2022-06-23 13:26
  • 阅读:1218

有没有什么webpack插件可以动态修改manifest.json 文件下的mp-weixin下的appid

分类:uni-app

有没有什么webpack插件可以动态修改manifest.json 文件下的mp-weixin下的appid

0 关注 分享

要回复文章请先登录注册

c***@foxmail.com

c***@foxmail.com

回复 c***@foxmail.com :
用vue-cli的env自定义VUE_APP_MP_APPID,只需要在你的.env.xxxx里配置就行
2022-06-23 13:26
c***@foxmail.com

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
w***@gmail.com

w***@gmail.com

解决了吗兄弟
2021-12-06 14:41
有为啊啊啊啊啊

有为啊啊啊啊啊

官方有更好的办法嘛,@官方
2021-08-14 13:32
有为啊啊啊啊啊

有为啊啊啊啊啊

感觉官方没给答复,要不直接用死的办法吧:构建完成后用node去修改project.config.json
2021-08-14 13:32