webpack.base.conf.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. "jQuery": "jQuery"
  45. },
  46. plugins: [
  47. new webpack.DllReferencePlugin({
  48. manifest
  49. }),
  50. new CompressionPlugin({
  51. algorithm: "gzip",
  52. test: /\.js$|\.html$|\.css$/, // 匹配文件名
  53. minRatio: 0.8, // 压缩率小于1才会压缩
  54. threshold: 10240, // 对超过10k的数据压缩
  55. deleteOriginalAssets: false, // 是否删除未压缩的源文件
  56. }),
  57. // new webpack.ProvidePlugin({
  58. // $: "jquery",
  59. // jQuery: "jquery",
  60. // 'window.jQuery': 'jquery',
  61. // jQuery: 'jquery'
  62. // })
  63. ],
  64. module: {
  65. rules: [
  66. {
  67. test: /\.vue$/,
  68. loader: 'vue-loader',
  69. options: vueLoaderConfig
  70. },
  71. {
  72. test: /\.js$/,
  73. loader: 'babel-loader',
  74. include: [
  75. resolve('src'),
  76. resolve('static'),
  77. resolve('/node_modules/element-ui'),
  78. ]
  79. },
  80. {
  81. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  82. loader: 'url-loader',
  83. options: {
  84. limit: 10000,
  85. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  86. }
  87. },
  88. {
  89. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  90. loader: 'url-loader',
  91. options: {
  92. limit: 10000,
  93. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  94. }
  95. }
  96. ]
  97. }
  98. }