-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.js
109 lines (94 loc) · 2.51 KB
/
webpack.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
#!/usr/bin/env node
/* eslint-disable no-console */
const getConfig = require('./webpack/get-config');
const chokidar = require('chokidar');
const webpack = require('webpack');
const paths = require('./paths');
const path = require('path');
const Styleguide = require('clientkit-styleguide');
const runStyleguide = function(config) {
if (!config.styleguide.disabled) {
const styleguide = new Styleguide('clientkit-styleguide', config.styleguide);
styleguide.fullConfig = config;
styleguide.execute(() => {});
}
};
const runWebpack = async function () {
let config = {};
try {
config = await getConfig();
} catch (error) {
console.log('There was an error getting the config!');
console.log(error);
process.exit(1);
}
try {
webpack(config.compilers, (err, stats) => {
if (err) {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
if (config.config.failOnError) {
process.exit(1);
}
}
runStyleguide(config.config);
console.log(stats.toString({
timings: !paths.isProduction,
builtAt: false,
assets: false,
cached: false,
cachedAssets: false,
colors: true,
chunks: false,
chunkGroups: false,
chunkModules: false,
chunkOrigins: false,
hash: false,
modules: false,
moduleTrace: false,
version: false
}));
if (config.config.failOnError && (err || stats.hasErrors())) {
process.exit(1);
}
});
} catch (error) {
console.log('There was an error running clientkit!');
console.log('Config was:');
console.log(config);
console.log(error);
process.exit(1);
}
};
const run = () => {
runWebpack();
if (paths.isDevTask) {
try {
const configPaths = [
path.join(paths.baseConfig, '/**/*.yaml'),
path.join(paths.primaryConfig, '/**/*.yaml')
];
const watcher = chokidar.watch(configPaths, {
cwd: paths.baseConfig,
ignoreInitial: true,
interval: 300,
persistent: true
});
const events = ['ready', 'add', 'change', 'unlink'];
watcher.on('all', event => {
if (events.includes(event)) {
if (process.send) {
process.send('Config file change');
}
}
});
} catch (error) {
console.log('There was an error running config watcher!');
console.log(error);
process.exit(1);
}
}
};
run();