This repository has been archived by the owner on Aug 7, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(AoT): stop using require.context in Angular apps (#574)
Calling `require.context` for the app directory adds a `ContextDependency` in webpack for it. That causes every change inside the app/ directory to emit a change event for the whole directory. There's a logic in the TypeScript compiler host (from [@ngtools/webpack](https://github.com/angular/angular-cli/blob/master/packages/ngtools/webpack/src/compiler_host.ts#L235)) that invalidates all files in the changed directory. The invalidation removes all cached information for the virtual files produced by the Angular AoT compilation (ngfactory files, etc.). Since these files are not in the cache anymore, webpack tries to resolve them from the filesystem and fails. The solution is to remove the `ContextDependency` for the `app` dir, which should also make the rebuilds much faster. fixes #566
- Loading branch information
Showing
5 changed files
with
29 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const loadCss = require("./load-application-css"); | ||
|
||
module.exports = function() { | ||
loadCss(function() { | ||
global.registerModule("./app.css", () => require("~/app")); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const loadCss = require("./load-application-css"); | ||
|
||
module.exports = function() { | ||
loadCss(function() { | ||
const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/); | ||
global.registerWebpackModules(appCssContext); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,8 @@ | ||
module.exports = function(isAngular) { | ||
module.exports = function (loadModuleFn) { | ||
const application = require("tns-core-modules/application"); | ||
require("tns-core-modules/ui/styling/style-scope"); | ||
|
||
if (isAngular) { | ||
global.registerModule("./app.css", () => require("~/app")); | ||
} else { | ||
const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/); | ||
global.registerWebpackModules(appCssContext); | ||
} | ||
loadModuleFn(); | ||
|
||
application.loadAppCss(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters