webpack.config.js 5.8 KB

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