The content of this section is derived from the content of the following links and is subject to the CC BY 4.0 license.
The following contents can be assumed to be the result of modifications and deletions based on the original contents if not specifically stated.
While Rspack supports multiple module syntaxes, we recommend following a single syntax for consistency and to avoid odd behaviors/bugs.
Rspack support ES6 module syntax natively, you can use static import
, export
and import()
syntax.
By adding comments to the import, we can do things such as name our chunk or select different modes.
webpackChunkName
: A name for the new chunk.
webpackPrefetch
: Tells the browser that the resource is probably needed for some navigation in the future (Available since 0.4.5).
webpackPreload
: Tells the browser that the resource might be needed during the current navigation (Available since 0.4.5).
Rspack is also support CommonJS
syntax natively, you can use require
and module.exports
syntax.
Rspack supports importing DataURI modules using the import
and require
syntax.
import
require
In addition, Base64 encoded requests are also supported:
The DataURI module can be used as a method to implement virtual modules, such as combining with a Loader to dynamically load custom modules at runtime.
Aside from the module syntaxes described above, Rspack also support some webpack-specific methods.
Specify a whole group of dependencies using a path to the directory
, an option to includeSubdirs
, a filter for more fine grained control of the modules included, and a mode to define the way how loading will work.
If mode is set to 'lazy', the underlying modules will be loaded asynchronously.
Indicates whether or not Hot Module Replacement is enabled and provides an interface to the process. See the HMR API page for details.
An alias for module.hot
, however import.meta.webpackHot
can be used in strict ESM while module.hot can't.
Depending on the configuration option node.__dirname
:
The resource query of the current module. If the following require call was made, then the query string would be available in file.js.
Access to the internal object of all modules.
It provides access to the hash of the compilation.
Equals the configuration option's output.publicPath
.
Access to name of current chunk.
Access the runtime id of current entry.