Files
mes-ui-d2/vue.config.js
liyang 779579c49b 完善 SourceCode
Former-commit-id: 178f8509b7aca79b0c7bf4e36a54e14c466813dc [formerly 178f8509b7aca79b0c7bf4e36a54e14c466813dc [formerly 178f8509b7aca79b0c7bf4e36a54e14c466813dc [formerly 178f8509b7aca79b0c7bf4e36a54e14c466813dc [formerly 6a4e78b1141e0b28cb1f123454915beaa04b34a4 [formerly 481c93d328485031a939f96ec72150897902f0c1]]]]]
Former-commit-id: b51e506942b1328bb045d516b218d70d6ce99b7d
Former-commit-id: edf669e53fb1b611b9ba2575f426decc71cbc7f9
Former-commit-id: ba6c0641d73df6de0e71ab867a382aa3633500e9 [formerly d5bff56112625461a64952f11cb2a212a0ce4327]
Former-commit-id: 6403f70864033aa261745b9528505ce3598335f7
Former-commit-id: b8c62ad0f37cb4188e91699d5efd0a58e5cefd8b
Former-commit-id: a51513084098497931e35db64057c88793254f5a
Former-commit-id: 5c546900deb043ae5b333f0cca1ce6b966c13a75
Former-commit-id: 497a03106487a227c21ca9444898d77ce8e7a3a1
2019-04-30 00:25:41 +08:00

122 lines
3.5 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)
// 增加环境变量
process.env.VUE_APP_VERSION = require('./package.json').version
process.env.VUE_APP_BUILD_TIME = require('dayjs')().format('YYYY-M-D HH:mm:ss')
// 基础路径 注意发布之前要先修改这里
let publicPath = '/'
module.exports = {
publicPath, // 根据你的实际情况更改这里
lintOnSave: true,
devServer: {
publicPath // 和 publicPath 保持一致
},
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')
)
// TRAVIS 构建 vue-loader 添加 filename
.when(process.env.VUE_APP_BUILD_MODE === 'TRAVIS' || process.env.NODE_ENV === 'development',
config => config.module
.rule('vue')
.use('vue-loader')
.loader('vue-loader')
.tap(options => {
options.exposeFilename = true
return options
})
)
// 非开发环境
.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('@api', resolve('src/api'))
// 判断环境加入模拟数据
const entry = config.entry('app')
if (process.env.VUE_APP_BUILD_MODE !== 'nomock') {
entry
.add('@/mock')
.end()
}
}
}