2019-09-25 17:08:45 +08:00
const VueFilenameInjector = require ( '@d2-projects/vue-filename-injector' )
2019-05-06 10:49:25 +08:00
2019-06-11 21:24:38 +08:00
const ThemeColorReplacer = require ( 'webpack-theme-color-replacer' )
const forElementUI = require ( 'webpack-theme-color-replacer/forElementUI' )
2018-07-16 22:22:55 +08:00
// 拼接路径
2018-10-27 18:48:22 +08:00
const resolve = dir => require ( 'path' ) . join ( _ _dirname , dir )
2018-07-16 22:22:55 +08:00
2018-12-14 11:16:10 +08:00
// 增加环境变量
process . env . VUE _APP _VERSION = require ( './package.json' ) . version
process . env . VUE _APP _BUILD _TIME = require ( 'dayjs' ) ( ) . format ( 'YYYY-M-D HH:mm:ss' )
2018-07-20 18:24:47 +08:00
// 基础路径 注意发布之前要先修改这里
2019-10-11 11:10:39 +08:00
let publicPath = process . env . VUE _APP _PUBLIC _PATH || '/'
2018-07-20 18:24:47 +08:00
2018-07-16 22:22:55 +08:00
module . exports = {
2019-05-21 23:51:29 +08:00
// 根据你的实际情况更改这里
publicPath ,
2018-07-16 22:22:55 +08:00
lintOnSave : true ,
devServer : {
2019-01-17 11:33:11 +08:00
publicPath // 和 publicPath 保持一致
2018-07-16 22:22:55 +08:00
} ,
2018-11-16 22:49:27 +08:00
css : {
loaderOptions : {
// 设置 scss 公用变量文件
sass : {
data : ` @import '~@/assets/style/public.scss'; `
}
}
} ,
2018-07-19 17:00:45 +08:00
// 默认设置: https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-service/lib/config/base.js
2018-07-16 22:22:55 +08:00
chainWebpack : config => {
2018-11-18 09:45:04 +08:00
/ * *
* 删除懒加载模块的 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' )
2018-09-12 08:10:16 +08:00
// 解决 cli3 热更新失效 https://github.com/vuejs/vue-cli/issues/1559
config . resolve
. symlinks ( true )
2019-06-14 22:16:44 +08:00
config
. plugin ( 'theme-color-replacer' )
. use ( ThemeColorReplacer , [ {
fileName : 'css/theme-colors.[contenthash:8].css' ,
matchColors : [
... forElementUI . getElementUISeries ( process . env . VUE _APP _ELEMENT _COLOR ) // Element-ui主色系列
] ,
externalCssFiles : [ './node_modules/element-ui/lib/theme-chalk/index.css' ] , // optional, String or string array. Set external css files (such as cdn css) to extract colors.
changeSelector : forElementUI . changeSelector
} ] )
2018-11-18 11:07:29 +08:00
config
// 开发环境
. when ( process . env . NODE _ENV === 'development' ,
// sourcemap不包含列信息
config => config . devtool ( 'cheap-source-map' )
)
2019-12-12 10:00:30 +08:00
// 预览环境构建 vue-loader 添加 filename
2019-05-10 09:56:55 +08:00
. when ( process . env . VUE _APP _SCOURCE _LINK === 'TRUE' ,
2019-05-06 10:49:25 +08:00
VueFilenameInjector ( config , {
propName : process . env . VUE _APP _SOURCE _VIEWER _PROP _NAME
} )
2019-04-29 22:38:08 +08:00
)
2018-07-16 22:22:55 +08:00
// 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
2018-07-17 16:14:19 +08:00
. add ( resolve ( 'src/assets/svg-icons/icons' ) )
2018-07-16 22:22:55 +08:00
. end ( )
. use ( 'svg-sprite-loader' )
. loader ( 'svg-sprite-loader' )
. options ( {
symbolId : 'd2-[name]'
} )
. end ( )
2018-07-25 09:47:43 +08:00
// image exclude
2018-07-16 22:22:55 +08:00
const imagesRule = config . module . rule ( 'images' )
imagesRule
. test ( /\.(png|jpe?g|gif|webp|svg)(\?.*)?$/ )
. exclude
2018-07-17 16:14:19 +08:00
. add ( resolve ( 'src/assets/svg-icons/icons' ) )
2018-07-16 22:22:55 +08:00
. end ( )
2018-07-17 21:54:38 +08:00
// 重新设置 alias
2018-07-19 17:00:45 +08:00
config . resolve . alias
2018-12-11 08:48:38 +08:00
. set ( '@api' , resolve ( 'src/api' ) )
2018-11-14 19:48:44 +08:00
// 判断环境加入模拟数据
2019-01-17 11:09:43 +08:00
const entry = config . entry ( 'app' )
2019-05-10 09:56:55 +08:00
if ( process . env . VUE _APP _BUILD _MODE !== 'NOMOCK' ) {
2018-11-14 16:24:56 +08:00
entry
. add ( '@/mock' )
. end ( )
}
2019-05-21 23:51:29 +08:00
} ,
2019-05-22 00:19:48 +08:00
// i18n
2019-05-21 23:51:29 +08:00
pluginOptions : {
i18n : {
2019-05-23 21:41:04 +08:00
locale : 'zh-chs' ,
fallbackLocale : 'en' ,
2019-05-21 23:51:29 +08:00
localeDir : 'locales' ,
enableInSFC : true
}
2018-07-16 22:22:55 +08:00
}
}