webpack.base.conf.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. var path = require('path')
  2. var utils = require('./utils')
  3. var config = require('../config')
  4. var vueLoaderConfig = require('./vue-loader.conf')
  5. const webpack = require('webpack')
  6. const manifest = require('../vendor-manifest.json')
  7. // Gzip
  8. const CompressionPlugin = require("compression-webpack-plugin");
  9. function resolve(dir) {
  10. return path.join(__dirname, '..', dir)
  11. }
  12. module.exports = {
  13. entry: {
  14. // app: './src/main.js',
  15. app: ['babel-polyfill', './src/main.js']
  16. },
  17. // 防止有依赖关联到fs而报错,浏览器不让用 fs
  18. node: {
  19. fs: "empty"
  20. },
  21. output: {
  22. path:process.env.NODE_ENV === 'production'? config.build.assetsRoot:config.test.assetsRoot,
  23. filename: '[name].js',
  24. publicPath: process.env.NODE_ENV === 'production'
  25. ? config.build.assetsPublicPath
  26. :process.env.NODE_ENV === 'test'
  27. ?config.test.assetsPublicPath
  28. :config.dev.assetsPublicPath
  29. },
  30. resolve: {
  31. extensions: ['.js', '.vue', '.json'],
  32. alias: {
  33. 'vue$': 'vue/dist/vue.esm.js',
  34. '@': resolve('src'),
  35. 'scss_global': '@/styles/global.scss',
  36. 'api': '@/api',
  37. 'utils': '@/utils',
  38. 'components': '@/components',
  39. 'common': '@/common'
  40. }
  41. },
  42. externals:{
  43. "vue":"Vue"
  44. },
  45. plugins: [
  46. new webpack.DllReferencePlugin({
  47. manifest
  48. }),
  49. new CompressionPlugin({
  50. algorithm: "gzip",
  51. test: /\.js$|\.html$|\.css$/, // 匹配文件名
  52. minRatio: 0.8, // 压缩率小于1才会压缩
  53. threshold: 10240, // 对超过10k的数据压缩
  54. deleteOriginalAssets: false, // 是否删除未压缩的源文件
  55. }),
  56. ],
  57. module: {
  58. rules: [
  59. {
  60. test: /\.vue$/,
  61. loader: 'vue-loader',
  62. options: vueLoaderConfig
  63. },
  64. {
  65. test: /\.js$/,
  66. loader: 'babel-loader',
  67. include: [
  68. resolve('src'),
  69. resolve('static'),
  70. resolve('/node_modules/element-ui'),
  71. ]
  72. },
  73. {
  74. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  75. loader: 'url-loader',
  76. options: {
  77. limit: 10000,
  78. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  79. }
  80. },
  81. {
  82. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  83. loader: 'url-loader',
  84. options: {
  85. limit: 10000,
  86. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  87. }
  88. }
  89. ]
  90. }
  91. }