oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.16k stars 2.77k forks source link

`bun --watch` does not reload when custom loader file changes #5844

Open joshkolenko opened 1 year ago

joshkolenko commented 1 year ago

What version of Bun is running?

1.0.2+37edd5a6e389265738e89265bcbdf2999cb81a49

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

I wrote a custom loader (plugin) to support importing .scss files. The loader is working as expected but when using bun --watch, the imported .scss file does not rerun the process on save.

You can reproduce by doing the following:

Create a .scss file styles.scss

h1 {
  color: red;

  span {
    font-weight: bold;
  }
}

Create a plugin sassLoader.js (and preload the plugin in bunfig.toml)

import { plugin } from 'bun';

plugin({
  name: 'sass',
  setup(build) {
    build.onLoad({ filter: /\.(sass|scss)$/ }, async args => {
      const contents = await Bun.file(args.path).text();
      return { exports: { default: contents }, loader: 'object' };
    });
  },
});
preload=['sassLoader.js']

Import the styles in a js file index.js

import styles from 'styles.scss';

console.log(styles);

Run bun --watch index.js

What is the expected behavior?

I'd expect that when the file that's imported is edited and saved, the watcher would rerun the process just like it does with imported files that are natively supported.

What do you see instead?

Instead, the watcher does not rerun, while other file types that are native (.jsx, .text, etc.) do rerun the process as expected.

Additional information

No response

nyxkrage commented 1 year ago

I am also experiencing this on Darwin 23.0.0 arm64 with bun version 1.0.2 from nixpkgs

joshgillies commented 8 months ago

Related issue https://github.com/oven-sh/bun/issues/4689

Jarred-Sumner commented 8 months ago

There's probably a workaround involving dynamic import + query string parameters that could be used in the meantime which would load the file as text without the loader (inside the loader) and that would add it to the list of watched files