-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathwebpack.config.js
108 lines (106 loc) · 2.73 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const apiMocker = require("connect-api-mocker");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const mode = process.env.NODE_ENV || "development";
module.exports = {
mode,
entry: {
main: "./src/app.js"
},
output: {
filename: "[name].js",
path: path.resolve("./dist")
},
devServer: {
overlay: true,
stats: "errors-only",
// before: (app, server, compiler) => {
// app.use(apiMocker('/api', 'mocks/api'));
// },
proxy: {
"/api": "http://localhost:8081"
},
hot: true
},
module: {
rules: [
{
test: /\.(scss|css)$/,
use: [
mode === "production"
? MiniCssExtractPlugin.loader // 프로덕션 환경
: "style-loader", // 개발 환경
"css-loader",
"sass-loader"
]
},
{
test: /\.(png|jpg|svg|gif)$/,
loader: "url-loader",
options: {
name: "[name].[ext]?[hash]",
limit: 10000 // 10Kb
}
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader" // 바벨 로더를 추가한다
}
]
},
plugins: [
new webpack.BannerPlugin({
banner: `빌드 날짜: ${new Date().toLocaleString()}`
}),
new webpack.DefinePlugin({}),
new HtmlWebpackPlugin({
template: "./src/index.html",
templateParameters: {
env: mode === "development" ? "(개발용)" : ""
},
minify:
mode === "production"
? {
collapseWhitespace: true, // 빈칸 제거
removeComments: true // 주석 제거
}
: false,
hash: mode === "production"
}),
new CleanWebpackPlugin(),
new CopyPlugin([
{
from: "./node_modules/axios/dist/axios.min.js",
to: "./axios.min.js" // 목적지 파일에 들어간다
}
]),
...(mode === "production"
? [new MiniCssExtractPlugin({ filename: `[name].css` })]
: [])
],
optimization: {
minimizer:
mode === "production"
? [
new OptimizeCSSAssetsPlugin(),
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true // 콘솔 로그를 제거한다
}
}
})
]
: []
},
externals: {
axios: "axios"
}
};