-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.prod.js
100 lines (95 loc) · 2.3 KB
/
webpack.config.prod.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
'use strict';
var NODE_ENV = process.env.NODE_ENV;
var fs = require('fs');
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin'); // html 템플릿 사용
var MiniCssExtractPlugin = require('mini-css-extract-plugin'); // css 파일 추출
var CompressionWebpackPlugin = require('compression-webpack-plugin');
var appDirectory = fs.realpathSync(process.cwd()); // 디렉토리 경로
var resolveApp = function (relativePath) {
return path.resolve(appDirectory, relativePath);
};
var paths = {
appPath: resolveApp('src/app.js'),
buildPath: resolveApp('dist'), // 배포 경로
appHtml: resolveApp('src/index.html'),
appSrc: resolveApp('src'),
appNodeModules: resolveApp('node_modules'),
};
module.exports = {
mode: NODE_ENV,
entry: {
app: paths.appPath,
},
output: {
path: paths.buildPath,
filename: '[name].bundle.js',
chunkFilename: '[name].chunk.js',
},
resolve: {
extensions: ['.js'],
/**
* before: var file = require('file.js');
* after: var file = require('file');
*/
modules: ['node_modules', paths.appSrc, paths.appNodeModules], // 절대 경로 설정
},
module: {
rules: [
// eslint
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
},
// babel
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader'
]
},
{
test: /\.scss$/,
use: [
// fallback to style-loader in development
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
},
{
test: /\.html$/,
loader: 'raw-loader',
exclude: paths.appHtml
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: paths.appHtml
}),
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new CompressionWebpackPlugin({ // gzip 압축
filename: '[path].gz[query]',
algorithm: 'gzip',
test: /\.(js|html)$/i,
threshold: 10240,
minRatio: 0.8
})
]
};