Giter Club home page Giter Club logo

babel-plugin-webpack-loaders's Introduction

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. It just replaces require - import statements with webpack loaders results. Look at babel build output diff to get the idea.

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 three examples here:

How it works

Look at minimal-example

  • You need to create webpack config file.

  • You need add to .babelrc next lines

  • Now you can run next javascript file

    // example.js
    import css from './example.css';
    console.log('css-modules result:', css);

    with command NODE_ENV=EXAMPLE ./node_modules/.bin/babel-node ./example.js and you get the console output

    css-modules result: { main: 'example__main--zYOjd', item: 'example__item--W9XoN' }
  • Here I placed output diff of this babel library build without and with plugin. As you can see plugin just replaces require with loaders results. All loaders and plugins applied to generated assets

Install

npm install --save-dev babel-cli babel-plugin-webpack-loaders

Examples

webpack configs, examples, .babelrc example, tests, minimal-example-repo

you can test local 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

Why

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

  • But I love to write css with sass
  • I just like webpack and its loaders (chaining, plugins, settings).
  • I want to opensource an UI library which heavily uses css-modules + sass and other webpack loaders. Library contains of many small modules and every module must be available to users independently like lodash/blabla/blublu. Now I can replace heavy build file with this plugin and just one command babel src --out-dir lib

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

Thanks to

Felix Kling and his astexplorer

James Kyle and his babel-plugin-handbook

Michal Kvasničák and his babel-plugin-css-modules-transform

babel-plugin-webpack-loaders's People

Contributors

istarkov avatar ntharim avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.