[英]How to get a filename renamed by Webpack?
I'm using a webassembly file compiled by Emscripten in my project. 我在项目中使用的是Emscripten编译的webassembly文件。 And since my project uses Webpack, it renames all files, then the Emscripten module can't find more the webassembly file.
而且由于我的项目使用Webpack,因此它将重命名所有文件,因此Emscripten模块找不到更多的webassembly文件。
Then I need to get the new filename of the webassembly file to can load it. 然后,我需要获取webassembly文件的新文件名才能加载它。
I found this workaround , but I want a better solution, because I don't want do change the webpack.config.js
with configurations about the .wasm
files. 我发现这个解决办法 ,但我希望有一个更好的解决办法,因为我不想做改变
webpack.config.js
与相关配置.wasm
文件。
Explain the context: I have a project called bursh
that it uses Webpack and imports a module called scissors
which it has the webassembly files. 解释背景:我有一个项目叫做
bursh
它使用的WebPack和进口模块称为scissors
,它具有webassembly文件。 So I'm looking for a solution which doesn't need to update the configurations, because of the isolation of responsibilities - doesn't make sense to set configurations at brush
for some reason by scissors
所以我在寻找,并不需要因为责任的分离的更新配置,解决方案-没有意义,在设定的配置
brush
出于某种原因被scissors
From your description you might want to look into copy-webpack-plugin . 根据您的描述,您可能需要研究copy-webpack-plugin 。 Webpack normally bundles multiple files into one or several larger files, but if you additionally want to copy files into your build, this plugin can do just that.
Webpack通常将多个文件捆绑为一个或几个较大的文件,但是如果您还想将文件复制到构建中,则此插件可以做到这一点。
I resolved the problem. 我解决了这个问题。 My solution is adding Webpack at
scissors
in order to set the configurations in this project. 我的解决方案是在
scissors
处添加Webpack以便在此项目中设置配置。
const path = require('path')
const rules = [
{
loader: 'file-loader',
test: /huffman\.wasm$/,
type: 'javascript/auto',
},
]
rules.concat()
module.exports = {
devtool: 'source-map',
entry: './src/index.js',
module: {
rules,
},
node: {
fs: 'empty',
},
output: {
filename: 'scissors.js',
libraryTarget: 'commonjs2',
path: path.join(__dirname, './dist'),
sourceMapFilename: 'scissors.js.map',
},
}
I don't know if this is the best solution, because now I have a Webpack in brush
project and also in scissors
project, then it will increase complexity in my code... But in this way I can keep the isolation of responsibilities. 我不知道这是否是最好的解决方案,因为现在我在
brush
项目和scissors
项目中都有一个Webpack,那么它将增加我的代码的复杂性……但是通过这种方式,我可以保持职责隔离。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.