npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webpack-blade-native-loader

v9.1.2

Published

Webpack loader for Laravel's blade template engine.

Downloads

160

Readme

webpack-blade-native-loader

A webpack loader for blade template engine using Laravel's Illuminate/View component itself.

How does it work?

This loader passes on the contents of your blade views to a PHP script. The PHP script sets up a ViewFactory to render the blade code to HTML. This means that your views are rendered entirely using PHP. The resulting HTML is passed back into the Webpack flow.

Requirements

As we're using PHP behind the scenes, you should have PHP available on your system. Please see the Laravel Docs for the minimal supported version.

Upon installing the loader, Illuminate/View is being pulled in using composer. To install composer on your system, please see getcomposer.org.

Getting Started

To begin, you'll need to install webpack-blade-native-loader:

$ npm install webpack-blade-native-loader --save-dev

Basic setup

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.blade\.php$/,
        use: [
          {
            loader: 'webpack-blade-native-loader',
            options: {
              viewDir: 'resources/views'
            }
          }
        ],
      },
    ],
  },
};

HtmlWebpackPlugin

This loader works great combined with HtmlWebpackPlugin. Here's an example how to set that up.

webpack.config.js

const pages = glob.sync('**/*.blade.php', {
  cwd: path.join(process.cwd(), `resources/views/`),
  root: '/',
})
.map((page) => new HtmlWebpackPlugin({
  filename: page.replace('.blade.php', '.html'),
  template: `resources/views/${page}`,
}));

module.exports.plugins.push(...pages);

This will render all of the blade files in the resources/views directory to HTML. If you're using partials, this might not be what you want. The updated example below filters out any views that contain an underscore in their paths. You can specify your own rules by modifying the filter statement or add more to suit your needs.

webpack.config.js

const pages = glob.sync('**/*.blade.php', {
  cwd: path.join(process.cwd(), `resources/views/`),
  root: '/',
})

// Filter out views that contain an underscore in their paths
.filter(filename => filename.indexOf('_') === -1)

.map((page) => new HtmlWebpackPlugin({
  filename: page.replace('.blade.php', '.html'),
  template: `resources/views/${page}`,
}));

module.exports.plugins.push(...pages);

Options

viewDir

Type: String Default: ''

The path of the directory where template files are located.

License

The MIT License (MIT). Please see License File for more information.

Credits

This package is being maintained by Esign. We're a creative digital agency located in Ghent, Belgium.