-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add async webpack.resolve support #27
Conversation
Switch the compiler to async mode, to allow webpack to resolve the included resources. The compilation is done in multiple passes until all paths are resolved (most of the time just 1 extra pass). Change the compiler export to a factory function so data can be passed from the loader to the compiler. Because of this structure the mapcache is not needed anymore. Create a util function to correctly generate template IDs that are the same between the loader and the compiler (previously they could differ). They always use the resolved webpack path as source for the ID. Skip dependencies in the token parsing that are not just a string. They will be handled at runtime, and are the responsibility from the template author. Also export the template tokens on the template function, so they can be used to register the template under a different name at runtime. This is useful when dealing with dynamic templates where you want to use `require.context` to bundle and register all your templates in your application bootstrap. Updated the test helper to make empty context available. Added a lot of comments in the code. re zimmo-be#26
Hi Arjan,
Thanks for your contribution!
I have a few remarks though:
- can you please make sure the existing tests pass?
- could you add some test cases covering the scenarios why you're making
these additions (ie. Template A referring to template B using a variable of
sorts)
- can you also fix the indenting in compiler.js? The changes look a bit
messy now :-)
Op 12 mrt. 2017 3:00 p.m. schreef "Arjan van Wijk" <notifications@github.com
…:
Switch the compiler to async mode, to allow webpack to resolve the
included resources. The compilation is done in multiple passes until
all paths are resolved (most of the time just 1 extra pass).
Change the compiler export to a factory function so data can be passed
from the loader to the compiler. Because of this structure the mapcache
is not needed anymore.
Create a util function to correctly generate template IDs that are the
same between the loader and the compiler (previously they could differ).
They always use the resolved webpack path as source for the ID.
Skip dependencies in the token parsing that are not just a string. They
will be handled at runtime, and are the responsibility from the template
author.
Also export the template tokens on the template function, so they can be
used to register the template under a different name at runtime. This is
useful when dealing with dynamic templates where you want to use
require.context to bundle and register all your templates in your
application bootstrap.
Updated the test helper to make empty context available.
Added a lot of comments in the code.
re #26 <#26>
------------------------------
You can view, comment on, or merge this pull request online at:
#27
Commit Summary
- Add async webpack.resolve support
File Changes
- *M* README.md
<https://github.com/zimmo-be/twig-loader/pull/27/files#diff-0> (59)
- *M* lib/compiler.js
<https://github.com/zimmo-be/twig-loader/pull/27/files#diff-1> (155)
- *M* lib/loader.js
<https://github.com/zimmo-be/twig-loader/pull/27/files#diff-2> (97)
- *D* lib/mapcache.js
<https://github.com/zimmo-be/twig-loader/pull/27/files#diff-3> (2)
- *A* lib/utils.js
<https://github.com/zimmo-be/twig-loader/pull/27/files#diff-4> (25)
- *M* package.json
<https://github.com/zimmo-be/twig-loader/pull/27/files#diff-5> (3)
- *M* test/fakeModuleSystem.js
<https://github.com/zimmo-be/twig-loader/pull/27/files#diff-6> (3)
Patch Links:
- https://github.com/zimmo-be/twig-loader/pull/27.patch
- https://github.com/zimmo-be/twig-loader/pull/27.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#27>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADSVlK_zxTFfDRM6jBb0IDLuwkQO6-5rks5rk_qEgaJpZM4MajCm>
.
|
|
Mark a failed resolve as false, so the compiler can ignore that resource and leave it in the template as is, so it can be picked up by Twig at runtime.
When not including `.twig` as extension, it will be added automatically. This is to create a scenario where a file can be resolve by webpack, and two different paths lead to the same resource. Also add a check on disk to allow cases where a template include value only exists at runtime as registered template.
When adding the behavior where a template must exists on disk to have it processed by the loader, the files do need to exist in disk. Also changed the include html to work with a resolve case where the '.twig' extension is added by the webpack resolve function.
These new tests will all fail when run on the old code.
@webberig All your remarks have been addressed. The test setup is not ideal, but it simulates some of the webpack resolve features that show how the old/current version is breaking, and where this PR passes. I have tested this version in my own project, but that is very limited (basically only a for loop with dynamic includes and some other includes, no blocks or embeds or template extends). If you have some projects where you use this library, I think it's wise to install this PR version (my branch) to see if those other cases behave the same as well. The |
README.md
Outdated
@@ -26,6 +28,26 @@ module.exports = { | |||
}; | |||
``` | |||
|
|||
### Webpack 2 |
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.
Since Webpack 2 and later is more likely, how about this goes before the "Webpack 1" docs? Also, you'll need to say "and later" since many are using version 3 or 4.
And, yeah, I know you wrote this PR 2 years ago. :-p
@@ -1,62 +1,102 @@ | |||
var path = require("path"); |
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.
The PR lists several files, including this one, as having “conflicts that must be resolved”.
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.
Hi @JohnAlbin,
I'm happy to make the required changes, but it would be good to know if this PR is going to be used at all in any way, since the original author seems afk after I made the requested changes :)
Let me know! Cheers
# Conflicts: # README.md # lib/compiler.js # lib/loader.js # package.json
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.
Sorry for the late reply. I've taken another look at the changes and will release this under version 0.5.0
Switch the compiler to async mode, to allow webpack to resolve the
included resources. The compilation is done in multiple passes until
all paths are resolved (most of the time just 1 extra pass).
Change the compiler export to a factory function so data can be passed
from the loader to the compiler. Because of this structure the mapcache
is not needed anymore.
Create a util function to correctly generate template IDs that are the
same between the loader and the compiler (previously they could differ).
They always use the resolved webpack path as source for the ID.
Skip dependencies in the token parsing that are not just a string. They
will be handled at runtime, and are the responsibility from the template
author.
Also export the template tokens on the template function, so they can be
used to register the template under a different name at runtime. This is
useful when dealing with dynamic templates where you want to use
require.context
to bundle and register all your templates in yourapplication bootstrap.
Updated the test helper to make empty context available.
Added a lot of comments in the code.
re #26