123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- const path = require('path')
- function resolve(dir) {
- return path.join(__dirname, dir)
- }
- const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
- const DEV = process.env.NODE_ENV == 'production';
- module.exports = {
- // 选项...
- publicPath: './',
- productionSourceMap: false,
- css: {
- extract: false,
- sourceMap: true,
- loaderOptions: {},
- },
- lintOnSave: false,
- devServer: {
- port: 8088,
- overlay: {
- warning: false,
- errors: false
- },
- disableHostCheck: true,
- },
- chainWebpack: (config) => {
- // 移除 prefetch 插件
- config.plugins.delete('prefetch')
- // 移除 preload 插件
- config.plugins.delete('preload');
- // ============压缩图片 start============
- // config.module
- // .rule('images')
- // .use('image-webpack-loader')
- // .loader('image-webpack-loader')
- // .options({bypassOnDebug: true})
- // .end()
- // ============压缩图片 end============
-
- //配置 svg-sprite-loader
- // 第一步:让其他svg loader不要对src/icons进行操作
- config.module
- .rule('svg')
- .exclude.add(resolve('src/icons/svg')) //注意:路径要具体到存放的svg的路径下,不然会报错
- .end()
- // 第二步:使用svg-sprite-loader 对 src/icons下的svg进行操作
- config.module
- .rule('icons')
- .test(/\.svg$/)
- .include.add(resolve('src/icons/svg')) //注意:路径要具体到存放的svg的路径下,不然会报错
- .end()
- .use('svg-sprite-loader')
- .loader('svg-sprite-loader')
- //定义规则 使用时 <svg class="icon"> <use xlink:href="#icon-svg文件名"></use> </svg>
- .options({
- symbolId: 'icon-[name]'
- })
- .end()
- },
- configureWebpack: config => {
- if(DEV){
- config.plugins.push(
- new UglifyJsPlugin({
- uglifyOptions: {
- //生产环境自动删除console
- compress: {
- drop_debugger: true,
- drop_console: true,
- pure_funcs: ['console.log']
- }
- },
- sourceMap: false,
- parallel: true
- })
- )
- }
- config.optimization.splitChunks = {
- cacheGroups: {
- vendors: {
- chunks: 'all',
- name: "chunk-vendors",
- test: /[\\/]node_modules[\\/]/,
- chunks: "initial",
- priority: 2,
- reuseExistingChunk: true,
- enforce: true
- },
- elementUI: {
- chunks: 'all',
- name: "stabled-elementui",
- test: /[\\/]node_modules[\\/]element-ui[\\/]/,
- priority: 3,
- reuseExistingChunk: true,
- enforce: true
- },
- echarts: {
- chunks: 'all',
- name: "stabled-echarts",
- test: /[\\/]node_modules[\\/]echarts[\\/]/,
- priority: 4,
- reuseExistingChunk: true,
- enforce: true
- },
- vue: {
- name: 'stabled-vue',
- test: /[\\/]node_modules[\\/]vue[\\/]/,
- chunks: "all",
- priority: 5,
- reuseExistingChunk: true,
- enforce: true
- },
- vuex: {
- name: 'stabled-vue',
- test: /[\\/]node_modules[\\/]vuex[\\/]/,
- chunks: "all",
- priority: 6,
- reuseExistingChunk: true,
- enforce: true
- },
- 'vue-router': {
- name: 'stabled-vue',
- test: /[\\/]node_modules[\\/]vue-router[\\/]/,
- chunks: "all",
- priority: 7,
- reuseExistingChunk: true,
- enforce: true
- },
- zrender: {
- name: "stabled-zrender",
- test: /[\\/]node_modules[\\/]zrender[\\/]/,
- chunks: "all",
- priority: 8,
- reuseExistingChunk: true,
- enforce: true
- }
- }
- }
- },
- }
|