@ngtools/webpack 13.0.0 → 13.0.4
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
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# Angular Compiler Webpack Plugin
|
|
2
2
|
|
|
3
3
|
Webpack 5.x plugin for the Angular Ahead-of-Time compiler. The plugin also supports Angular JIT mode.
|
|
4
|
+
When this plugin is used outside of the Angular CLI, the Ivy linker will also be needed to support
|
|
5
|
+
the usage of Angular libraries. An example configuration of the Babel-based Ivy linker is provided
|
|
6
|
+
in the linker section. For additional information regarding the linker, please see: https://v13.angular.io/guide/creating-libraries#consuming-partial-ivy-code-outside-the-angular-cli
|
|
4
7
|
|
|
5
8
|
## Usage
|
|
6
9
|
|
|
@@ -13,6 +16,7 @@ exports = {
|
|
|
13
16
|
/* ... */
|
|
14
17
|
module: {
|
|
15
18
|
rules: [
|
|
19
|
+
/* ... */
|
|
16
20
|
{
|
|
17
21
|
test: /\.[jt]sx?$/,
|
|
18
22
|
loader: '@ngtools/webpack',
|
|
@@ -23,6 +27,7 @@ exports = {
|
|
|
23
27
|
plugins: [
|
|
24
28
|
new AngularWebpackPlugin({
|
|
25
29
|
tsconfig: 'path/to/tsconfig.json',
|
|
30
|
+
// ... other options as needed
|
|
26
31
|
}),
|
|
27
32
|
],
|
|
28
33
|
};
|
|
@@ -38,3 +43,38 @@ The loader works with webpack plugin to compile the application's TypeScript. It
|
|
|
38
43
|
- `directTemplateLoading` [default: `true`] - Causes the plugin to load component templates (HTML) directly from the filesystem. This is more efficient if only using the `raw-loader` to load component templates. Do not enable this option if additional loaders are configured for component templates.
|
|
39
44
|
- `fileReplacements` [default: none] - Allows replacing TypeScript files with other TypeScript files in the build. This option acts on fully resolved file paths.
|
|
40
45
|
- `inlineStyleFileExtension` [default: none] - When set inline component styles will be processed by Webpack as files with the provided extension.
|
|
46
|
+
|
|
47
|
+
## Ivy Linker
|
|
48
|
+
|
|
49
|
+
The Ivy linker can be setup by using the Webpack `babel-loader` package.
|
|
50
|
+
If not already installed, add the `babel-loader` package using your project's package manager.
|
|
51
|
+
Then in your webpack config, add the `babel-loader` with the following configuration.
|
|
52
|
+
If the `babel-loader` is already present in your configuration, the linker plugin can be added to
|
|
53
|
+
the existing loader configuration as well.
|
|
54
|
+
Enabling caching for the `babel-loader` is recommended to avoid reprocessing libraries on
|
|
55
|
+
every build.
|
|
56
|
+
For additional information regarding the `babel-loader` package, please see: https://github.com/babel/babel-loader/tree/main#readme
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import linkerPlugin from '@angular/compiler-cli/linker/babel';
|
|
60
|
+
|
|
61
|
+
exports = {
|
|
62
|
+
/* ... */
|
|
63
|
+
module: {
|
|
64
|
+
rules: [
|
|
65
|
+
/* ... */
|
|
66
|
+
{
|
|
67
|
+
test: /\.[cm]?js$/,
|
|
68
|
+
use: {
|
|
69
|
+
loader: 'babel-loader',
|
|
70
|
+
options: {
|
|
71
|
+
cacheDirectory: true,
|
|
72
|
+
compact: false,
|
|
73
|
+
plugins: [linkerPlugin],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngtools/webpack",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.4",
|
|
4
4
|
"description": "Webpack plugin that AoT compiles your Angular components and modules.",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"typings": "src/index.d.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"homepage": "https://github.com/angular/angular-cli",
|
|
27
27
|
"dependencies": {},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@angular/compiler-cli": "^13.0.0
|
|
29
|
+
"@angular/compiler-cli": "^13.0.0",
|
|
30
30
|
"typescript": "~4.4.3",
|
|
31
31
|
"webpack": "^5.30.0"
|
|
32
32
|
},
|
|
@@ -5,5 +5,8 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
+
import { LoaderContext } from 'webpack';
|
|
8
9
|
export declare const DirectAngularResourceLoaderPath: string;
|
|
9
|
-
export default function (
|
|
10
|
+
export default function (this: LoaderContext<{
|
|
11
|
+
esModule?: 'true' | 'false';
|
|
12
|
+
}>, content: string): string;
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.DirectAngularResourceLoaderPath = void 0;
|
|
11
11
|
exports.DirectAngularResourceLoaderPath = __filename;
|
|
12
12
|
function default_1(content) {
|
|
13
|
-
|
|
13
|
+
const { esModule } = this.getOptions();
|
|
14
|
+
return `${esModule === 'false' ? 'module.exports =' : 'export default'} ${JSON.stringify(content)};`;
|
|
14
15
|
}
|
|
15
16
|
exports.default = default_1;
|
|
@@ -88,7 +88,7 @@ function visitDecorator(nodeFactory, node, typeChecker, directTemplateLoading, r
|
|
|
88
88
|
}
|
|
89
89
|
return nodeFactory.updateDecorator(node, nodeFactory.updateCallExpression(decoratorFactory, decoratorFactory.expression, decoratorFactory.typeArguments, [nodeFactory.updateObjectLiteralExpression(objectExpression, properties)]));
|
|
90
90
|
}
|
|
91
|
-
function visitComponentMetadata(nodeFactory, node, styleReplacements, directTemplateLoading, resourceImportDeclarations, moduleKind, inlineStyleFileExtension) {
|
|
91
|
+
function visitComponentMetadata(nodeFactory, node, styleReplacements, directTemplateLoading, resourceImportDeclarations, moduleKind = ts.ModuleKind.ES2015, inlineStyleFileExtension) {
|
|
92
92
|
if (!ts.isPropertyAssignment(node) || ts.isComputedPropertyName(node.name)) {
|
|
93
93
|
return node;
|
|
94
94
|
}
|
|
@@ -97,7 +97,8 @@ function visitComponentMetadata(nodeFactory, node, styleReplacements, directTemp
|
|
|
97
97
|
case 'moduleId':
|
|
98
98
|
return undefined;
|
|
99
99
|
case 'templateUrl':
|
|
100
|
-
const
|
|
100
|
+
const loaderOptions = moduleKind < ts.ModuleKind.ES2015 ? '?esModule=false' : '';
|
|
101
|
+
const url = getResourceUrl(node.initializer, directTemplateLoading ? `!${direct_resource_1.DirectAngularResourceLoaderPath}${loaderOptions}!` : '');
|
|
101
102
|
if (!url) {
|
|
102
103
|
return node;
|
|
103
104
|
}
|
|
@@ -165,10 +166,10 @@ function isComponentDecorator(node, typeChecker) {
|
|
|
165
166
|
}
|
|
166
167
|
return false;
|
|
167
168
|
}
|
|
168
|
-
function createResourceImport(nodeFactory, url, resourceImportDeclarations, moduleKind
|
|
169
|
+
function createResourceImport(nodeFactory, url, resourceImportDeclarations, moduleKind) {
|
|
169
170
|
const urlLiteral = nodeFactory.createStringLiteral(url);
|
|
170
171
|
if (moduleKind < ts.ModuleKind.ES2015) {
|
|
171
|
-
return nodeFactory.
|
|
172
|
+
return nodeFactory.createCallExpression(nodeFactory.createIdentifier('require'), [], [urlLiteral]);
|
|
172
173
|
}
|
|
173
174
|
else {
|
|
174
175
|
const importName = nodeFactory.createIdentifier(`__NG_CLI_RESOURCE__${resourceImportDeclarations.length}`);
|