gajus / write-file-webpack-plugin

Forces webpack-dev-server to write bundle files to the file system.
Other
527 stars 54 forks source link

Support files with absolute paths #36

Closed candu closed 7 years ago

candu commented 7 years ago

I'm using html-webpack-plugin to output an HTML file to an absolute path outside of output.path. When I run webpack-dev-server with write-file-webpack-plugin enabled, it instead interprets that absolute path relative to the outputPath option provided to the plugin.

For instance, using configuration like this:

{
  devServer: {
    ...
    outputPath: '/path/to/outputDir'
  },
  output: {
    path: '/path/to/outputDir'
  }
  ...
  plugins: [
    new HtmlWebpackPlugin({filename: '/absolute/path/to/html/output', ...}),
    new WriteFileWebpackPlugin()
  ]
}

this plugin writes the HTML file to /path/to/outputDir/absolute/path/to/html/output, not /absolute/path/to/html/output as expected.

I suspect this line is responsible, and should be changed to something like:

let outputFilePath = assetPath;
if (!path.isAbsolute(outputFilePath)) {
  outputFilePath = path.join(outputPath, outputFilePath);
}