Files
mes-ui-d2/vue.config.js
liyang 99e8058039 no message
Former-commit-id: 81ed749f0cc0919e3560d59536a7a2bfb3d32cec [formerly 81ed749f0cc0919e3560d59536a7a2bfb3d32cec [formerly 81ed749f0cc0919e3560d59536a7a2bfb3d32cec [formerly 81ed749f0cc0919e3560d59536a7a2bfb3d32cec [formerly efed8ea3185d767af26a8c7ac0022056443ccddf [formerly d2ef4da90c85f2aaffe40ad9582961b86fcf79e6]]]]]
Former-commit-id: dafb9ad722dc1cbfafbe7e935de82bce4c332178
Former-commit-id: 0af9a05e9e579c3c65a39c0fba5f23c9a0da64a2
Former-commit-id: c2f06e6fa5c46fd71c14f7a24a17644873855fc8 [formerly cd9acd8f3b7207615d4c94cbca727c36e8d7bf24]
Former-commit-id: e9bafe627ad08e8d749003ccdc89a7102c8a7d50
Former-commit-id: 78a36587924dd602ff6e162bb7e7db4e324aaec7
Former-commit-id: 8c626144ba89409472f214b95a075e6917235600
Former-commit-id: 2a7f31432021e3ac207f813730311db6a30ccdcc
Former-commit-id: 4feb9a4d4a6fb4accd617a1c90ce7cdb81fd591c
2019-05-22 16:43:31 +08:00

120 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()
}
},
// i18n
pluginOptions: {
i18n: {
locale: 'en',
fallbackLocale: 'zh-chs',
localeDir: 'locales',
enableInSFC: true
}
}
}