-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
116 lines (106 loc) · 2.82 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
109
110
111
112
113
114
115
116
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// 로더 개발자를 위한 로그 제거
process.noDeprecation = true;
const defaultEnv = {
dev: false,
production: true
};
module.exports = (env = defaultEnv) => ({
context: path.join(__dirname),
entry: [
...env.dev ? [
'react-hot-loader/patch',
'webpack-dev-server/client?http://0.0.0.0:8080',
'webpack/hot/only-dev-server',
'./src/index.jsx',
] : ['./src/index.jsx'],
path.join(__dirname, 'src/index.jsx')
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
},
devtool: env.dev ? 'inline-source-map' : 'cheap-module-source-map',
devServer: {
inline: true,
hot: true,
filename: 'bundle.js',
publicPath: '/',
historyApiFallback: true,
contentBase: path.join(__dirname, '/dist/'),
open: true,
},
module: {
rules: [
{
test: /.(js|jsx)$/,
exclude: /node_modules/,
include: path.join(__dirname, 'src'),
use: [{
loader: 'babel-loader',
options: {
babelrc: true,
presets: [
['es2015', { modules: false }],
'react',
],
plugins: ['react-hot-loader/babel'],
}
}]
},
{
test: /\.(css|sass|scss)$/,
use: env.dev ?
[
'style-loader',
'css-loader',
// 'sass-loader',
]
: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{ loader: 'css-loader', query: { modules: true, sourceMaps: true } },
{ loader: 'sass-loader' },
]
}),
}
]
},
plugins: [
...env.dev ? [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({
template: './src/index.html',
minify: {
collapseWhitespace: true,
keepClosingSlash: true,
removeComments: true
}
}),
] : [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.optimize.UglifyJsPlugin(),
new ExtractTextPlugin('styles.css'),
new webpack.optimize.CommonsChunkPlugin({
name: 'commons',
filename: 'commons.js',
minChunks: Infinity
}),
new HtmlWebpackPlugin({
template: './src/index.html',
minify: {
collapseWhitespace: true,
keepClosingSlash: true,
removeComments: true
}
}),
]
]
});