1 Star 0 Fork 34

kjkjkjkjkss/企业培训学员端_mobile

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
vue.config.js 5.12 KB
Copy Edit Raw Blame History
yicheng authored 2024-05-26 11:50 . edit:文档类型细分
const path = require('path')
const defaultSettings = require('./src/config/index.js')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const OUTPUT_FILE_NAME = process.env.outputDir
const FileManagerPlugin = require('filemanager-webpack-plugin')
const resolve = dir => path.join(__dirname, dir)
// page title
const name = defaultSettings.title || 'vue mobile template'
// 生产环境,测试和正式
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV)
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
publicPath: process.env.NODE_ENV === "production" ? "/mobile/" : "/mobile/",
// publicPath: process.env.NODE_ENV === 'development' ? '/h5' : '/h5/', //署应用包时的基本 URL。 vue-router history模式使用
outputDir: `dist/${OUTPUT_FILE_NAME}`, // 生产环境构建文件的目录
assetsDir: 'static', // outputDir的静态资源(js、css、img、fonts)目录
lintOnSave: false,
productionSourceMap: false, // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
devServer: {
host: 'localhost',
port: 8090, // 端口
open: true, // 启动后打开浏览器
proxy: {
//配置跨域
// [process.env.VUE_APP_BASE_API]: {
// target: `https://web.seeklove.space`,
// changeOrigin: true,
// ws: false,
// pathRewrite: {
// ['^' + process.env.VUE_APP_BASE_API]: ''
// }
// }
}
},
css: {
extract: IS_PROD,
sourceMap: false,
loaderOptions: {
less: {
lessOptions: {
modifyVars: {
hack: `true; @import "assets/css/vant-theme.less";`
}
}
}
}
},
configureWebpack: config => {
config.devtool = false;
config.name = name
config.plugins.push(
new FileManagerPlugin({
events: {
onEnd: {
delete: [`./${OUTPUT_FILE_NAME}.zip`],
archive: [
{
source: `./dist/${OUTPUT_FILE_NAME}`,
destination: `./${OUTPUT_FILE_NAME}.zip`
}
]
}
}
})
)
// 为生产环境修改配置...
// if (IS_PROD) {
// // externals
// config.externals = externals
// }
},
chainWebpack: config => {
config.plugins.delete('preload') // TODO: need test
config.plugins.delete('prefetch') // TODO: need test
// set svg-sprite-loader
config.module.rule('svg').exclude.add(resolve('src/assets/icons')).end()
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('src/assets/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
.end()
// 别名 alias
config.resolve.alias
.set('@', resolve('src'))
.set('assets', resolve('src/assets'))
.set('api', resolve('src/api'))
.set('views', resolve('src/views'))
.set('components', resolve('src/components'))
.set('@static', resolve('static'))
/**
* 设置保留空格
*/
config.module
.rule('vue')
.use('vue-loader')
.loader('vue-loader')
.tap(options => {
options.compilerOptions.preserveWhitespace = true
return options
})
.end()
/**
* 打包分析
*/
if (IS_PROD) {
config.plugin('webpack-report').use(BundleAnalyzerPlugin, [
{
analyzerMode: 'static'
}
])
}
config
// https://webpack.js.org/configuration/devtool/#development
.when(!IS_PROD, config => config.devtool('cheap-source-map'))
config.when(IS_PROD, config => {
config
.plugin('ScriptExtHtmlWebpackPlugin')
.after('html')
.use('script-ext-html-webpack-plugin', [
{
// 将 runtime 作为内联引入不单独存在
inline: /runtime\..*\.js$/
}
])
.end()
config.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
// cacheGroups 下可以可以配置多个组,每个组根据test设置条件,符合test条件的模块
commons: {
name: 'chunk-commons',
test: resolve('src/components'),
minChunks: 3, // 被至少用三次以上打包分离
priority: 5, // 优先级
reuseExistingChunk: true // 表示是否使用已有的 chunk,如果为 true 则表示如果当前的 chunk 包含的模块已经被抽取出去了,那么将不会重新生成新的。
},
node_vendors: {
name: 'chunk-libs',
chunks: 'initial', // 只打包初始时依赖的第三方
test: /[\\/]node_modules[\\/]/,
priority: 10
},
vantUI: {
name: 'chunk-vantUI', // 单独将 vantUI 拆包
priority: 20, // 数字大权重到,满足多个 cacheGroups 的条件时候分到权重高的
test: /[\\/]node_modules[\\/]_?vant(.*)/
}
}
})
config.optimization.runtimeChunk('single')
})
}
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kjkjkjkjkss/training_mobile.git
git@gitee.com:kjkjkjkjkss/training_mobile.git
kjkjkjkjkss
training_mobile
企业培训学员端_mobile
master

Search