Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7625 from webpack/bugfix/multiple-assets-same-file
allow emitting to the same filename when hash matches
- Loading branch information
Showing
6 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
it("should allow reference the same wasm multiple times", function() { | ||
return import("./module").then(function(module) { | ||
const result = module.run(); | ||
expect(result).toEqual(84); | ||
}); | ||
}); | ||
|
||
it("should allow reference the same wasm multiple times (other chunk)", function() { | ||
return import("./module?2").then(function(module) { | ||
const result = module.run(); | ||
expect(result).toEqual(84); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { getNumber } from "./wasm.wat?1"; | ||
import { getNumber as getNumber2 } from "./wasm.wat?2"; | ||
|
||
export function run() { | ||
return getNumber() + getNumber2(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly"); | ||
|
||
module.exports = function(config) { | ||
return supportsWebAssembly(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(module | ||
(type $t0 (func (param i32 i32) (result i32))) | ||
(type $t1 (func (result i32))) | ||
(func $add (export "add") (type $t0) (param $p0 i32) (param $p1 i32) (result i32) | ||
(i32.add | ||
(get_local $p0) | ||
(get_local $p1))) | ||
(func $getNumber (export "getNumber") (type $t1) (result i32) | ||
(i32.const 42))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const { CachedSource } = require("webpack-sources"); | ||
|
||
/** @typedef {import("../../../lib/Compilation")} Compilation */ | ||
|
||
module.exports = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.wat$/, | ||
loader: "wast-loader", | ||
type: "webassembly/experimental" | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
function() { | ||
this.hooks.compilation.tap( | ||
"Test", | ||
/** | ||
* @param {Compilation} compilation Compilation | ||
* @returns {void} | ||
*/ | ||
compilation => { | ||
compilation.moduleTemplates.webassembly.hooks.package.tap( | ||
"Test", | ||
source => { | ||
// this is important to make each returned value a new instance | ||
return new CachedSource(source); | ||
} | ||
); | ||
} | ||
); | ||
} | ||
] | ||
}; |