Comments (7)
If you are trying to append and access additional information to AssetInfo object across compilation stages, please use compilation.updateAsset
to update assetInfo
, compilation.getAsset
or compilation.getAssets
to retrieve assetInfo
.
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
from rspack.
This helped, thank you. I was able to move forward a little bit.
1) Do you know if there is a way to replace compilation.assets[ filePath ].source()
?
I searched for updateAsset
in the repo and found that there is also getAssetSource
, but seems like it's internal only.
rspack/crates/node_binding/binding.d.ts
Line 26 in b05f523
rspack/packages/rspack/src/Compilation.ts
Line 978 in b05f523
2) Also, I wasn't able to confirm this fully, because I'm getting Process finished with exit code -1073741571 (0xC00000FD)
(stack overflow?).
I understand this is probably not related, but may be you know what may be causing this?
from rspack.
- Do you know if there is a way to replace
compilation.assets[ filePath ].source()
? I searched forupdateAsset
in the repo and found that there is alsogetAssetSource
, but seems like it's internal only.
rspack/crates/node_binding/binding.d.ts
Line 26 in b05f523
rspack/packages/rspack/src/Compilation.ts
Line 978 in b05f523
Calling compilation.getAsset(<name>)
or compilation.getAssets()
gives you Asset object with source
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;
});
}
from rspack.
- Also, I wasn't able to confirm this fully, because I'm getting
Process finished with exit code -1073741571 (0xC00000FD)
(stack overflow?). I understand this is probably not related, but may be you know what may be causing this?
I am not sure what it means. Can you create a minimal reproduction that triggers this error?
from rspack.
- Do you know if there is a way to replace
compilation.assets[ filePath ].source()
? I searched forupdateAsset
in the repo and found that there is alsogetAssetSource
, but seems like it's internal only.
rspack/crates/node_binding/binding.d.ts
Line 26 in b05f523
rspack/packages/rspack/src/Compilation.ts
Line 978 in b05f523
Calling
compilation.getAsset(<name>)
orcompilation.getAssets()
gives you Asset object withsource
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; }); }
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 v1.0.0-alpha.2
now.
from rspack.
Is there access to compilation.valueCacheVersions
?
I only found this:
- https://github.com/search?q=repo%3Aweb-infra-dev%2Frspack+valueCacheVersions&type=code
- https://github.com/search?q=repo%3Aweb-infra-dev%2Frspack+value_Cache_Versions&type=code
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 }`;
}
from rspack.
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 workOnly this worked, but seems like it's a band-aid:
const fileMapSource = compilation.getAsset( filePath ).source._valueAsString; // did work
You were using the wrong API. Check out webpack-sources.
from rspack.
Related Issues (20)
- [Feature]: builtin-lightningcss-loader add support for `visitor` option HOT 1
- [Feature]: export types related to builtin:lightningcss-loader HOT 5
- [Bug]: Regression between beta4 and beta5 semicolon incorrectly added.
- [Feature]: Could you help to upgrade the built-in SWC loader to use the latest version of SWC? HOT 4
- [Bug]: 初始化之后run dev报错
- [Bug][DevServer]: `TypeError: Cannot read properties of undefined (reading 'get')` when making network request to compiled asset HOT 2
- [Bug]: Module Federation typeError: Cannot set properties of undefined (setting 'constructor')
- [Bug]: binding resolver_factory and rust resolver_factory should share same instance
- [Bug]: Using `builtin:swc-loader` with other loaders generate wrong source-map HOT 1
- [Bug]: bundle `modern-module` with css import stmt: incorrect webpack module map invoking HOT 2
- Enable loader type module test for Node 20
- [Bug]: 1.0.1-beta.15 production rename function name , Class too HOT 1
- [Bug]: Using `extensionAlias` with non-exist `package.json#module` cause error
- [Bug]: TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher') HOT 1
- Infra: improve e2e test stability HOT 1
- [Tracking]: Stabilize Rust Public API HOT 3
- [Bug]: css module has HMR but tsx file not update css name
- [Bug]: Set target to es3, but template literals are not transpiled HOT 1
- [Bug]: HOT 1
- [Bug]: export of comma-separated strings from scss modules does not work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rspack.