forked from jantimon/html-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-examples.js
53 lines (45 loc) · 1.37 KB
/
build-examples.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
/**
* This file is just a helper to compile all examples.
*
* You could do the same by going into each example and execute
* `webpack`
*/
var webpackMajorVersion = require('webpack/package.json').version.split('.')[0];
var fs = require('fs');
var path = require('path');
var rimraf = require('rimraf');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
if (webpackMajorVersion >= '2') {
var extractOriginal = ExtractTextPlugin.extract;
ExtractTextPlugin.extract = function (fallback, use) {
return extractOriginal({
fallback: fallback,
use: use
});
};
}
var examples = fs.readdirSync(__dirname).filter(function (file) {
return fs.statSync(path.join(__dirname, file)).isDirectory();
});
examples.forEach(function (exampleName) {
var examplePath = path.join(__dirname, exampleName);
var configFile = path.join(examplePath, 'webpack.config.js');
rimraf.sync(path.join(examplePath, 'dist', 'webpack-' + webpackMajorVersion));
webpack(require(configFile), function (err, stats) {
if (err) {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
return;
}
const info = stats.toJson();
if (stats.hasErrors()) {
console.error(info.errors);
}
if (stats.hasWarnings()) {
console.warn(info.warnings);
}
});
});