简体   繁体   English

Isotope.js 和 Webpack - 可能吗?

[英]Isotope.js and Webpack - possible?

I'm trying to get my webpack setup working with isotope.js.我正在尝试让我的 webpack 设置与 isotope.js 一起工作。 The problem I'm running into is that when webpack goes to compile, it can't find a window and throws an error.我遇到的问题是,当 webpack 进行编译时,它找不到窗口并抛出错误。

Tried the following:尝试了以下方法:

In myfile.js在 myfile.js 中

import Isotope from 'isotope-layout';

webpack.config.js webpack.config.js

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

but it throws the following error:但它会引发以下错误:

/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)

What am I doing wrong here, or what would be the better way to get this accomplished?我在这里做错了什么,或者什么是实现这一目标的更好方法?

Try:尝试:

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...});

Try something along尝试一些东西

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

That seems to work for me.这似乎对我有用。 Note that this solution depends on imports-loader ;请注意,此解决方案依赖于import-loader

You can likely push this to your Webpack configuration rather than solving it inline.您可以将其推送到您的 Webpack 配置,而不是内联解决它。 Just hoping this answer points you to the right direction.只是希望这个答案为您指明了正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM