Skip to content

How can we set source map target file name to a different path? #91

Open
@hzsrc

Description

@hzsrc

For a security purpose, we'd like to build the source map file to an different path. Like this:
/css/main.css => /src-map-files/main.css.map
As to js files, by source-map-dev-tool-plugin, we can set a filename option to resolve this:

        new webpack.SourceMapDevToolPlugin({
            filename: 'src-map-files/[filebase].map',
            append: false
        })

It is implemented in this file node_modules/webpack/lib/SourceMapDevToolPlugin.js:

    let sourceMapFile = compilation.getPath(sourceMapFilename, {
        chunk,
        filename: options.fileContext
            ? path.relative(options.fileContext, filename)
            : filename,
        query,
        basename: basename(filename),
        contentHash: createHash("md4")
            .update(sourceMapString)
            .digest("hex")
    });

I read the source code of optimize-css-assets-webpack-plugin, I found the target assets name is fixed:

    const parse = url.parse(assetName);
    const assetInfo = {
      path: parse.pathname,
      query: parse.query ? `?${parse.query}` : '',
    };
    // ......
    assets.setAsset(`${assetInfo.path}.map${assetInfo.query}`, r.map.toString());

How can we set source map target file name to a different path? Will you implement this filename option in the future?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions