2017-10-30 20:56:57 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
2018-04-28 01:02:02 +08:00
|
|
|
const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin");
|
2017-10-30 20:56:57 +08:00
|
|
|
|
|
|
|
class FetchCompileWasmTemplatePlugin {
|
|
|
|
apply(compiler) {
|
2018-02-25 09:00:20 +08:00
|
|
|
compiler.hooks.thisCompilation.tap(
|
|
|
|
"FetchCompileWasmTemplatePlugin",
|
|
|
|
compilation => {
|
2018-04-28 14:53:30 +08:00
|
|
|
const mainTemplate = compilation.mainTemplate;
|
2018-04-28 01:02:02 +08:00
|
|
|
const generateLoadBinaryCode = path =>
|
|
|
|
`fetch(${mainTemplate.requireFn}.p + ${path})`;
|
|
|
|
|
2018-04-30 14:35:06 +08:00
|
|
|
const plugin = new WasmMainTemplatePlugin(generateLoadBinaryCode, true);
|
|
|
|
plugin.apply(mainTemplate);
|
2018-02-25 09:00:20 +08:00
|
|
|
}
|
|
|
|
);
|
2017-10-30 20:56:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = FetchCompileWasmTemplatePlugin;
|