How to change `sourceMappingURL` by using webpack

The SourceMapDevToolPlugin plugin is an option.

new webpack.SourceMapDevToolPlugin({
    filename: '[file].map',
    append: '\n//# sourceMappingURL=' + path + '[url]'
});

Finally this is possible in Webpack 3 using guide from the @omj's response and following configuration

  devtool: 'hidden-source-map', // SourceMap without reference in original file

  new webpack.SourceMapDevToolPlugin({
    filename: '[file].map',
    append: `\n//# sourceMappingURL=${path}[url]`
  })

Update (Webpack v3.10.0):

A new option has been added since Webpack v3.10.0. The option called publicPath:

new webpack.SourceMapDevToolPlugin({
  filename: '[file].map',
  publicPath: 'https://example.com/dev/'
});

Note the devtool: false. You need that if you want to provide custom values. This works for webpack 4.x:

module.exports = {
  // ...
  devtool: false,
  plugins: [
    new webpack.SourceMapDevToolPlugin({
       filename: 'sourcemaps/[file].map',
       publicPath: 'https://example.com/project/',
       fileContext: 'public'
  })
  ]
};