webpack.config.common.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. },]
  48. },
  49. {
  50. test: /\.(css)$/,
  51. use: [
  52. { loader: 'style-loader' },
  53. { loader: 'css-loader', options: cssLoaderOptions },
  54. ],
  55. },
  56. {
  57. test: /\.(scss)$/,
  58. use: [
  59. { loader: 'style-loader' },
  60. { loader: 'css-loader', options: scssLoaderOptions },
  61. { loader: 'postcss-loader', options: postCSSLoaderOptions },
  62. { loader: 'sass-loader' },
  63. ],
  64. },
  65. {
  66. test: /\.svg$/,
  67. use: [{
  68. loader: '@svgr/webpack',
  69. options: {
  70. svgoConfig: {
  71. plugins: {
  72. removeViewBox: false
  73. }
  74. }
  75. }
  76. }, 'url-loader'],
  77. },
  78. ]
  79. },
  80. plugins: [
  81. new HtmlWebpackPlugin({
  82. template: './public/index.html',
  83. }),
  84. new webpack.HotModuleReplacementPlugin(),
  85. new Dotenv(),
  86. new webpack.DefinePlugin({
  87. 'process.env': JSON.stringify(process.env)
  88. })
  89. ],
  90. };