Skip to content

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

Description

@fed

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;

Activity

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

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions