• Stars
    star
    99
  • Rank 343,315 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🚽 Webcomponents webpack loader.

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: {
    rules: [
      {
        test: /\.js$/, // handles js files. <script src="path.js"></script> and import 'path';
        use: [{
          loader: 'babel-loader',
        }],
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|gif|svg)$/, // handles assets. eg <img src="path.png">
        use: [{
          loader: 'file-loader',
          options: {
            name: '[name].[ext]?[hash]'
          }
        }]
      },
      {
        test: /\.html$/, // handles html files. <link rel="import" href="path.html"> and import 'path.html';
        use: [
          // if you not using es6 inside html remove babel-loader
          {

            loader: 'babel-loader',
            // similarly you can use coffee, typescript etc.
          },
          {
            loader: 'wc-loader',
            options: {
              minify: true,
            },
          }]
      },
    ],
  ]
}

Using es6, typescript, coffee etc inside html

In the following config

{
  test: /\.html$/,
  use: [
    {
      loader: 'babel-loader', // change this line
    },
    {
      loader: 'wc-loader',
      options: {
        minify: true,
      },
    }]
},

if you are using es6 inside html use

loader: 'babel-loader'

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

loader: 'ts-loader'
loader: 'coffee-loader'

Options

You can either specify options as part of the loader string or as options property

{
  loader: 'wc-loader',
  options: {
    minify: true
  }
}

'Root-relative' URLs

For urls that start with a /, the default behavior is to not translate them. You'll get a file not found error in the browser. (/path = example.com/path for the browser) If a root query parameter is set, however, it will be prepended to the url and then translated.

<!-- file.html -->
<img src="/image.jpg">
// webpack config. options.root can also be used

loader: 'wc-loader?root=/absolue/path/to/root/folder'

// or

loader: 'wc-loader?root=' + path.resolve('relative/path/to/root/folder')

// example

loader: 'wc-loader?root=/'

Minify html

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

options: {
   minify: true,
   minifierOptions: {
     // custom options
   }
}

Like it?

⭐ this repo

Found a bug?

Raise an issue!

License

MIT. Check licence file.

More Repositories

1

polymer-apollo

🚀 Polymer Apollo Integration
JavaScript
78
star
2

redux-api-saga

Redux API Saga - REACT API calls made simple
TypeScript
18
star
3

kickstart-meteor-polymer

⚡ Kickstart a Meteor - Polymer project with MWC packages. (Flow Router is used to route)
JavaScript
15
star
4

GitHunt-Polymer

An example of a client-side app built with Polymer and Apollo Client.
HTML
12
star
5

polymer-webpack-demo

polymer webpack demo using wc-loader
HTML
11
star
6

mac-gestures

mac like gestures for linux systems
Perl
9
star
7

polymer-weight

🐌 See which component is making the app slow.
JavaScript
9
star
8

polymer-apollo-meteor-demo

Polymer Apollo Meteor Integration
HTML
7
star
9

NEWS

Desktop news app
HTML
6
star
10

kickstart-meteor-polymer-with-auth

⚡ kickstart a meteor polymer project using mwc projects
JavaScript
6
star
11

walk-tour

polymer app tour.
JavaScript
4
star
12

prisma-parser

TypeScript
4
star
13

polymer-apollo-frontpage

Polymer Apollo Integration
JavaScript
3
star
14

morph-animation

Element to element morphing using Polymer
JavaScript
3
star
15

kickstart-meteor-polymer-with-app-route

Demo for meteor + polymer using meteorwebcomponents projects.
JavaScript
3
star
16

grow-iot-react

grow iot react implementation
JavaScript
2
star
17

grow-rest-api

Rest API for Grow-IoT project
JavaScript
2
star
18

graffiti

create custom dashboard
PLpgSQL
2
star
19

grow-graphql-api

JavaScript
2
star
20

polymer-admin

Admin dashboard made with polymer
HTML
2
star
21

phrase-loader

Polymer phrase loader. Inspired from https://codepen.io/hoqqanen/pen/zvqGEG
JavaScript
2
star
22

link-loader

HTML webpack loader with link imports support.
JavaScript
2
star
23

dotfiles

Vim Script
1
star
24

html5-utils

html5 utils
JavaScript
1
star
25

regex-tester

JS Regex tester with text loaded from server side text files. Made with meteor+polymer+synthesis
HTML
1
star
26

react-apollo-sample

TypeScript
1
star
27

meteor-polymer-offline

Offline First App with Meteor & Polymer
JavaScript
1
star
28

react-search

TypeScript
1
star
29

link-loader-demo

Demo for https://github.com/aruntk/link-loader
HTML
1
star
30

rangy

rangy for meteor
JavaScript
1
star