webpack.base.conf.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. 'use strict'
  2. const path = require('path')
  3. const utils = require('./utils')
  4. const config = require('../config')
  5. const vueLoaderConfig = require('./vue-loader.conf')
  6. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); //可视化依赖
  7. function resolve(dir) {
  8. return path.join(__dirname, '..', dir)
  9. }
  10. module.exports = {
  11. context: path.resolve(__dirname, '../'),
  12. entry: {
  13. app: './src/main.js'
  14. },
  15. output: {
  16. path: config.build.assetsRoot,
  17. filename: '[name].js',
  18. publicPath: process.env.NODE_ENV === 'production' ?
  19. config.build.assetsPublicPath : config.dev.assetsPublicPath
  20. },
  21. resolve: {
  22. extensions: ['.js', '.vue', '.json'],
  23. alias: {
  24. 'vue$': 'vue/dist/vue.esm.js',
  25. '@': resolve('src'),
  26. }
  27. },
  28. module: {
  29. rules: [{
  30. test: /\.vue$/,
  31. loader: 'vue-loader',
  32. options: vueLoaderConfig
  33. },
  34. {
  35. test: /\.js$/,
  36. loader: 'babel-loader',
  37. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  38. },
  39. {
  40. test: /\.(png|jpe?g|gif|svg|cur)(\?.*)?$/,
  41. loader: 'url-loader',
  42. options: {
  43. limit: 10000,
  44. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  45. }
  46. // loader: 'image-webpack-loader', //压缩图片
  47. // options: {
  48. // mozjpeg: {
  49. // progressive: true,
  50. // quality: 50
  51. // },
  52. // // optipng.enabled: false will disable optipng
  53. // optipng: {
  54. // enabled: false,
  55. // },
  56. // pngquant: {
  57. // quality: [0.5, 0.65],
  58. // speed: 4
  59. // },
  60. // gifsicle: {
  61. // interlaced: false,
  62. // },
  63. // //ios不支持
  64. // // webp: {
  65. // // quality: 100
  66. // // }
  67. // }
  68. },
  69. {
  70. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  71. loader: 'url-loader',
  72. options: {
  73. limit: 10000,
  74. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  75. }
  76. },
  77. {
  78. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  79. loader: 'url-loader',
  80. options: {
  81. limit: 10000,
  82. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  83. }
  84. },
  85. ]
  86. },
  87. node: {
  88. // prevent webpack from injecting useless setImmediate polyfill because Vue
  89. // source contains it (although only uses it if it's native).
  90. setImmediate: false,
  91. // prevent webpack from injecting mocks to Node native modules
  92. // that does not make sense for the client
  93. dgram: 'empty',
  94. fs: 'empty',
  95. net: 'empty',
  96. tls: 'empty',
  97. child_process: 'empty'
  98. },
  99. externals: {
  100. 'vue': 'Vue',
  101. // 'ViewUI': 'view-design',
  102. // 'axios': 'axios',
  103. "echarts": "echarts",
  104. },
  105. // 启动依赖关系可视化窗口,绑定端口8919
  106. // plugins: [
  107. // new BundleAnalyzerPlugin({ analyzerPort: 8919 }),
  108. // ]
  109. }