@ngtools/webpack 13.0.0 → 13.1.0-next.1

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.0",
3
+ "version": "13.1.0-next.1",
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 || ^13.0.0-next",
29
+ "@angular/compiler-cli": "^13.0.0 || ^13.1.0-next",
30
30
  "typescript": "~4.4.3",
31
31
  "webpack": "^5.30.0"
32
32
  },
package/src/ivy/loader.js CHANGED
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.default = exports.angularWebpackLoader = void 0;
30
30
  const path = __importStar(require("path"));
31
31
  const symbol_1 = require("./symbol");
32
+ const JS_FILE_REGEXP = /\.[cm]?js$/;
32
33
  function angularWebpackLoader(content, map) {
33
34
  const callback = this.async();
34
35
  if (!callback) {
@@ -36,7 +37,7 @@ function angularWebpackLoader(content, map) {
36
37
  }
37
38
  const fileEmitter = this[symbol_1.AngularPluginSymbol];
38
39
  if (!fileEmitter || typeof fileEmitter !== 'object') {
39
- if (this.resourcePath.endsWith('.js')) {
40
+ if (JS_FILE_REGEXP.test(this.resourcePath)) {
40
41
  // Passthrough for JS files when no plugin is used
41
42
  this.callback(undefined, content, map);
42
43
  return;
@@ -48,7 +49,7 @@ function angularWebpackLoader(content, map) {
48
49
  .emit(this.resourcePath)
49
50
  .then((result) => {
50
51
  if (!result) {
51
- if (this.resourcePath.endsWith('.js')) {
52
+ if (JS_FILE_REGEXP.test(this.resourcePath)) {
52
53
  // Return original content for JS files if not compiled by TypeScript ("allowJs")
53
54
  this.callback(undefined, content, map);
54
55
  }