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
-
Tracking issue of <Fill in the RFC title above>
Summary
Use
rspack-sources
to 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-sources
not 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 decoratedSource
with a provided string./******/
inJavascriptModulesPlugin.renderMain
ConcatSource
: Concatenate multipleSource
s or strings to a single source.Template.renderChunkModules
Template.renderRuntimeModules
ReplaceSource
: Decorates aSource
with 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.render
inCompilation.createChunkAssets
this.generator.generate
inNormalModule.codeGeneration
For source map generation will reference the implementation of SourceMapDevToolPlugin, and EvalSourceMapDevToolPlugin will choose to implement after SourceMapDevToolPlugin is implemented.
Reference-level explanation
Source
inrspack-sources
will implement these methods:NormalModule.size
which 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))
atprocessAssets
hook.Since SourceMapDevToolPlugin gets source map from
compilation.assets
, so it will be very simple to generate source map once all source code useSource
s to represent.Where did webpack use
Source
s?normalModule.originalSource
:createSource
process loaders resultcreateSourceForAsset
:loaderContext.emitFile
CompilationAssets { [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
Hash
on trait object?JsModule.render
is using ast to render js code for now, have some gap between webpack.Beta Was this translation helpful? Give feedback.
All reactions