简体   繁体   English

使用webpack导入requirejs amd模块

[英]import requirejs amd module with webpack

I'm using Converse.js and it's prebuilt into the RequireJS/AMD syntax. 我正在使用Converse.js ,它已预先构建到RequireJS / AMD语法中。 Including the file from a CDN you could use it like require(['converse'], function (converse) { /* .. */ }) . 包括来自CDN的文件,你可以使用它像require(['converse'], function (converse) { /* .. */ }) How is it possible to use this with webpack? 如何在webpack中使用它? I would like to bundle converse.js with my webpack output. 我想将converse.js与我的webpack输出捆绑在一起。

I have the file on disk, and want to import it like 我有磁盘上的文件,并希望导入它像

import converse from './converse.js';
converse.initialize({ .. });

Webpack picks up the file and bundles it correctly, although it's not useable yet as it throws 'initialize is not a function'. Webpack拾取文件并正确捆绑它,虽然它不可用,因为它抛出'初始化不是一个函数'。 What am I missing? 我错过了什么?

I suspect the way their bundle is built will not work correctly with how Webpack evaluates modules in a limited context. 我怀疑他们的bundle的构建方式无法正常运行Webpack如何在有限的上下文中评估模块。

From their builds , taking the built AMD module via NPM without dependencies should be parsable by Webpack and it will enable you to provide the dependencies to avoid dupes in the final output. 他们的构建中 ,通过NPM构建的AMD模块没有依赖关系应该可以通过Webpack进行解析,它将使您能够提供依赖关系以避免在最终输出中使用dupe。

If all else fails, using the script-loader will evaluate the script in the global context and you'd get the same experience as if you'd have followed their usage guidelines to reference it from a CDN, just don't forget to configure the globals for your linter. 如果所有其他方法都失败了,使用脚本加载器将在全局上下文中评估脚本,并且您将获得相同的体验,就好像您已遵循其使用准则从CDN引用它一样,只是不要忘记配置你的linter的全局变量。

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

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