@roots/bud-compiler 4.7.0-7 → 5.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -31
- package/lib/cjs/Compiler/index.js +122 -80
- package/lib/cjs/Compiler/index.js.map +1 -1
- package/lib/cjs/index.js +13 -3
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/Compiler/index.js +116 -75
- package/lib/esm/Compiler/index.js.map +1 -1
- package/lib/esm/index.js +12 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/tsconfig-esm.tsbuildinfo +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -8
- package/types/Compiler/index.d.ts +63 -16
- package/types/Compiler/index.d.ts.map +1 -1
- package/types/index.d.ts +10 -2
- package/types/index.d.ts.map +1 -1
package/README.md
CHANGED
@@ -1,59 +1,74 @@
|
|
1
1
|
<p align="center">
|
2
|
-
<img alt="Bud" src="https://cdn.roots.io/app/uploads/logo-bud.svg" height="100"
|
2
|
+
<img alt="Bud" src="https://cdn.roots.io/app/uploads/logo-bud.svg" height="100" />
|
3
3
|
</p>
|
4
4
|
|
5
5
|
<p align="center">
|
6
|
-
<img
|
7
|
-
|
8
|
-
|
6
|
+
<img
|
7
|
+
alt="MIT License"
|
8
|
+
src="https://img.shields.io/github/license/roots/bud?color=%23525ddc&style=flat-square"
|
9
|
+
/>
|
10
|
+
<a href="https://app.fossa.com/projects/git%2Bgithub.com%2Froots%2Fbud?ref=badge_small" alt="FOSSA Status">
|
11
|
+
<img src="https://app.fossa.com/api/projects/git%2Bgithub.com%2Froots%2Fbud.svg?type=small"/>
|
12
|
+
</a>
|
13
|
+
<a href="https://www.npmjs.com/package/@roots/bud">
|
14
|
+
<img src="https://img.shields.io/npm/v/@roots/bud.svg?color=%23525ddc&style=flat-square" />
|
15
|
+
</a>
|
16
|
+
<a href="https://codecov.io/gh/roots/bud">
|
17
|
+
<img src="https://codecov.io/gh/roots/bud/branch/next/graph/badge.svg?token=DRJ28OD8XD"/>
|
9
18
|
</a>
|
10
|
-
<a href="https://
|
11
|
-
<img
|
19
|
+
<a href="https://twitter.com/rootswp">
|
20
|
+
<img
|
21
|
+
alt="Follow Roots"
|
22
|
+
src="https://img.shields.io/twitter/follow/rootswp.svg?color=%23525ddc&style=flat-square"
|
23
|
+
/>
|
12
24
|
</a>
|
13
25
|
</p>
|
14
26
|
|
27
|
+
|
15
28
|
<h1 align="center">
|
16
29
|
<strong>@roots/bud-compiler</strong>
|
17
30
|
</h1>
|
18
31
|
|
19
|
-
|
20
|
-
|
21
|
-
The compiler provides controls and renders Bud's built-in development server.
|
22
|
-
|
32
|
+
> Compilation handler
|
23
33
|
## Installation
|
24
34
|
|
25
|
-
|
26
|
-
|
35
|
+
Install **@roots/bud-compiler** to your project.
|
36
|
+
|
37
|
+
```shell
|
38
|
+
yarn add @roots/bud-compiler
|
27
39
|
```
|
28
40
|
|
29
|
-
##
|
41
|
+
## Documentation
|
30
42
|
|
31
|
-
|
43
|
+
For more information on utilizing this package [check out our dedicated docs](https://budjs.netlify.app)
|
32
44
|
|
33
|
-
|
45
|
+
## Community
|
34
46
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
47
|
+
Keep track of development and community news.
|
48
|
+
|
49
|
+
- Participate on the [Roots Discourse](https://discourse.roots.io)
|
50
|
+
- Follow [@rootswp on Twitter](https://twitter.com/rootswp)
|
51
|
+
- Read and subscribe to the [Roots blog](https://roots.io/blog/)
|
52
|
+
- Subscribe to the [Roots Newsletter](https://roots.io/subscribe/)
|
53
|
+
- Listen to the [Roots Radio podcast](https://roots.io/podcast/)
|
40
54
|
|
41
55
|
## Contributing
|
42
56
|
|
43
57
|
Contributions are welcome from everyone.
|
44
58
|
|
45
|
-
We have [
|
59
|
+
We have [contribution guidelines](https://github.com/roots/guidelines/blob/master/CONTRIBUTING.md) to help you get started.
|
46
60
|
|
47
|
-
##
|
61
|
+
## Sponsors
|
48
62
|
|
49
63
|
Help support our open-source development efforts by [becoming a patron](https://www.patreon.com/rootsdev).
|
50
64
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
65
|
+
<a href="https://kinsta.com/?kaid=OFDHAJIXUDIV"><img src="https://cdn.roots.io/app/uploads/kinsta.svg" alt="Kinsta" width="200" height="150"/></a>
|
66
|
+
<a href="https://k-m.com/"><img src="https://cdn.roots.io/app/uploads/km-digital.svg" alt="KM Digital" width="200" height="150"/></a>
|
67
|
+
<a href="https://carrot.com/"><img src="https://cdn.roots.io/app/uploads/carrot.svg" alt="Carrot" width="200" height="150"/></a>
|
68
|
+
<a href="https://www.c21redwood.com/"><img src="https://cdn.roots.io/app/uploads/c21redwood.svg" alt="C21 Redwood Realty" width="200" height="150"/></a>
|
69
|
+
<a href="https://wordpress.com/"><img src="https://cdn.roots.io/app/uploads/wordpress.svg" alt="WordPress.com" width="200" height="150"/></a>
|
70
|
+
<a href="https://icons8.com/"><img src="https://cdn.roots.io/app/uploads/icons8.svg" alt="Icons8" width="200" height="150"/></a>
|
71
|
+
<a href="https://www.harnessup.com/"><img src="https://cdn.roots.io/app/uploads/harness-software.svg" alt="Harness Software" width="200" height="150"/></a>
|
72
|
+
<a href="https://www.codersclan.com/"><img src="https://cdn.roots.io/app/uploads/coders-clan.svg" alt="Coders Clan" width="200" height="150"/></a>
|
73
|
+
<a href="https://generodigital.com/"><img src="https://cdn.roots.io/app/uploads/genero.svg" alt="Genero" width="200" height="150"/></a>
|
74
|
+
<a href="https://motto.ca/roots"><img src="https://cdn.roots.io/app/uploads/motto.svg" alt="Motto" width="200" height="150"/></a>
|
@@ -1,85 +1,131 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Compiler = void 0;
|
3
4
|
const tslib_1 = require("tslib");
|
4
5
|
const bud_framework_1 = require("@roots/bud-framework");
|
5
|
-
const webpack_1 = tslib_1.__importStar(require("webpack"));
|
6
|
-
const lodash_1 = require("lodash");
|
7
6
|
const autobind_decorator_1 = require("autobind-decorator");
|
8
|
-
|
7
|
+
const webpack_1 = require("webpack");
|
8
|
+
/**
|
9
|
+
* Initial state
|
10
|
+
*
|
11
|
+
* @public
|
12
|
+
*/
|
13
|
+
const INITIAL_STATS = {
|
14
|
+
assets: [],
|
15
|
+
errors: [],
|
16
|
+
warnings: [],
|
17
|
+
};
|
18
|
+
/**
|
19
|
+
* Wepback compilation controller class
|
20
|
+
*
|
21
|
+
* @public
|
22
|
+
*/
|
23
|
+
class Compiler extends bud_framework_1.Service {
|
9
24
|
constructor() {
|
10
25
|
super(...arguments);
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
26
|
+
/**
|
27
|
+
* Compilation stats
|
28
|
+
*
|
29
|
+
* @public
|
30
|
+
*/
|
31
|
+
this.stats = INITIAL_STATS;
|
32
|
+
/**
|
33
|
+
* True if compiler is already instantiated
|
34
|
+
*
|
35
|
+
* @public
|
36
|
+
*/
|
17
37
|
this.isCompiled = false;
|
18
38
|
}
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
get progress() {
|
26
|
-
return this._progress;
|
27
|
-
}
|
28
|
-
set progress(progress) {
|
29
|
-
this._progress = progress;
|
30
|
-
}
|
31
|
-
get instance() {
|
32
|
-
return this._instance;
|
33
|
-
}
|
34
|
-
set instance(instance) {
|
35
|
-
this._instance = instance;
|
36
|
-
}
|
39
|
+
/**
|
40
|
+
* {@inheritDoc @roots/bud-framework#Service.register}
|
41
|
+
*
|
42
|
+
* @public
|
43
|
+
* @decorator `@bind`
|
44
|
+
*/
|
37
45
|
register() {
|
38
|
-
this.app.hooks.on('
|
39
|
-
|
40
|
-
});
|
46
|
+
this.app.hooks.on('before', () => []);
|
47
|
+
this.app.hooks.on('after', () => []);
|
41
48
|
}
|
49
|
+
/**
|
50
|
+
* Initiates compilation
|
51
|
+
*
|
52
|
+
* @returns the compiler instance
|
53
|
+
*
|
54
|
+
* @public
|
55
|
+
* @decorator `@bind`
|
56
|
+
*/
|
42
57
|
compile() {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
config.push(parent);
|
52
|
-
}
|
53
|
-
this.app.children.getValues().forEach(child => {
|
54
|
-
var _a;
|
55
|
-
((_a = child === null || child === void 0 ? void 0 : child.build) === null || _a === void 0 ? void 0 : _a.config) && config.push(child.build.config);
|
56
|
-
});
|
57
|
-
this.app.info('Compilers: %s', config.map(({ name }) => name).join(' '));
|
58
|
-
config.forEach(cfg => {
|
59
|
-
var _a, _b, _c;
|
60
|
-
cfg.entry &&
|
61
|
-
this.app.info('%s entry count: %s', cfg.name, (_a = Object.entries(cfg.entry)) === null || _a === void 0 ? void 0 : _a.length);
|
62
|
-
((_c = (_b = cfg.module) === null || _b === void 0 ? void 0 : _b.rules[0]) === null || _c === void 0 ? void 0 : _c.oneOf) &&
|
63
|
-
this.app.info('%s rules count: %s', cfg.name, cfg.module.rules[0].oneOf.length);
|
64
|
-
});
|
65
|
-
return config;
|
58
|
+
let instance;
|
59
|
+
if (this.isCompiled)
|
60
|
+
this.instance.close(() => {
|
61
|
+
instance = this.setup(this.before());
|
62
|
+
});
|
63
|
+
else
|
64
|
+
instance = this.setup(this.before());
|
65
|
+
return instance;
|
66
66
|
}
|
67
|
+
/**
|
68
|
+
* @public
|
69
|
+
* @decorator `@bind`
|
70
|
+
*/
|
67
71
|
setup(config) {
|
68
|
-
this.instance =
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
this.instance = this.app.isDevelopment
|
73
|
+
? (0, webpack_1.webpack)(config, this.callback)
|
74
|
+
: (0, webpack_1.webpack)(config);
|
75
|
+
if (this.app.isProduction) {
|
76
|
+
this.instance.hooks.done.tap(this.app.name, stats => {
|
77
|
+
stats && Object.assign(this.stats, stats.toJson());
|
78
|
+
this.instance.close(err => {
|
79
|
+
err && this.stats.errors.push(err);
|
80
|
+
});
|
75
81
|
});
|
76
|
-
}
|
82
|
+
}
|
77
83
|
new webpack_1.ProgressPlugin((...args) => {
|
78
84
|
this.progress = args;
|
79
85
|
}).apply(this.instance);
|
80
|
-
this.app.hooks.filter('done');
|
81
86
|
return this.instance;
|
82
87
|
}
|
88
|
+
/**
|
89
|
+
* Returns final webpack configuration
|
90
|
+
*
|
91
|
+
* @public
|
92
|
+
* @decorator `@bind`
|
93
|
+
*/
|
94
|
+
before() {
|
95
|
+
const config = [];
|
96
|
+
this.stats = INITIAL_STATS;
|
97
|
+
this.isCompiled = true;
|
98
|
+
this.app.hooks.filter('before').map(cb => cb(this.app));
|
99
|
+
this.app.parent &&
|
100
|
+
this.app.error(`Trying to compile a child directly.`);
|
101
|
+
/**
|
102
|
+
* Attempt to use the parent instance in the compilation if there are entries
|
103
|
+
* registered to it or if it has no child instances registered.
|
104
|
+
*/
|
105
|
+
if (this.app.build.config.entry || !this.app.hasChildren) {
|
106
|
+
this.app.info('using parent compiler');
|
107
|
+
config.push(this.app.build.config);
|
108
|
+
}
|
109
|
+
/**
|
110
|
+
* If there are {@link Framework.children} instances, iterate through
|
111
|
+
* them and add to `config`
|
112
|
+
*/
|
113
|
+
this.app.hasChildren &&
|
114
|
+
this.app.children.getValues().map(({ build, name }) => {
|
115
|
+
name &&
|
116
|
+
(() => {
|
117
|
+
this.app.info(`using ${name} compiler`);
|
118
|
+
config.push(build.config);
|
119
|
+
})();
|
120
|
+
});
|
121
|
+
return config;
|
122
|
+
}
|
123
|
+
/**
|
124
|
+
* Compilation callback
|
125
|
+
*
|
126
|
+
* @public
|
127
|
+
* @decorator `@bind`
|
128
|
+
*/
|
83
129
|
callback(...args) {
|
84
130
|
/**
|
85
131
|
* production mode callback takes two parameters (webpack err and stats)
|
@@ -92,29 +138,25 @@ class default_1 extends bud_framework_1.Service {
|
|
92
138
|
this.app.when(stats, () => {
|
93
139
|
this.stats = stats.toJson(this.app.build.config.stats);
|
94
140
|
});
|
95
|
-
this.
|
96
|
-
|
97
|
-
|
98
|
-
this.app.when(this.app.store.get('ci'), () => {
|
99
|
-
stats && console.log(stats.toString());
|
100
|
-
err && console.error(err);
|
101
|
-
});
|
141
|
+
err && this.stats.errors.push(err);
|
142
|
+
const doneCallbacks = this.app.hooks.filter('done');
|
143
|
+
doneCallbacks === null || doneCallbacks === void 0 ? void 0 : doneCallbacks.map((cb) => cb(this.app));
|
102
144
|
}
|
103
145
|
}
|
104
|
-
tslib_1.__decorate([
|
146
|
+
(0, tslib_1.__decorate)([
|
105
147
|
autobind_decorator_1.boundMethod
|
106
|
-
],
|
107
|
-
tslib_1.__decorate([
|
148
|
+
], Compiler.prototype, "register", null);
|
149
|
+
(0, tslib_1.__decorate)([
|
108
150
|
autobind_decorator_1.boundMethod
|
109
|
-
],
|
110
|
-
tslib_1.__decorate([
|
151
|
+
], Compiler.prototype, "compile", null);
|
152
|
+
(0, tslib_1.__decorate)([
|
111
153
|
autobind_decorator_1.boundMethod
|
112
|
-
],
|
113
|
-
tslib_1.__decorate([
|
154
|
+
], Compiler.prototype, "setup", null);
|
155
|
+
(0, tslib_1.__decorate)([
|
114
156
|
autobind_decorator_1.boundMethod
|
115
|
-
],
|
116
|
-
tslib_1.__decorate([
|
157
|
+
], Compiler.prototype, "before", null);
|
158
|
+
(0, tslib_1.__decorate)([
|
117
159
|
autobind_decorator_1.boundMethod
|
118
|
-
],
|
119
|
-
exports.
|
160
|
+
], Compiler.prototype, "callback", null);
|
161
|
+
exports.Compiler = Compiler;
|
120
162
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Compiler/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Compiler/index.ts"],"names":[],"mappings":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D,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CACb,CAAA;IACH,CAAC;CACF;AA/HC;IADC,gCAAI;wCAIJ;AAWD;IADC,gCAAI;uCAWJ;AAOD;IADC,gCAAI;qCAqBJ;AASD;IADC,gCAAI;sCAoCJ;AASD;IADC,gCAAI;wCAuBJ;AAlKH,4BAmKC"}
|
package/lib/cjs/index.js
CHANGED
@@ -1,7 +1,17 @@
|
|
1
1
|
"use strict";
|
2
|
+
// Copyright (c) Roots Foundation, LLC. All rights reserved.
|
3
|
+
// Licensed under the MIT license.
|
2
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
5
|
exports.Compiler = void 0;
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
/**
|
7
|
+
* The {@link @roots/bud-compiler# | @roots/bud-compiler} package implements the
|
8
|
+
* {@link @roots/bud-framework#Compiler | Compiler interface}
|
9
|
+
*
|
10
|
+
* @see https://roots.io/bud
|
11
|
+
* @see https://github.com/roots/bud
|
12
|
+
*
|
13
|
+
* @core @packageDocumentation @betaDocumentation
|
14
|
+
*/
|
15
|
+
var Compiler_1 = require("./Compiler");
|
16
|
+
Object.defineProperty(exports, "Compiler", { enumerable: true, get: function () { return Compiler_1.Compiler; } });
|
7
17
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAElC;;;;;;;;GAQG;AAEH,uCAAmC;AAA3B,oGAAA,QAAQ,OAAA"}
|
@@ -1,83 +1,128 @@
|
|
1
1
|
import { __decorate } from "tslib";
|
2
|
-
import { Service } from '@roots/bud-framework';
|
3
|
-
import webpack, { ProgressPlugin } from 'webpack';
|
4
|
-
import { noop, isEqual } from 'lodash';
|
2
|
+
import { Service, } from '@roots/bud-framework';
|
5
3
|
import { boundMethod as bind } from 'autobind-decorator';
|
6
|
-
|
4
|
+
import { ProgressPlugin, webpack } from 'webpack';
|
5
|
+
/**
|
6
|
+
* Initial state
|
7
|
+
*
|
8
|
+
* @public
|
9
|
+
*/
|
10
|
+
const INITIAL_STATS = {
|
11
|
+
assets: [],
|
12
|
+
errors: [],
|
13
|
+
warnings: [],
|
14
|
+
};
|
15
|
+
/**
|
16
|
+
* Wepback compilation controller class
|
17
|
+
*
|
18
|
+
* @public
|
19
|
+
*/
|
20
|
+
export class Compiler extends Service {
|
7
21
|
constructor() {
|
8
22
|
super(...arguments);
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
23
|
+
/**
|
24
|
+
* Compilation stats
|
25
|
+
*
|
26
|
+
* @public
|
27
|
+
*/
|
28
|
+
this.stats = INITIAL_STATS;
|
29
|
+
/**
|
30
|
+
* True if compiler is already instantiated
|
31
|
+
*
|
32
|
+
* @public
|
33
|
+
*/
|
15
34
|
this.isCompiled = false;
|
16
35
|
}
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
get progress() {
|
24
|
-
return this._progress;
|
25
|
-
}
|
26
|
-
set progress(progress) {
|
27
|
-
this._progress = progress;
|
28
|
-
}
|
29
|
-
get instance() {
|
30
|
-
return this._instance;
|
31
|
-
}
|
32
|
-
set instance(instance) {
|
33
|
-
this._instance = instance;
|
34
|
-
}
|
36
|
+
/**
|
37
|
+
* {@inheritDoc @roots/bud-framework#Service.register}
|
38
|
+
*
|
39
|
+
* @public
|
40
|
+
* @decorator `@bind`
|
41
|
+
*/
|
35
42
|
register() {
|
36
|
-
this.app.hooks.on('
|
37
|
-
|
38
|
-
});
|
43
|
+
this.app.hooks.on('before', () => []);
|
44
|
+
this.app.hooks.on('after', () => []);
|
39
45
|
}
|
46
|
+
/**
|
47
|
+
* Initiates compilation
|
48
|
+
*
|
49
|
+
* @returns the compiler instance
|
50
|
+
*
|
51
|
+
* @public
|
52
|
+
* @decorator `@bind`
|
53
|
+
*/
|
40
54
|
compile() {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
config.push(parent);
|
50
|
-
}
|
51
|
-
this.app.children.getValues().forEach(child => {
|
52
|
-
var _a;
|
53
|
-
((_a = child === null || child === void 0 ? void 0 : child.build) === null || _a === void 0 ? void 0 : _a.config) && config.push(child.build.config);
|
54
|
-
});
|
55
|
-
this.app.info('Compilers: %s', config.map(({ name }) => name).join(' '));
|
56
|
-
config.forEach(cfg => {
|
57
|
-
var _a, _b, _c;
|
58
|
-
cfg.entry &&
|
59
|
-
this.app.info('%s entry count: %s', cfg.name, (_a = Object.entries(cfg.entry)) === null || _a === void 0 ? void 0 : _a.length);
|
60
|
-
((_c = (_b = cfg.module) === null || _b === void 0 ? void 0 : _b.rules[0]) === null || _c === void 0 ? void 0 : _c.oneOf) &&
|
61
|
-
this.app.info('%s rules count: %s', cfg.name, cfg.module.rules[0].oneOf.length);
|
62
|
-
});
|
63
|
-
return config;
|
55
|
+
let instance;
|
56
|
+
if (this.isCompiled)
|
57
|
+
this.instance.close(() => {
|
58
|
+
instance = this.setup(this.before());
|
59
|
+
});
|
60
|
+
else
|
61
|
+
instance = this.setup(this.before());
|
62
|
+
return instance;
|
64
63
|
}
|
64
|
+
/**
|
65
|
+
* @public
|
66
|
+
* @decorator `@bind`
|
67
|
+
*/
|
65
68
|
setup(config) {
|
66
|
-
this.instance =
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
this.instance = this.app.isDevelopment
|
70
|
+
? webpack(config, this.callback)
|
71
|
+
: webpack(config);
|
72
|
+
if (this.app.isProduction) {
|
73
|
+
this.instance.hooks.done.tap(this.app.name, stats => {
|
74
|
+
stats && Object.assign(this.stats, stats.toJson());
|
75
|
+
this.instance.close(err => {
|
76
|
+
err && this.stats.errors.push(err);
|
77
|
+
});
|
73
78
|
});
|
74
|
-
}
|
79
|
+
}
|
75
80
|
new ProgressPlugin((...args) => {
|
76
81
|
this.progress = args;
|
77
82
|
}).apply(this.instance);
|
78
|
-
this.app.hooks.filter('done');
|
79
83
|
return this.instance;
|
80
84
|
}
|
85
|
+
/**
|
86
|
+
* Returns final webpack configuration
|
87
|
+
*
|
88
|
+
* @public
|
89
|
+
* @decorator `@bind`
|
90
|
+
*/
|
91
|
+
before() {
|
92
|
+
const config = [];
|
93
|
+
this.stats = INITIAL_STATS;
|
94
|
+
this.isCompiled = true;
|
95
|
+
this.app.hooks.filter('before').map(cb => cb(this.app));
|
96
|
+
this.app.parent &&
|
97
|
+
this.app.error(`Trying to compile a child directly.`);
|
98
|
+
/**
|
99
|
+
* Attempt to use the parent instance in the compilation if there are entries
|
100
|
+
* registered to it or if it has no child instances registered.
|
101
|
+
*/
|
102
|
+
if (this.app.build.config.entry || !this.app.hasChildren) {
|
103
|
+
this.app.info('using parent compiler');
|
104
|
+
config.push(this.app.build.config);
|
105
|
+
}
|
106
|
+
/**
|
107
|
+
* If there are {@link Framework.children} instances, iterate through
|
108
|
+
* them and add to `config`
|
109
|
+
*/
|
110
|
+
this.app.hasChildren &&
|
111
|
+
this.app.children.getValues().map(({ build, name }) => {
|
112
|
+
name &&
|
113
|
+
(() => {
|
114
|
+
this.app.info(`using ${name} compiler`);
|
115
|
+
config.push(build.config);
|
116
|
+
})();
|
117
|
+
});
|
118
|
+
return config;
|
119
|
+
}
|
120
|
+
/**
|
121
|
+
* Compilation callback
|
122
|
+
*
|
123
|
+
* @public
|
124
|
+
* @decorator `@bind`
|
125
|
+
*/
|
81
126
|
callback(...args) {
|
82
127
|
/**
|
83
128
|
* production mode callback takes two parameters (webpack err and stats)
|
@@ -90,28 +135,24 @@ export default class default_1 extends Service {
|
|
90
135
|
this.app.when(stats, () => {
|
91
136
|
this.stats = stats.toJson(this.app.build.config.stats);
|
92
137
|
});
|
93
|
-
this.
|
94
|
-
|
95
|
-
|
96
|
-
this.app.when(this.app.store.get('ci'), () => {
|
97
|
-
stats && console.log(stats.toString());
|
98
|
-
err && console.error(err);
|
99
|
-
});
|
138
|
+
err && this.stats.errors.push(err);
|
139
|
+
const doneCallbacks = this.app.hooks.filter('done');
|
140
|
+
doneCallbacks === null || doneCallbacks === void 0 ? void 0 : doneCallbacks.map((cb) => cb(this.app));
|
100
141
|
}
|
101
142
|
}
|
102
143
|
__decorate([
|
103
144
|
bind
|
104
|
-
],
|
145
|
+
], Compiler.prototype, "register", null);
|
105
146
|
__decorate([
|
106
147
|
bind
|
107
|
-
],
|
148
|
+
], Compiler.prototype, "compile", null);
|
108
149
|
__decorate([
|
109
150
|
bind
|
110
|
-
],
|
151
|
+
], Compiler.prototype, "setup", null);
|
111
152
|
__decorate([
|
112
153
|
bind
|
113
|
-
],
|
154
|
+
], Compiler.prototype, "before", null);
|
114
155
|
__decorate([
|
115
156
|
bind
|
116
|
-
],
|
157
|
+
], Compiler.prototype, "callback", null);
|
117
158
|
//# sourceMappingURL=index.js.map
|