Replies: 1 comment 1 reply
-
|
Can you elaborate on the foreseeable changes for |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Tracking issue of <Fill in the RFC title above>Summary
Use
rspack-sourcesto represent source code and source map as same as webpack.Motivation
When your source code has gone through transformations, debugging in the browser becomes a problem. Source maps solve this problem by providing a mapping between the original and the transformed source code. In addition to source compiling to JavaScript, this works for styling as well.
Guide-level explanation
The 'sources' in
rspack-sourcesnot only represents source map, but also represents source code, even source buffer.RawSource: Represents source code without source map, it will not create source map for the source code.OriginalSource: Represents source code, it will create source map for the source code, but the source map is created by splitting the source code at typical statement borders (;,{,}), its quality is more worse than source map created by parser which use ast internally.SourceMapSource: Represents source code with source map, optionally having an additional source map for the original source (before transformations).PrefixSource: Prefix every line of the decoratedSourcewith a provided string./******/inJavascriptModulesPlugin.renderMainConcatSource: Concatenate multipleSources or strings to a single source.Template.renderChunkModulesTemplate.renderRuntimeModulesReplaceSource: Decorates aSourcewith replacements and insertions of source code, usally used in dependencies.default export@url()CachedSource: It tries to reused cached results from other methods to avoid calculations, usally used after modify is finished.fileManifest.renderinCompilation.createChunkAssetsthis.generator.generateinNormalModule.codeGenerationFor source map generation will reference the implementation of SourceMapDevToolPlugin, and EvalSourceMapDevToolPlugin will choose to implement after SourceMapDevToolPlugin is implemented.
Reference-level explanation
Sourceinrspack-sourceswill implement these methods:NormalModule.sizewhich used in optimize and stats (SplitChunksPlugin, DefaultStatsFactoryPlugin...).Source.source()to emit string.Source.buffer()to emit buffer and string, e.g. write out assets incompilation.emitAssets.Source.map()to generateSourceMap.SourceMapDevToolPlugin will iterate
compilation.assets, then emit asset's source map bycompilation.emitAsset(sourceMapFile, new RawSource(asset.source.map())), or append the source mapping url comment after the source code bycompilation.updateAsset(file, new ConcatSource(source, comment))atprocessAssetshook.Since SourceMapDevToolPlugin gets source map from
compilation.assets, so it will be very simple to generate source map once all source code useSources to represent.Where did webpack use
Sources?normalModule.originalSource:createSourceprocess loaders resultcreateSourceForAsset:loaderContext.emitFileCompilationAssets { [index: string]: Source }AsyncSeriesHook<[CompilationAssets], ProcessAssetsAdditionalOptions>SyncHook<[CompilationAssets]>AsyncSeriesHook<[CompilationAssets], ProcessAssetsAdditionalOptions>SyncHook<[CompilationAssets]>AsyncSeriesHook<[CompilationAssets]>AsyncSeriesHook<[string, AssetEmittedInfo]>SyncWaterfallHook<[RenderManifestEntry[], RenderManifestOptions]>SyncWaterfallHook<[Source, RenderContext]>Dependency.Template.apply()Prior art
webpack-sources, webpack/lib/SourceMapDevToolPlugin
Unresolved questions
Hashon trait object?JsModule.renderis using ast to render js code for now, have some gap between webpack.Beta Was this translation helpful? Give feedback.
All reactions