webpack.base.conf.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * Copyright 1999-2019 Seata.io Group.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. const path = require('path');
  17. const HtmlWebpackPlugin = require('html-webpack-plugin');
  18. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  19. const CopyWebpackPlugin = require('copy-webpack-plugin');
  20. const isDev = process.env.NODE_ENV !== 'production';
  21. function resolve(dir) {
  22. return path.join(__dirname, '..', dir);
  23. }
  24. module.exports = {
  25. entry: {
  26. main: './src/index.tsx',
  27. },
  28. output: {
  29. filename: './js/[name].js',
  30. path: path.resolve(__dirname, '../dist'),
  31. },
  32. resolve: {
  33. extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
  34. alias: {
  35. '@': resolve('src'),
  36. utils: resolve('src/utils'),
  37. components: resolve('src/components'),
  38. pages: resolve('src/pages'),
  39. },
  40. },
  41. node: {
  42. fs: 'empty'
  43. },
  44. module: {
  45. rules: [
  46. {
  47. test: /\.(css|scss)$/,
  48. use: [isDev ? 'style-loader' : MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
  49. },
  50. {
  51. test: /\.(js|jsx)$/,
  52. loader: 'eslint-loader',
  53. enforce: 'pre',
  54. include: [resolve('src')],
  55. },
  56. {
  57. test: /\.(js|jsx|ts|tsx)$/,
  58. include: [resolve('src')],
  59. use: ['babel-loader'],
  60. },
  61. {
  62. test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
  63. loader: 'url-loader',
  64. options: {
  65. limit: 10000,
  66. name: '/img/[name].[hash:8].[ext]',
  67. },
  68. },
  69. {
  70. test: /\.(ttf|woff|svg)$/,
  71. use: [
  72. {
  73. loader: 'url-loader',
  74. options: {
  75. name: '/fonts/[name].[hash:8].[ext]',
  76. },
  77. },
  78. ],
  79. },
  80. ],
  81. },
  82. plugins: [
  83. new HtmlWebpackPlugin({
  84. filename: 'index.html',
  85. template: './public/index.html',
  86. minify: !isDev,
  87. }),
  88. new CopyWebpackPlugin([
  89. {
  90. from: resolve('public'),
  91. to: './',
  92. ignore: ['index.html'],
  93. },
  94. ]),
  95. ],
  96. };