webpack.config.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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': '#58a3ff',
  7. '@link-color': '#58a3ff',
  8. '@border-radius-base': '0px'
  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. 'user/signIn': ['webpack-dev-server/client?http://0.0.0.0:8080', // WebpackDevServer host and port
  21. 'webpack/hot/only-dev-server',
  22. './js/user/signIn.js'
  23. ],
  24. //user-account
  25. 'user/account/index': ['webpack-dev-server/client?http://0.0.0.0:8080', // WebpackDevServer host and port
  26. 'webpack/hot/only-dev-server',
  27. './js/user/account/index.js'
  28. ],
  29. 'user/account/set': ['webpack-dev-server/client?http://0.0.0.0:8080', // WebpackDevServer host and port
  30. 'webpack/hot/only-dev-server',
  31. './js/user/account/set.js'
  32. ],
  33. //admin
  34. 'admin/index': ['webpack-dev-server/client?http://0.0.0.0:8080', // WebpackDevServer host and port
  35. 'webpack/hot/only-dev-server',
  36. './js/admin/index.js'
  37. ]
  38. //vendors: ['jquery','antd']
  39. //path.resolve(__dirname, './js/index.js'),
  40. },
  41. output: {
  42. path: path.resolve(__dirname, './build'),
  43. filename: '[name].js',
  44. },
  45. module: {
  46. loaders: [{
  47. test: /\.jsx?$/,
  48. exclude: /node_modules/,
  49. loader: 'babel-loader',
  50. query: {
  51. "presets": ["es2015", "react"],
  52. "plugins": [
  53. ["antd", {
  54. "style": true
  55. }]
  56. ]
  57. }
  58. //loaders: ['babel-loader?presets[]=es2015,presets[]=react']
  59. },
  60. //{
  61. //test: /\.module\.less$/,
  62. //loader: 'style!css!less?{"modifyVars":{"@primary-color": "#1DA57A"}}'
  63. //},
  64. {
  65. test: /\.css$/,
  66. loader: 'style!css'
  67. }, {
  68. test: /\.less$/,
  69. loader: `style!css!less?{"modifyVars":${JSON.stringify(theme)}}`
  70. }, {
  71. test: /\.(png|jpg)$/,
  72. loader: 'url?limit=8192&name=[path][name].[ext]'
  73. }
  74. //{test: /\.(png|jpg)$/, loader: 'file' }
  75. ]
  76. },
  77. resolve: {
  78. extensions: ['', '.js', '.jsx']
  79. },
  80. plugins: [
  81. new ExtractTextPlugin('[name].bundle.css', {
  82. allChunks: true
  83. }),
  84. //user
  85. new HtmlWebpackPlugin({
  86. title: '用户首页',
  87. filename: 'user/index.html',
  88. template: './template/template.html',
  89. chunks:['user/index','vendors']
  90. }),
  91. new HtmlWebpackPlugin({
  92. title: '用户登录',
  93. filename: 'user/login.html',
  94. template: './template/template.html',
  95. chunks:['user/login','vendors']
  96. }),
  97. new HtmlWebpackPlugin({
  98. title: '用户注册',
  99. filename: 'user/signIn.html',
  100. template: './template/template.html',
  101. chunks:['user/signIn','vendors']
  102. }),
  103. //user-account
  104. new HtmlWebpackPlugin({
  105. title: '用户中心-首页',
  106. filename: 'user/account/index.html',
  107. template: './template/template.html',
  108. chunks:['user/account/index','vendors']
  109. }),
  110. new HtmlWebpackPlugin({
  111. title: '用户中心-首页',
  112. filename: 'user/account/set.html',
  113. template: './template/template.html',
  114. chunks:['user/account/set','vendors']
  115. }),
  116. //admin
  117. new HtmlWebpackPlugin({
  118. title: 'admin_index',
  119. filename: 'admin/index.html',
  120. template: './template/template.html',
  121. chunks:['admin/index','vendors']
  122. })
  123. //这个使用uglifyJs压缩你的js代码
  124. //new webpack.optimize.UglifyJsPlugin({minimize: true}),
  125. //把入口文件里面的数组打包成verdors.js
  126. //new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'),
  127. ]
  128. };