webpack.config.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. const path = require('path');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. const { DEV, DEBUG } = process.env;
  4. process.env.BABEL_ENV = DEV ? 'development' : 'production';
  5. process.env.NODE_ENV = DEV ? 'development' : 'production';
  6. module.exports = {
  7. entry: './src/index.tsx',
  8. output: {
  9. path: path.join(__dirname, '/public'),
  10. filename: 'bundle.js'
  11. },
  12. devServer: {
  13. port: 8080
  14. },
  15. module: {
  16. rules: [
  17. {
  18. test: /\.(js|jsx)$/,
  19. exclude: /node_modules/,
  20. loader: 'babel-loader',
  21. },
  22. {
  23. test: /\.tsx?$/,
  24. loader: 'ts-loader',
  25. exclude: [/node_modules/],
  26. },
  27. {
  28. test: /\.css$/,
  29. use: [ 'style-loader', 'css-loader' ],
  30. },
  31. {
  32. test: /\.(png|jpg|gif|woff|woff2|eot|ttf|otf|svg)$/,
  33. exclude: /node_modules/,
  34. use: ['file-loader'],
  35. },
  36. {
  37. test: /\.md$/,
  38. use: 'raw-loader',
  39. },
  40. {
  41. test: /\.(less)$/,
  42. exclude: /\.module\.less$/,
  43. use: [
  44. {
  45. loader: 'css-loader',
  46. options: {
  47. importLoaders: 2,
  48. sourceMap: !!DEV,
  49. },
  50. },
  51. {
  52. loader: 'less-loader',
  53. options: {
  54. sourceMap: !!DEV,
  55. },
  56. },
  57. ],
  58. },
  59. {
  60. test: /\.(sass|scss)$/,
  61. use: [
  62. {
  63. loader: 'css-loader',
  64. options: {
  65. importLoaders: 2,
  66. sourceMap: !!DEV,
  67. },
  68. },
  69. {
  70. loader: 'sass-loader',
  71. options: {
  72. sourceMap: !!DEV,
  73. },
  74. },
  75. ],
  76. },
  77. ]
  78. },
  79. resolve: {
  80. modules: ['node_modules'],
  81. extensions: [ '.tsx', '.ts', '.js', '.jsx'],
  82. fallback: {
  83. crypto: require.resolve('crypto-browserify'),
  84. stream: require.resolve('stream-browserify'),
  85. path: false,
  86. fs: false,
  87. }
  88. },
  89. plugins:[
  90. new HtmlWebpackPlugin({
  91. template: path.join(__dirname,'/public/index.html')
  92. })
  93. ]
  94. }