CC 4.0 License

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.


Rspack is also support CommonJS syntax natively, you can use require and module.exports syntax.

DataURI Module

Rspack supports importing DataURI modules using the import and require syntax.


import DataURI from 'data:text/javascript,export default 42';


require('data:text/javascript,module.exports = 42');

In addition, Base64 encoded requests are also supported:

const {
} = require('data:text/javascript;charset=utf-8;base64,ZXhwb3J0IGNvbnN0IG51bWJlciA9IDQyOwpleHBvcnQgZnVuY3Rpb24gZm4oKSB7CiAgcmV0dXJuICJIZWxsbyB3b3JsZCI7Cn0=');

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.


  (directory: String),
  (includeSubdirs: Boolean) /* optional, default true */,
  (filter: RegExp) /* optional, default /^\.\/.*$/, any file */,
  (mode: String) /* optional, 'sync' | 'eager' | 'weak' | 'lazy' | 'lazy-once', default 'sync' */

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.

Module Variables (webpack-specific)

Indicates whether or not Hot Module Replacement is enabled and provides an interface to the process. See the HMR API page for details.

import.meta.webpackHot (webpack-specific)

An alias for, however import.meta.webpackHot can be used in strict ESM while can't.

__dirname (NodeJS)

Depending on the configuration option node.__dirname:

  • false: Not defined
  • mock: equal to '/'
  • true: node.js __dirname If used inside an expression that is parsed by the Parser, the configuration option is treated as true.

__resourceQuery (webpack-specific)

The resource query of the current module. If the following require call was made, then the query string would be available in file.js.

__resourceQuery === '?test';

webpack_modules (webpack-specific)

Access to the internal object of all modules.

webpack_hash (webpack-specific)

It provides access to the hash of the compilation.

webpack_public_path (webpack-specific)

Equals the configuration option's output.publicPath.