okikio / bundlejs

An online tool to quickly bundle & minify your projects, while viewing the compressed gzip/brotli bundle size, all running locally on your browser.
https://bundlejs.com
MIT License
751 stars 13 forks source link

Fetch the versions mentioned in package.json. #56

Closed tyagirajat200 closed 10 months ago

tyagirajat200 commented 1 year ago

If I provide the complete package.json with dependencies, the code bundling process should fetch the versions mentioned in package.json instead of always fetching the latest version. Please guide me on the possible ways to achieve this.

Link -> Click here

okikio commented 1 year ago

Yeah, sorry that's a bug 🐛 😅, I'll try to get this fixed. In the meantime you can overcome this issue by manually setting the version for the module E.g.

// Click Build for the Bundled, Minified & Compressed package size
export * from "react@17.0.2";
export * from "react-dom@17.0.2";
class App extends Component {
  constructor() {
    super();
    this.state = {
      name: 'React',
    };
  }

  render() {
    return 'Raj';
  }
}
tyagirajat200 commented 1 year ago

Hi @okikio , Thank you for your prompt reply. Kindly inform us once the issue has been resolved.

tyagirajat200 commented 1 year ago

Hi @okikio ,

Can the required code be included solely? For instance:

import { zip } from 'https://unpkg.com/lodash-es@4.17.15/lodash.js';
console.log(zip([1, 2], ['a', 'b']));

In this scenario, the bundler should fetch and incorporate only the zip method from lodash, rather than including all of its methods, which is the current behavior.

Link -> https://bundlejs.com/?q=https%3A%2F%2Funpkg.com%2Flodash-es%404.17.15%2Flodash.js&treeshake=%5B*%5D&text=%22console.log%28zip%28%5B1%2C+2%5D%2C+%5B%27a%27%2C+%27b%27%5D%29%29%22

okikio commented 1 year ago

It's because you're fetching from the URL, it's much harder to determine what to treeshake when a package is being fetched from a URL directly

Here is the fix,

// Click Build for the Bundled, Minified & Compressed package size
import { zip } from "lodash-es@4.17.15";
console.log(zip([1, 2], ['a', 'b']))

Link -> https://bundlejs.com/?q=(import)lodash-es@4.17.15&treeshake={+zip+}&text=console.log(zip([1,+2],+['a',+'b']))