New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-webpack-loaders

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-webpack-loaders

babel 6 plugin which allows to use webpack loaders

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
353
decreased by-39.97%
Maintainers
1
Weekly downloads
 
Created
Source

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

Install

npm install --save-dev babel-cli css-loader postcss-loader style-loader babel-plugin-webpack-loaders

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": true,
          }
        ]
      ]
    }
  }
}

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,

Verbose mode in config

By default babel caches compiled files, if you need to view webpack stdout output run commands with BABEL_DISABLE_CACHE=1 prefix

Keywords

FAQs

Package last updated on 02 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc