Files
ClassContent/历届学生/逯帅帅/项目开发/上课项目/vuecli3/vue.config.js
2024-09-27 02:06:13 +08:00

117 lines
2.6 KiB
JavaScript

const path = require('path');
const CompressionPlugin = require('compression-webpack-plugin')
var cdn = {
css: [
'https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.1/theme-chalk/index.min.css'
],
js: [
'https://cdn.bootcss.com/vue/2.6.11/vue.runtime.min.js',
'https://cdn.bootcss.com/vue-router/3.2.0/vue-router.min.js',
'https://cdn.bootcss.com/axios/0.21.1/axios.min.js',
'https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.1/index.min.js',
]
}
module.exports = {
publicPath: './',
lintOnSave: false,
productionSourceMap: false,
parallel: require('os').cpus().length > 1,
devServer: {
hot: false,
port: 1314,
compress: true,
open: false,
openPage: '#/',
overlay: {
warnings: false,
errors: true
},
proxy: {
'/apis': {
target: 'http://115.159.153.142:9010/h5',
changeOrigin: true,
ws: true,
pathRewrite: {
'^/apis': ''
}
}
}
},
configureWebpack:(config) => {
config.externals = {
'vue': 'Vue',
'vue-router': 'VueRouter',
'axios': 'axios',
'vant': 'vant'
}
return {
plugins: [new CompressionPlugin({
test: /\.js$|\.html$|\.css/, //匹配文件名
threshold: 10240, //对超过10k的数据进行压缩
deleteOriginalAssets: false //是否删除原文件
})]
};
},
chainWebpack: (config) => {
// 设置别名
config.resolve.alias
.set('@',resolve('./src'))
.set('@c',resolve('./src/components'))
.set('@router',resolve('./src/router'))
.set('@views',resolve('./src/views'))
.set('@page',resolve('./src/assets/styl/page'))
/**
* 导入全局css
* @type {*[]}
*/
const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
types.forEach(type => addStyleResource(config.module.rule('stylus').oneOf(type)))
// 第三方模块使用外链
config.plugin('html').tap(args => {
args[0].cdn = cdn;
return args;
});
/**
* 移除不必要的 prefetch 和 preload请求
*/
config.plugins.delete('prefetch');
config.plugins.delete('preload');
// 配置pug
config.module.rule('pug')
.test(/\.pug$/)
.use('pug-html-loader')
.loader('pug-html-loader')
.end();
}
}
function resolve(dir){
return path.join(__dirname,dir)
}
function addStyleResource (rule) {
rule.use('style-resource')
.loader('style-resources-loader')
.options({
patterns: [
path.resolve(__dirname, './src/assets/styl/_.styl'),
],
})
}