2018-06-29 16:03:21 +08:00
|
|
|
const { CachedSource } = require("webpack-sources");
|
2019-10-09 23:11:34 +08:00
|
|
|
const { AsyncWebAssemblyModulesPlugin } = require("../../../../").wasm;
|
2018-06-29 16:03:21 +08:00
|
|
|
|
2019-10-02 14:54:21 +08:00
|
|
|
/** @typedef {import("../../../../lib/Compilation")} Compilation */
|
2018-06-29 16:03:21 +08:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.wat$/,
|
|
|
|
loader: "wast-loader",
|
2019-07-15 21:03:29 +08:00
|
|
|
type: "webassembly/async"
|
2018-06-29 16:03:21 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2019-06-05 19:25:15 +08:00
|
|
|
experiments: {
|
|
|
|
asyncWebAssembly: true,
|
|
|
|
importAwait: true
|
|
|
|
},
|
2018-06-29 16:03:21 +08:00
|
|
|
plugins: [
|
2020-03-29 06:10:15 +08:00
|
|
|
function () {
|
2018-06-29 16:03:21 +08:00
|
|
|
this.hooks.compilation.tap(
|
|
|
|
"Test",
|
|
|
|
/**
|
|
|
|
* @param {Compilation} compilation Compilation
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
compilation => {
|
2019-10-02 14:54:21 +08:00
|
|
|
AsyncWebAssemblyModulesPlugin.getCompilationHooks(
|
|
|
|
compilation
|
|
|
|
).renderModuleContent.tap("Test", source => {
|
|
|
|
// this is important to make each returned value a new instance
|
|
|
|
return new CachedSource(source);
|
|
|
|
});
|
2018-06-29 16:03:21 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|