webpack.base.conf.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. output: {
  18. path:process.env.NODE_ENV === 'production'? config.build.assetsRoot:config.test.assetsRoot,
  19. filename: '[name].js',
  20. publicPath: process.env.NODE_ENV === 'production'
  21. ? config.build.assetsPublicPath
  22. :process.env.NODE_ENV === 'test'
  23. ?config.test.assetsPublicPath
  24. :config.dev.assetsPublicPath
  25. },
  26. resolve: {
  27. extensions: ['.js', '.vue', '.json'],
  28. alias: {
  29. 'vue$': 'vue/dist/vue.esm.js',
  30. '@': resolve('src'),
  31. 'scss_global': '@/styles/global.scss',
  32. 'api': '@/api',
  33. 'utils': '@/utils',
  34. 'components': '@/components',
  35. 'common': '@/common'
  36. }
  37. },
  38. externals:{
  39. "vue":"Vue"
  40. },
  41. plugins: [
  42. new webpack.DllReferencePlugin({
  43. manifest
  44. }),
  45. new CompressionPlugin({
  46. algorithm: "gzip",
  47. test: /\.js$|\.html$|\.css$/, // 匹配文件名
  48. minRatio: 0.8, // 压缩率小于1才会压缩
  49. threshold: 10240, // 对超过10k的数据压缩
  50. deleteOriginalAssets: false, // 是否删除未压缩的源文件
  51. }),
  52. ],
  53. module: {
  54. rules: [
  55. {
  56. test: /\.vue$/,
  57. loader: 'vue-loader',
  58. options: vueLoaderConfig
  59. },
  60. {
  61. test: /\.js$/,
  62. loader: 'babel-loader',
  63. include: [
  64. resolve('src'),
  65. resolve('static'),
  66. resolve('/node_modules/element-ui'),
  67. ]
  68. },
  69. {
  70. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  71. loader: 'url-loader',
  72. options: {
  73. limit: 10000,
  74. name: utils.assetsPath('img/[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. }