2018-10-29 05:55:36 +00:00
|
|
|
'use strict'
|
2019-03-15 10:08:12 +00:00
|
|
|
require('@babel/register')
|
2019-03-17 13:05:46 +00:00
|
|
|
require('module-alias/register')
|
2018-10-29 05:55:36 +00:00
|
|
|
const path = require('path')
|
2019-03-17 13:05:46 +00:00
|
|
|
const { default: settings } = require('./src/settings.js')
|
2019-03-14 09:23:32 +00:00
|
|
|
const { name } = settings
|
2018-10-29 05:55:36 +00:00
|
|
|
|
|
|
|
function resolve(dir) {
|
|
|
|
return path.join(__dirname, dir)
|
|
|
|
}
|
|
|
|
|
2019-03-15 10:08:12 +00:00
|
|
|
const port = 9527 // dev port
|
|
|
|
|
2018-10-29 07:02:06 +00:00
|
|
|
// Explanation of each configuration item You can find it in https://cli.vuejs.org/config/
|
2018-10-29 05:55:36 +00:00
|
|
|
module.exports = {
|
2018-10-29 07:02:06 +00:00
|
|
|
/**
|
|
|
|
* You can set by yourself according to actual condition
|
|
|
|
* You will need to set this if you plan to deploy your site under a sub path,
|
|
|
|
* for example GitHub pages. If you plan to deploy your site to https://foo.github.io/bar/,
|
|
|
|
* then assetsPublicPath should be set to "/bar/".
|
|
|
|
* In most cases please use '/' !!!
|
2019-03-08 09:57:14 +00:00
|
|
|
* Detail https://cli.vuejs.org/config/#publicPath
|
2018-10-29 07:02:06 +00:00
|
|
|
*/
|
2019-03-08 09:57:14 +00:00
|
|
|
publicPath: '/',
|
2018-10-29 07:02:06 +00:00
|
|
|
outputDir: 'dist',
|
|
|
|
assetsDir: 'static',
|
2019-03-11 08:29:59 +00:00
|
|
|
lintOnSave: process.env.NODE_ENV === 'development' ? 'error' : false,
|
2018-10-29 07:02:06 +00:00
|
|
|
productionSourceMap: false,
|
2018-10-29 05:55:36 +00:00
|
|
|
devServer: {
|
2019-03-15 10:08:12 +00:00
|
|
|
port: port,
|
2018-10-29 05:55:36 +00:00
|
|
|
open: true,
|
2018-10-29 07:02:06 +00:00
|
|
|
overlay: {
|
|
|
|
warnings: false,
|
|
|
|
errors: true
|
|
|
|
},
|
2018-10-29 05:55:36 +00:00
|
|
|
proxy: {
|
|
|
|
'/api': {
|
2018-10-29 07:02:06 +00:00
|
|
|
target: `http://localhost:${port}/mock`,
|
2018-10-29 05:55:36 +00:00
|
|
|
changeOrigin: true,
|
|
|
|
pathRewrite: {
|
|
|
|
'^/api': ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
after(app) {
|
2018-10-29 07:02:06 +00:00
|
|
|
const bodyParser = require('body-parser')
|
2019-03-15 10:08:12 +00:00
|
|
|
|
2018-10-29 05:55:36 +00:00
|
|
|
// parse app.body
|
|
|
|
// http://expressjs.com/en/4x/api.html#req.body
|
|
|
|
app.use(bodyParser.json())
|
2019-03-08 10:33:36 +00:00
|
|
|
app.use(bodyParser.urlencoded({
|
|
|
|
extended: true
|
|
|
|
}))
|
2018-10-29 05:55:36 +00:00
|
|
|
|
|
|
|
// import ES2015 module from common.js module
|
|
|
|
const { default: mocks } = require('./mock')
|
|
|
|
for (const mock of mocks) {
|
2019-03-17 13:05:46 +00:00
|
|
|
console.log(mock, mock.response)
|
2018-10-29 05:55:36 +00:00
|
|
|
app.all(mock.route, mock.response)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
configureWebpack: {
|
2018-10-29 07:02:06 +00:00
|
|
|
// We provide the app's title in Webpack's name field, so that
|
|
|
|
// it can be accessed in index.html to inject the correct title.
|
2019-03-11 08:29:59 +00:00
|
|
|
name: name,
|
2018-10-29 05:55:36 +00:00
|
|
|
resolve: {
|
|
|
|
alias: {
|
2018-10-29 07:02:06 +00:00
|
|
|
'@': resolve('src')
|
2018-10-29 05:55:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
chainWebpack(config) {
|
2019-03-08 10:33:36 +00:00
|
|
|
config.plugins.delete('preload') // TODO: need test
|
|
|
|
config.plugins.delete('prefetch') // TODO: need test
|
2018-10-29 05:55:36 +00:00
|
|
|
config.module
|
|
|
|
.rule('svg')
|
|
|
|
.exclude.add(resolve('src/icons'))
|
|
|
|
.end()
|
2018-10-29 07:02:06 +00:00
|
|
|
config.module
|
|
|
|
.rule('icons')
|
|
|
|
.test(/\.svg$/)
|
|
|
|
.include.add(resolve('src/icons'))
|
|
|
|
.end()
|
|
|
|
.use('svg-sprite-loader')
|
|
|
|
.loader('svg-sprite-loader')
|
|
|
|
.options({
|
|
|
|
symbolId: 'icon-[name]'
|
|
|
|
})
|
|
|
|
.end()
|
2019-03-08 10:33:36 +00:00
|
|
|
config.module
|
|
|
|
.rule('vue')
|
|
|
|
.use('vue-loader')
|
|
|
|
.loader('vue-loader')
|
|
|
|
.tap(options => {
|
|
|
|
options.compilerOptions.preserveWhitespace = true
|
|
|
|
return options
|
|
|
|
})
|
|
|
|
.end()
|
2018-10-29 07:02:06 +00:00
|
|
|
config
|
|
|
|
.when(process.env.NODE_ENV === 'development',
|
|
|
|
config => config.devtool('cheap-source-map')
|
|
|
|
)
|
|
|
|
|
|
|
|
config
|
|
|
|
.when(process.env.NODE_ENV !== 'development',
|
|
|
|
config => {
|
|
|
|
config
|
2019-03-11 08:29:59 +00:00
|
|
|
// .plugin('ScriptExtHtmlWebpackPlugin')
|
|
|
|
// .after('html')
|
|
|
|
// .use('script-ext-html-webpack-plugin', [{
|
|
|
|
// // `runtime` must same as runtimeChunk name. default is `runtime`
|
|
|
|
// inline: /runtime\..*\.js$/
|
|
|
|
// }])
|
|
|
|
// .end()
|
2018-10-29 07:02:06 +00:00
|
|
|
config
|
|
|
|
.optimization.splitChunks({
|
|
|
|
chunks: 'all',
|
|
|
|
cacheGroups: {
|
|
|
|
libs: {
|
|
|
|
name: 'chunk-libs',
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
priority: 10,
|
|
|
|
chunks: 'initial' // 只打包初始时依赖的第三方
|
|
|
|
},
|
|
|
|
elementUI: {
|
|
|
|
name: 'chunk-elementUI', // 单独将 elementUI 拆包
|
|
|
|
priority: 20, // 权重要大于 libs 和 app 不然会被打包进 libs 或者 app
|
|
|
|
test: /[\\/]node_modules[\\/]element-ui[\\/]/
|
|
|
|
},
|
|
|
|
commons: {
|
|
|
|
name: 'chunk-commons',
|
|
|
|
test: resolve('src/components'), // 可自定义拓展你的规则
|
|
|
|
minChunks: 3, // 最小公用次数
|
|
|
|
priority: 5,
|
|
|
|
reuseExistingChunk: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
config.optimization.runtimeChunk('single')
|
|
|
|
}
|
|
|
|
)
|
2018-10-29 05:55:36 +00:00
|
|
|
}
|
|
|
|
}
|