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

Avoid generating version file when ran with webpack-dev-server #2

Open
fed opened this issue Feb 6, 2017 · 6 comments
Open

Avoid generating version file when ran with webpack-dev-server #2

fed opened this issue Feb 6, 2017 · 6 comments
Assignees

Comments

@fed
Copy link
Owner

fed commented Feb 6, 2017

Right now the version file gets written to disk even when running webpack-dev-server. That shouldn't be the case.

This seems to work just fine with Webpack 1 (seen here):

/**
 * When 'webpack' program is used, constructor name is equal to 'NodeOutputFileSystem'.
 * When 'webpack-dev-server' program is used, constructor name is equal to 'MemoryFileSystem'.
 */
const isMemoryFileSystem = (outputFileSystem: Object): boolean => {
  return outputFileSystem.constructor.name === 'MemoryFileSystem';
};

if (!isMemoryFileSystem(compiler.outputFileSystem) && !options.force) {
  return false;
}

Basically the plugin's apply method receives compiler as its first argument. In the function above:

outputFileSystem = compiler.outputFileSystem.constructor.name;

However it seems compiler.outputFileSystem.constructor.name is always NodeOutputFileSystem for Webpack 2.

More info on the compiler object on the official docs.

Could also use process.argv[1] to get the path to the file being executed, but this won't work if Webpack Dev Server gets executed from the CLI. Should try to use a combination of the two:

const isDevServer = process.argv[1].indexOf('webpack-dev-server') > -1 || someOtherCondition;
@fed fed added the enhancement label Feb 6, 2017
@fed fed self-assigned this Feb 6, 2017
@gugu
Copy link

gugu commented Feb 16, 2017

I think it is fine, that file is written in development mode too. We have a code, which checks this file and suggest user to reload page. So we want, that it will work equally on dev and production

@fed
Copy link
Owner Author

fed commented Feb 20, 2017

Thanks for your comment @gugu! Good to know you're using this on your project :)

With this change I'm planning on doing we'll still have the version file written to disk whenever you run Webpack, independently of the environment you pass is. This should be backwards compatible with your app, btw.

What doesn't sound quite right atm is that we shouldn't have the version file generated when running webpack-dev-server — that is, on your local development environment, as all of the other generated files are served from memory.

Do you mind telling me a lil bit more about ur approach to prompting users to refresh the page, just to make sure I won't be breaking ur app?

Cheers!

@gugu
Copy link

gugu commented Feb 20, 2017

Oh, sorry, I misunderstood task

@fed
Copy link
Owner Author

fed commented Feb 20, 2017

Not a prob!! Will let u know when I roll out this change so that you can make sure we haven't broken your app 👍

@jcq
Copy link

jcq commented Aug 22, 2017

I'm actually not seeing the file at all when using webpack-dev-server. It works great when I run production build script, generating the file exactly where it should be. But I don't see any evidence that the file is being generated when running in dev.

From this thread, I would assume that the file would be actually getting written to disk (even if that's supposed to change in the future), but I don't see it. I also get a 404 when I attempt to access the file at the correct path on localhost from my code. Is there an option that I'm missing to make sure it still gets generated under these conditions?

@fed
Copy link
Owner Author

fed commented Oct 4, 2017

Hi @jcq, thanks for your message and sorry for the delay in my response. I've just put together an example to demo this behaviour when running webpack-dev-server. To give it a try, you can clone this repo, cd into the example directory, and run npm install && npm start (more thorough instructions on the README file). The file is currently getting written to disk with webpack-dev-server by default, there's no further config you need to make. Have a look at the webpack.config.js file to see if it has any difference with yours. Yell out if you need any help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants