1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- console.log('vue.config.js 已加载,当前环境:', process.env.NODE_ENV)
-
- const fs = require('fs')
- const ENV_CONFIG = require('./config/environment.js')
- const manifestPath = `${__dirname}/manifest.json`;
- let Manifest = fs.readFileSync(manifestPath, {
- encoding: 'utf-8'
- })
-
- function replaceManifest(path, value) {
- const arr = path.split('.')
- const len = arr.length
- const lastItem = arr[len - 1]
-
- let i = 0
- let ManifestArr = Manifest.split(/\n/)
-
- for (let index = 0; index < ManifestArr.length; index++) {
- const item = ManifestArr[index]
- if (new RegExp(`"${arr[i]}"`).test(item)) ++i
- if (i === len) {
- const hasComma = /,/.test(item)
- ManifestArr[index] = item.replace(
- new RegExp(`"${lastItem}"[\\s\\S]*:[\\s\\S]*`),
- `"${lastItem}": ${value}${hasComma ? ',' : ''}`
- )
- break
- }
- }
-
- Manifest = ManifestArr.join('\n')
- }
- // 读取环境变量内容
- const appid = ENV_CONFIG[process.env.UNI_SCRIPT].appid
-
- console.log(9999)
- console.log(appid)
-
- if (appid) {
- replaceManifest('mp-weixin.appid', `"${appid}"`)
- }
-
- fs.writeFileSync(manifestPath, Manifest, {
- flag: 'w'
- })
-
- module.exports = {
- parallel: true, // 开启编译缓存
- productionSourceMap: false, // 关闭 Sourcemap
- transpileDependencies: [
- '*'
- ]
- }
|