1. const path = require('path')
    2. module.exports = {
    3. publicPath: process.env.NODE_ENV === 'production' ? '/isight/' : '/',
    4. productionSourceMap: false, // 生产环境不需要source map
    5. pluginOptions: {
    6. // vue add style-resources-loader添加插件
    7. 'style-resources-loader': {
    8. preProcessor: 'scss',
    9. patterns: [path.resolve(__dirname, 'src/assets/styles/variables.scss')]
    10. },
    11. // vue add lodash添加插件
    12. lodash: {
    13. // 是否开启ProvidePlugin, 默认false
    14. provide: true
    15. }
    16. },
    17. chainWebpack: config => {
    18. // 移除 preload 插件
    19. config.plugins.delete('preload')
    20. // 移除 prefetch 插件
    21. config.plugins.delete('prefetch')
    22. },
    23. configureWebpack: config => {
    24. // 打包优化参考:https://blog.csdn.net/weixin_43638968/article/details/109093199
    25. config.optimization = {
    26. runtimeChunk: 'single',
    27. splitChunks: {
    28. chunks: 'all',
    29. maxInitialRequests: Infinity,
    30. minSize: 1000 * 60,
    31. cacheGroups: {
    32. vendor: {
    33. test: /[\\/]node_modules[\\/]/,
    34. name (module) {
    35. // 排除node_modules 然后吧 @ 替换为空 ,考虑到服务器的兼容
    36. const packageName = module.context.match(
    37. /[\\/]node_modules[\\/](.*?)([\\/]|$)/
    38. )[1]
    39. return `${packageName.replace('@', '')}`
    40. }
    41. }
    42. }
    43. }
    44. }
    45. }
    46. }