I want to manually parse source maps to do some stack trace manipulation. For that I use the popular source-map module.
To run that module in the browser I have to pass it the path to the web assembly. Such as*:
require("source-map/lib/mappings.wasm");
sourceMap.SourceMapConsumer.initialize({
"lib/mappings.wasm": "lib/mappings.wasm"
});
* This is pseudocode as I am actually using Scala.js but that is irrelevant to the question.
I have configured webpack to copy that file:
test: /.wasm$/,
type: 'javascript/auto',
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'lib',
publicPath: 'lib'
}
}
]
This all works great.
What I would like to know whether I can get webpack to replace a require with the public path? Something like:
sourceMap.SourceMapConsumer.initialize({
"lib/mappings.wasm": require("source-map/lib/mappings.wasm");
)}
I've seen some funky looking require statements like require("file-loader!source-map/lib/mappings.wasm")
but I don't know what that syntax is. Is there documentation on that?
question from:
https://stackoverflow.com/questions/65915036/webpack-replace-require-with-public-path 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…