webpack.config.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. const WebpackDevServer = require('webpack-dev-server');
  6. let theme = {
  7. '@primary-color': '#58a3ff',
  8. '@link-color': '#58a3ff'
  9. };
  10. module.exports = {
  11. entry: {
  12. 'user/index': ['webpack-dev-server/client?http://127.0.0.1:80', // WebpackDevServer host and port
  13. 'webpack/hot/only-dev-server',
  14. './js/user/index.js'
  15. ],
  16. 'user/login': ['webpack-dev-server/client?http://127.0.0.1:80', // WebpackDevServer host and port
  17. 'webpack/hot/only-dev-server',
  18. './js/user/login.js'
  19. ],
  20. 'user/signIn': ['webpack-dev-server/client?http://127.0.0.1:80', // WebpackDevServer host and port
  21. 'webpack/hot/only-dev-server',
  22. './js/user/signIn.js'
  23. ],
  24. 'user/certify': ['webpack-dev-server/client?http://127.0.0.1:80', // WebpackDevServer host and port
  25. 'webpack/hot/only-dev-server',
  26. './js/user/certify.js'
  27. ],
  28. //user-account
  29. 'user/account/index': ['webpack-dev-server/client?http://127.0.0.1:80', // WebpackDevServer host and port
  30. 'webpack/hot/only-dev-server',
  31. './js/user/account/index.js'
  32. ],
  33. 'user/account/set': ['webpack-dev-server/client?http://127.0.0.1:80', // WebpackDevServer host and port
  34. 'webpack/hot/only-dev-server',
  35. './js/user/account/set.js'
  36. ],
  37. 'user/account/services': ['webpack-dev-server/client?http://127.0.0.1:80', // WebpackDevServer host and port
  38. 'webpack/hot/only-dev-server',
  39. './js/user/account/services.js'
  40. ],
  41. //admin
  42. 'admin/index': ['webpack-dev-server/client?http://127.0.0.1:80', // WebpackDevServer host and port
  43. 'webpack/hot/only-dev-server',
  44. './js/admin/index.js'
  45. ],
  46. 'admin/login': ['webpack-dev-server/client?http://127.0.0.1:80', // WebpackDevServer host and port
  47. 'webpack/hot/only-dev-server',
  48. './js/admin/login.js'
  49. ],
  50. 'admin/userManage': ['webpack-dev-server/client?http://127.0.0.1:80', // WebpackDevServer host and port
  51. 'webpack/hot/only-dev-server',
  52. './js/admin/userManage.js'
  53. ],
  54. 'admin/servicesManage/patent': ['webpack-dev-server/client?http://127.0.0.1:80', // WebpackDevServer host and port
  55. 'webpack/hot/only-dev-server',
  56. './js/admin/servicesManage/patent.js'
  57. ]
  58. //vendors: ['jquery','antd']
  59. //path.resolve(__dirname, './js/index.js'),
  60. },
  61. output: {
  62. path: path.resolve(__dirname, './build'),
  63. filename: '[name].js'
  64. },
  65. module: {
  66. loaders: [{
  67. test: /\.jsx?$/,
  68. exclude: /node_modules/,
  69. loader: 'babel-loader',
  70. query: {
  71. "presets": ["es2015", "react"],
  72. "plugins": [
  73. ["antd", {
  74. "style": true
  75. }]
  76. ]
  77. }
  78. //loaders: ['babel-loader?presets[]=es2015,presets[]=react']
  79. },
  80. //{
  81. //test: /\.module\.less$/,
  82. //loader: 'style!css!less?{"modifyVars":{"@primary-color": "#1DA57A"}}'
  83. //},
  84. {
  85. test: /\.css$/,
  86. loader: 'style!css'
  87. }, {
  88. test: /\.less$/,
  89. loader: `style!css!less?{"modifyVars":${JSON.stringify(theme)}}`
  90. }, {
  91. test: /\.(png|jpg)$/,
  92. loader: 'url?limit=8192&name=[path][name].[ext]'
  93. }
  94. //{test: /\.(png|jpg)$/, loader: 'file' }
  95. ]
  96. },
  97. resolve: {
  98. extensions: ['', '.js', '.jsx']
  99. },
  100. plugins: [
  101. new ExtractTextPlugin('[name].bundle.css', {
  102. allChunks: true
  103. }),
  104. //user
  105. new HtmlWebpackPlugin({
  106. title: '用户首页',
  107. filename: 'user/index.html',
  108. template: './template/template.html',
  109. chunks: ['user/index', 'vendors']
  110. }),
  111. new HtmlWebpackPlugin({
  112. title: '用户登录',
  113. filename: 'user/login.html',
  114. template: './template/template.html',
  115. chunks: ['user/login', 'vendors']
  116. }),
  117. new HtmlWebpackPlugin({
  118. title: '用户注册',
  119. filename: 'user/signIn.html',
  120. template: './template/template.html',
  121. chunks: ['user/signIn', 'vendors']
  122. }),
  123. new HtmlWebpackPlugin({
  124. title: '用户认证',
  125. filename: 'user/certify.html',
  126. template: './template/template.html',
  127. chunks: ['user/certify', 'vendors']
  128. }),
  129. //user-account
  130. new HtmlWebpackPlugin({
  131. title: '用户中心-首页',
  132. filename: 'user/account/index.html',
  133. template: './template/template.html',
  134. chunks: ['user/account/index', 'vendors']
  135. }),
  136. new HtmlWebpackPlugin({
  137. title: '用户中心-设置',
  138. filename: 'user/account/set.html',
  139. template: './template/template.html',
  140. chunks: ['user/account/set', 'vendors']
  141. }),
  142. new HtmlWebpackPlugin({
  143. title: '用户中心-科技服务',
  144. filename: 'user/account/services.html',
  145. template: './template/template.html',
  146. chunks: ['user/account/services', 'vendors']
  147. }),
  148. //admin
  149. new HtmlWebpackPlugin({
  150. title: '管理员-首页',
  151. filename: 'admin/index.html',
  152. template: './template/template.html',
  153. chunks: ['admin/index', 'vendors']
  154. }),
  155. new HtmlWebpackPlugin({
  156. title: '管理员-登录',
  157. filename: 'admin/login.html',
  158. template: './template/template.html',
  159. chunks: ['admin/login', 'vendors']
  160. }),
  161. new HtmlWebpackPlugin({
  162. title: '管理员-用户管理',
  163. filename: 'admin/userManage.html',
  164. template: './template/template.html',
  165. chunks: ['admin/userManage', 'vendors']
  166. }),
  167. //admin-servicesManage
  168. new HtmlWebpackPlugin({
  169. title: '管理员-科技服务管理-专利',
  170. filename: 'admin/servicesManage/patent.html',
  171. template: './template/template.html',
  172. chunks: ['admin/servicesManage/patent', 'vendors']
  173. }),
  174. //这个使用uglifyJs压缩你的js代码
  175. //new webpack.optimize.UglifyJsPlugin({minimize: true}),
  176. //把入口文件里面的数组打包成verdors.js
  177. //new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'),
  178. ]
  179. };