FredKSchott / snowpack

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️
https://www.snowpack.dev
MIT License
19.48k stars 922 forks source link

[BUG] Using plugin overrides buildOptions #3296

Open amithm7 opened 3 years ago

amithm7 commented 3 years ago

Bug Report Quick Checklist

Describe the bug

While using plugin: '@snowpack/plugin-webpack' and build option clean set to false, files in out directory still get cleared.

To Reproduce

  1. Set buildOptions clean: false, and use plugin '@snowpack/plugin-webpack'.
  2. Write a file to your build out directory.
  3. Now build with snowpack: snowpack build --watch

The file written before snowpack build gets removed. As I am using --watch flag, this behaviour doesn't reproduce in subsequent writes.

Expected behavior

Build out directory files be preserved as clean: false option is set.

jalovatt commented 3 years ago

Yeah, @snowpack/plugin-webpack explicitly cleans the build folder:

https://github.com/snowpackjs/snowpack/blob/680272eb19c43ef88f9d83e436e7131444c53407/plugins/plugin-webpack/plugin.js#L236-L239

The reasoning makes sense to me, but IMO it shouldn't be forced. For instance, if you run the plugin with manifest: true it could reasonably just remove all of the files listed in manifest.json from the previous build and not touch anything else.

I've found it easiest to have the Webpack plugin write to a separate folder entirely, i.e.:

['@snowpack/plugin-webpack', {
  extendConfig: (config) => {
    config.output.path = path.resolve(__dirname, 'dist')
  }
}]

That way build is always the plain Snowpack build and dist has your final bundle. Keeps things tidier, IMO, and it leaves build/index.html linked to the original files instead of updating it with the hashed ones so you can always check that things are being built the way you want before Webpack does its thing.

theseyi commented 3 years ago

@jalovatt I like your approach, rather than having both tools (webpack and snowpack build) build to the same output folder, however, the method you proposed above config.output.path = path.resolve(__dirname, 'dist') does not contain the index.html entry point? do you have a solution that just leverages @snowpack/plugin-webpack?

jalovatt commented 3 years ago

@jalovatt I like your approach, rather than having both tools (webpack and snowpack build) build to the same output folder, however, the method you proposed above config.output.path = path.resolve(__dirname, 'dist') does not contain the index.html entry point? do you have a solution that just leverages @snowpack/plugin-webpack?

Sorry, I forgot that I was using a local branch when I suggested that. For anyone else reading this, there is a PR to have the plugin respect the user's config.output.path: #3255