Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack을 local, dev, prod로 분리한다. #866

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ts-jest": "^28.0.7"
},
"scripts": {
"start": "webpack serve --open --config webpack/webpack.dev.js",
"start": "webpack serve --open --config webpack/webpack.local.js",
"build": "webpack --mode=production --config webpack/webpack.prod.js",
"build-dev": "webpack --mode=production --config webpack/webpack.dev.js",
"storybook": "start-storybook -p 6006",
Expand Down
8 changes: 7 additions & 1 deletion frontend/webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ module.exports = {
path: path.join(__dirname, '../dist'),
filename: '[name].[contenthash].js',
publicPath: '/',
clean: true,
pathinfo: false,
},
resolve: {
alias: {
'@': path.resolve(__dirname, '/src'),
},
modules: ['node_modules'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
symlinks: false,
},
devServer: {
historyApiFallback: true,
Expand Down Expand Up @@ -45,4 +46,9 @@ module.exports = {
}),
new CleanWebpackPlugin(),
],
optimization: {
runtimeChunk: {
name: (entrypoint) => `runtime-${entrypoint.name}`,
},
},
};
13 changes: 10 additions & 3 deletions frontend/webpack/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ dotenv.config({
});

module.exports = merge(common, {
mode: 'development',
devtool: 'eval-cheap-module-source-map',
mode: 'production',
devtool: false,
cache: {
type: 'filesystem',
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
cacheCompression: false,
cacheDirectory: true,
},
},
],
},
Expand All @@ -26,6 +33,6 @@ module.exports = merge(common, {
}),
],
optimization: {
minimize: true,
minimize: false,
},
});
34 changes: 34 additions & 0 deletions frontend/webpack/webpack.local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { merge } = require('webpack-merge');
const common = require('./webpack.common');
const path = require('path');
const webpack = require('webpack');
const dotenv = require('dotenv');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

dotenv.config({
path: path.join(__dirname, './.env.development'),
});

module.exports = merge(common, {
mode: 'development',
devtool: 'eval-cheap-module-source-map',
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)?$/,
loader: 'babel-loader',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local 환경에서만 작동한다면, 해당 경우 ts-loader를 적용하여도 문제 없지 않을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ts-loader를 이용할시 emotion의 css-props를 못쓰기 때문에 ui가 깨지기 때문에 babel-loader를 이용하였습니다.

exclude: /node_modules/,
options: {
cacheCompression: false,
cacheDirectory: true,
},
},
],
},
plugins: [
new ForkTsCheckerWebpackPlugin(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loader를 ts-loader로 설정하지 않아도 해당 플러그인이 작동하나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 문제없이 동작합니다.

new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env),
}),
],
});
7 changes: 7 additions & 0 deletions frontend/webpack/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ dotenv.config({

module.exports = merge(common, {
mode: 'production',
cache: {
type: 'filesystem',
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
cacheCompression: false,
cacheDirectory: true,
},
},
],
},
Expand Down