const path = require('path'); const cdn = { externals: {}, js: [], css: [], }; // 是否为开发环境 module.exports = { // 项目目录 publicPath:'./', // 输出目录 outputDir:'dist', devServer: { headers: { "Access-Control-Allow-Origin": "*", }, port: 5444 }, // 兼容性 transpileDependencies: [ // 可以是字符串或正则表达式 'ant-design-vue', ], runtimeCompiler: true, //关闭Eslint检测 lintOnSave: false, productionSourceMap: false, chainWebpack: (config) => { config.module .rule('swf') .test(/.swf$/) .use('url-loader') .loader('url-loader') .tap((options) => { return { limit: 10000, }; }); // 移除 prefetch 插件 config.plugins.delete('prefetch') config.plugins.delete('prefetch-index'); // 移除 preload 插件,避免加载多余的资源 config.plugins.delete('preload'); config.plugins.delete('preload-index'); // 配置cdn引入 config.plugin('html').tap((args) => { args[0].cdn = cdn; return args; }); }, configureWebpack: config => { // CDN引入的文件 config.externals = cdn.externals; // 公共代码抽离 config.optimization = { // 分割代码块 splitChunks: { cacheGroups: { //公用模块抽离 common: { chunks: 'initial', minSize: 0, //大于0个字节 minChunks: 2, //抽离公共代码时,这个代码块最小被引用的次数 }, //第三方库抽离 vendor: { priority: 1, //权重 test: /node_modules/, chunks: 'initial', minSize: 0, //大于0个字节 minChunks: 2, //在分割之前,这个代码块最小应该被引用的次数 }, }, }, }; // 入口文件 config.entry.app = ["babel-polyfill", "./src/main.js"]; }, }