webpack.config.common.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const HtmlWebpackPlugin = require('html-webpack-plugin');
  4. const autoprefixer = require('autoprefixer');
  5. const Dotenv = require('dotenv-webpack');
  6. const commonCSSLoaderOptions = {
  7. importLoaders: 2,
  8. url: false
  9. };
  10. const cssLoaderOptions = {
  11. ...commonCSSLoaderOptions,
  12. modules: false
  13. };
  14. const scssLoaderOptions = {
  15. ...commonCSSLoaderOptions,
  16. modules: true,
  17. localIdentName: '[name]_[local]--[hash:base64:5]'
  18. };
  19. const postCSSLoaderOptions = {
  20. ident: 'postcss',
  21. plugins: () => [autoprefixer(),],
  22. };
  23. module.exports = {
  24. //core-js/features/object: ie 대응
  25. entry: ['core-js/features/object', './src/index.tsx', './assets/css/common.css'],
  26. output: {
  27. filename: 'bundle.[hash].js',
  28. publicPath: '/'
  29. },
  30. resolve: {
  31. alias: {
  32. '@src': path.resolve('./src'),
  33. '@assets': path.resolve('./assets'),
  34. },
  35. extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', 'scss']
  36. },
  37. node: {
  38. fs: 'empty'
  39. },
  40. module: {
  41. rules: [
  42. {
  43. test: /\.(js|jsx|ts|tsx)$/,
  44. exclude: /node_modules/,
  45. use: [{
  46. loader: 'babel-loader',
  47. options: {
  48. presets: [
  49. '@babel/preset-env',
  50. '@babel/preset-react',
  51. '@babel/preset-typescript',
  52. ],
  53. }
  54. }],
  55. },
  56. {
  57. test: /\.(css)$/,
  58. use: [
  59. { loader: 'style-loader' },
  60. { loader: 'css-loader', options: cssLoaderOptions },
  61. ],
  62. },
  63. {
  64. test: /\.(scss)$/,
  65. use: [
  66. { loader: 'style-loader' },
  67. { loader: 'css-loader', options: scssLoaderOptions },
  68. { loader: 'postcss-loader', options: postCSSLoaderOptions },
  69. { loader: 'sass-loader' },
  70. ],
  71. },
  72. {
  73. test: /\.svg$/,
  74. use: [{
  75. loader: '@svgr/webpack',
  76. options: {
  77. svgoConfig: {
  78. plugins: {
  79. removeViewBox: false
  80. }
  81. }
  82. }
  83. }, 'url-loader'],
  84. },
  85. ]
  86. },
  87. plugins: [
  88. new HtmlWebpackPlugin({
  89. template: './public/index.html',
  90. }),
  91. new webpack.HotModuleReplacementPlugin(),
  92. new Dotenv(),
  93. new webpack.DefinePlugin({
  94. 'process.env': JSON.stringify(process.env)
  95. })
  96. ],
  97. };