草庐IT

NAPI模块

全部标签

javascript - RequireJS 单个文件中的多个模块

我想将多个模块合并到一个文件中,但找不到有关如何操作的官方文档。现在我正在使用下面的方法,它有效,但我想知道以下内容:技术上是否正确?RequireJS如何检查模块是否已加载?使用模块名还是文件名?此解决方案是否会在某些情况下多次初始化模块?index.htmlrequirejs.config({paths:{'a':'test','b':'test'}});require(['a','b'],function(){console.log('a&bloaded');});test.jsconsole.log('loadingtest.js');//Ihavesomeinithere,l

javascript - 如何使用 goog.provide 和 goog.require 加载我自己的 js 模块?

我们正在尝试将项目的打包方式从dojo切换到google闭包,但到目前为止我们还没有成功。这是一个简单的例子,说明了我们正在努力完成的事情:goog.require("foo.bar");functionmain(){foo.bar.echo("helloworld")}Thenin/foo/bar.jsIhave:goog.provide("foo.bar");foo.bar.echo=function(s){console.debug(s);}我在firebug中收到的错误如下:goog.requirecouldnotfind:foo.barfooisnotdefined当我查看“

javascript - 如何在 ES6 模块中导入部分对象

在reactdocumentation我找到了这种导入PureRenderMixin的方法varPureRenderMixin=require('react/addons').addons.PureRenderMixin;怎么改成ES6风格。我唯一能做的就是:importaddonsfrom"react/addons";letPureRenderMixin=addons.addons.PureRenderMixin;希望有更好的方法 最佳答案 不幸的是importstatements不像objectdestructuring那样工作

javascript - Backbone Marionette 和 RequireJS 模块

我正在使用Marionette开始一个大型javascript应用程序。Marionette应用程序具有应用程序模块的概念,RequireJS也用于将代码分解为模块,目前我有这个用于开始我的应用程序:require(["jquery","underscore","backbone","marionette"],function($,_,Backbone,Marionette){$(function(){App=newMarionette.Application();App.addInitializer(function(options){App.addRegions({mainArea

javascript - Webpack:导出到窗口中的现有模块

我的目标是使用Webpack将一个独立的组件导出到一个假定的全局对象中。index.htmlvarMyApp=window.MyApp||{};MyApp.something=MyApp.something||{};////othermodules/componentsloadedhere...//MyApp.something.myIsolatedModule.run();在上面的例子中,我假设有一个全局对象/模块,它有一个属性something,它将有其他模块附加到它。所以我想将我的隔离模块附加到全局MyApp.something对象,而不破坏MyApp或MyApp.somethi

javascript - (Webpack) 如何分块动态模块依赖

我刚刚意识到,如果您使用require.ensure()动态加载模块,webpack将不会分析和分块依赖关系。这在某种程度上是有道理的,有人可能会争辩说,webpack不知道这些模块是否曾经被传输过,但我们能强制webpack完成这项工作吗?例子是:app.js:require.ensure(['module1.js'],(require)=>{//atsomepointrequire('module1.js');},'Module1');require.ensure(['module2.js'],(require)=>{//atsomepointrequire('module2.js

javascript - 检查模块是否已经加载到 Webpack 中?

我在一家拥有自定义JS模块打包器的公司工作。该实现有一个函数requireIfLoaded允许您要求一个模块,但前提是它已经被加载。如果模块尚未加载,则会抛出错误。使用requireIfLoaded不会捆绑模块。这大大减少了我们的文件大小。这是一个有用的例子:if(page===PROFILE){//ProfileHelpershouldalreadybedownloadedifwe'reontheprofilepage.constProfileHelper=requireIfLoaded('ProfileHelper');ProfileHelper.doSomething();}el

javascript - 用构造函数揭示模块模式

我在找出实现它的最佳方法时遇到了一些麻烦。我想要一个具有构造函数的模块,该构造函数接受一个参数,该参数存储它以供以后在模块中使用。varModuleB=function(moduleA){this.moduleA=moduleA;}ModuleB.prototype=function(){//privatestuff/functionsfunctionsomeMethod(){moduleA.doSomething();}//publicapireturn{someMethod:someMethod};}();在其他文件中//ModuleAdefinedelsewherevarmodu

javascript - 我如何构建一个从另一个入口点包导入模块的 webpack 包?

我正在尝试生成依赖于另一个包的第二个webpack包。每个页面都需要bundle-one,但只有部分页面需要bundle-two。例如,假设我有以下入口点脚本(这些都是微不足道的例子,只是用它们来说明要点):bundle-one.jsimport$from'jquery';$(document).data('key','value');bundle-two.jsimport$from'jquery';constvalue=$(document).data('key');我知道我可以使用CommonsChunkPlugin生成包含WebPack加载器和jQuery的commons.js文

javascript - Webpack 缺少模块 'Module Not Found'

我目前正在开发一个Reactwebpackbabel等站点,并尝试首次构建。构建成功,但是当我打开浏览器时出现以下错误:UncaughtError:Cannotfindmodule"/Users/michael.nakayama/Documents/Development/jamsesh/node_modules/webpack/node_modules/node-libs-browser/node_modules/process/browser.js"此模块存在。在我的浏览器中转到该实际url会显示有问题的文件。但是我不明白为什么webpack找不到它。我不知道这是babel6问题还