webpack.config.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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:8000', // 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:8000', // 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:8000', // 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:8000', // WebpackDevServer host and port
  25. 'webpack/hot/only-dev-server',
  26. './js/user/certify.js'
  27. ],
  28. 'user/groupCertify': ['webpack-dev-server/client?http://127.0.0.1:8000', // WebpackDevServer host and port
  29. 'webpack/hot/only-dev-server',
  30. './js/user/groupCertify.js'
  31. ],
  32. //user-account
  33. 'user/account/index': ['webpack-dev-server/client?http://127.0.0.1:8000', // WebpackDevServer host and port
  34. 'webpack/hot/only-dev-server',
  35. './js/user/account/index.js'
  36. ],
  37. 'user/account/set': ['webpack-dev-server/client?http://127.0.0.1:8000', // WebpackDevServer host and port
  38. 'webpack/hot/only-dev-server',
  39. './js/user/account/set.js'
  40. ],
  41. 'user/account/services': ['webpack-dev-server/client?http://127.0.0.1:8000', // WebpackDevServer host and port
  42. 'webpack/hot/only-dev-server',
  43. './js/user/account/services.js'
  44. ],
  45. //admin
  46. 'admin/index': ['webpack-dev-server/client?http://127.0.0.1:8000', // WebpackDevServer host and port
  47. 'webpack/hot/only-dev-server',
  48. './js/admin/index.js'
  49. ],
  50. 'admin/login': ['webpack-dev-server/client?http://127.0.0.1:8000', // WebpackDevServer host and port
  51. 'webpack/hot/only-dev-server',
  52. './js/admin/login.js'
  53. ],
  54. 'admin/userManage': ['webpack-dev-server/client?http://127.0.0.1:8000', // WebpackDevServer host and port
  55. 'webpack/hot/only-dev-server',
  56. './js/admin/userManage.js'
  57. ],
  58. 'admin/servicesManage/patent': ['webpack-dev-server/client?http://127.0.0.1:8000', // WebpackDevServer host and port
  59. 'webpack/hot/only-dev-server',
  60. './js/admin/servicesManage/patent.js'
  61. ],
  62. 'admin/servicesManage/copyright': ['webpack-dev-server/client?http://127.0.0.1:80', // WebpackDevServer host and port
  63. 'webpack/hot/only-dev-server',
  64. './js/admin/servicesManage/copyright.js'
  65. ],
  66. 'admin/servicesManage/highTech': ['webpack-dev-server/client?http://127.0.0.1:80', // WebpackDevServer host and port
  67. 'webpack/hot/only-dev-server',
  68. './js/admin/servicesManage/highTech.js'
  69. ]
  70. //vendors: ['jquery','antd']
  71. //path.resolve(__dirname, './js/index.js'),
  72. },
  73. output: {
  74. path: path.resolve(__dirname, './build'),
  75. filename: '[name].js'
  76. },
  77. module: {
  78. rules: [{
  79. test: /\.jsx?$/,
  80. exclude: /node_modules/,
  81. use: {
  82. loader: 'babel-loader',
  83. options: {
  84. "presets": ["es2015", "react"],
  85. "plugins": [
  86. ["antd", {
  87. "style": true
  88. }]
  89. ]
  90. }
  91. }
  92. },
  93. {
  94. test: /\.less$/,
  95. use: ExtractTextPlugin.extract({
  96. fallback: 'style-loader',
  97. use: [{
  98. loader: 'css-loader',
  99. options: {
  100. importLoaders: 1
  101. }
  102. }, {
  103. loader: 'less-loader',
  104. options: {
  105. modifyVars: theme
  106. }
  107. }]
  108. })
  109. }, {
  110. test: /\.(png|jpg)$/,
  111. use: [{
  112. loader: 'url-loader',
  113. options: {
  114. limit: 8192,
  115. name: '[path][name].[ext]'
  116. }
  117. }]
  118. }
  119. ]
  120. },
  121. resolve: {
  122. extensions: ['.js', '.jsx']
  123. },
  124. plugins: [
  125. new ExtractTextPlugin({
  126. filename: "[name].css",
  127. disable: false,
  128. allChunks: true
  129. }),
  130. //user
  131. new HtmlWebpackPlugin({
  132. title: '用户首页',
  133. filename: 'user/index.html',
  134. template: './template/template.html',
  135. chunks: ['user/index', 'vendors']
  136. }),
  137. new HtmlWebpackPlugin({
  138. title: '用户登录',
  139. filename: 'user/login.html',
  140. template: './template/template.html',
  141. chunks: ['user/login', 'vendors']
  142. }),
  143. new HtmlWebpackPlugin({
  144. title: '用户注册',
  145. filename: 'user/signIn.html',
  146. template: './template/template.html',
  147. chunks: ['user/signIn', 'vendors']
  148. }),
  149. new HtmlWebpackPlugin({
  150. title: '个人用户认证',
  151. filename: 'user/certify.html',
  152. template: './template/template.html',
  153. chunks: ['user/certify', 'vendors']
  154. }),
  155. new HtmlWebpackPlugin({
  156. title: '团体用户认证',
  157. filename: 'user/groupCertify.html',
  158. template: './template/template.html',
  159. chunks: ['user/groupCertify', 'vendors']
  160. }),
  161. //user-account
  162. new HtmlWebpackPlugin({
  163. title: '用户中心-首页',
  164. filename: 'user/account/index.html',
  165. template: './template/template.html',
  166. chunks: ['user/account/index', 'vendors']
  167. }),
  168. new HtmlWebpackPlugin({
  169. title: '用户中心-设置',
  170. filename: 'user/account/set.html',
  171. template: './template/template.html',
  172. chunks: ['user/account/set', 'vendors']
  173. }),
  174. new HtmlWebpackPlugin({
  175. title: '用户中心-科技服务',
  176. filename: 'user/account/services.html',
  177. template: './template/template.html',
  178. chunks: ['user/account/services', 'vendors']
  179. }),
  180. //admin
  181. new HtmlWebpackPlugin({
  182. title: '管理员-首页',
  183. filename: 'admin/index.html',
  184. template: './template/template.html',
  185. chunks: ['admin/index', 'vendors']
  186. }),
  187. new HtmlWebpackPlugin({
  188. title: '管理员-登录',
  189. filename: 'admin/login.html',
  190. template: './template/template.html',
  191. chunks: ['admin/login', 'vendors']
  192. }),
  193. new HtmlWebpackPlugin({
  194. title: '管理员-用户管理',
  195. filename: 'admin/userManage.html',
  196. template: './template/template.html',
  197. chunks: ['admin/userManage', 'vendors']
  198. }),
  199. //admin-servicesManage
  200. new HtmlWebpackPlugin({
  201. title: '管理员-科技服务管理-专利',
  202. filename: 'admin/servicesManage/patent.html',
  203. template: './template/template.html',
  204. chunks: ['admin/servicesManage/patent', 'vendors']
  205. }),
  206. new HtmlWebpackPlugin({
  207. title: '管理员-科技服务管理-软著',
  208. filename: 'admin/servicesManage/copyright.html',
  209. template: './template/template.html',
  210. chunks: ['admin/servicesManage/copyright', 'vendors']
  211. }),
  212. new HtmlWebpackPlugin({
  213. title: '管理员-科技服务管理-高企',
  214. filename: 'admin/servicesManage/highTech.html',
  215. template: './template/template.html',
  216. chunks: ['admin/servicesManage/highTech', 'vendors']
  217. }),
  218. //这个使用uglifyJs压缩你的js代码
  219. //new webpack.optimize.UglifyJsPlugin({minimize: true}),
  220. //把入口文件里面的数组打包成verdors.js
  221. //new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'),
  222. ]
  223. };