健康同学微信公众号h5项目
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

123 行
4.1KB

  1. const path = require('path');
  2. const defaultSettings = require('./src/config/index.js');
  3. /* const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; */
  4. const resolve = dir => path.join(__dirname, dir);
  5. // page title
  6. const name = defaultSettings.title || 'health-student';
  7. // 生产环境,测试和正式
  8. const IS_PROD = ['production', 'test'].includes(process.env.NODE_ENV);
  9. const { defineConfig } = require('@vue/cli-service');
  10. module.exports = defineConfig({
  11. publicPath: './', // 署应用包时的基本 URL。 vue-router hash 模式使用
  12. // publicPath: '/app/', //署应用包时的基本 URL。 vue-router history模式使用
  13. outputDir: 'dist', // 生产环境构建文件的目录
  14. lintOnSave: !IS_PROD,
  15. productionSourceMap: false, // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  16. devServer: {
  17. port: 9093, // 端口
  18. open: false, // 启动后打开浏览器
  19. hot: true, //热更新
  20. client: {
  21. overlay: {
  22. // 当出现编译器错误或警告时,在浏览器中显示全屏覆盖层
  23. warnings: false,
  24. errors: false
  25. }
  26. }
  27. // proxy: {
  28. // //配置跨域
  29. // '/api': {
  30. // target: "https://test.xxx.com",
  31. // // ws:true,
  32. // changOrigin:true,
  33. // pathRewrite:{
  34. // '^/api':'/'
  35. // }
  36. // }
  37. // }
  38. },
  39. css: {
  40. extract: true, // 是否将组件中的 CSS 提取至一个独立的 CSS 文件中 (而不是动态注入到 JavaScript 中的 inline 代码)。
  41. sourceMap: false,
  42. loaderOptions: {
  43. scss: {
  44. // 向全局sass样式传入共享的全局变量, $src可以配置图片cdn前缀
  45. // 详情: https://cli.vuejs.org/guide/css.html#passing-options-to-pre-processor-loaders
  46. additionalData: `
  47. @import "assets/css/mixin.scss";
  48. @import "assets/css/variables.scss";
  49. `
  50. }
  51. }
  52. },
  53. configureWebpack: config => {
  54. config.name = name;
  55. // 为生产环境修改配置...
  56. },
  57. chainWebpack: config => {
  58. // 别名 alias
  59. config.resolve.alias
  60. .set('@', resolve('src'))
  61. .set('assets', resolve('src/assets'))
  62. .set('api', resolve('src/api'))
  63. .set('views', resolve('src/views'))
  64. .set('components', resolve('src/components'));
  65. /**
  66. * 设置保留空格
  67. */
  68. config.module
  69. .rule('vue')
  70. .use('vue-loader')
  71. .loader('vue-loader')
  72. .tap(options => {
  73. options.compilerOptions.preserveWhitespace = true;
  74. return options;
  75. })
  76. .end();
  77. /**
  78. * 打包分析
  79. */
  80. if (IS_PROD) {
  81. /* config.plugin('webpack-report').use(BundleAnalyzerPlugin, [
  82. {
  83. analyzerMode: 'static'
  84. }
  85. ]); */
  86. }
  87. config
  88. // https://webpack.js.org/configuration/devtool/#development
  89. .when(!IS_PROD, config => config.devtool('cheap-source-map'));
  90. config.when(IS_PROD, config => {
  91. config.optimization.splitChunks({
  92. chunks: 'all',
  93. cacheGroups: {
  94. // cacheGroups 下可以可以配置多个组,每个组根据test设置条件,符合test条件的模块
  95. commons: {
  96. name: 'chunk-commons',
  97. test: resolve('src/components'),
  98. minChunks: 3, // 被至少用三次以上打包分离
  99. priority: 5, // 优先级
  100. reuseExistingChunk: true // 表示是否使用已有的 chunk,如果为 true 则表示如果当前的 chunk 包含的模块已经被抽取出去了,那么将不会重新生成新的。
  101. },
  102. node_vendors: {
  103. name: 'chunk-libs',
  104. chunks: 'initial', // 只打包初始时依赖的第三方
  105. test: /[\\/]node_modules[\\/]/,
  106. priority: 10
  107. },
  108. vantUI: {
  109. name: 'chunk-vantUI', // 单独将 vantUI 拆包
  110. priority: 20, // 数字大权重到,满足多个 cacheGroups 的条件时候分到权重高的
  111. test: /[\\/]node_modules[\\/]_?vant(.*)/
  112. }
  113. }
  114. });
  115. config.optimization.runtimeChunk('single');
  116. });
  117. }
  118. });