// const UglifyJsPlugin = require('uglifyjs-webpack-plugin') const path = require('path'); const resolve = dir => { return path.join(__dirname, dir) } let timeStamp = new Date().getTime(); let externals = {} let cdn = { css: [], js: [] } const isProduction = process.env.VUE_APP_ENV == 'production' // 判断是否是生产环境 if (isProduction) { externals = { /** * externals 对象属性解析: * '包名' : '在项目中引入的名字' */ 'vue': 'Vue', 'vant': 'vant', 'element-ui': 'ELEMENT', } 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/vant@2.12/lib/vant.min.js', //vant 'https://unpkg.com/element-ui/lib/index.js', // element-ui js ] } } module.exports = { configureWebpack: { output: { // 输出重构 打包编译后的js文件名称,添加时间戳. filename: `js/js[name].${timeStamp}.js`, chunkFilename: `js/chunk.[id].${timeStamp}.js`, }, resolve: { alias: { '@': path.resolve(__dirname, 'src') } }, externals, }, css: { extract: { // 打包后css文件名称添加时间戳 filename: `css/[name].${timeStamp}.css`, chunkFilename: `css/chunk.[id].${timeStamp}.css`, }, loaderOptions: { css: { }, // 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 }) config.module .rule('svg') .exclude.add(resolve('src/icons')) .end() config.module .rule('icons') .test(/\.svg$/) .include.add(resolve('src/icons')) .end() .use('svg-sprite-loader') .loader('svg-sprite-loader') .options({ symbolId: 'icon-[name]' }) .end() } // configureWebpack: { // plugins: [ // //打包环境去掉console.log // new UglifyJsPlugin({ // uglifyOptions: { // compress: { // drop_console: true, //注释console // drop_debugger: true, //注释debugger // pure_funcs: ['console.log'], //移除console.log // }, // }, // }), // ], // } }