如何在webpack中使用Material Design Lite ?

How can I use Material Design Lite with webpack?

本文关键字:Material Design Lite webpack      更新时间:2023-09-26

我一直在玩ReactJs,我需要在每个componentDidMount()处理程序中调用componentHandler.upgradeDom()

是否有一种方法,不必调用upgradeDom上全局定义的componentHandler,而是使用webpack导入材料设计生活作为一个模块?

在github上有这个讨论,但是看起来库不会很快升级到导出componentHandler

所以我使用了webpack的exports-loader插件。我的webpack.config.js看起来像这样:

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

这意味着在我的模块中我现在可以调用

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