-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.babel.js
140 lines (116 loc) · 3.05 KB
/
webpack.config.babel.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import autoprefixer from 'autoprefixer';
// import ExtractTextPlugin from 'extract-text-webpack-plugin';
import HtmlPlugin from 'html-webpack-plugin';
import path from 'path';
import webpack from 'webpack';
const isProd = process.env.NODE_ENV === 'production';
//////////////////////// FILEPATH ///////////////////////
/////////////////////////////////////////////////////////
const imagesFolder = 'public/assets/img/',
buildFolder = 'dist',
sourceFolder = 'src',
PATHS = {
build : path.resolve(__dirname, buildFolder),
src : path.resolve(__dirname, sourceFolder),
node_modules : path.resolve(__dirname, 'node_modules'),
appJS : path.resolve(__dirname, `${sourceFolder}/index.js`),
indexHTML : path.resolve(__dirname, `${sourceFolder}/index.html`)
};
//////////////////////// PLUGINS ////////////////////////
/////////////////////////////////////////////////////////
const HtmlPluginOptions = {
template: PATHS.indexHTML,
minify: {
collapseWhitespace: true
},
hash: true
};
const ExtractTextPluginOptions = {
filename: '[name].bundle.css',
disable: !isProd,
allChunks: true,
ignoreOrder: false
};
const devServerOptions = {
contentBase: PATHS.build,
compress: true,
port: 6969,
stats: 'errors-only',
open: true,
hot: true,
openPage: ''
};
const pluginsDev = [
autoprefixer,
new HtmlPlugin(HtmlPluginOptions),
// new ExtractTextPlugin(ExtractTextPluginOptions),
new webpack.HotModuleReplacementPlugin()
];
const pluginsProd = [
require('autoprefixer'),
// new HtmlPlugin(HtmlPluginOptions),
// new ExtractTextPlugin(ExtractTextPluginOptions)
];
var pluginsList = isProd ? pluginsProd : pluginsDev;
//////////////////////// LOADERS ////////////////////////
/////////////////////////////////////////////////////////
const postcss = {
loader: 'postcss-loader',
options: {
sourceMap: 'inline',
plugins() {
return [autoprefixer({ browsers: 'last 3 versions' })];
}
}
};
const scss = {
loader: 'sass-loader',
options: {
sourceMap: 'inline',
includePaths: [PATHS.node_modules]
}
}
const styles = {
test: /\.scss$/,
use: ['style-loader', 'css-loader?sourceMap', postcss, scss]
};
const javascript = {
test: /\.(js|jsx)$/,
use: 'babel-loader',
exclude: /node_modules/
};
const images = {
test: /\.(jpe?g|svg|png|gif)$/i,
use: [
`file-loader?name=${imagesFolder}[name].[ext]`
]
};
const html = {
test: /\.(html)$/,
use: {
loader: 'html-loader',
options: {
attrs: ['img:src', 'link:href']
}
}
};
//////////////////////// WEBPACK ////////////////////////
/////////////////////////////////////////////////////////
const webpackConfig = {
entry: {
app: PATHS.appJS
},
output: {
path: PATHS.build,
filename: '[name].bundle.js'
},
module: {
rules: [javascript, styles, images, html]
},
resolve: {
modules: [PATHS.src, 'node_modules'],
},
devServer: devServerOptions,
plugins: pluginsList
};
export default webpackConfig;