Skip to content

fix: only require parsers if need be#9002

Closed
farfromrefug wants to merge 3 commits into
NativeScript:masterfrom
Akylas:parsers_fix
Closed

fix: only require parsers if need be#9002
farfromrefug wants to merge 3 commits into
NativeScript:masterfrom
Akylas:parsers_fix

Conversation

@farfromrefug
Copy link
Copy Markdown
Collaborator

this also allows to remove them from bundle.
However this is not the best way. We should use something like global.cssParser so that weback automatically removes the code

this also allows to remove them from bundle.
However this is not the best way. We should use global vars for cssParser so that weback automatically removes the code
@cla-bot cla-bot Bot added the cla: yes label Nov 1, 2020
if (this._source) {
switch (parser) {
case 'css-tree':
const cssTreeParse = require('../../css/css-tree-parser').cssTreeParse;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd wonder too if this would be subject to sideEffects when tree shaking is utilized? - perhaps the global.cssParser option in webpack configs may be a nice way to remove these blocks for those not used.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't webpack has no way of knowing we use one or the other. So it will add the 3. That s why I talked about global var for cssParder so that webpack can remove what we don't use

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding yet another global, we can add "magic" strings

In this case, I would do

switch(__CSS_PARSER__) {

and just make ts happy with

declare readonly var __CSS_PARSER__: string

in global-types.d.ts

We would inject the variable with the DefinePlugin in webpack.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think it would work Igor. Dont know if the tree shaker will clean the switch . I think we have to something like if (__CSS_PARSER__ === 'rework')...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, we can convert to if/else if's

This rollup repl shows it working!

I expect it to work the same through webpack as well!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Various React ecosystem packages use if(__DEV__){} blocks explicitly because Webpack does treeshake paths based on the value of the constant defined by WebpackDefinePlugin, if it’s any help.

@NathanWalker NathanWalker added the ready for test TSC needs to test this and confirm against live production apps and automated test suites label Nov 6, 2020
Comment thread packages/core/ui/styling/style-scope.ts Outdated
Co-authored-by: Igor Randjelovic <rigor789@gmail.com>
@NathanWalker
Copy link
Copy Markdown
Contributor

@farfromrefug I believe this is obsolete since we merged this dce7408 in with the release branch, is that correct?
If that commit handles what this PR would, feel free to close this PR as changes from a different pr were already brought in which we believe covers this.
/cc @rigor789

@farfromrefug
Copy link
Copy Markdown
Collaborator Author

Yes it is !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes ready for test TSC needs to test this and confirm against live production apps and automated test suites

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants