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

one-blade

v0.0.2

Published

Laravel Mix extension which lets you use blade components like Vue3's single file components.

Downloads

5

Readme

Single File Blade Components

Software License Latest Version on NPM

Laravel Mix extension which lets you use blade components like Vue's single file components.

Single File Blade Components

Usage

First, install the extension.

npm install single-file-blade-components --save-dev

Then, require it within your webpack.mix.js file:

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

require('single-file-blade-components');


mix.sfbc('resources/views/components/alert.blade.php', 'public/js/alert.js');

// or

mix.singleFileBladeComponent('resources/views/components/alert.blade.php', 'public/js/alert.js');

How it works

This extension extracts JS/CSS from blade file into separate JS/CSS file. During build process, it extracts style or x-style tag content into a separate css file and script or x-script tag content into a separate js file.

Video demo

Examples:

Minimal example

alert.blade.php

<x-template>
    <div class="title">
        Hello {{ $bladeVarialbe }},
        <button id="btn">Sign In</button>
    </div>
</x-template>

<style>
    .title {
        color: #333;
        font-size: 20px;
    }
</style>

<script>
    document.querySelector('click', function(){
        alert('hello');
    })
</script>

webpack.mix.js

mix.sfbc('resources/views/components/alert.blade.php', 'dist/js/alert.js');

Note: You will have to create x-template blade component.

CSS Pre-Processors

Use `lang' attribute to set css pre-processor

<x-template>
    <div>
        <h1>Hello</h1>
    </div>
</div>
</x-template>

<x-style lang="scss">
    div {
        h1 {
            color: #333;
        }
    }
</x-style>

CSS extraction

By default CSS declared in the blade file will be extracted into a separate file. You can disable this behavior by setting the extract attribute value as false.

For extract="false", it keeps CSS in the js file and gets injected into the dom via JS.

<x-template>
    <h1>Hello</h1>
</div>
</x-template>

<x-style extract="false">
    h1 {
        color: #333;
    }
</x-style>

Options

This plugin use mini-css-extract-plugin for css extraction. You can change mini-css-extract-plugin configuration via miniCssExtractPlugin option.

mix.options({
    miniCssExtractPlugin: {
        filename: '[name].css'
    }
})

Caveat

Code written in script or style tag should not be rendered directly on the frontend as it is a untranspiled code. To avoid this you can wrap script and style tag in falsy if statement or create x-style and x-script blade component.

@if(false)
    <style>
        h1 {
            color: red;
        }
    </style>
@endif

@if(false)
    <script>
        alert('test');
    </script>
@endif