Files
mes-ui-d2/vue.config.js
liyang 28d9817885 优化写法
Former-commit-id: 30723ec95813747dbd55054b42d7b480489b2ab0 [formerly 30723ec95813747dbd55054b42d7b480489b2ab0 [formerly 30723ec95813747dbd55054b42d7b480489b2ab0 [formerly 30723ec95813747dbd55054b42d7b480489b2ab0 [formerly 00103fb3d8da9c47bb9a7ede036a0aacd75efcd8 [formerly 033b78abeacaf34e7b49bf7737757fd31b4e0389]]]]]
Former-commit-id: 6cce6f23a44636b918dc98ca3398c01165158143
Former-commit-id: b53123a9ce1e9a27b6108955eef6d52d4cce11ad
Former-commit-id: 353dbb0ad9d402ad10c082a442e32b9edd89b076 [formerly da553cc21680df7ac5a9baf7416fe9dbf840ad32]
Former-commit-id: 6b5a9da647f6d5467682bc42c568a52422bbe61d
Former-commit-id: 9e64087cfd10811375f0afb5e50a27ba4ddf7aee
Former-commit-id: e791cca914171ee88101e28585068a7e600ef199
Former-commit-id: 31a432c983a493278037032ad2963b4fd67e3b70
Former-commit-id: b9242379f9958374fe9eecee97d6bb56e1ab6a67
2018-11-18 11:07:29 +08:00

115 lines
3.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
// 拼接路径
const resolve = dir => require('path').join(__dirname, dir)
// 基础路径 注意发布之前要先修改这里
let baseUrl = '/'
module.exports = {
baseUrl: baseUrl, // 根据你的实际情况更改这里
lintOnSave: true,
devServer: {
publicPath: baseUrl // 和 baseUrl 保持一致
},
css: {
loaderOptions: {
// 设置 scss 公用变量文件
sass: {
data: `@import '~@/assets/style/public.scss';`
}
}
},
// 默认设置: https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-service/lib/config/base.js
chainWebpack: config => {
/**
* 删除懒加载模块的 prefetch preload降低带宽压力
* https://cli.vuejs.org/zh/guide/html-and-static-assets.html#prefetch
* https://cli.vuejs.org/zh/guide/html-and-static-assets.html#preload
* 而且预渲染时生成的 prefetch 标签是 modern 版本的,低版本浏览器是不需要的
*/
config.plugins
.delete('prefetch')
.delete('preload')
// 解决 cli3 热更新失效 https://github.com/vuejs/vue-cli/issues/1559
config.resolve
.symlinks(true)
config
// 开发环境
.when(process.env.NODE_ENV === 'development',
// sourcemap不包含列信息
config => config.devtool('cheap-source-map')
)
// 非开发环境
.when(process.env.NODE_ENV !== 'development', config => {
config.optimization
.minimizer([
new UglifyJsPlugin({
uglifyOptions: {
// 移除 console
// 其它优化选项 https://segmentfault.com/a/1190000010874406
compress: {
warnings: false,
drop_console: true,
drop_debugger: true,
pure_funcs: ['console.log']
}
}
})
])
})
// markdown
config.module
.rule('md')
.test(/\.md$/)
.use('text-loader')
.loader('text-loader')
.end()
// i18n
config.module
.rule('i18n')
.resourceQuery(/blockType=i18n/)
.use('i18n')
.loader('@kazupon/vue-i18n-loader')
.end()
// svg
const svgRule = config.module.rule('svg')
svgRule.uses.clear()
svgRule
.include
.add(resolve('src/assets/svg-icons/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'd2-[name]'
})
.end()
// image exclude
const imagesRule = config.module.rule('images')
imagesRule
.test(/\.(png|jpe?g|gif|webp|svg)(\?.*)?$/)
.exclude
.add(resolve('src/assets/svg-icons/icons'))
.end()
// 重新设置 alias
config.resolve.alias
.set('@', resolve('src'))
// node
config.node
.set('__dirname', true)
.set('__filename', true)
// babel-polyfill 加入 entry
const entry = config.entry('app')
entry
.add('babel-polyfill')
.end()
// 判断环境加入模拟数据
if (process.env.VUE_APP_BUILD_MODE !== 'nomock') {
entry
.add('@/mock')
.end()
}
}
}