简体   繁体   English

Rollup 要我创建全局变量。 如何使用“导出默认值”?

[英]Rollup wants me to create global variables. How can I use 'export default'?

I have a small app I am converting to use rollup.我有一个小应用程序,我正在转换为使用汇总。 It uses ES6 modules - when I run rollup -c , it complains about one of my ES6 modules:它使用 ES6 模块 - 当我运行rollup -c ,它会抱怨我的 ES6 模块之一:

/js/monogram.js (imported by src\main.js)
(!) Missing global variable name
Use output.globals to specify browser global variable names corresponding to external modules
/js/monogram.js (guessing 'drawMonogram')
created public\js\bundle.js in 311ms

The module monogram.js uses:模块monogram.js使用:

export default drawMonogram

I am importing it with:我正在导入它:

import drawMonogram from '/js/monogram.js';

Both of these worked before rollup .这两个都在rollup之前工作。 Is this now not OK?现在这样不行吗?

Should I actually make output.globals to specify a global name?我真的应该让output.globals指定一个全局名称吗?

Why do I need a global variable?为什么我需要一个全局变量? Is the global requirement from ES6 modules (I'd have thought modules would be in a functional scope) or rollup? ES6 模块的全局要求(我原以为模块在功能范围内)还是汇总?

Rollup's error is completely unrelated to the problem. Rollup 的错误与问题完全无关。 It's simply not able to import the module at that path.它根本无法在该路径导入模块。 Using ES6 modules in browser,在浏览器中使用 ES6 模块,

import drawMonogram from '/js/monogram.js';

Was relative to the web server root.相对于 Web 服务器根。 However using rollup on the developmnt box,但是在开发框上使用rollup

import drawMonogram from '/js/monogram.js';

is considered relative to / on the hard disk.被认为是相对于硬盘上的 /。 Using a relative import fixed the errror.使用相对导入修复了错误。

import drawMonogram from './monogram.js';

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

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