问题描述
我正在尝试将汇总库捆绑在一起。
在此库中,我正在发出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
],