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

@mahpooya/intervi-mix

v1.0.11

Published

Laravel Mix extensions set (Fork for update dependencies)

Downloads

19

Readme

@mahpooya/intervi-mix

This package contains laravel mix extensions and in future maybe other mix and webpack related stuff.

Extensions

SVG Loader For React + SCSS/LESS/CSS

This extension replaces default mix behavior of processing SVG files. This might be especially useful when you want to use SVG images inline inside your code as a React Components. This is impossible by default, as mix treats SVGs as standard images, and loads them using just a simple file-loader and img-loader. When your SVGs are inside fonts directory, they're treated as a font, and loaded using only a file-loader. Because mix's rules catches all SVGs within your app, it's impossible to simply add your custom loader as it won't take effect because of default mix rules.

The way this extension works, is defining some new rule for .svg files, with two different loaders used depending on the issuer. For tsx, jsx, ts, js files it will load SVG as a React Component using SVGR loader. For sass, scss, less, css files it will behave the same as originally in the mix, so will resolve SVG into file path. Finally, we override default mix rules to prevent them catching SVG files. That way only our custom rule will be used, and you can now import your SVG files like below:

JS/TS/JSX/TSX

import React    from "react";
import SomeIcon from "../assets/some-icon-path.svg";

const ExampleComponent: React.FunctionComponent = () => (
  <div className="some-icon-wrapper">
    <SomeIcon/>
  </div>
);

export default ExampleComponent;

Above code will result into this when rendered:


<div class="some-icon-wrapper">
  <svg role="img" viewBox="0 0 16 16">
    <!-- Your SVG content here -->
  </svg>
</div>

SCSS/SASS/LESS/CSS

.button {
    background-image: url("../assets/some-button-icon.svg");
}

Just like default when using mix, above code will result into this when compiled to CSS:

.button {
    background-image: url("/images/some-button-icon.svg?86fa50164b5f5197fb5647a1dea78b48");
}

Installation

yarn add --dev @mahpooya/intervi-mix

# or when using npm

npm install --save-dev @mahpooya/intervi-mix

Usage

Simply require a package in your webpack.mix.js file and use a loader extensions like in example below:

const mix = require('@mahpooya/laravel-mix');

require('@mahpooya/intervi-mix');

// ...

mix.ts('resources/js/app.tsx', 'public/js/app.js');
mix.useInterviSvgLoader();

// ...

Configuration

Because we use some standard loaders that mix comes with, we might need to provide some extra parameters for these loaders. The useInterviSvgLoader method accepts a config parameters which you can use to provide some custom options. These are the configs that are used by mix internally. Because mix doesn't allow to read its config outside, we had to create a copy of its default config parameters in our extension. You don't have to provide any configuration, unless you need to override any of the below default parameters:

mix.useInterviSvgLoader({
  fileLoaderDirs: {
    images: "images",
    fonts:  "fonts",
  },

  imgLoaderOptions: {
    enabled:  true,
    gifsicle: {},
    mozjpeg:  {},
    optipng:  {},
    svgo:     {},
  },

  resourceRoot: "/",
});

TypeScript Support

When you use TypeScript you will have to define proper modules to import images and SVG files as react components. You can simply create a declaration file somewhere in the path which is included in your type script compiler. Here is example declaration that we use in our apps:

resources/js/assets.d.ts

declare module "*.svg" {
  import React = require("react");
  const ReactComponent: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
  export default ReactComponent;
}

declare module "*.jpg" {
  const content: string;
  export default content;
}

declare module "*.jpeg" {
  const content: string;
  export default content;
}

declare module "*.png" {
  const content: string;
  export default content;
}

declare module "*.gif" {
  const content: string;
  export default content;
}

declare module "*.webp" {
  const content: string;
  export default content;
}