Configuration
mini-rspack provides a webpack-compatible configuration API. This page documents the available configuration options.
Configuration Object
The configuration object is passed to the createCompiler
function:
const { createCompiler } = require('mini-rspack');
const compiler = createCompiler({
// Configuration options
});
Basic Configuration
Here's a basic configuration example:
const path = require('path');
const { createCompiler } = require('mini-rspack');
const compiler = createCompiler({
mode: 'development',
devtool: false,
watch: false,
context: './',
entry: {
entries: {
main: './src/index.js'
}
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js'
},
resolve: {
extensions: ['.js', '.json']
},
module: {
rules: [
{
test: '\\.js$',
use: [
path.resolve(__dirname, './loaders/babel-loader.js')
]
}
]
},
plugins: [
'EmitPlugin'
]
});
Configuration Options
mode
- Type:
String
- Default:
'production'
- Possible values:
'development'
,'production'
Sets the mode of the compilation. This affects how the code is bundled and optimized.
mode: 'development'
devtool
- Type:
Boolean
- Default:
false
Controls source map generation.
devtool: false
watch
- Type:
Boolean
- Default:
false
Enables watch mode for automatic rebuilds when files change.
watch: true
context
- Type:
String
- Default:
'./'
The base directory for resolving entry points and loaders.
context: path.resolve(__dirname, 'src')
entry
- Type:
Object
- Required:
true
Defines the entry points of the application.
entry: {
entries: {
main: './src/index.js',
vendor: './src/vendor.js'
}
}
output
- Type:
Object
- Required:
true
Configures how and where to output the bundled files.
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js'
}
output.path
- Type:
String
- Required:
true
The output directory for the bundled files.
path: path.resolve(__dirname, 'dist')
output.filename
- Type:
String
- Default:
'[name].js'
The filename pattern for the bundled files. The [name]
placeholder is replaced with the entry point name.
filename: '[name].[contenthash].js'
resolve
- Type:
Object
- Optional
Configures how modules are resolved.
resolve: {
extensions: ['.js', '.json', '.jsx']
}
resolve.extensions
- Type:
Array<String>
- Default:
['.js', '.json']
The file extensions to try when resolving modules.
extensions: ['.js', '.json', '.jsx', '.ts', '.tsx']
module
- Type:
Object
- Optional
Configures how different modules are treated.
module: {
rules: [
{
test: '\\.js$',
use: [
path.resolve(__dirname, './loaders/babel-loader.js')
]
}
]
}
module.rules
- Type:
Array<Object>
- Default:
[]
An array of rules for how modules are processed.
rules: [
{
test: '\\.js$',
use: [
path.resolve(__dirname, './loaders/babel-loader.js')
]
},
{
test: '\\.css$',
use: [
path.resolve(__dirname, './loaders/style-loader.js'),
path.resolve(__dirname, './loaders/css-loader.js')
]
}
]
module.rules[].test
- Type:
String
- Required:
true
A regex pattern that matches the files to be processed by this rule.
test: '\\.js$'
module.rules[].use
- Type:
Array<String>
- Required:
true
An array of loader paths to be applied to the matched files. The loaders are applied from right to left.
use: [
path.resolve(__dirname, './loaders/babel-loader.js')
]
plugins
- Type:
Array<String>
- Default:
[]
An array of plugin names to be applied to the compilation.
plugins: [
'EmitPlugin',
'HtmlWebpackPlugin'
]
Next Steps
- Plugins: Learn about the available plugins
- Loaders: Learn about the available loaders
- Architecture: Understand the architecture of mini-rspack