@roots/bud-build 5.3.2 → 5.6.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 +1 -1
- package/lib/cjs/Build/config/builder.js +117 -0
- package/lib/cjs/Build/config/builder.unwrap.js +35 -0
- package/lib/cjs/Build/config/filenameFormat.js +17 -0
- package/lib/cjs/Build/config/index.js +24 -0
- package/lib/cjs/Build/index.js +157 -50
- package/lib/cjs/Build/items.js +101 -111
- package/lib/cjs/Build/loaders.js +55 -53
- package/lib/cjs/Build/rules.js +18 -25
- package/lib/cjs/Item/index.js +36 -24
- package/lib/cjs/Loader/index.js +10 -56
- package/lib/cjs/Rule/index.js +29 -43
- package/lib/cjs/index.js +1 -8
- package/lib/cjs/shared/Base.js +10 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/types/Build/config/builder.d.ts +15 -0
- package/types/Build/config/builder.d.ts.map +1 -0
- package/types/Build/config/builder.unwrap.d.ts +19 -0
- package/types/Build/config/builder.unwrap.d.ts.map +1 -0
- package/types/Build/config/filenameFormat.d.ts +13 -0
- package/types/Build/config/filenameFormat.d.ts.map +1 -0
- package/types/Build/config/index.d.ts +3 -0
- package/types/Build/config/index.d.ts.map +1 -0
- package/types/Build/index.d.ts +66 -15
- package/types/Build/index.d.ts.map +1 -1
- package/types/Build/items.d.ts +62 -71
- package/types/Build/items.d.ts.map +1 -1
- package/types/Build/loaders.d.ts +45 -54
- package/types/Build/loaders.d.ts.map +1 -1
- package/types/Build/rules.d.ts +13 -14
- package/types/Build/rules.d.ts.map +1 -1
- package/types/Item/index.d.ts +19 -11
- package/types/Item/index.d.ts.map +1 -1
- package/types/Loader/index.d.ts +10 -24
- package/types/Loader/index.d.ts.map +1 -1
- package/types/Rule/index.d.ts +25 -33
- package/types/Rule/index.d.ts.map +1 -1
- package/types/index.d.ts +1 -8
- package/types/index.d.ts.map +1 -1
- package/types/shared/Base.d.ts +5 -1
- package/types/shared/Base.d.ts.map +1 -1
- package/lib/cjs/Build/config.js +0 -265
- package/lib/cjs/Item/item.dependencies.js +0 -6
- package/lib/cjs/Item/item.interface.js +0 -7
- package/types/Build/config.d.ts +0 -10
- package/types/Build/config.d.ts.map +0 -1
- package/types/Item/item.dependencies.d.ts +0 -4
- package/types/Item/item.dependencies.d.ts.map +0 -1
- package/types/Item/item.interface.d.ts +0 -2
- package/types/Item/item.interface.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ yarn add @roots/bud-build --dev
|
|
|
24
24
|
|
|
25
25
|
## Documentation
|
|
26
26
|
|
|
27
|
-
For more information on utilizing this package [check out our dedicated docs](https://
|
|
27
|
+
For more information on utilizing this package [check out our dedicated docs](https://bud.js.org)
|
|
28
28
|
|
|
29
29
|
## Community
|
|
30
30
|
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.build = void 0;
|
|
4
|
+
const builder_unwrap_1 = require("./builder.unwrap");
|
|
5
|
+
const filenameFormat_1 = require("./filenameFormat");
|
|
6
|
+
/**
|
|
7
|
+
* Initializes configuration builder hooks
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* All hooks in the `build` namespace are initialized here with
|
|
11
|
+
* the exception of `build.cache` which is handled in {@link Framework.cache}
|
|
12
|
+
*
|
|
13
|
+
* @param app - the Framework instance
|
|
14
|
+
* @returns Promise
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
async function build(app) {
|
|
19
|
+
/**
|
|
20
|
+
* App bound unwrap
|
|
21
|
+
*/
|
|
22
|
+
const unwrap = builder_unwrap_1.unwrap.bind(app);
|
|
23
|
+
app.hooks
|
|
24
|
+
.on('build.cache', () => app.cache.configuration)
|
|
25
|
+
.hooks.on('build.context', () => app.context.projectDir)
|
|
26
|
+
.hooks.on('build.mode', app.mode)
|
|
27
|
+
.hooks.on('build.module', () => ({
|
|
28
|
+
noParse: app.hooks.filter('build.module.noParse'),
|
|
29
|
+
rules: app.hooks.filter('build.module.rules'),
|
|
30
|
+
unsafeCache: app.hooks.filter('build.module.unsafeCache'),
|
|
31
|
+
}))
|
|
32
|
+
.hooks.on('build.module.rules', () => [
|
|
33
|
+
...app.hooks.filter('build.module.rules.before'),
|
|
34
|
+
{
|
|
35
|
+
oneOf: app.hooks.filter('build.module.rules.oneOf'),
|
|
36
|
+
},
|
|
37
|
+
...app.hooks.filter('build.module.rules.after'),
|
|
38
|
+
])
|
|
39
|
+
.hooks.on('build.module.rules.oneOf', () => Object.values(app.build.rules).map(rule => rule.toWebpack()))
|
|
40
|
+
.hooks.on('build.name', app.name)
|
|
41
|
+
.hooks.on('build.output', () => ({
|
|
42
|
+
assetModuleFilename: app.hooks.filter('build.output.assetModuleFilename'),
|
|
43
|
+
chunkFilename: app.hooks.filter('build.output.chunkFilename'),
|
|
44
|
+
clean: app.hooks.filter('build.output.clean'),
|
|
45
|
+
filename: app.hooks.filter('build.output.filename'),
|
|
46
|
+
path: app.hooks.filter('build.output.path'),
|
|
47
|
+
pathinfo: app.hooks.filter('build.output.pathinfo'),
|
|
48
|
+
publicPath: app.hooks.filter('build.output.publicPath'),
|
|
49
|
+
}))
|
|
50
|
+
.hooks.on('build.output.assetModuleFilename', () => (0, filenameFormat_1.filenameFormat)(app, '[ext]'))
|
|
51
|
+
.hooks.on('build.output.chunkFilename', () => (0, filenameFormat_1.filenameFormat)(app))
|
|
52
|
+
.hooks.on('build.output.filename', () => (0, filenameFormat_1.filenameFormat)(app))
|
|
53
|
+
.hooks.on('build.output.path', () => app.path('@dist'))
|
|
54
|
+
.hooks.on('build.optimization', () => ({
|
|
55
|
+
emitOnErrors: app.hooks.filter('build.optimization.emitOnErrors'),
|
|
56
|
+
minimize: app.hooks.filter('build.optimization.minimize'),
|
|
57
|
+
minimizer: app.hooks.filter('build.optimization.minimizer'),
|
|
58
|
+
moduleIds: app.hooks.filter('build.optimization.moduleIds'),
|
|
59
|
+
runtimeChunk: app.hooks.filter('build.optimization.runtimeChunk'),
|
|
60
|
+
splitChunks: app.hooks.filter('build.optimization.splitChunks'),
|
|
61
|
+
}))
|
|
62
|
+
.hooks.async('build.plugins', async () => await app.extensions.make())
|
|
63
|
+
.hooks.on('build.recordsPath', () => app.path(`@storage/${app.name}/modules.json`))
|
|
64
|
+
.hooks.async('build.resolve', async () => {
|
|
65
|
+
const alias = await app.hooks.filterAsync('build.resolve.alias');
|
|
66
|
+
const extensions = Array.from(app.hooks.filter('build.resolve.extensions'));
|
|
67
|
+
const modules = await app.hooks.filterAsync('build.resolve.modules');
|
|
68
|
+
return { alias, extensions, modules };
|
|
69
|
+
})
|
|
70
|
+
.hooks.async('build.resolve.modules', async (value) => {
|
|
71
|
+
return Array.from(new Set([
|
|
72
|
+
...(value ?? []),
|
|
73
|
+
app.hooks.filter('location.@src'),
|
|
74
|
+
app.hooks.filter('location.@modules'),
|
|
75
|
+
]));
|
|
76
|
+
})
|
|
77
|
+
.hooks.on('build.target', () => app.project.has('manifest.browserslist') &&
|
|
78
|
+
app.project.isArray('manifest.browserslist')
|
|
79
|
+
? `browserslist:${app.path('package.json')}`
|
|
80
|
+
: undefined)
|
|
81
|
+
.hooks.on('build.infrastructureLogging', () => ({
|
|
82
|
+
console: app.hooks.filter('build.infrastructureLogging.console'),
|
|
83
|
+
}));
|
|
84
|
+
/**
|
|
85
|
+
* Safe
|
|
86
|
+
*/
|
|
87
|
+
app.hooks
|
|
88
|
+
.on('build.bail', unwrap('build.bail'))
|
|
89
|
+
.hooks.on('build.devtool', unwrap('build.devtool'))
|
|
90
|
+
.hooks.on('build.loader', unwrap('build.loader'))
|
|
91
|
+
.hooks.on('build.module.rules.before', unwrap('build.module.rules.before'))
|
|
92
|
+
.hooks.on('build.module.rules.after', unwrap('build.module.rules.after'))
|
|
93
|
+
.hooks.on('build.module.unsafeCache', unwrap('build.module.unsafeCache'))
|
|
94
|
+
.hooks.on('build.module.noParse', unwrap('build.module.noParse'))
|
|
95
|
+
.hooks.on('build.infrastructureLogging.level', unwrap('build.infrastructureLogging.level'))
|
|
96
|
+
.hooks.on('build.infrastructureLogging.console', unwrap('build.infrastructureLogging.console'))
|
|
97
|
+
.hooks.on('build.node', unwrap('build.node'))
|
|
98
|
+
.hooks.on('build.optimization.emitOnErrors', unwrap('build.optimization.emitOnErrors'))
|
|
99
|
+
.hooks.on('build.optimization.minimize', unwrap('build.optimization.minimize'))
|
|
100
|
+
.hooks.on('build.optimization.minimizer', unwrap('build.optimization.minimizer'))
|
|
101
|
+
.hooks.on('build.optimization.moduleIds', unwrap('build.optimization.moduleIds'))
|
|
102
|
+
.hooks.on('build.optimization.removeEmptyChunks', unwrap('build.optimization.removeEmptyChunks'))
|
|
103
|
+
.hooks.on('build.optimization.runtimeChunk', unwrap('build.optimization.runtimeChunk'))
|
|
104
|
+
.hooks.on('build.optimization.splitChunks', unwrap('build.optimization.splitChunks'))
|
|
105
|
+
.hooks.on('build.output.clean', unwrap('build.output.clean'))
|
|
106
|
+
.hooks.on('build.output.pathinfo', unwrap('build.output.pathinfo'))
|
|
107
|
+
.hooks.on('build.output.publicPath', unwrap('build.output.publicPath', 'auto'))
|
|
108
|
+
.hooks.on('build.parallelism', unwrap('build.parallelism'))
|
|
109
|
+
.hooks.on('build.performance', unwrap('build.performance'))
|
|
110
|
+
.hooks.on('build.profile', unwrap('build.profile'))
|
|
111
|
+
.hooks.async('build.resolve.alias', unwrap('build.resolve.alias'))
|
|
112
|
+
.hooks.on('build.resolve.extensions', unwrap('build.resolve.extensions'))
|
|
113
|
+
.hooks.on('build.stats', unwrap('build.stats'))
|
|
114
|
+
.hooks.on('build.watch', unwrap('build.watch'))
|
|
115
|
+
.hooks.on('build.watchOptions', unwrap('build.watchOptions'));
|
|
116
|
+
}
|
|
117
|
+
exports.build = build;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unwrap = void 0;
|
|
4
|
+
const bud_support_1 = require("@roots/bud-support");
|
|
5
|
+
const { isUndefined } = bud_support_1.lodash;
|
|
6
|
+
/**
|
|
7
|
+
* Unwrap initialValue
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Returns the initializing value for a hook
|
|
11
|
+
* If the value is available from {@link Framework.store}, the store value is used.
|
|
12
|
+
* Otherwise, it will return the fallback value (if supplied)
|
|
13
|
+
*
|
|
14
|
+
* @param this - Application
|
|
15
|
+
* @param key - store key
|
|
16
|
+
* @param fallback - fallback value
|
|
17
|
+
* @returns hook function
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
function unwrap(key, fallback) {
|
|
22
|
+
return (value) => {
|
|
23
|
+
const initValue = this.store.has(key)
|
|
24
|
+
? this.maybeCall(this.store.get(key))
|
|
25
|
+
: value;
|
|
26
|
+
if (!isUndefined(initValue)) {
|
|
27
|
+
return initValue;
|
|
28
|
+
}
|
|
29
|
+
if (!isUndefined(fallback)) {
|
|
30
|
+
return fallback;
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.unwrap = unwrap;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filenameFormat = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Filename
|
|
6
|
+
*
|
|
7
|
+
* @param app - Framework
|
|
8
|
+
* @param ext - Filename extension
|
|
9
|
+
*
|
|
10
|
+
* @returns filename format
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
const filenameFormat = (app, ext) => app.store.is('features.hash', true)
|
|
15
|
+
? app.store.get('hashFormat').concat(ext ?? '.js')
|
|
16
|
+
: app.store.get('fileFormat').concat(ext ?? '.js');
|
|
17
|
+
exports.filenameFormat = filenameFormat;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.builder = void 0;
|
|
23
|
+
const builder = __importStar(require("./builder"));
|
|
24
|
+
exports.builder = builder;
|
package/lib/cjs/Build/index.js
CHANGED
|
@@ -24,26 +24,33 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
__setModuleDefault(result, mod);
|
|
25
25
|
return result;
|
|
26
26
|
};
|
|
27
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
-
};
|
|
30
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
28
|
exports.Build = void 0;
|
|
32
|
-
const
|
|
29
|
+
const Framework = __importStar(require("@roots/bud-framework"));
|
|
33
30
|
const bud_support_1 = require("@roots/bud-support");
|
|
31
|
+
const lodash_1 = require("lodash");
|
|
32
|
+
const Item_1 = require("../Item");
|
|
33
|
+
const Loader_1 = require("../Loader");
|
|
34
34
|
const Rule_1 = require("../Rule");
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
35
|
+
const config = __importStar(require("./config"));
|
|
36
|
+
const items = __importStar(require("./items"));
|
|
37
|
+
const loaders = __importStar(require("./loaders"));
|
|
38
38
|
const rules = __importStar(require("./rules"));
|
|
39
|
-
const {
|
|
39
|
+
const { isUndefined } = bud_support_1.lodash;
|
|
40
40
|
const { ensureFile, writeFile } = bud_support_1.fs;
|
|
41
41
|
/**
|
|
42
42
|
* Webpack configuration builder class
|
|
43
43
|
*
|
|
44
44
|
* @public
|
|
45
45
|
*/
|
|
46
|
-
class Build extends
|
|
46
|
+
class Build extends Framework.Service {
|
|
47
|
+
constructor() {
|
|
48
|
+
super(...arguments);
|
|
49
|
+
/**
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
this.config = {};
|
|
53
|
+
}
|
|
47
54
|
/**
|
|
48
55
|
* Service booted event
|
|
49
56
|
*
|
|
@@ -51,7 +58,10 @@ class Build extends bud_framework_1.Service {
|
|
|
51
58
|
* @decorator `@bind`
|
|
52
59
|
*/
|
|
53
60
|
async registered() {
|
|
54
|
-
this.app.hooks
|
|
61
|
+
this.app.hooks
|
|
62
|
+
.action('event.build.before', async (app) => app.time(`build.make`))
|
|
63
|
+
.hooks.action('event.build.after', async (app) => app.timeEnd(`build.make`))
|
|
64
|
+
.hooks.action('event.build.after', this.writeFinalConfig);
|
|
55
65
|
}
|
|
56
66
|
/**
|
|
57
67
|
* Make webpack configuration
|
|
@@ -60,28 +70,58 @@ class Build extends bud_framework_1.Service {
|
|
|
60
70
|
* @decorator `@bind`
|
|
61
71
|
*/
|
|
62
72
|
async make() {
|
|
63
|
-
await this.app.hooks.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
await this.app.hooks.fire('event.build.before');
|
|
74
|
+
await Promise.all([
|
|
75
|
+
['entry', true],
|
|
76
|
+
['plugins', true],
|
|
77
|
+
['resolve', true],
|
|
78
|
+
['bail'],
|
|
79
|
+
['cache'],
|
|
80
|
+
['context'],
|
|
81
|
+
['devtool'],
|
|
82
|
+
['experiments'],
|
|
83
|
+
['externals'],
|
|
84
|
+
['infrastructureLogging'],
|
|
85
|
+
['loader'],
|
|
86
|
+
['mode'],
|
|
87
|
+
['module'],
|
|
88
|
+
['name'],
|
|
89
|
+
['node'],
|
|
90
|
+
['output'],
|
|
91
|
+
['optimization'],
|
|
92
|
+
['parallelism'],
|
|
93
|
+
['performance'],
|
|
94
|
+
['profile'],
|
|
95
|
+
['recordsPath'],
|
|
96
|
+
['stats'],
|
|
97
|
+
['target'],
|
|
98
|
+
['watch'],
|
|
99
|
+
['watchOptions'],
|
|
100
|
+
]
|
|
101
|
+
.map(this.memoMap)
|
|
102
|
+
.filter(Boolean)
|
|
103
|
+
.map(this.memoMapValue));
|
|
104
|
+
await this.app.hooks.fire('event.build.after');
|
|
83
105
|
return this.config;
|
|
84
106
|
}
|
|
107
|
+
memoMap(...args) {
|
|
108
|
+
const [[key, ...rest]] = args;
|
|
109
|
+
if (!this.app.hooks.has(`build.${key}`))
|
|
110
|
+
return false;
|
|
111
|
+
const type = rest.length && rest.shift() ? 'async' : 'sync';
|
|
112
|
+
const count = this.app.hooks.count(`build.${key}`);
|
|
113
|
+
return [key, type, count];
|
|
114
|
+
}
|
|
115
|
+
async memoMapValue([propKey, type, _count]) {
|
|
116
|
+
const propValue = type == 'async'
|
|
117
|
+
? await this.app.hooks.filterAsync(`build.${propKey}`)
|
|
118
|
+
: this.app.hooks.filter(`build.${propKey}`);
|
|
119
|
+
if (isUndefined(propValue))
|
|
120
|
+
return;
|
|
121
|
+
Object.assign(this.config, {
|
|
122
|
+
[propKey]: propValue,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
85
125
|
/**
|
|
86
126
|
* Service register event
|
|
87
127
|
*
|
|
@@ -95,7 +135,7 @@ class Build extends bud_framework_1.Service {
|
|
|
95
135
|
});
|
|
96
136
|
Object.assign(this, {
|
|
97
137
|
loaders: this.app
|
|
98
|
-
.container(
|
|
138
|
+
.container(loaders)
|
|
99
139
|
.getEntries()
|
|
100
140
|
.reduce(reducer, this.loaders),
|
|
101
141
|
rules: this.app
|
|
@@ -103,39 +143,92 @@ class Build extends bud_framework_1.Service {
|
|
|
103
143
|
.getEntries()
|
|
104
144
|
.reduce(reducer, this.rules),
|
|
105
145
|
items: this.app
|
|
106
|
-
.container(
|
|
146
|
+
.container(items)
|
|
107
147
|
.getEntries()
|
|
108
148
|
.reduce(reducer, this.items),
|
|
109
149
|
});
|
|
110
|
-
await
|
|
150
|
+
await config.builder.build(this.app);
|
|
111
151
|
}
|
|
112
152
|
/**
|
|
113
153
|
* Set a rule
|
|
114
154
|
*
|
|
115
155
|
* @param name - rule key
|
|
116
|
-
* @param
|
|
156
|
+
* @param options - rule constructor properties
|
|
117
157
|
* @returns the rule
|
|
118
158
|
*
|
|
119
159
|
* @public
|
|
120
160
|
* @decorator `@bind`
|
|
121
161
|
*/
|
|
122
|
-
setRule(name,
|
|
123
|
-
Object.assign(this.rules, {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
162
|
+
setRule(name, options) {
|
|
163
|
+
Object.assign(this.rules, { [name]: this.makeRule(options) });
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Make a rule
|
|
168
|
+
*
|
|
169
|
+
* @param options - rule constructor properties
|
|
170
|
+
* @returns the rule
|
|
171
|
+
*
|
|
172
|
+
* @public
|
|
173
|
+
* @decorator `@bind`
|
|
174
|
+
*/
|
|
175
|
+
makeRule(options) {
|
|
176
|
+
return new Rule_1.Rule(() => this.app, options);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Set a rule
|
|
180
|
+
*
|
|
181
|
+
* @param name - rule key
|
|
182
|
+
* @param options - rule constructor properties
|
|
183
|
+
* @returns the rule
|
|
184
|
+
*
|
|
185
|
+
* @public
|
|
186
|
+
* @decorator `@bind`
|
|
187
|
+
*/
|
|
188
|
+
setLoader(name, options) {
|
|
189
|
+
Object.assign(this.loaders, { [name]: this.makeLoader(options) });
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Make a rule
|
|
194
|
+
*
|
|
195
|
+
* @param options - rule constructor properties
|
|
196
|
+
* @returns the rule
|
|
197
|
+
*
|
|
198
|
+
* @public
|
|
199
|
+
* @decorator `@bind`
|
|
200
|
+
*/
|
|
201
|
+
makeLoader(options) {
|
|
202
|
+
return new Loader_1.Loader(() => this.app, options);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Set a rule
|
|
206
|
+
*
|
|
207
|
+
* @param name - rule key
|
|
208
|
+
* @param options - rule constructor properties
|
|
209
|
+
* @returns the rule
|
|
210
|
+
*
|
|
211
|
+
* @public
|
|
212
|
+
* @decorator `@bind`
|
|
213
|
+
*/
|
|
214
|
+
setItem(name, options) {
|
|
215
|
+
const processedOptions = (0, lodash_1.isFunction)(options)
|
|
216
|
+
? options(this.makeItem())
|
|
217
|
+
: this.makeItem(options);
|
|
218
|
+
Object.assign(this.items, { [name]: processedOptions });
|
|
219
|
+
return this;
|
|
127
220
|
}
|
|
128
221
|
/**
|
|
129
222
|
* Make a rule
|
|
130
223
|
*
|
|
131
|
-
* @param
|
|
224
|
+
* @param options - rule constructor properties
|
|
132
225
|
* @returns the rule
|
|
133
226
|
*
|
|
134
227
|
* @public
|
|
135
228
|
* @decorator `@bind`
|
|
136
229
|
*/
|
|
137
|
-
|
|
138
|
-
return new
|
|
230
|
+
makeItem(options) {
|
|
231
|
+
return new Item_1.Item(() => this.app, options);
|
|
139
232
|
}
|
|
140
233
|
/**
|
|
141
234
|
* Write final configuration to storage directory
|
|
@@ -145,17 +238,12 @@ class Build extends bud_framework_1.Service {
|
|
|
145
238
|
*/
|
|
146
239
|
async writeFinalConfig() {
|
|
147
240
|
try {
|
|
148
|
-
const filePath = this.app.path(
|
|
149
|
-
this.log('log', {
|
|
150
|
-
message: `writing webpack dump to disk`,
|
|
151
|
-
suffix: filePath,
|
|
152
|
-
});
|
|
241
|
+
const filePath = this.app.path(`@storage/${this.config.name}/webpack.config.js`);
|
|
153
242
|
await ensureFile(filePath);
|
|
154
|
-
await writeFile(filePath, `module.exports =
|
|
243
|
+
await writeFile(filePath, `module.exports = ${this.app.json.stringify(this.config, null, 2)}`);
|
|
155
244
|
}
|
|
156
245
|
catch (error) {
|
|
157
|
-
this.
|
|
158
|
-
this.log(`error`, error);
|
|
246
|
+
this.app.error(`failed to write webpack.config.json`);
|
|
159
247
|
}
|
|
160
248
|
}
|
|
161
249
|
}
|
|
@@ -165,6 +253,13 @@ __decorate([
|
|
|
165
253
|
__decorate([
|
|
166
254
|
bud_support_1.bind
|
|
167
255
|
], Build.prototype, "make", null);
|
|
256
|
+
__decorate([
|
|
257
|
+
bud_support_1.bind
|
|
258
|
+
], Build.prototype, "memoMap", null);
|
|
259
|
+
__decorate([
|
|
260
|
+
bud_support_1.bind,
|
|
261
|
+
(0, bud_support_1.memo)()
|
|
262
|
+
], Build.prototype, "memoMapValue", null);
|
|
168
263
|
__decorate([
|
|
169
264
|
bud_support_1.bind
|
|
170
265
|
], Build.prototype, "register", null);
|
|
@@ -174,6 +269,18 @@ __decorate([
|
|
|
174
269
|
__decorate([
|
|
175
270
|
bud_support_1.bind
|
|
176
271
|
], Build.prototype, "makeRule", null);
|
|
272
|
+
__decorate([
|
|
273
|
+
bud_support_1.bind
|
|
274
|
+
], Build.prototype, "setLoader", null);
|
|
275
|
+
__decorate([
|
|
276
|
+
bud_support_1.bind
|
|
277
|
+
], Build.prototype, "makeLoader", null);
|
|
278
|
+
__decorate([
|
|
279
|
+
bud_support_1.bind
|
|
280
|
+
], Build.prototype, "setItem", null);
|
|
281
|
+
__decorate([
|
|
282
|
+
bud_support_1.bind
|
|
283
|
+
], Build.prototype, "makeItem", null);
|
|
177
284
|
__decorate([
|
|
178
285
|
bud_support_1.bind
|
|
179
286
|
], Build.prototype, "writeFinalConfig", null);
|