Comments (4)
+1
Would love to use this twig plugin but I need to pipe with the html loader so I can integrate with the url loader, for images.
Any help greatly appreciated.
from twig-loader.
Hi!
Please take a look at this section of the webpack documentation:
http://webpack.github.io/docs/how-to-write-a-loader.html#do-only-a-single-task
Firstly, it will explain why we won't implement what you're asking in this loader, as it would violate the single task rule.
But coincidently, it will also gives an example for your use case. The apply-loader will probably do what you want.
from twig-loader.
Oh, my bad, so sorry.
It does much more sense using concrete loaders, and the apply loader saved the day, so thanks for your suggestion.
I'll leave this here in case anyone else is struggling with the same (or, if you prefer, I can make a pull request to put it in the docs, up to you).
// File: twigVariables.js
module.exports = {
name: 'Mufasa'
}
// File webpack.config.js
var twigVariables = require('./twigVariables.js');
module.exports = {
// ...
module: {
loaders: {
{
test: /\.twig$/,
loader: "apply?{ obj: " + JSON.stringify(twigVariables) + "}!twig"
}
}
}
}
Note:
This doesn't allow you to pipe it directly to something like html-loader, because it's still js. Although, it complains if you try to use an other loader like val-loader, so I've run out of ideas. Anyway, I hope that something of this was useful.
from twig-loader.
This loader's purpose is to COMPILE twig templates, not actually RENDER them. If you are trying to render HTML during build-time, this loader is not the tool you need.
Since I don't have use cases for this in my own projects, I can't provide a working example, but - in theory - you should create a JS file that imports TwigJS directly (not the loader) and renders a given template. After that, you can use Apply-loader to execute the rendering and add the result to your webpack chunks.
from twig-loader.
Related Issues (20)
- How to include images with html-webpack-plugin + twig-loader? HOT 3
- Work with HtmlWebpackPlugin HOT 2
- How to pass rendered output through to another loader? HOT 1
- How to set twig options? HOT 1
- Resolve paths HOT 6
- TwigException: Unable to find template file <hash> using webpack resolve HOT 2
- Rendering not work HOT 1
- Comparison Operator===not Supported HOT 1
- {% include %} inside {% set %} does not work :( HOT 1
- Unable to include twig files outside project path HOT 9
- Module build fails after updating to 0.5.0 HOT 4
- Spaceless tag deprecated. HOT 2
- Cannot be installed along `twig` anymore, unable to resolve dependency tree
- Unable to include twig component HOT 2
- How to use with webpack encore, set directory for templates HOT 1
- no webpack 5 support
- Filtre Trans not working HOT 1
- how install this twig-loader?
- Rollup/Vite support HOT 2
- Is it safe to assume that this project is not maintained anymore? HOT 1
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 twig-loader.