webpack.base.conf.js 1.6 KB

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