admin管理员组文章数量:1327257
i have this module
import * as cborg from 'cborg'
import { CID } from 'multiformats/cid'
function cidEncoder (obj) {
}
....
when i build module with this mand line
"bundle": "./node_modules/.bin/esbuild ./dist/index.mjs --bundle --outfile=./dist/out.mjs",
I have bundle without export default
when i build module with this mand line
"build": "./node_modules/.bin/esbuild ./src/index.js --target=es2020 --outfile=./dist/index.mjs",
This import not include in module
import * as cborg from 'cborg'
import { CID } from 'multiformats/cid'
How can i create module with include all modules in one file ?
i have this module
import * as cborg from 'cborg'
import { CID } from 'multiformats/cid'
function cidEncoder (obj) {
}
....
when i build module with this mand line
"bundle": "./node_modules/.bin/esbuild ./dist/index.mjs --bundle --outfile=./dist/out.mjs",
I have bundle without export default
when i build module with this mand line
"build": "./node_modules/.bin/esbuild ./src/index.js --target=es2020 --outfile=./dist/index.mjs",
This import not include in module
import * as cborg from 'cborg'
import { CID } from 'multiformats/cid'
How can i create module with include all modules in one file ?
Share Improve this question asked Jan 2, 2023 at 22:29 SergeySergey 7021 gold badge12 silver badges27 bronze badges1 Answer
Reset to default 8It looks like you haven't specified a platform
, so the default will be browser, and according to the esbuild docs the output format
(which you also haven't specified) will default to iife:
When the platform is set to browser (the default value):
- When bundling is enabled the default output format is set to iife, which wraps the generated JavaScript code in an immediately-invoked function expression to prevent variables from leaking into the global scope.
So given that you're trying to generate an ESM module (i.e. based on the *.mjs
extension on the build output file) you'll need an esm output format, which is the default when specifying a neutral platform
:
"bundle": "esbuild ./src/index.js --bundle --platform=neutral --outfile=./dist/out.mjs",
You'll also need to add a default export to your index.js
file:
import * as cborg from 'cborg'
import { CID } from 'multiformats/cid'
export default function cidEncoder (obj) {
...
}
Hope that helps.
本文标签: javascriptHow create bundle with esbuild with import modulesStack Overflow
版权声明:本文标题:javascript - How create bundle with esbuild with import modules - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742210940a2433698.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论