邃芒官网、邃芒慧影、口播(H5) https://m.metavatar.cc
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

140 行
3.9 KiB

  1. // const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
  2. const CompressionWebpackPlugin = require('compression-webpack-plugin');
  3. const path = require('path');
  4. const resolve = dir => {
  5. return path.join(__dirname, dir)
  6. }
  7. let timeStamp = new Date().getTime();
  8. let externals = {}
  9. let cdn = { css: [], js: [] }
  10. // const isProduction = process.env.VUE_APP_ENV == 'production' // 判断是否是生产环境
  11. const isProduction = true
  12. if (isProduction) {
  13. externals = {
  14. /**
  15. * externals 对象属性解析:
  16. * '包名' : '在项目中引入的名字'
  17. */
  18. 'vue': 'Vue',
  19. 'vant': 'vant',
  20. 'element-ui': 'ELEMENT',
  21. 'vuex': 'Vuex',
  22. 'vue-router': 'VueRouter',
  23. }
  24. cdn = {
  25. css: [
  26. 'https://unpkg.com/element-ui/lib/theme-chalk/index.css' // element-ui css 样式表
  27. ],
  28. js: [
  29. // vue must at first!
  30. 'https://unpkg.com/vue@2.6.12/dist/vue.js', // vuejs
  31. 'https://unpkg.com/vant@2.12/lib/vant.min.js', //vant
  32. 'https://unpkg.com/element-ui/lib/index.js', // element-ui js
  33. 'https://cdn.bootcdn.net/ajax/libs/vuex/4.0.0/vuex.global.min.js',//vuex
  34. 'https://cdn.bootcdn.net/ajax/libs/vue-router/4.0.6/vue-router.global.min.js',//vue-router
  35. ]
  36. }
  37. }
  38. module.exports = {
  39. configureWebpack: {
  40. output: { // 输出重构 打包编译后的js文件名称,添加时间戳.
  41. filename: `js/js[name].${timeStamp}.js`,
  42. chunkFilename: `js/chunk.[id].${timeStamp}.js`,
  43. },
  44. resolve: {
  45. alias: {
  46. '@': path.resolve(__dirname, 'src')
  47. }
  48. },
  49. externals,
  50. },
  51. css: {
  52. extract: { // 打包后css文件名称添加时间戳
  53. filename: `css/[name].${timeStamp}.css`,
  54. chunkFilename: `css/chunk.[id].${timeStamp}.css`,
  55. },
  56. loaderOptions: {
  57. css: {
  58. },
  59. // postcss: {
  60. // // options here will be passed to postcss-loader
  61. // plugins: [require('postcss-px2rem')({
  62. // remUnit: 75
  63. // })]
  64. // }
  65. }
  66. },
  67. pwa: {
  68. iconPaths: {
  69. favicon32: 'favicon.ico',
  70. favicon16: 'favicon.ico',
  71. appleTouchIcon: 'favicon.ico',
  72. maskIcon: 'favicon.ico',
  73. msTileImage: 'favicon.ico'
  74. }
  75. },
  76. //http://www.metavatar.cc/
  77. devServer: {
  78. overlay: {
  79. warnings: false,
  80. errors: false
  81. },
  82. proxy: {
  83. '/api': {
  84. // target: 'https://smapitestmalls,iformall.com/C/api',
  85. target: process.env.VUE_APP_API_ROOT+'/api',
  86. changeOrigin: true,
  87. pathRewrite: {
  88. '^/api': ''
  89. },
  90. },
  91. }
  92. },
  93. lintOnSave: false,
  94. publicPath: './', // 打包后引用的资源路径
  95. chainWebpack: config => {
  96. // favicon图标
  97. config.plugin('html').tap(args => {
  98. args[0].favicon = './public/favicon.ico';
  99. return args;
  100. });
  101. // 注入cdn变量 (打包时会执行)
  102. config.plugin('html').tap(args => {
  103. args[0].cdn = cdn // 配置cdn给插件
  104. return args
  105. })
  106. // 压缩js
  107. config.plugin('compression-webpack-plugin').use(new CompressionWebpackPlugin({
  108. test: /\.(js|css|scss)$/, // 匹配文件名
  109. threshold: 20480, // 对超过20k的数据压缩
  110. minRatio: 0.8,
  111. deleteOriginalAssets: true // 删除源文件
  112. }))
  113. }
  114. // configureWebpack: {
  115. // plugins: [
  116. // //打包环境去掉console.log
  117. // new UglifyJsPlugin({
  118. // uglifyOptions: {
  119. // compress: {
  120. // drop_console: true, //注释console
  121. // drop_debugger: true, //注释debugger
  122. // pure_funcs: ['console.log'], //移除console.log
  123. // },
  124. // },
  125. // }),
  126. // ],
  127. // }
  128. }