webpack.base.conf.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var path = require('path');
  2. var htmlWebpackPlugin = require('html-webpack-plugin');
  3. var webpack = require('webpack');
  4. var AutodllWebpackpackPlugin = require('autodll-webpack-plugin');
  5. var config = {
  6. entry: {
  7. index: path.resolve(__dirname, '../src/js/main.js'),
  8. login: path.resolve(__dirname, '../src/js/login.js')
  9. },
  10. output: {
  11. path: path.resolve(__dirname, '../dist'),
  12. filename: '[name].[hash].js'
  13. },
  14. module:{
  15. rules: [
  16. {
  17. test: /\.js$/,
  18. include: path.resolve(__dirname + '/src'),
  19. use: [
  20. 'babel-loader'
  21. ],
  22. exclude: /node_modules/
  23. },
  24. {
  25. test: /\.(png|svg|jpg|gif)$/,
  26. use: [
  27. {
  28. loader: "file-loader",
  29. options: {
  30. name: "[name].[ext]",
  31. publicPath: "./static/",
  32. outputPath: "static/"
  33. }
  34. }
  35. ]
  36. }
  37. ]
  38. },
  39. plugins: [
  40. new htmlWebpackPlugin({
  41. filename: "login.html",
  42. title: "login",
  43. template: path.resolve(__dirname, '../src/login.html'),
  44. chunks: ['login']
  45. }),
  46. new htmlWebpackPlugin({
  47. filename: "index.html",
  48. title: "index",
  49. template: path.resolve(__dirname, '../src/index.html'),
  50. chunks: ['index']
  51. }),
  52. new AutodllWebpackpackPlugin({
  53. inject: true,
  54. debugger: true,
  55. filename: '[name].js',
  56. path: './dll',
  57. entry: {
  58. vendor: ['jquery']
  59. }
  60. }), // 单独打包第三方库
  61. new webpack.optimize.SplitChunksPlugin() //提取公共代码
  62. ],
  63. resolve: {
  64. extensions: ['.js', '.css', '.less']// 省去后缀
  65. }
  66. }
  67. module.exports = config;