-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Question] Convert Rollup build script to esbuild #4147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The main challenge to do that is to replicate the behavior of // run-esbuild.mjs
import * as esbuild from 'esbuild'
import { getModules } from './node_modules/rollup-plugin-polyfill-node/dist/es/modules.js'
await esbuild.build({
entryPoints: ['index.js'],
bundle: true,
format: 'esm',
outfile: 'linter.mjs',
plugins: [polyfill()],
banner: { js: 'if (!global) { var global = globalThis || window; }' },
inject: ['./inject.js'],
logLevel: 'info'
}).catch(() => process.exit(1))
await esbuild.build({
entryPoints: ['example/script.js'],
bundle: true,
outfile: 'example/bundle.js',
logLevel: 'info'
}).catch(() => process.exit(1))
function polyfill() {
const mods = getModules()
return {
name: 'polyfill',
setup(build) {
// Not all node builtins are captured here, just work for the example case.
build.onResolve({ filter: /^node:|^(process|_inherits)$/ }, args => {
const name = args.path.replace('node:', '')
if (mods.has(name)) {
return { namespace: 'polyfill', path: name, sideEffects: false }
}
})
build.onLoad({ namespace: 'polyfill', filter: /(?:)/ }, args => {
return { contents: mods.get(args.path) }
})
}
}
}
// inject.js
import process from 'node:process'
export { process } Save the I saw your issue when running the browserified eslint inside a web extension doesn't work UziTech/eslint-linter-browserify#519. The error message says the CSP forbids running any untrusted code (via Anyway, this is not a problem with esbuild. |
Thank you for taking time to look into this issue. I managed to get it built with your script, although as you have mentioned, it doesn’t solve the Ajv issue. If I may ask, what is the purpose of await esbuild.build({
entryPoints: ['example/script.js'],
bundle: true,
outfile: 'example/bundle.js',
logLevel: 'info'
}).catch(() => process.exit(1)) I get ...
|
@erosman It is used to bundle the e2e test in that repo: https://github.com/UziTech/eslint-linter-browserify/blob/master/example/script.js. Since I'm using a relative path, the build script must be executed (i.e. with cwd) in the root folder of the repo to make it find the correct file. |
I am a novice and trying to convert eslint-linter-browserify Rollup build script to esbuild by trial & error.
However, it runs into errors.
After adding
platform: 'node
, esbuild generates the build without error but the resulted file, when imported into the browser, has the following error:Any help will be greatly appreciated.
build.js
The text was updated successfully, but these errors were encountered: