-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
81 lines (73 loc) · 2.81 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
/*
Okay folks, want to learn a little bit about webpack?
*/
const path = require('path');
// eslint-disable-next-line no-unused-vars
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
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: /\.(js)$/, // see how we match anything that ends in `.js`? Cool
use: [
{
loader: 'babel-loader',
options: { presets: ['@babel/preset-env'] }, // this is one way of passing options
},
],
};
/*
This is our postCSS loader which gets fed into the next loader. I'm setting it up in it's own variable because its a didgeridog
*/
const postcss = {
loader: 'postcss-loader',
options: {
plugins() {
return [autoprefixer()];
},
},
};
// this is our sass/css loader. It handles files that are require('something.scss')
const styles = {
test: /\.(scss)$/,
// here we pass the options as query params b/c it's short.
// remember above we used an object for each loader instead of just a string?
// We don't just pass an array of loaders, we run them through the extract plugin so they can be outputted to their own .css file
use: ExtractTextPlugin.extract(['css-loader?sourceMap', postcss, 'sass-loader?sourceMap']),
};
// 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/vgc-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 everthing 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: [
// here is where we tell it to output our css to a separate file
new ExtractTextPlugin('style.css'),
],
};
// webpack is cranky about some packages using a soon to be deprecated API. shhhhhhh
process.noDeprecation = true;
module.exports = config;