webpack.config.js 4.6 KB

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