-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
71 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,63 @@ const CompressionWebpackPlugin = require('compression-webpack-plugin') | |
function resolve(dir) { | ||
return path.join(__dirname, dir) | ||
} | ||
//对一些不经常改动的库,可以通过cdn引入,webpack不对他们打包 | ||
let externals = { | ||
'vue': 'Vue', | ||
'axios': 'axios', | ||
'element-ui': 'ELEMENT', | ||
'vue-router': 'VueRouter', | ||
'vuex': 'Vuex' | ||
} | ||
const cdn={ | ||
css:[ | ||
//element-ui css | ||
'https://unpkg.com/element-ui/lib/theme-chalk/index.css' | ||
], | ||
js:[ | ||
//vue | ||
'https://unpkg.com/[email protected]/dist/vue.min.js', | ||
//axios | ||
'http://cdn.staticfile.org/axios/0.19.0-beta.1/axios.min.js', | ||
//vuex | ||
'https://unpkg.com/[email protected]/dist/vuex.min.js', | ||
//vue-router | ||
'https://unpkg.com/[email protected]/dist/vue-router.min.js', | ||
//element | ||
'https://unpkg.com/[email protected]/lib/index.js' | ||
] | ||
} | ||
module.exports = { | ||
//基本路径 | ||
publicPath: './', | ||
//输出文件目录 | ||
outputDir: 'dist', | ||
//放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。 | ||
assetsDir: 'static', | ||
//生产环境不需要生产map文件 | ||
productionSourceMap:false, | ||
chainWebpack: config => { | ||
//这里是对环境的配置,不同的环境对应不同的BASE_URL | ||
config.plugin('define').tap(args => { | ||
args[0]['process.env'].BASE_URL = JSON.stringify(process.env.BASE_URL) | ||
return args; | ||
}); | ||
//设置别名 | ||
config.resolve.alias | ||
//代码分割 | ||
config.optimization.minimize(true); | ||
config.optimization.splitChunks({ | ||
chunks: 'all' | ||
}) | ||
//只在生产环境生效 | ||
if(process.env.NODE_ENV==='production'){ | ||
config.externals(externals) | ||
config.plugin('html') | ||
.tap(args=>{ | ||
args[0].cdn=cdn; | ||
return args | ||
}) | ||
} | ||
//设置别名 | ||
config.resolve.alias | ||
.set('@', resolve('src')) | ||
}, | ||
// webpack插件配置 | ||
|