-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathwebpack.config.js
More file actions
141 lines (124 loc) · 3.26 KB
/
Copy pathwebpack.config.js
File metadata and controls
141 lines (124 loc) · 3.26 KB
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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const merge = require('webpack-merge');
const validate = require('webpack-validator');
// Custom webpack configurations
const parts = require('./lib/parts');
// https://webpack.github.io/docs/configuration.html#devtool
var sourceMaps = {
development:{
devtool: 'eval-source-map'
},
production:{
devtool: 'source-map'
}
};
const PATHS = {
app: path.join(__dirname, 'app'),
style:[
path.join(__dirname, 'node_modules', 'purecss'),
path.join(__dirname, 'app', 'main.css')
],
build: path.join(__dirname, 'build'),
assets: path.join(__dirname, 'app','assets')
};
const common = {
module:{
preLoaders: [
{
test: /\.jsx?$/,
loaders: ['eslint-loader'],
// define an include so we check just the files we need
include: PATHS.app,
exclude: '/node_modules'
}
],
loaders: [
{
test: /\.jsx?$/,
loaders: ['babel?cacheDirectory'],
include: PATHS.app,
exclude: '/node_modules'
},
{
test: require.resolve('react'),
loader: 'expose?React'
},
{
//IMAGE LOADER
test: /\.(jpe?g|png|gif|svg)$/i,
loader:'file'
},
]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
// Entry accepts a path or an object of entries.
// We'll be using the latter form given it's
// convenient with more complex configurations.
entry: {
// 'whatwg-fetch': ['whatwg-fetch'],
style: PATHS.style,
app: PATHS.app,
vendor: ['react','react-dom','es6-promise','isomorphic-fetch'],
},
output: {
path: PATHS.build,
filename: '[name].[hash].js',
chunkFilename: '[hash].js'
},
plugins: [
new HtmlWebpackPlugin({
title: 'ReactJS - Course.',
template: './app/index.ejs', // Load a custom template (ejs by default but can be changed)
inject: 'body' // Inject all scripts into the body (this is the default so you can skip it)
})
]
};
var config;
// Detect how npm is run and branch based on that
switch(process.env.npm_lifecycle_event) {
case 'build':
case 'stats':
config = merge(
common,
sourceMaps.production,
parts.setFreeVariable(
'process.env.NODE_ENV',
'production'
),
parts.clean(PATHS.build),
parts.minify(),
parts.copyStaticAssets(PATHS.assets),
parts.purifyCSS([PATHS.app]),
parts.extractCSS(PATHS.style)
);
break;
case 'test':
case 'test:watch':
config = merge(common,
sourceMaps.development,
parts.setupCSS(PATHS.style),
parts.devServer({
host: process.env.HOST,
port: process.env.PORT
})
);
// Remove entry.style to avoid conflicts with karma (no pun intended)
delete config.entry.style;
break;
default:
config = merge(common,
sourceMaps.development,
parts.setupCSS(PATHS.style),
parts.devServer({
host: process.env.HOST,
port: process.env.PORT
})
);
}
// Run validator in quiet mode to avoid output in stats
module.exports = validate(config, {
quiet: true
});