1
|
|
|
/** |
2
|
|
|
* The external dependencies. |
3
|
|
|
*/ |
4
|
|
|
const { ProvidePlugin, WatchIgnorePlugin } = require('webpack'); |
5
|
|
|
const CleanWebpackPlugin = require('clean-webpack-plugin'); |
6
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin'); |
7
|
|
|
const ManifestPlugin = require('webpack-manifest-plugin'); |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* The internal dependencies. |
11
|
|
|
*/ |
12
|
|
|
const utils = require('./lib/utils'); |
13
|
|
|
const configLoader = require('./config-loader'); |
14
|
|
|
const spriteSmith = require('./spritesmith'); |
15
|
|
|
const postcss = require('./postcss'); |
16
|
|
|
const browsersync = require('./browsersync'); |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Setup the env. |
20
|
|
|
*/ |
21
|
|
|
const { env: envName } = utils.detectEnv(); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Setup babel loader. |
25
|
|
|
*/ |
26
|
|
|
const babelLoader = { |
27
|
|
|
loader: 'babel-loader', |
28
|
|
|
options: { |
29
|
|
|
cacheDirectory: true, |
30
|
|
|
comments: false, |
31
|
|
|
presets: [ |
32
|
|
|
[ |
33
|
|
|
'env', |
34
|
|
|
{ |
35
|
|
|
targets: { |
36
|
|
|
browsers: ['last 3 versions'], |
37
|
|
|
}, |
38
|
|
|
}, |
39
|
|
|
], |
40
|
|
|
// airbnb not included as stage-2 already covers it |
41
|
|
|
'stage-2', |
42
|
|
|
], |
43
|
|
|
}, |
44
|
|
|
}; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Setup extract text plugin. |
48
|
|
|
*/ |
49
|
|
|
const extractSass = new ExtractTextPlugin({ |
50
|
|
|
filename: 'styles/[name].css', |
51
|
|
|
}); |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Setup webpack plugins. |
55
|
|
|
*/ |
56
|
|
|
const plugins = [ |
57
|
|
|
new CleanWebpackPlugin(utils.distPath(), { |
58
|
|
|
root: utils.themeRootPath(), |
59
|
|
|
}), |
60
|
|
|
new WatchIgnorePlugin([ |
61
|
|
|
utils.distImagesPath('sprite.png'), |
62
|
|
|
utils.distImagesPath('[email protected]'), |
63
|
|
|
]), |
64
|
|
|
new ProvidePlugin({ |
65
|
|
|
$: 'jquery', |
66
|
|
|
jQuery: 'jquery', |
67
|
|
|
}), |
68
|
|
|
extractSass, |
69
|
|
|
spriteSmith, |
70
|
|
|
browsersync, |
71
|
|
|
new ManifestPlugin(), |
72
|
|
|
]; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Export the configuration. |
76
|
|
|
*/ |
77
|
|
|
module.exports = { |
78
|
|
|
/** |
79
|
|
|
* The input. |
80
|
|
|
*/ |
81
|
|
|
entry: require('./webpack/entry'), |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* The output. |
85
|
|
|
*/ |
86
|
|
|
output: require('./webpack/output'), |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Resolve utilities. |
90
|
|
|
*/ |
91
|
|
|
resolve: require('./webpack/resolve'), |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Resolve the dependencies that are available in the global scope. |
95
|
|
|
*/ |
96
|
|
|
externals: require('./webpack/externals'), |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Setup the transformations. |
100
|
|
|
*/ |
101
|
|
|
module: { |
102
|
|
|
rules: [ |
103
|
|
|
/** |
104
|
|
|
* Add support for blogs in import statements. |
105
|
|
|
*/ |
106
|
|
|
{ |
107
|
|
|
enforce: 'pre', |
108
|
|
|
test: /\.(js|jsx|css|scss)$/, |
109
|
|
|
use: 'import-glob', |
110
|
|
|
}, |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Handle the theme config.json. |
114
|
|
|
*/ |
115
|
|
|
{ |
116
|
|
|
test: utils.themeRootPath('config.json'), |
117
|
|
|
use: configLoader, |
118
|
|
|
}, |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Handle scripts. |
122
|
|
|
*/ |
123
|
|
|
{ |
124
|
|
|
test: utils.tests.scripts, |
125
|
|
|
exclude: /node_modules/, |
126
|
|
|
use: babelLoader, |
127
|
|
|
}, |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Handle styles. |
131
|
|
|
*/ |
132
|
|
|
{ |
133
|
|
|
test: utils.tests.styles, |
134
|
|
|
use: extractSass.extract({ |
135
|
|
|
publicPath: '../', |
136
|
|
|
use: [ |
137
|
|
|
{ |
138
|
|
|
loader: 'css-loader', |
139
|
|
|
options: { |
140
|
|
|
minimize: false, |
141
|
|
|
}, |
142
|
|
|
}, |
143
|
|
|
{ |
144
|
|
|
loader: 'postcss-loader', |
145
|
|
|
options: postcss, |
146
|
|
|
}, |
147
|
|
|
'sass-loader', |
148
|
|
|
], |
149
|
|
|
}), |
150
|
|
|
}, |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Handle images. |
154
|
|
|
*/ |
155
|
|
|
{ |
156
|
|
|
test: utils.tests.images, |
157
|
|
|
use: [ |
158
|
|
|
{ |
159
|
|
|
loader: 'file-loader', |
160
|
|
|
options: { |
161
|
|
|
name: file => `images/[name].${utils.filehash(file).substr(0, 10)}.[ext]`, |
162
|
|
|
}, |
163
|
|
|
}, |
164
|
|
|
], |
165
|
|
|
}, |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Handle fonts. |
169
|
|
|
*/ |
170
|
|
|
{ |
171
|
|
|
test: utils.tests.fonts, |
172
|
|
|
use: [ |
173
|
|
|
{ |
174
|
|
|
loader: 'file-loader', |
175
|
|
|
options: { |
176
|
|
|
name: file => `fonts/[name].${utils.filehash(file).substr(0, 10)}.[ext]`, |
177
|
|
|
}, |
178
|
|
|
}, |
179
|
|
|
], |
180
|
|
|
}, |
181
|
|
|
], |
182
|
|
|
}, |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Setup the transformations. |
186
|
|
|
*/ |
187
|
|
|
plugins, |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Setup the development tools. |
191
|
|
|
*/ |
192
|
|
|
mode: envName, |
|
|
|
|
193
|
|
|
cache: true, |
194
|
|
|
bail: false, |
195
|
|
|
watch: true, |
196
|
|
|
devtool: 'source-map', |
197
|
|
|
}; |
198
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.