如何使用提取polyfill,汇总和打字稿创建umd包?

问题描述

我正在尝试将汇总库捆绑在一起。

在此库中,我正在发出http请求。 我想使用MainMenu并在节点上运行代码时使用polyfill。 我无法正确配置。 它可以在节点上运行,但不能在浏览器中运行,或者相反。

这是我的配置文件的样子:

var _main_node: MainNode

func _enter_tree():
    _main_node = get_parent()

func _on_Button_pressed():
    var target_scene = "Opening Scene"
    _main_node.loadNewScene(target_scene)
    _main_node.freeScene(_main_node.current_scene)

这是我在代码中导入提取的方式:

fetch

在浏览器中很好用✅

在节点中,我出现以下错误❌:

 module.exports = [{
    input: 'src/mylibrary.ts',output: {
      name: LIB_NAME,file: getOutputFileName(
        resolve(ROOT,pkg.browser),env === 'production'
      ),format: 'umd',globals: {
        fetch: 'cross-fetch',},plugins: [
     typescript({
      useTsconfigDeclarationDir: true,tsconfigOverride: {
        allowJs: false,includes: ['src'],exclude: ['tests','examples','*.js','scripts'],esModuleInterop: true,}),nodeResolve({
        mainFields: ['jsnext','main'],preferBuiltins: true,browser: true,commonjs({
        include: ['node_modules/**'],json(),env === 'production' ? terser() : {},// will minify the file in production mode
    ],}]

当我查看捆绑的umd时,它来自这里:

import 'cross-fetch/polyfill'

任何想法可能是什么问题?

解决方法

我忘记在cross-fetch键(第2行)中添加external

以下示例对我有用:

 {
    input: 'src/meilisearch.ts',// directory to transpilation of typescript
    external: ['cross-fetch','cross-fetch/polyfill'],output: {
      name: LIB_NAME,file: getOutputFileName(
        // will add .min. in filename if in production env
        resolve(ROOT,pkg.browser),env === 'production'
      ),format: 'umd',sourcemap: env === 'production',// create sourcemap for error reporting in production mode
    },plugins: [
     typescript({
      useTsconfigDeclarationDir: true,tsconfigOverride: {
        allowJs: false,includes: ['src'],exclude: ['tests','examples','*.js','scripts'],esModuleInterop: true,},}),babel({
        babelrc: false,extensions: ['.ts'],presets: [
          [
            '@babel/preset-env',{
              modules: false,targets: {
                browsers: ['last 2 versions','ie >= 11'],],nodeResolve({
        mainFields: ['jsnext','main'],preferBuiltins: true,browser: true,commonjs({
        include: ['node_modules/**'],json(),env === 'production' ? terser() : {},// will minify the file in production mode
    ],

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...