webpack.base.conf.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // 存放dev和prod配置
  2. const path = require('path');
  3. const webpack = require('webpack');
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. const VueLoaderPlugin = require('vue-loader/lib/plugin');
  6. // 第三方库单独打包
  7. const AutoDllPlugin = require('autodll-webpack-plugin');
  8. // 分离css,打包到单独文件
  9. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  10. module.exports = {
  11. entry: {
  12. bundle: path.resolve(__dirname, '../src/main.js')
  13. },
  14. output: {
  15. path: path.resolve(__dirname, '../dist'),
  16. filename: '[name].[hash].js'
  17. },
  18. module: {
  19. rules: [
  20. {
  21. test: /\.vue$/,
  22. loader: 'vue-loader'
  23. },
  24. {
  25. test: /\.js$/,
  26. use: ['babel-loader'],
  27. include: path.resolve(__dirname + '/src/'),
  28. exclude: /node_modules/
  29. },
  30. {
  31. test: /\.(png|svg|jpg|gif)$/,
  32. use: [
  33. 'file-loader'
  34. ]
  35. },
  36. {
  37. test: /\.(woff|woff2|eot|ttf|otf)$/,
  38. use: [
  39. 'file-loader'
  40. ]
  41. }
  42. ]
  43. },
  44. plugins: [
  45. new webpack.HashedModuleIdsPlugin(), // 解决vender后面的hash每次都改变
  46. new HtmlWebpackPlugin({
  47. template: path.resolve(__dirname, '../index.html')
  48. }),
  49. new AutoDllPlugin({
  50. inject: true, // will inject the DLL bundle to index.html
  51. debug: true,
  52. filename: '[name]_[hash].js',
  53. path: './dll',
  54. entry: {
  55. vendor: ['vue', 'vue-router', 'vuex', 'element-ui']
  56. }
  57. }), //单独打包第三方库
  58. new VueLoaderPlugin(), // 它的职责是将你定义过的其它规则复制并应用到 .vue 文件里相应语言的块
  59. new webpack.optimize.SplitChunksPlugin() // 提取公共代码
  60. ],
  61. resolve: {
  62. extensions: ['.js', '.css', '.vue'],// 省去后缀
  63. alias: {
  64. 'vue$': 'vue/dist/vue.esm.js', //配置别名 确保webpack可以找到.vue文件
  65. "@": path.resolve(__dirname, '../src'),
  66. "components": path.resolve(__dirname, '../src/components'),
  67. "utils": path.resolve(__dirname + '../src/utils')
  68. },
  69. modules: ['node_modules']
  70. }
  71. }