Comments (6)
Hi @lgersman !
Since v0.0.18, nanobundle has "standalone mode", which tries to inline all dependencies. In standalone mode, you can specify explicitly which dependency will not be inlined.
https://github.com/cometkim/nanobundle/tree/v0.0.18#embedding-dependencies
I'm not sure this option and microbundle's option you mentioned is met your requirement.
Can you provide some esbuild or rollup config you use for it?
from espub.
Hello @cometkim,
the reason for my question is that i would like to use your nanobundle to bundle Wordpress Gutenberg blocks. These blocks consists of Javascript running in the browser inside the Gutenberg Editor.
The Gutenberg Editor provides React and many of the @wordpress/* packages via global variable windows.wp
(Example: import { Button } from ''@wordpress/components';
is available in the browser via const { Button } = windows.wp.components;
).
That means that these packages dont need to be bundled but transpiled to access the import using global variables (like window.React
and window.wp.components
).
in Rollup you would declare that like this :
const config = {
input: 'foo.js,
output: {
file: `dist/foo.js`,
format: 'iife',
globals: {
react: 'React',
'@wordpress/components': 'wp.components'
},
....
},
The transpilation is also possible using esbuild (see here : https://github.com/lgersman/ix-article-esbuild-2021/blob/develop/bin/esbuild-bundle.mjs#L64)
from espub.
Ok, I understand your requirement.
I'm trying to keep the config of nanobundle as simple as possible. I could also explore a good place for additional config per dependency in package.json
(e.g. peerDependencyMeta
), but I think import maps would be a simpler way to do this.
vendor/wp-components.js
export const {
Button,
} = window.wp.components;
import-maps.json
or package.json
{
"imports": {
"@wordpress/components": "./vendor/wp-components.js"
}
}
from espub.
Good morning,
I understand your reasons (simplicity !) but some packages may expose dozens of exports ... which will result in a huge amount of import map code.
Don't you think there is a better way to expose globals ?
from espub.
Of course, simplicity is important, but there is another big problem here.
Adding personal opinions without esbuild config already existing or well-known standards is against the goal of the nanobundle.
Maybe it makes sense to provide an escape hatch that allows custom plugins for other cases.
from espub.
from espub.
Related Issues (20)
- `--standalone` flag doesn't work
- Bundling Types for a `.cts` File Doesn't Work in a Project With `type` set to `module` HOT 1
- CSS modules
- Support build without bundling HOT 2
- Enable declarationMap by default
- duplicate of tsconfck on the public npm registry HOT 1
- Plan to next build tool
- Minify using terser
- Subpath imports condition
- Support CSS bundling
- ESBuild codegen
- jsx transform doesn't work HOT 19
- Clean command
- Migrate to Clipanion HOT 3
- Dependency Dashboard
- Support for outputting bundles with JSX extensions HOT 1
- `--no-sourcemap` flag not working HOT 1
- How to generate only index.d.ts without bundle files? HOT 3
- Support custom condition
- Support subpath imports
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from espub.