Clarkie
Clarkie

Reputation: 7550

How can I use Material Design Lite with webpack?

I've been playing around with ReactJs and I'm needing to call componentHandler.upgradeDom() in each componentDidMount() handler.

Is there a way to not have to call upgradeDom on globally defined componentHandler and instead use webpack to import material design lite as a module?

Upvotes: 2

Views: 3286

Answers (1)

Clarkie
Clarkie

Reputation: 7550

There is this discussion on github but it doesn't look like the library will be upgraded soon to export componentHandler.

So instead I used the exports-loader plugin for webpack. My webpack.config.js looks like this:

module: {
    loaders: [
        { test: /\.js$/, loader: 'jsx-loader?insertPragma=React.DOM&harmony' },
        { test: /\.js$/, loader: 'exports-loader' }
    ]
},

This means that in my modules I can now call

var ch = require('exports?componentHandler!material-design-lite/material.js');
ch.upgradeDom();

Upvotes: 4

Related Questions