-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
135 lines (115 loc) · 3.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
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
"use strict";
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextWebpackPlugin = require('extract-text-webpack-plugin');
// The <script_name> in `npm run <script_name>`
const INVOCATION = process.env.npm_lifecycle_event;
const DEVELOPMENT = INVOCATION === 'start' || INVOCATION === 'dash';
const PRODUCTION = process.env.NODE_ENV === 'production';
const devConfig = require('./webpack.config.dev');
const prodConfig = require('./webpack.config.prod');
const pkgJson = require('./package.json');
/**
* webpack.config.js
*
* This constructs/merges a webpack config.
* - Webpack will call this function
* - Checks `INVOCATION` to determine whether to run development or production builds
*
*/
module.exports = () => {
let config = {
context: `${__dirname}/src/client`,
entry: {
bundle: [
'./app/index.js'
],
// Everything in the `dependencies` should be considered a `vendor` library
vendor: [].concat(Object.keys(pkgJson.dependencies)),
},
output: {
path : `${__dirname}/dist`,
filename : '[name].[chunkhash].js',
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest'],
}),
/**
* This renders out an `./dist/index.html` with all scripts, title etc. attached
*/
new HtmlWebpackPlugin({
title : pkgJson.description || pkgJson.name,
filename : 'index.html',
template : './app/index.html',
}),
new ExtractTextWebpackPlugin({
filename: '[name].[chunkhash].css'
}),
],
resolve: {
modules: ['src/shared/', 'node_modules'],
extensions: ['.js', '.jsx', '.json']
},
performance: { hints: false },
module: {
rules: [
// JS
{
test : /\.jsx?$/,
use : ['babel-loader'],
exclude : [/node_modules/],
// ESLINT - ADD BACK WHEN PROJECT HAS ESLINT
// rules: [
// {
// enforce : 'pre',
// use : [{
// loader : 'eslint-loader',
// options : {
// cache : true,
// quiet : true,
// // Causes `npm run build` to fail on lint errors
// // but development does not
// emitWarning: DEVELOPMENT,
// },
// }],
// },
// ],
},
// SASS
{
test : /\.s[ac]ss$/,
exclude: /node_modules/,
loader: ExtractTextWebpackPlugin.extract({
fallbackLoader: 'style-loader',
loader: [
{
loader : 'css-loader',
options : { sourceMap: DEVELOPMENT },
},
{
loader : 'sass-loader',
options : { sourceMap: DEVELOPMENT },
},
],
})
},
// ASSETS
{
test : /\.(png|jpg|gif|woff|woff2|eot|svg)$/,
use : [
{ loader: 'url-loader', options: { limit: 8192 } },
],
},
],
},
};
if (DEVELOPMENT) {
config = webpackMerge(config, devConfig());
} else if (PRODUCTION) {
config = webpackMerge(config, prodConfig());
}
// console.log(JSON.stringify(config, 2, 2));
return config;
};