This reverts commit 810407cde0 [formerly 06c2000def6d103aff231bd7a53a02d9ace87ca2] [formerly b12df0763e624fb55c9832ce4c7ec93ec881b19b] [formerly aef4bbe6556d4bc4b6eb561c28148dd8b4395cbf] [formerly 58b881a85f8baab6e6ef578575953de17bff0d40] [formerly 90771d09b3356812c438fa9cb8fa713c7fe86762] [formerly 4f1713142447f154592c4b74fb5e167df4287be1 [formerly 6daa81e0511c54daab83f96ff69c37b0cd55cc55]] [formerly eb82e859e47e2ec91f48023c705189e538b986e8] [formerly 2084d2f5552ba9ed91ce295cf7bc04e4d2a64e49] [formerly 93a57ab73023e37e7bd418f4221db12507653d74 [formerly 93a57ab73023e37e7bd418f4221db12507653d74 [formerly 93a57ab73023e37e7bd418f4221db12507653d74 [formerly 93a57ab73023e37e7bd418f4221db12507653d74 [formerly 331c42f3cf9c23bf114ea692b3aa23662d0963a5 [formerly a5f9f2449758fcc55395ccba72fb785b1764b593]]]]]].
Former-commit-id: cd1111a8660b1b8d3ce70abf0da421dd9e3c4585 [formerly cd1111a8660b1b8d3ce70abf0da421dd9e3c4585 [formerly cd1111a8660b1b8d3ce70abf0da421dd9e3c4585 [formerly cd1111a8660b1b8d3ce70abf0da421dd9e3c4585 [formerly e2bde741e1e71f84e69d9dd43b91e42cf1232624 [formerly 4981841af60ee395b89342a56583c14e0005f4ed]]]]]
Former-commit-id: baa090fe90d70c27cfd03ce1d2f608b59bdbc2a9
Former-commit-id: 392bae4192ceccc772d364b750f7ed1c7c9820a2
Former-commit-id: 9526616de130ea626e8a6cd37b8e76023c18c7bb [formerly bc53762a5f3db8f66a670cdba19760ca8ddbf944]
Former-commit-id: 587812dd74866fa0512ec7f791735f9ed8b3d508
Former-commit-id: a2fd8638fcbeda02b5d55a41d0fb1fd7859f5c31
Former-commit-id: b125c4c7d74f5a460bfb9b5613a3606f1b82bb47
Former-commit-id: ceb39f1a45afbc913f585073d43ec8addce8a7b6
Former-commit-id: a342aa6aab9e2af77edc228ab4a7317bd50a54d8
110 lines
3.3 KiB
JavaScript
110 lines
3.3 KiB
JavaScript
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()
|
||
}
|
||
}
|
||
}
|