webpack.config.js 3.2 KB

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