rollup-plugin-esbuild icon indicating copy to clipboard operation
rollup-plugin-esbuild copied to clipboard

`experimentalBundling: true` ignores `define` object

Open johnrees opened this issue 3 years ago • 0 comments

I've made a branch to demonstrate experimentalBundling not using the define config object

First I added an extra task to package.json, which uses a different config file to the current example

"example:experimental": "npm run build && rollup -c example/rollup.config.experimental.js",

rollup.config.js remains unchanged (except for disabling minify)

rollup.config.experimental.js looks like this -

const esbuild = require('../dist/index')

export default {
  input: 'example/index.js',
  output: {
    file: 'example/dist/index.experimental.js', // different output filename
    format: 'cjs',
  },
  plugins: [
    esbuild({
      experimentalBundling: true, // enable experimental
      minify: false,
      define: {
        'process.env.MESSAGE': `"${process.env.MESSAGE}"`,
      },
    }),
  ],
}

I then ran -

MESSAGE='hello from env'  npm run example
MESSAGE='hello from env'  npm run example:experimental

the output of the regular build was as expected

'use strict';

class Foo {
  render() {
    return /* @__PURE__ */ React.createElement("div", {
      className: "hehe"
    }, "hello from env");
  }
}

console.log(Foo);

but the experimental build output had not swapped in the "hello from env" message

'use strict';

// example/foo.tsx
var Foo = class {
  render() {
    return /* @__PURE__ */ React.createElement("div", {
      className: "hehe"
    }, process.env.MESSAGE);
  }
};
var foo_default = Foo;

// example/index.js
console.log(foo_default);

johnrees avatar Oct 11 '21 11:10 johnrees