publicPath = 'https://bcd.com/c2c/shop/dist' // 测试环境静态资源css、js等cdn路径
fontPublicPath = ''
imgPublicPath = ''
} else {
publicPath = '/'
fontPublicPath = ''
imgPublicPath = ''
}
const devServerHost = 'localhost';
const devServerPort = '8080'; // 端口号
const devServerOpen = true; // 热启动后自动打开浏览器
module.exports = {
// 配置生成dist里面static的cdn资源路径(测试环境为./,正式环境走cdn路径)
publicPath: publicPath,
// 输出文件目录(默认dist)
outputDir,
// 配置放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录
assetsDir,
devServer: {
host: devServerHost,
port: devServerPort,
open: devServerOpen, // 构建完成自动打开浏览器
// eslint检测影响代码编译,注释调不会影响代码编译
// overlay: {
// warnings: true,
// errors: true
// }
},
lintOnSave: processEnv === 'development' ? true : false, // 开发环境开启eslint,测试和线上编辑代码禁止eslint
// webpack 配置,键值对象时会合并配置,为方法时会改写配置
configureWebpack: config => {
// 扩展资源,不将部分资源js等打入包内引用cdn资源
let externals = {
// 'swiper': 'Swiper',
};
config.externals = externals;
//警告 webpack 的性能提示
config.performance = {
hints: isPro ? 'warning' : false, // 本地开发不显示警告
// 入口起点的最大体积
maxEntrypointSize: 512000, // 500kib
// 生成文件的最大体积
maxAssetSize: 307200, // 300kib
// 只给出 js 文件的性能提示
assetFilter(assetFilename) {
return assetFilename.endsWith('.js');
}
};
},
// webpack 链接 API,用于生成和修改 webapck 配置
chainWebpack: (config) => {
// 取消 chunks,每个页面只对应一个单独的 JS / CSS
config.optimization.splitChunks({
cacheGroups: {}
});
// 全局配置node_modules中的模块,使用时无需引入
config.plugin('provide').use(webpack.ProvidePlugin, [{
$: "n-zepto",
Zepto: "n-zepto",
"window.Zepto": "n-zepto"
}]);
config.module
.rule('images')
.use('url-loader')
.loader('url-loader')
.tap(options => Object.assign(options, {
limit: 10240, // 小于10k,压缩图片 => base64
// limit: 3000,
publicPath: imgPublicPath,
name: `[name].[hash:8].[ext]`
}))
// 设置fonts字体文件引用的路径
config.module
.rule('fonts')
.test(/.(woff2?|eot|ttf|otf)(?.*)?$/i)










