// const UglifyJsPlugin = require('uglifyjs-webpack-plugin') const path = require('path'); let externals = {} let cdn = { css: [], js: [] } const isProduction = process.env.VUE_APP_ENV == 'production' // 判断是否是生产环境 if (isProduction) { externals = { /** * externals 对象属性解析: * '包名' : '在项目中引入的名字' */ 'vue': 'Vue', 'element-ui': 'ELEMENT', 'xlsx': 'XLSX' } cdn = { css: [ 'https://unpkg.com/element-ui/lib/theme-chalk/index.css' // element-ui css 样式表 ], js: [ // vue must at first! 'https://unpkg.com/vue@2.6.12/dist/vue.js', // vuejs 'https://unpkg.com/element-ui/lib/index.js', // element-ui js 'https://cdn.jsdelivr.net/npm/xlsx@0.16.6/dist/xlsx.full.min.js' // xlsx ] } } module.exports = { configureWebpack: { resolve: { alias: { '@': path.resolve(__dirname, 'src') } }, externals, }, css: { loaderOptions: { css: { // options here will be passed to css-loader }, // postcss: { // // options here will be passed to postcss-loader // plugins: [require('postcss-px2rem')({ // remUnit: 75 // })] // } } }, pwa: { iconPaths: { favicon32: 'favicon.ico', favicon16: 'favicon.ico', appleTouchIcon: 'favicon.ico', maskIcon: 'favicon.ico', msTileImage: 'favicon.ico' } }, //http://www.metavatar.cc/ devServer: { overlay: { warnings: false, errors: false }, proxy: { '/api': { // target: 'https://smapitestmalls,iformall.com/C/api', target: process.env.VUE_APP_API_ROOT+'/api', changeOrigin: true, pathRewrite: { '^/api': '' }, }, } }, lintOnSave: false, publicPath: './', // 打包后引用的资源路径 chainWebpack: config => { config.plugin('html').tap(args => { args[0].favicon = './public/favicon.ico'; return args; }); // 注入cdn变量 (打包时会执行) config.plugin('html').tap(args => { args[0].cdn = cdn // 配置cdn给插件 return args }) } // configureWebpack: { // plugins: [ // //打包环境去掉console.log // new UglifyJsPlugin({ // uglifyOptions: { // compress: { // drop_console: true, //注释console // drop_debugger: true, //注释debugger // pure_funcs: ['console.log'], //移除console.log // }, // }, // }), // ], // } }