GithubHelp home page GithubHelp logo

Combine with other loaders about twig-loader HOT 4 CLOSED

zimmo-be avatar zimmo-be commented on September 7, 2024
Combine with other loaders

from twig-loader.

Comments (4)

nickkessler avatar nickkessler commented on September 7, 2024 2

+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.

webberig avatar webberig commented on September 7, 2024

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.

auburus avatar auburus commented on September 7, 2024

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.

webberig avatar webberig commented on September 7, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.