-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
71 lines (63 loc) · 2.28 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
const path = require('path');
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: ['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({ browsers: 'last 3 versions' })]; }
}
};
// this is our sass/css loader. It handles files that are require('something.scss')
const styles = {
test: /\.(scss)$/,
use: ExtractTextPlugin.extract(['css-loader?sourceMap', postcss, 'sass-loader?sourceMap'])
};
// We can also use plugins - this one will compress the crap out of our JS
const uglify = new webpack.optimize.UglifyJsPlugin({ // eslint-disable-line
compress: { warnings: false }
});
// 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/delicious-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
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'
},
module: {
rules: [javascript, styles]
},
// 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;