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-for-babel-plugin

v0.0.3

Published

babel 6 plugin which allows to use webpack loaders

Downloads

6

Readme

Build Status

babel-plugin-webpack-loaders

This babel 6 plugin allows you to use webpack loaders in babel. It's now easy to run universal apps on the server without additional build steps and to create libraries as usual with babel src --out-dir lib command.

For now this plugin is at alpha quality and tested on webpack loaders I use in my projects. These loaders are file-loader, url-loader, css-loader, style-loader, sass-loader, postcss-loader. Plugin supports all webpack features like loaders chaining, webpack plugins, and all loaders params. It's easy because this plugin just uses webpack.

There are two examples here:

How it works

You need to create webpack config file, like this

// webpack.config.js css-modules loader example
module.exports = {
  output: {
    // YOU NEED TO SET libraryTarget: 'commonjs2'
    libraryTarget: 'commonjs2',
    path: './build',
  },
  module: {
    loaders: [
      {
        test: /\.css$/,
        loaders: [
          'style-loader',
          'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]--[hash:base64:5]',
          'postcss-loader',
        ],
      },
    ],
  },
};

You need to add to .babelrc next lines like here

{
  "presets": ["es2015"],
  "env": {
    "EXAMPLES_RUN": {
      "plugins": [
        [
          "babel-plugin-webpack-loaders",
          {
            "config": "./webpack.config.js",
            "verbose": false,
          }
        ]
      ]
    }
  }
}

And now you can include css with support of css-modules into js file

.main {
  display: flex;
}

.item {
  flex: 1 1 auto;
}
import css from './some.css';
console.log(css);

Run NODE_ENV=EXAMPLES_RUN babel-node your.js and you get console output

{ main: 'some__main--2kmsh', item: 'some__item--ocDmM' }

you can test this and other examples just cloning this repo and running next commands

npm install

# example above
npm run example-run

# library example - build library with a lot of modules
npm run example-build
# and now you can use your library using just node
node build/myCoolLibrary/myCoolLibrary.js

# test sources are also good examples
npm run test

Install

npm install babel-plugin-webpack-loaders

Examples

webpack configs

examples

.babelrc example

tests

Why

The source of inspiration of this plugin is babel-plugin-css-modules-transform

  • But I love to write css with sass (sometimes with less or with scss), and it's easy to configure with webpack loaders, with full support of images and fonts preloading as base64 (using url-loader).

  • Webpack already has a lot of loaders with a lot of params, so I could reuse them

  • I have a lot of webpack configs where all troubles with params and settings was solved

How plugin works internally

Plugin tests all require pathes with test regexps from webpack config loaders,