momocow / webpack-userscript

A Webpack plugin for userscript projects. 🙈
https://cow.moe/webpack-userscript/
MIT License
202 stars 21 forks source link

Restarting dev server resets build version #14

Closed Juraj-Masiar closed 4 years ago

Juraj-Masiar commented 5 years ago

Hello,

First of all, thank you for making this useful plugin!

I've just started to use it and I noticed that if I stop the server and start it again, it will generate v1.0.0-build.2 again which is usually older than the version I had before and I have to reinstall the script manually (by clicking "Downgrade").

Is there a way to remember build number to make development easier? Or maybe just use current time: Date.now() as build version, that way it will always generate bigger number.

Something like this in your index.js:

buildNo: Date.now(),
momocow commented 5 years ago

Reasonable request. Thanks for the feedback.

momocow commented 5 years ago

@Juraj-Masiar It actually can be achieved in the current version with using HeaderProvider. HeaderProvider will be called after each compilation.

In the webpack.config.js, construct the plugin instance with the following options,

new WebpackUserscript({
  headers ({ version }) {
    const buildTime = Date.now()
    return {
      version: `${version}-build.${buildTime}`
    }
  }
})

Instead of changing the current buildNo, I think a new variable buildTime can be provided as well in the future version, then you can use it in the template string instead of using HeaderProvider function.

Juraj-Masiar commented 5 years ago

Nice! It works perfect! Good thinking :) Feel free to close this, but I do like the idea with the buildTime variable, I'm sure other would appreciate it as well.

Thanks again for fast fix!

momocow commented 4 years ago

Closed by #18

Released in v2.4.0.