webpack.config.js 3.2 KB

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