Giter VIP home page Giter VIP logo

Comments (6)

cometkim avatar cometkim commented on May 10, 2024

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.

lgersman avatar lgersman commented on May 10, 2024

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.

cometkim avatar cometkim commented on May 10, 2024

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.

lgersman avatar lgersman commented on May 10, 2024

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.

cometkim avatar cometkim commented on May 10, 2024

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.

lgersman avatar lgersman commented on May 10, 2024

from espub.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.