You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

119 lines
3.7 KiB

;
const path = require('path');
const defaultSettings = require('./src/settings.js');
function resolve(dir) {
return path.join(__dirname, dir);
}
// page title
const name = defaultSettings.title || 'winbox-admin-pro';
// dev port
const port = process.env.port || process.env.npm_config_port || 9528;
// All configuration item explanations can be find in https://cli.vuejs.org/config/
module.exports = {
publicPath: './', // 基本路径
outputDir: 'dist', // 输出文件目录
assetsDir: 'static',
filenameHashing: true, // 生成的静态资源在它们的文件名中包含了 hash 以便更好的控制缓存
lintOnSave: process.env.NODE_ENV === 'development', // eslint-loader 是否在保存的时候检查
productionSourceMap: false, // 生产环境是否生成 sourceMap 文件
devServer: {
port: port,
open: true, // 自动用浏览器打开网页
overlay: { // 编译错误或警告时,在浏览器中显示全屏
warnings: false,
errors: true
},
before: require('./mock/mock-server.js')
},
configureWebpack: {
name: name,
resolve: {
modules: [path.resolve('node_modules'), 'node_modules'],
alias: {
'@': resolve('src')
}
},
entry: './src/main.js'
},
chainWebpack(config) {
// it can improve the speed of the first screen, it is recommended to turn on preload
config.plugin('preload').tap(() => [
{
rel: 'preload',
fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/], // to ignore runtime.js
include: 'initial'
}
]);
// when there are many pages, it will cause too many meaningless requests
config.plugins.delete('prefetch');
// set svg-sprite-loader
config.module
.rule('svg')
.exclude.add(resolve('src/icons'))
.end();
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();
config
.when(process.env.NODE_ENV !== 'development',
config => {
config
.plugin('ScriptExtHtmlWebpackPlugin')
.after('html')
.use('script-ext-html-webpack-plugin', [{
// `runtime` must same as runtimeChunk name. default is `runtime`
inline: /runtime\..*\.js$/
}])
.end();
config
.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
libs: {
name: 'chunk-libs',
test: /[\\/]node_modules[\\/]/,
priority: 10,
chunks: 'initial' // only package third parties that are initially dependent
},
winboxUI: { // split winboxUI into a single package
name: 'chunk-winboxUI',
priority: 20,
test: /[\\/]node_modules[\\/]_?winbox-ui(.*)/
},
commons: {
name: 'chunk-commons',
test: resolve('src/components'), // can customize your rules
minChunks: 3, // minimum common number
priority: 5,
reuseExistingChunk: true
}
}
});
// https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
config.optimization.runtimeChunk('single');
}
);
},
pluginOptions: {
'style-resources-loader': {
preProcessor: 'less',
patterns: [
path.resolve(__dirname, './src/styles/variable.less'),
path.resolve(__dirname, './src/styles/common/fonts.less')
]
}
}
};