Giter Site home page Giter Site logo

Comments (8)

ben-rogerson avatar ben-rogerson commented on May 30, 2024 1

Hey @ryanscherler I've just released v1.2.0 which adds the functionality you're after. Enjoy!

from laravel-mix-twig-to-html.

ryanscherler avatar ryanscherler commented on May 30, 2024 1

Awesome Ben! Thanks so much for updating to use globs! Stoked to try this out and integrate into our 'starter' setup

from laravel-mix-twig-to-html.

ben-rogerson avatar ben-rogerson commented on May 30, 2024

Hey Ryan, I'm glad you're enjoying it.
Globbing the paths is a good idea so I'll add support for it in the next release.

In the meantime, my other package get-files-in will help grab those twig/html files. If you have any files you don't want included you just need to prefix the folder with an underscore (eg: _pages).
For your example you'd use it like this:

const templateFiles = getFilesIn('src/templates/pages', ['twig', 'html'], true)

mix.twigToHtml({
    files: templateFiles,
    fileBase: 'src/templates/pages',
    twigOptions: { data: {} },
    enabled: true,
  })

from laravel-mix-twig-to-html.

ben-rogerson avatar ben-rogerson commented on May 30, 2024

ps: the code snippit you provided just needs a small update to use a comma instead of pipe for the filetype matching:

files: ['src/templates/pages/**/*.{twig,html}'],

from laravel-mix-twig-to-html.

ryanscherler avatar ryanscherler commented on May 30, 2024

Quick question - the plugin also seems to inject the CSS / JS into the page? - is it possible to suppress this? e.g. we use Stimulus / Turbolinks and they need to be loaded into the head rather than prepended to the body.

from laravel-mix-twig-to-html.

ben-rogerson avatar ben-rogerson commented on May 30, 2024

That all seems possible and looks like it's a two-step process.

First step: Disable injections.
You can do this by setting your file config like this:

const mix = require('laravel-mix');

require('laravel-mix-twig-to-html');

const files = [
    {
        template: 'src/templates/pages/**/*.{twig,html}',
        inject: false, // disable asset tag injection
    }
]

mix.twigToHtml({
    files: files,
    fileBase: 'src/templates',
});

Then you need to specify the headTag and bodyTag positions in your twig base template(s) and add a filter where necessary:

<%= htmlWebpackPlugin
  .tags
  .headTags
  .filter((tag) => tag.tagName === 'meta')
  .join('') 
%>

The injections should be fully customisable - take a look at this example

Alternatively, instead of inject: false you could try setting inject: 'head' or inject: 'body'.

Hope that helps!

from laravel-mix-twig-to-html.

ryanscherler avatar ryanscherler commented on May 30, 2024

Oh thats great! I'll close my PR which addressed this with a fileOptions config param.

from laravel-mix-twig-to-html.

ben-rogerson avatar ben-rogerson commented on May 30, 2024

thanks Ryan!

from laravel-mix-twig-to-html.

Related Issues (7)

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.