Files
mes-ui-d2/vue.config.js
liyang 7e5bd78fdb add i18n
Former-commit-id: e40632a3129a3147d4692474f05fcac1a8fb05da [formerly e40632a3129a3147d4692474f05fcac1a8fb05da [formerly e40632a3129a3147d4692474f05fcac1a8fb05da [formerly e40632a3129a3147d4692474f05fcac1a8fb05da [formerly 8a560e505164fe5718e1f386ecd8c84d213726b1 [formerly 0582bf632cbd9db5164fb2c454399fd1bd64ba41]]]]]
Former-commit-id: d0e35c73fc91d65ac612adf939e15f2c05a6dc1f
Former-commit-id: e6f9e3c3173dc757fd348cfc493055cdf4ed55a7
Former-commit-id: 3ea8c7bf97ab2e1b91986c7cd1a92da4200ecbc0 [formerly f4ffd12918a98e51b9f5f53a0102254e12ccc634]
Former-commit-id: 5eddfc5487865adcbef1d176ab1fabf305614efc
Former-commit-id: 044b0bf737fed573bd305b036c236b0a227bf0e1
Former-commit-id: f85fe58ea89d29b4579023de9829347012d29bc6
Former-commit-id: c91fbfc5efab828f43c8c51216c604a3987973b4
Former-commit-id: d96ee1048ea756123890a74af896b14a851c375d
2019-05-21 23:51:29 +08:00

124 lines
3.4 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 VueFilenameInjector = require('./tools/vue-filename-injector')
// 拼接路径
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_SCOURCE_LINK === 'TRUE',
VueFilenameInjector(config, {
propName: process.env.VUE_APP_SOURCE_VIEWER_PROP_NAME
})
)
// 非开发环境
.when(process.env.NODE_ENV !== 'development', config => {
config.optimization
.minimizer([
new UglifyJsPlugin({
uglifyOptions: {
// 移除 console
// 其它优化选项 https://segmentfault.com/a/1190000010874406
compress: {
drop_console: true,
drop_debugger: true,
pure_funcs: ['console.log']
}
}
})
])
})
// markdown
config.module
.rule('md')
.test(/\.md$/)
.use('text-loader')
.loader('text-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()
}
},
pluginOptions: {
i18n: {
locale: 'en',
fallbackLocale: 'zh',
localeDir: 'locales',
enableInSFC: true
}
}
}