Add a globals.registerWebpackModules that can register dynamic require webpack context #5087
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The web pack require can now create a dynamic require context, and that context can be fed into the modules so the .js and .css files can be loaded through web pack loaders.
Consider the following
bundle.config.js
:This will make a context for the entire app (
~/
is theapp/
) folder and recursively require all files that end in...page.xml
,...page.css
,...page.ts
etc. Webpack will create a map such as:for the bundle.js, (note they can be added to the vendor.js and get into the snapshot for android too) and then when the {N} builder resolves a page, it will load the css and js files from that map.
The last argument of
require.context
is a regex so it allows great flexibility.Developers will no longer need to
global.registerModule
for each of their JavaScript files as long as they can figure out a convention (like placing all views in aviews
folder, or postfixing each page withpage.*
, or if they are happy listing each .js file fromapp/
.This utility is designed to work with the nativescript-dev-webpack's
PlatformFSPlugin
orNativeScriptAngularCompilerPlugin
that would virtually map file.android.* and file.ios.* to file.*.