-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
165 lines (151 loc) · 4.64 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// This is the "development" configuration for Webpack, for production use webpack.dist.config.js
// Code has been commented below describing what each configuration step is doing
const webpack = require('webpack');
const path = require('path');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const WebpackNotifierPlugin = require('webpack-notifier');
module.exports = {
// specify the root module for our application aka entry point
// the react-hot-loader/patch preceeds this bc [email protected]
entry: {
bundle: ['babel-polyfill', 'react-hot-loader/patch', './src/index.js'],
},
// what type of source maps to use
devtool: 'eval-source-map',
// where the compiled code is placed
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[hash].js',
},
// what file extensions should webpack look for
resolve: {
extensions: ['.js', '.jsx', '.json', '.geojson'],
},
// what to do with different types of modules, e.g. sass, js, jsx, json, geojson
module: {
rules: [
// Lint JS and transpile ES6 to ES5
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
},
],
},
// Use Sass and transpile to CSS
// PostCSS is included here so that we can use things like AutoPrefixer
{
test: /\.scss$/,
use: [
{
loader: 'style-loader', // creates style nodes from JS strings
},
{
loader: 'css-loader', // translates CSS into CommonJS
},
{
loader: 'postcss-loader', // postcss loader so we can use autoprefixer
options: {
config: {
path: 'postcss.config.js',
},
},
},
{
loader: 'sass-loader', // compiles Sass to CSS
},
// allows for importing variables via JS or JSON files
{
loader: '@epegzz/sass-vars-loader',
options: {
files: [path.resolve(__dirname, 'src/common/styleVars.js')],
},
},
],
},
// allows for using ES6 import for JSON and GeoJSON files, no async loading!
{
test: /\.(json|geojson)$/,
use: 'json-loader',
},
// load svg files as React Components, because why not?
{
test: /\.svg$/,
use: [
'babel-loader',
{
loader: 'svgr/lib/webpack',
options: {
svgo: false,
icon: true,
},
},
],
},
// load images
// url-loader will base64 encode images smaller than options.limit
// otherwise it behaves just like file-loader
{
test: /\.(jpe?g|png|gif)$/,
loader: 'url-loader',
options: {
limit: 8192,
},
},
// load local fonts if they exist
// for more info see https://survivejs.com/webpack/loading/fonts/
{
test: /\.(eot|ttf|woff|woff2)$/,
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
},
},
],
},
// webpack dev-server configuration
devServer: {
compress: true, // use compression
port: 8889, // what port on localhost content will be served from
hotOnly: true, // for hot-module-replacement
},
plugins: [
// lints CSS, see the .stylelintrc.json file for more or to customize
new StyleLintPlugin({
configFile: '.stylelintrc.json',
files: '**/*.scss',
failOnError: false,
quiet: false,
syntax: 'scss',
}),
// set the process.env.NODE_ENV var to "development"
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
}),
// enable hot-module-replacement
new webpack.HotModuleReplacementPlugin(),
// codesplitting: vendor libraries
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
// eslint-disable-next-line
minChunks: function(module) {
// this assumes your vendor imports exist in the node_modules directory
return module.context && module.context.indexOf('node_modules') !== -1;
},
}),
// codesplitting: source
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity,
}),
// allows for appending script and link tags for bundled JS and CSS
new HTMLWebpackPlugin({
template: 'src/index.html',
}),
// desktop notification when webpack updates
new WebpackNotifierPlugin({ alwaysNotify: true }),
],
};