Comments (3)
Thanks for the report.
Currently, the path to the module that resoves to the Twing environment needs to be absolute:
options: {
environmentModulePath: path.resolve('twingEnv.js'),
renderContext: {
foo: 'bar'
}
}
It makes sense to me because require
will consider it as a node_modules
package if it comes without a path prefix. For information I also tried with a relative path like ./twingEnv.js
and it doesn't work. Again, it makes sense since require
will try to resolve it from the directory of the loader script itself.
Anyway, this means that either the documentation is wrong (and then I need to fix it) or the loader should resolve the path itself before requiring it (and then I need to fix it :D ).
I'm not the most appropriate guy to take that kind of design decision about webpack (I barely use it), but my thought is that it should be possible to use a node_modules
package as environmentModulePath
or have something like module-alias
do the resolution job and that twing-loader
should not get in the way - i.e. it should not try to resolve environmentModulePath
by any mean.
So I'm tempted to consider that the current design decision is the best one and that the documentation needs to be fixed.
What do you think?
from twing-loader.
Why use a path and not directly some js ? User could use require for file or node module.
from twing-loader.
That was my first idea. It works perfectly when using "render at compile time" but when the template needs to be rendered at runtime, the environment used to compile it is needed in the bundle. And except if I'm wrong, the only way to have webpack include the environment into the bundle is to require it from its path in the loader output.
This is done here:
Line 53 in b20bf0e
Once again, there may be some better approach and I'm totally open to them. I'm currently looking at how other loaders deal with this - I know for sure that some forks of twig-loader
that allows for customization use the same approach but I'm not sure there is no better way.
Edit: handlebars-loader also uses that approach when one want to provide a custom runtime.
from twing-loader.
Related Issues (20)
- Possible to use namespaces in browser? HOT 11
- Windows compatibility HOT 5
- Migrate to Twing@3
- Webpack do not reload page when Twig template is edited HOT 4
- twing-loader is not compatible with Twing@4 HOT 2
- How to use with html-webpack-plugin HOT 2
- Update variables in "renderContext"
- npm prepare script should be used instead of prepack
- Catch Twing errors and emit them with Webpack API HOT 2
- Warnings with webpack 5 and HtmlWebpackPlugin
- Webpack 5 support HOT 1
- Using with Storybook HTML (which doesn't seem to like promises) HOT 3
- Feature request: option to render templates surrounded by HTML comments indicating Twig file's path
- Loading templates from string HOT 2
- How to force new TwingEnvironment when loading through webpack? HOT 1
- interpolation in include statements
- `source` function is not supported
- twing-loader is not compatible with Twing@6 HOT 2
- Improve the README
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twing-loader.