Skip to content

sourceMappingURL is broken when webpack.SourceMapDevToolPlugin is used #72

@gribnoysup

Description

@gribnoysup

If a custom config for the webpack.SourceMapDevToolPlugin is used and the output.publicPath is set in the webpack config, the logic that adjusts the source map url breaks it:

Configuration

const { SourceMapDevToolPlugin } = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const HtmlWebpackInlineSourcePlugin = require("html-webpack-inline-source-plugin");

module.exports = {
  devtool: false,
  output: {
    publicPath: "/foo/bar"
  },
  plugins: [
    new HtmlWebpackPlugin({ inlineSource: ".(js|css)$" }),
    new HtmlWebpackInlineSourcePlugin(),
    new SourceMapDevToolPlugin({
      filename: "[file].map",
      append: `\n//# sourceMappingURL=https://example.com/[file].map`
    })
  ]
};

Current Output

//# sourceMappingURL=/foo/bar/https:/example.com/main.js.map

Expected Output

//# sourceMappingURL=https://example.com/main.js.map

Reproduction repo: https://github.com/gribnoysup/html-webpack-inline-source-plugin-with-custom-sourcemap

Looking at the initial issue and the PR that introduced this sourceMappingURL processing, seems like it will in general work only with the assumption that your index.html and all the other assets are served from the same domain and with the same folder structure for the assets, so it would be nice to be able to opt out as this is not the only case possible especially with the more custom webpack configurations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions