1 | const ora = require('ora');
|
2 | const { start } = require('../src');
|
3 | const base = require('./base');
|
4 |
|
5 | module.exports = (middleware, args, cli) => {
|
6 | const spinner = ora({ text: 'Building project' });
|
7 |
|
8 | return base({
|
9 | cli,
|
10 | middleware,
|
11 | args,
|
12 | NODE_ENV: 'development',
|
13 | commandHandler(config, neutrino) {
|
14 | if (!args.start) {
|
15 | spinner.enabled = global.interactive;
|
16 | spinner.start();
|
17 | }
|
18 |
|
19 | return start(config, neutrino);
|
20 | },
|
21 | errorsHandler() {
|
22 | spinner.fail('Building project failed');
|
23 | },
|
24 | successHandler(compiler) {
|
25 | if (args.quiet || !compiler) {
|
26 | return;
|
27 | }
|
28 |
|
29 | if (!compiler.options.devServer) {
|
30 | spinner.succeed('Build completed');
|
31 |
|
32 | const building = ora({
|
33 | text: 'Performing initial build',
|
34 | enabled: global.interactive
|
35 | });
|
36 |
|
37 | compiler.plugin('done', () => {
|
38 | building.succeed('Build completed');
|
39 | });
|
40 | compiler.plugin('compile', () => {
|
41 | building.text = 'Source changed, re-compiling';
|
42 | building.start();
|
43 | });
|
44 | } else {
|
45 | const { devServer } = compiler.options;
|
46 | const url = `${devServer.https ? 'https' : 'http'}://${devServer.public}`;
|
47 | const building = ora({
|
48 | text: 'Waiting for initial build to finish',
|
49 | enabled: global.interactive
|
50 | });
|
51 |
|
52 | spinner.succeed(`Development server running on: ${url}`);
|
53 | building.start();
|
54 | compiler.plugin('done', () => {
|
55 | building.succeed('Build completed');
|
56 | });
|
57 | compiler.plugin('compile', () => {
|
58 | building.text = 'Source changed, re-compiling';
|
59 | building.start();
|
60 | });
|
61 | }
|
62 | }
|
63 | });
|
64 | };
|