webpack.config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. const path = require('path');
  2. const join = path.join;
  3. const resolve = path.resolve;
  4. const webpack = require('webpack');
  5. const tmpdir = require('os').tmpdir;
  6. const HtmlWebpackPlugin = require('html-webpack-plugin');
  7. const htmlPlugin = new HtmlWebpackPlugin({
  8. template: './src/index.html',
  9. filename: './index.html',
  10. favicon: './favicon.ico'
  11. });
  12. const config = require('./config/env-config');
  13. // mock data
  14. const appData = require('./config/data.json');
  15. const statistic = appData.statistic;
  16. const user = appData.user;
  17. const category = appData.category;
  18. module.exports = {
  19. entry: './src/App.jsx',
  20. resolve: {
  21. alias: {
  22. page: path.resolve(__dirname, 'src/page'),
  23. component: path.resolve(__dirname, 'src/component'),
  24. util: path.resolve(__dirname, 'src/util'),
  25. api: path.resolve(__dirname, 'src/api')
  26. },
  27. modules: ['node_modules', join(__dirname, '../node_modules')],
  28. extensions: ['.web.tsx', '.web.ts', '.web.jsx', '.web.js', '.ts', '.tsx', '.js', '.jsx', '.json']
  29. },
  30. output: {
  31. publicPath: '/'
  32. },
  33. module: {
  34. rules: [
  35. {
  36. test: /\.jsx?$/,
  37. exclude: /node_module/,
  38. use: {
  39. loader: 'babel-loader',
  40. options: {
  41. presets: ['react', 'env'],
  42. cacheDirectory: true,
  43. cacheDirectory: tmpdir(),
  44. presets: [
  45. require.resolve('babel-preset-es2015-ie'),
  46. require.resolve('babel-preset-react'),
  47. require.resolve('babel-preset-stage-0')
  48. ],
  49. plugins: [
  50. require.resolve('babel-plugin-add-module-exports'),
  51. require.resolve('babel-plugin-transform-decorators-legacy'),
  52. ['import', { libraryName: 'antd', libraryDirectory: 'es', style: 'css' }]
  53. ]
  54. }
  55. }
  56. },
  57. {
  58. test: /\.css$/,
  59. loader: 'style-loader!css-loader'
  60. },
  61. {
  62. test: /\.(eot|woff|woff2|ttf)/,
  63. loader: 'url-loader?limit=30000&name=fonts/[hash:8].[name].[ext]'
  64. },
  65. // {
  66. // test: /\.css$/,
  67. // exclude: /node_module/,
  68. // use: [
  69. // {
  70. // loader: 'style-loader'
  71. // },
  72. // {
  73. // loader: 'css-loader',
  74. // options: {
  75. // modules: true,
  76. // importLoaders: 1,
  77. // sourceMap: true,
  78. // localIdentName: '[path][name]__[local]--[hash:base64:5]'
  79. // }
  80. // }
  81. // ]
  82. // },
  83. {
  84. test: /\.scss$/,
  85. use: [
  86. {
  87. loader: 'style-loader'
  88. },
  89. {
  90. loader: 'css-loader'
  91. },
  92. {
  93. loader: 'sass-loader'
  94. },
  95. {
  96. loader: 'sass-resources-loader',
  97. options: {
  98. resources: './src/style/resources.scss'
  99. }
  100. }
  101. ]
  102. }
  103. ]
  104. },
  105. devServer: {
  106. port: 8080,
  107. historyApiFallback: true,
  108. before(app) {
  109. app.get('/api/statistic', function(req, res) {
  110. res.json(statistic);
  111. });
  112. },
  113. proxy: {
  114. '/manage': {
  115. // target: 'https://bird.ioliu.cn/v1?url=http://adminv2.happymmall.com/manage/',
  116. target: 'http://adminv2.happymmall.com',
  117. changeOrigin: true
  118. // target: 'https://www.baidu.com',
  119. // pathRewrite: { '^/manage': '' },
  120. // secure: false
  121. },
  122. '/user/logout.do': { target: 'http://adminv2.happymmall.com', changeOrigin: true }
  123. }
  124. },
  125. plugins: [
  126. htmlPlugin,
  127. new webpack.DefinePlugin({
  128. 'process.env.BASE_URL': '"' + process.env.BASE_URL + '"'
  129. })
  130. ]
  131. };