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

Only add once for --watch mode #4

Closed
silverwind opened this issue Aug 17, 2020 · 4 comments · Fixed by #6
Closed

Only add once for --watch mode #4

silverwind opened this issue Aug 17, 2020 · 4 comments · Fixed by #6

Comments

@silverwind
Copy link
Contributor

silverwind commented Aug 17, 2020

When running webpack --watch with incremental compilations and with a static string type source, the module will still add it on every incremental build which is useless and spams the log unneccesarily. Suggesting to emit a string asset only once during --watch. Function/Promise sources should of course be emitted every build because their content may change.

@silverwind silverwind changed the title Only add once Only add once for --watch mode Aug 17, 2020
@sindresorhus
Copy link
Owner

👍

@silverwind
Copy link
Contributor Author

silverwind commented Aug 17, 2020

Not super familar with webpack API, but I think we need to find the correct hook and then call compilation.emitAsset() in it (as opposed to mutating compilation.assets which this module currently does).

@sibiraj-s
Copy link

You can do this.

const existingAsset = compilation.getAsset('assetName')

if(!existingAsset) {
  compilation.emitAsset('assetName',  source)
}

@silverwind
Copy link
Contributor Author

Thanks. Maybe I'll incorporate that in #6 if input is a string (If it's a function, we need to emit every time).

silverwind added a commit to silverwind/add-asset-webpack-plugin that referenced this issue Nov 10, 2020
silverwind added a commit to silverwind/add-asset-webpack-plugin that referenced this issue Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants