Isotope.js和Webpack - 可能吗?

时间:2015-06-26 15:37:46

标签: javascript node.js jquery-isotope webpack

我试图让我的webpack设置与isotope.js一起使用。我遇到的问题是,当webpack进行编译时,它无法找到一个窗口并抛出错误。

尝试以下方法:

在myfile.js

import Isotope from 'isotope-layout';

webpack.config.js

loaders: [{ test: /isotope-layout/, loader: 'imports?this=>window!isotope-layout' }

但它会引发以下错误:

/ipb/node_modules/lodash/index.js" as it exceeds the max of "100KB".

/Users/user/Development/ipb/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:206
                    throw e;
                          ^
ReferenceError: window is not defined
    at Object.<anonymous> (/Users/user/Development/ipb/node_modules/isotope-layout/js/isotope.js:60:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at DependenciesBlock.loadPitch (/Users/user/Development/ipb/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:193:17)
    at DependenciesBlock.loadPitch (/Users/user/Development/ipb/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:186:21)
    at DependenciesBlock.loadPitch (/Users/user/Development/ipb/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:223:61)

我在这里做错了什么,或者更好的方法是什么?

2 个答案:

答案 0 :(得分:3)

尝试:

var $ = require('jquery');
var jQueryBridget = require('jquery-bridget');
var Isotope = require('isotope-layout');
// make Isotope a jQuery plugin
jQueryBridget( 'isotope', Isotope, $ );
// now you can use $().isotope()
$('.grid').isotope({// options...});

答案 1 :(得分:0)

尝试一下

var Isotope = require('imports?$=jquery!isotope-layout/dist/isotope.pkgd');

这似乎对我有用。请注意,此解决方案取决于imports-loader;

您可以将其推送到Webpack配置而不是内联解决。希望这个答案能指出你正确的方向。