Can webpack works like polymer cli?

241 views Asked by At

I am studying Lit element and Material Design Component(MDC).

For MDC, I have to use webpack-dev-server as getting started says.

But For Lit element, I have to use Polyemr cli because Polymer Cli can import libraries by name.

like this.

  import { LitElement, html } from '@polymer/lit-element';

So I am looking for the way I can import polymer by name using webpack. Or how I can use MDC using Polymer cli.

Could you give me some advice?

1

There are 1 answers

0
daKmoR On

LitElement works just fine with webpack. The only thing you need to do is configure it to also compile it's source.

In most webpack configs you will have something like this

module: {
    rules: [
        {
            test: /\.js$/,
            use: "babel-loader",
            exclude: /node_modules/
        }
    ]
},

But if you replace it with something like this

module: {
    rules: [
        {
            test: /\.js$/,
            use: "babel-loader",
            exclude: (modulePath) => {
                return (
                    /node_modules/.test(modulePath) &&
                    !/node_modules\/lit-html/.test(modulePath) &&
                    !/node_modules\/lit-element/.test(modulePath)
                )
            },
        }
    ]
},

Then it will also be transpiled and should work just fine.