選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

vue.config.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. console.log('vue.config.js 已加载,当前环境:', process.env.NODE_ENV)
  2. const fs = require('fs')
  3. const ENV_CONFIG = require('./config/environment.js')
  4. const manifestPath = `${__dirname}/manifest.json`;
  5. let Manifest = fs.readFileSync(manifestPath, {
  6. encoding: 'utf-8'
  7. })
  8. function replaceManifest(path, value) {
  9. const arr = path.split('.')
  10. const len = arr.length
  11. const lastItem = arr[len - 1]
  12. let i = 0
  13. let ManifestArr = Manifest.split(/\n/)
  14. for (let index = 0; index < ManifestArr.length; index++) {
  15. const item = ManifestArr[index]
  16. if (new RegExp(`"${arr[i]}"`).test(item)) ++i
  17. if (i === len) {
  18. const hasComma = /,/.test(item)
  19. ManifestArr[index] = item.replace(
  20. new RegExp(`"${lastItem}"[\\s\\S]*:[\\s\\S]*`),
  21. `"${lastItem}": ${value}${hasComma ? ',' : ''}`
  22. )
  23. break
  24. }
  25. }
  26. Manifest = ManifestArr.join('\n')
  27. }
  28. // 读取环境变量内容
  29. const appid = ENV_CONFIG[process.env.UNI_SCRIPT].appid
  30. console.log(9999)
  31. console.log(appid)
  32. if (appid) {
  33. replaceManifest('mp-weixin.appid', `"${appid}"`)
  34. }
  35. fs.writeFileSync(manifestPath, Manifest, {
  36. flag: 'w'
  37. })
  38. module.exports = {
  39. parallel: true, // 开启编译缓存
  40. productionSourceMap: false, // 关闭 Sourcemap
  41. transpileDependencies: [
  42. '*'
  43. ]
  44. }