簡體   English   中英

Rollup 要我創建全局變量。 如何使用“導出默認值”?

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

我有一個小應用程序,我正在轉換為使用匯總。 它使用 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

模塊monogram.js使用:

export default drawMonogram

我正在導入它:

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

這兩個都在rollup之前工作。 現在這樣不行嗎?

我真的應該讓output.globals指定一個全局名稱嗎?

為什么我需要一個全局變量? ES6 模塊的全局要求(我原以為模塊在功能范圍內)還是匯總?

Rollup 的錯誤與問題完全無關。 它根本無法在該路徑導入模塊。 在瀏覽器中使用 ES6 模塊,

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

相對於 Web 服務器根。 但是在開發框上使用rollup

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

被認為是相對於硬盤上的 /。 使用相對導入修復了錯誤。

import drawMonogram from './monogram.js';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM