GithubHelp home page GithubHelp logo

wc-loader's Introduction

WC Loader

Webcomponents webpack loader . Supports hot code reload. ๐Ÿšฝ ๐Ÿ˜œ

DEMO - https://github.com/aruntk/polymer-webpack-demo

Polymer Webpack Apollo-Graphql Demo - https://github.com/aruntk/githunt-polymer

About

wc-loader helps you use webcomponents (polymer, x-tags etc also) with webpack.

Under the hood

wc-loader uses parse5 which parses HTML the way the latest version of your browser does. Does not use any regex to parse html. :)

Main functions
  1. Handles html link imports. With Hot Code Reload Support
  2. Handles external script files (script src). With Hot Code Reload Support
  3. Handles external css files (link rel stylesheet)
  4. Handles template tags.
  5. Removes comments and unecessary whitespaces.
  6. Handles loading order of html and js inside the polymer files
  7. Adds components to document during runtime.

Installation

npm i -D wc-loader

Usage

module: {
  loaders: [
    {
      test: /\.html$/, // handles html files. <link rel="import" href="path.html"> and import 'path.html';
      loader: 'wc-loader' 
      // if you are using es6 inside html use 
      // loader: 'babel-loader!wc-loader'
      // similarly you can use coffee, typescript etc. pipe wc result through the respective loader.
    },
    {
      test: /\.js$/, // handles js files. <script src="path.js"></script> and import 'path';
      loader: 'babel-loader',
      exclude: /node_modules/
    },
    {
      test: /\.(png|jpg|gif|svg)$/, // handles assets. eg <img src="path.png">
      loader: 'file-loader',
      query: {
        name: '[name].[ext]?[hash]'
      }
    },
  ]
}

Using es6, typescript, coffee etc inside html

if you are using es6 inside html use

loader: 'babel-loader!wc-loader'

similarly you can use coffee, typescript etc. pipe wc result through the respective loader.

loader: 'ts-loader!wc-loader'
loader: 'coffee-loader!wc-loader'

Options

Minify html

loader: 'babel-loader!wc-loader?minify=true'

default options are

const defaultMinifierOptions = {
  collapseWhitespace: true,
  customAttrAssign: [/\$=/],
  ignoreCustomFragments: [/style\$?="\[\[.*?\]\]"/],
}

Use custom options - by config setting minifierOptions

Refer https://github.com/kangax/html-minifier for more info

Like it?

โญ this repo

Found a bug?

Raise an issue!

License

MIT. Check licence file.

wc-loader's People

Contributors

0xr avatar 4esnog avatar aruntk avatar

Watchers

 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.