vue.config.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. const path = require('path')
  2. const minify = process.env.NODE_ENV === 'development' ? false : {
  3. collapseWhitespace: true,
  4. removeComments: true,
  5. removeRedundantAttributes: true,
  6. removeScriptTypeAttributes: true,
  7. removeStyleLinkTypeAttributes: true,
  8. useShortDoctype: true,
  9. minifyCSS: true,
  10. minifyJS: true
  11. }
  12. function resolve(dir) {
  13. return path.join(__dirname, dir)
  14. }
  15. module.exports = {
  16. publicPath: '/',
  17. lintOnSave: true,
  18. runtimeCompiler: true,
  19. pages: {
  20. index: {
  21. entry: 'src/main.js',
  22. template: 'public/index.html',
  23. filename: 'index.html',
  24. chunks: ['chunk-vendors', 'chunk-common', 'index'],
  25. minify
  26. },
  27. preview: {
  28. entry: 'src/views/preview/main.js',
  29. template: 'public/preview.html',
  30. filename: 'preview.html',
  31. chunks: ['chunk-vendors', 'chunk-common', 'preview'],
  32. minify
  33. }
  34. },
  35. pluginOptions: {
  36. 'style-resources-loader': {
  37. preProcessor: 'less',
  38. patterns: [
  39. path.resolve(__dirname, './src/styles/variables.less')
  40. ]
  41. }
  42. },
  43. devServer: {
  44. overlay: {
  45. // 错误信息显示到浏览器上
  46. warnings: true,
  47. errors: true
  48. }
  49. },
  50. css: {
  51. // 开启样式追溯
  52. sourceMap: true
  53. },
  54. productionSourceMap: false,
  55. chainWebpack(config) {
  56. config.resolve.alias.set('@', resolve('src'))
  57. // set svg-sprite-loader
  58. config.module
  59. .rule('svg')
  60. .exclude.add(resolve('src/icons'))
  61. .end()
  62. config.module
  63. .rule('icons')
  64. .test(/\.svg$/)
  65. .include.add(resolve('src/icons'))
  66. .end()
  67. .use('svg-sprite-loader')
  68. .loader('svg-sprite-loader')
  69. .options({
  70. symbolId: 'icon-[name]'
  71. })
  72. .end()
  73. }
  74. }