webpack.base.conf.js 2.0 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. module.exports = {
  9. entry: {
  10. bundle: [path.resolve(__dirname, '../src/main.js')]
  11. },
  12. output: {
  13. path: path.resolve(__dirname, '../resourcesWeb'),
  14. filename: '[name].[hash].js',
  15. publicPath: '/'
  16. },
  17. module: {
  18. rules: [
  19. {
  20. test: /\.vue$/,
  21. loader: 'vue-loader'
  22. },
  23. {
  24. test: /\.js$/,
  25. use: ['babel-loader'],
  26. include: path.resolve(__dirname + '/src/'),
  27. exclude: /node_modules/
  28. },
  29. {
  30. test: /\.(png|svg|jpg|gif)$/,
  31. use: [
  32. 'file-loader'
  33. ]
  34. },
  35. {
  36. test: /\.(woff|woff2|eot|ttf|otf)$/,
  37. use: [
  38. 'file-loader'
  39. ]
  40. }
  41. ]
  42. },
  43. plugins: [
  44. new webpack.HashedModuleIdsPlugin(), // 解决vender后面的hash每次都改变
  45. new HtmlWebpackPlugin({
  46. inject: true,
  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']
  56. }
  57. }), //单独打包第三方库
  58. new VueLoaderPlugin(), // 它的职责是将你定义过的其它规则复制并应用到 .vue 文件里相应语言的块
  59. new webpack.optimize.SplitChunksPlugin() // 提取公共代码
  60. ],
  61. resolve: {
  62. extensions: ['.js', '.scss', '.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. }