-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
126 lines (115 loc) · 3.77 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
117
118
119
120
121
122
123
124
125
126
// webpack setup tutorial for js|jsx, html:
// https://www.valentinog.com/blog/babel/
// webpack setup tutorial for s|css:
// https://github.com/pixelgoo/simple_webpack_boilerplate,
// https://dev.to/pixelgoo/how-to-configure-webpack-from-scratch-for-a-basic-website-46a5
// boostrap 4 and font-awespme setup tutorial:
// for webpack 4: https://medium.com/@estherfalayi/webpack-4-nicknamed-legato-is-out-and-the-community-is-still-on-the-hots-for-it-i-am-too-e9bee3d2e4a
// // webpack 3: https://medium.com/@estherfalayi/setting-up-webpack-for-bootstrap-4-and-font-awesome-eb276e04aaeb
// how to setup webpack quick-start: https://getbootstrap.com/docs/4.5/getting-started/webpack/
// very useful reference:
// webpack starter kit project with bootstrap4: https://github.com/nuesslerm/webpack-starter-kit
// for file-loader config: https://github.com/nuesslerm/webpack-starter-kit/blob/master/webpack.config.js
const webpack = require('webpack');
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// DOESN'T WORK v
// if (process.env.NODE_ENV !== 'production') {
// module.exports.devServer = {
// contentBase: path.join(__dirname, 'src'),
// watchContentBase: true,
// hot: true,
// open: true,
// inline: true,
// };
// }
module.exports = {
entry: ['./src/index.js'],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'main.js',
},
devServer: {
contentBase: path.join(__dirname, 'src'),
watchContentBase: true,
hot: true,
open: true,
inline: true,
},
// this is an html plugin that will automatically create an index.html from template
// and insert your JS bundle there.
plugins: [
new HtmlWebPackPlugin({
template: path.resolve('./src/index.html'),
// needs to be index.html
filename: 'index.html',
}),
new MiniCssExtractPlugin({
// filename doesn't need to be specified; will be main.css
filename: '[name].css',
// chunkFilename: '[id].css',
}),
new webpack.HotModuleReplacementPlugin(),
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
// options: {
// presets: ['@babel/preset-env', '@babel/preset-react'],
// },
},
},
{
test: /\.html$/,
use: {
loader: 'html-loader',
},
},
{
test: /\.(sa|sc|c)ss$/,
// exclude: /node_modules/,
use: [
{
// After all CSS loaders we use plugin to do his work.
// It gets all transformed CSS and extracts it into separate
// single bundled file
loader: MiniCssExtractPlugin.loader,
},
{ loader: 'css-loader' },
{
// Then we apply postCSS fixes like autoprefixer and minifying
loader: 'postcss-loader',
},
{
// First we transform SASS to standard CSS
loader: 'sass-loader?sourceMap',
// options: {
// implementation: require('sass'),
// },
},
],
},
{
test: /\.(png|jpe?g|gif|svg)$/,
use: [
{
// make sure that the asset storage folder is called "./src/images"
//
// name needs to be the same path as referenced in the style file, ie.
// if background: url('./images/header.jpg')
// then ?name=./images/[name].[ext]'
//
// if background: url('images/header.jpg')
// then ?name=images/[name].[ext]'
loader: 'file-loader?name=./images/[name].[ext]',
},
],
},
],
},
};