-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
executable file
·52 lines (41 loc) · 1.39 KB
/
build.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
#!/usr/bin/env node
const path = require('path');
const emoji = require('node-emoji');
const chalk = require('chalk');
const Bundler = require('parcel-bundler');
const entryFile = path.join(__dirname, 'src', 'style.css');
const defaultOptions = {
minify: false,
sourceMaps: false,
logLevel: 0
};
const targets = {
user: {
...defaultOptions,
},
};
console.log();
console.log(`${emoji.get('package')} ${chalk.yellow.bold(process.env.NODE_ENV.toUpperCase())} build`);
console.log();
(async () => {
for (const [target, options] of Object.entries(targets)) {
const outFile = `style.${target}.css`;
const bundler = new Bundler(entryFile, {
...options,
outFile,
})
bundler.on('bundled', (bundle) => {
console.log(chalk.green(`${emoji.get('tada')} ${chalk.bold(target)} [${chalk.white(outFile)}] bundled`))
});
bundler.on('buildStart', () => console.log(chalk.grey(`${emoji.get('hammer_and_wrench')} Building ${target}...`)))
bundler.on('buildError', err => {
console.error();
console.error(emoji.get('red_circle'), chalk.red('Build Failed! '), chalk.bold.white(err.message))
console.error(`in file: ${chalk.bold(err.file)}`);
console.error(`on line: ${chalk.bold(err.line)}`);
console.error(`at column: ${chalk.bold(err.column)}`);
console.error(chalk.grey(err.stack));
});
await bundler.bundle();
}
})();