-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
75 lines (68 loc) · 2.43 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
/*
Okay folks, want to learn a little bit about webpack?
*/
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const devMode = process.env.NODE_ENV !== 'production';
// const webpack = require('webpack');
// const autoprefixer = require('autoprefixer');
/*
webpack sees every file as a module.
How to handle those files is up to loaders.
We only have a single entry point (a .js file) and everything is required from that js file
*/
// This is our JavaScript rule that specifies what to do with .js files
const javascript = {
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
const styles = {
test: /\.scss$/,
use: [
// fallback to style-loader in development
process.env.NODE_ENV !== 'production' ? 'style-loader' : MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader"
]
};
// OK - now it's time to put it all together
const config = {
entry: {
// we only have 1 entry, but I've set it up for multiple in the future
App: './public/javascripts/app.js'
},
// we're using sourcemaps and here is where we specify which kind of sourcemap to use
devtool: 'source-map',
// Once things are done, we kick it out to a file.
output: {
// path is a built in node module
// __dirname is a variable from node that gives us the
path: path.resolve(__dirname, 'public', 'dist'),
// we can use "substitutions" in file names like [name] and [hash]
// name will be `App` because that is what we used above in our entry
filename: '[name].bundle.js'
},
// remember we said webpack sees everything as modules and how different loaders are responsible for different file types? Here is is where we implement them. Pass it the rules for our JS and our styles
module: {
rules: [javascript, styles]
},
// finally we pass it an array of our plugins - uncomment if you want to uglify
// plugins: [uglify]
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: devMode ? '[name].css' : '[name].[hash].css',
chunkFilename: devMode ? '[id].css' : '[id].[hash].css',
}),
]
};
// webpack is cranky about some packages using a soon to be deprecated API. shhhhhhh
process.noDeprecation = true;
module.exports = config;