webpack.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. const webpack = require('webpack');
  2. const path = require('path');
  3. const ExtractTextPlugin = require("extract-text-webpack-plugin");
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. let theme = {
  6. '@primary-color': '#1DA57A',
  7. '@link-color': '#1DA57A',
  8. '@border-radius-base': '8px'
  9. };
  10. module.exports = {
  11. entry: {
  12. 'user/index': ['webpack-dev-server/client?http://0.0.0.0:8080', // WebpackDevServer host and port
  13. 'webpack/hot/only-dev-server',
  14. './js/user/index.js'
  15. ],
  16. 'user/login': ['webpack-dev-server/client?http://0.0.0.0:8080', // WebpackDevServer host and port
  17. 'webpack/hot/only-dev-server',
  18. './js/user/login.js'
  19. ],
  20. 'admin/index': ['webpack-dev-server/client?http://0.0.0.0:8080', // WebpackDevServer host and port
  21. 'webpack/hot/only-dev-server',
  22. './js/admin/index.js'
  23. ]
  24. //vendors: ['jquery','antd']
  25. //path.resolve(__dirname, './js/index.js'),
  26. },
  27. output: {
  28. path: path.resolve(__dirname, './build'),
  29. filename: '[name].js',
  30. },
  31. module: {
  32. loaders: [{
  33. test: /\.jsx?$/,
  34. exclude: /node_modules/,
  35. loader: 'babel-loader',
  36. query: {
  37. "presets": ["es2015", "react"],
  38. "plugins": [
  39. ["antd", {
  40. "style": true
  41. }]
  42. ]
  43. }
  44. //loaders: ['babel-loader?presets[]=es2015,presets[]=react']
  45. },
  46. //{
  47. //test: /\.module\.less$/,
  48. //loader: 'style!css!less?{"modifyVars":{"@primary-color": "#1DA57A"}}'
  49. //},
  50. {
  51. test: /\.css$/,
  52. loader: 'style!css'
  53. }, {
  54. test: /\.less$/,
  55. loader: `style!css!less?{"modifyVars":${JSON.stringify(theme)}}`
  56. }, {
  57. test: /\.(png|jpg)$/,
  58. loader: 'url?limit=8192&name=[path][name].[ext]'
  59. }
  60. //{test: /\.(png|jpg)$/, loader: 'file' }
  61. ]
  62. },
  63. resolve: {
  64. extensions: ['', '.js', '.jsx']
  65. },
  66. plugins: [
  67. new ExtractTextPlugin('[name].bundle.css', {
  68. allChunks: true
  69. }),
  70. //user
  71. new HtmlWebpackPlugin({
  72. title: 'user_index',
  73. filename: 'user/index.html',
  74. template: './template/template.html',
  75. chunks:['user/index','vendors']
  76. }),
  77. new HtmlWebpackPlugin({
  78. title: 'user_login',
  79. filename: 'user/login.html',
  80. template: './template/template.html',
  81. chunks:['user/login','vendors']
  82. }),
  83. //admin
  84. new HtmlWebpackPlugin({
  85. title: 'admin_index',
  86. filename: 'admin/index.html',
  87. template: './template/template.html',
  88. chunks:['admin/index','vendors']
  89. })
  90. //这个使用uglifyJs压缩你的js代码
  91. //new webpack.optimize.UglifyJsPlugin({minimize: true}),
  92. //把入口文件里面的数组打包成verdors.js
  93. //new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'),
  94. ]
  95. };