-
-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: access to compilation.assetsInfo
in compilation.hooks.processAssets.tap
#7033
Comments
If you are trying to append and access additional information to AssetInfo object across compilation stages, please use These getters and setters are necessary for bidirectional conversion between Js Object and their corresponding Rust structs under the hood. Otherwise, only knownAssetInfo will be persisted across compilation stages: Let me know if this helped |
This helped, thank you. I was able to move forward a little bit. 1) Do you know if there is a way to replace
2) Also, I wasn't able to confirm this fully, because I'm getting |
Calling getAssets(): ReadonlyArray<Asset> {
const assets = this.#inner.getAssets();
return assets.map(asset => {
return Object.defineProperties(asset, {
info: {
value: JsAssetInfo.__from_binding(asset.info)
},
source: {
get: () => this.__internal__getAssetSource(asset.name)
}
}) as unknown as Asset;
});
} |
I am not sure what it means. Can you create a minimal reproduction that triggers this error? |
One custom plugin emits a new asset with: const fileContents = JSON.stringify( fileListJson );
compilation.emitAsset( fullPath, new compiler.webpack.sources.RawSource( fileContents ) ); And in another custom plugin I tried: compilation.getAsset( filePath ).source(); // didn't work
compilation.getAsset( filePath ).source.get(); // didn't work
compilation.getAsset( filePath ).source.toString(); // didn't work Only this worked, but seems like it's a band-aid: const fileMapSource = compilation.getAsset( filePath ).source._valueAsString; // did work Its usage is: const fileMap = JSON.parse( fileMapSource ); I'm on |
Is there access to I only found this:
My usage in the same custom plugin: const foundAsset = findAsset( pathInMap, compilation.assetsInfo );
if ( foundAsset ) {
let assetPathPrefix = '';
for ( const [ key, value ] of compilation.valueCacheVersions ) {
// @todo Find less error-prone way.
if ( key.includes( 'webpack/DefinePlugin process.env.ASSET_PATH' ) ) {
assetPathPrefix = value
// “/” gets (re)added later
// @todo This is all dirty. Find a better way.
.replace( '/', '' )
.replace( /"/gu, '' );
}
}
filePath = `${ assetPathPrefix }${ foundAsset }`;
} |
You were using the wrong API. Check out webpack-sources. |
This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
What problem does this feature solve?
Hi! I was trying to migrate my webpack v5 setup with several custom-built webpack plugins to Rspack v1.0.0-alpha.0, but faced a blocker:
One of my custom webpack plugins uses the assets info metadata in the
processAssets
compilation hook, but it'sundefined
in Rspack.My use case:
Besides regular webpack entries, my setup also processes pre-webpack legacy JS, CSS, and image files added via CopyWebpackPlugin: their content hash gets added into the file name, and on
processAssets
I generate a map of originalsourceFilename
s to the new paths, which is then used by a non-Node.js server to replace original file references with the ones that have content hash in them.Is there another way to get the assets info metadata in Rspack?
If not, is it something you can add?
Thank you.
What does the proposed API of configuration look like?
Example:
See https://webpack.js.org/api/compilation-hooks/#assets-info
The text was updated successfully, but these errors were encountered: