-
-
Notifications
You must be signed in to change notification settings - Fork 40
CSS loader parsing CSS to JSON, platform suffix resolver and platform file system plugins #290
Conversation
run ci |
P.S. Registering |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we now modify the webapck config templates so that they use the plugin instead of resolve/extensions?
css2json-loader.js
Outdated
@@ -0,0 +1,41 @@ | |||
console.log("Here: " + __dirname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably leftover console.log
css2json-loader.js
Outdated
.map(importRule => importRule.import.replace(/[\'\"]/gm, "")); | ||
} | ||
|
||
// Identity loader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And a leftover comment :)
PlatformSuffixPlugin.js
Outdated
|
||
PlatformSuffixPlugin.prototype.apply = function(resolver) { | ||
var platform = this.platform; | ||
var platforms = this.platforms; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
platforms
is not used anywhere. Probably not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move the plugin to the plugins/ dir and export it from plugins/index.js. The plugins are then reexported from the root index.js and can be required with "nativescript-dev-webpaxk/SomePlugin". Maybe we should do the same for the loaders.
e6018ce
to
f1ba503
Compare
ci |
testsappng |
sdk |
run ci |
7783002
to
b381813
Compare
css2json-loader
The config can now be set to resolve .css files as:
This will use the parser from
tns-core-modules/css
to parse the CSS content and convert it to a module that exports a JSON. The JSON generated is quite verbose so times should be carefully measured on real devices whether it is better to use this approach. For example our CSS parser may be able to parse the CSS theme faster than the JS module is loaded parsed etc.PlatformSuffixPluing
The PlatformSuffixPluing is used like:
When a 'file' is resolved it checks if on the filesystem a file with a
.platofrm.
suffix exists, and if it does, resolves to it, otherwise resolves to the original file. This should eliminate the need to register extensions like[".android.ts", ".ts", ".android.css", ".css"]
and use just[".ts", ".css"]
. I've tested the approach in .js apps, we should further test this with Angular and TypeScript apps.PlatformFSPlugin
This plugin is applied by adding:
This plugin is a preferred approach to the PlatformSuffixPluing as it will work on file system level, it will virtually filter the files from other platforms, and rename the files from the current platform. E.g. on the following tree:
The webpack's compiler.inputFileSystem will map readdir, readFile, readJson etc. to behave for android as:
angular tooling with the RC works with this fs. Further the extensions doesn't need to be provided with
[".android.ts", ".ts", ".android.css", ".css"]
suffixes but use[".ts", ".css"]
instead.This also makes using web pack contexts easier, since when the files are enumerated their names will be properly mapped, for example:
Will create internal map for
app
andplatform
to resolve toapp/app.css
and theapp/platform.android.css
, this can be used to express the vanilla {N} apps convention and put all CSS, XML and .ts/.js files within the app folder in such contexts.It should be possible to use it to create a project with shared web, ios and android modules.