Skip to content
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

Define property causes bundle to minify #331

Closed
1 task done
pavel-krasnov opened this issue Aug 2, 2023 · 7 comments · Fixed by #333 or #334
Closed
1 task done

Define property causes bundle to minify #331

pavel-krasnov opened this issue Aug 2, 2023 · 7 comments · Fixed by #333 or #334
Labels
bug Something isn't working pending triage released

Comments

@pavel-krasnov
Copy link

pavel-krasnov commented Aug 2, 2023

Bug description

  1. Given the provided template, I run npm start and get a minified bundle under the dist folder.
  2. I set optimization.minimize to false to disable Webpack minimization.
  3. I run npm start and get a not minified bundle under the dist folder.
  4. I add the following to replace values in the bundle:
new EsbuildPlugin({
  define: {
    'process.env.ENV': JSON.stringify('value'),
  },
}),
  1. I run npm start and get a minified bundle under the dist folder.
  2. Adding minify: false to the plugin options constructor argument doesn't change anything.

It looks like uing EsbuildPlugin to define values causes minification no matter what.

Minimal reproduction link

https://stackblitz.com/edit/node-dawpgq

Environment

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.20.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.4.2 - /usr/local/bin/npm
  npmPackages:
    esbuild-loader: ^3.0.0 => 3.0.0 
    webpack: ^5.75.0 => 5.75.0

Can you contribute a fix?

  • I’m interested in opening a pull request for this issue.
@pavel-krasnov pavel-krasnov added bug Something isn't working pending triage labels Aug 2, 2023
@privatenumber
Copy link
Owner

Good catch.

You can turn off minification by setting one of these properties to false:
https://github.com/esbuild-kit/esbuild-loader/blob/1a758b41a850897072560f853d44a1607328a255/src/plugin.ts#L132-L136

Previously, it was called the "EsbuildMinifyPlugin". I should've also changed this default behavior when I renamed it to the generic "EsbuildPlugin".

I will change this default behavior but it will have to be in the next breaking.

@pavel-krasnov
Copy link
Author

Thank you, it works. Here is what I did:

// No need of this anymore.
// optimization: {
//   minimize: false,
//   minimizer: [
//     // Use esbuild to minify
//     new EsbuildPlugin({}),
//   ],
// },

plugins: [
  new EsbuildPlugin({
    define: {
      'process.env.ENV': JSON.stringify('value'),
    },
    // This is enough.
    minifyIdentifiers: false,
  }),
],

@privatenumber
Copy link
Owner

Preparing the v4 release where this is fixed. Would you mind helping test?

npm install -D 'esbuild-kit/esbuild-loader#npm/v4'

@pavel-krasnov
Copy link
Author

It worked without the minify option after installing the new version, thank you.

@privatenumber
Copy link
Owner

🎉 This issue has been resolved in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@pavel-krasnov
Copy link
Author

@privatenumber I'm afraid now using the plugin causes bandle to not minify even in cases I want to minify.

@privatenumber
Copy link
Owner

If you can explain, please file a new issue.

I'm locking this thread as the original issue is resolved.

Repository owner locked as resolved and limited conversation to collaborators Aug 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working pending triage released
Projects
None yet
2 participants