Modern.js Module
This section introduces how to migrate a project using Modern.js Module to Rslib.
Adapt package.json
Rslib has a minimal dependency footprint. For the basic functionality you only need the package @rslib/core.
You can create a new Rslib project by following the Quick start to see the package.json file. Then update your existing package.json file like below:
- Remove the fields
main,lint-staged,simple-git-hooks,sideEffectsandpublishConfig - Change the
typesfield from./dist/types/index.d.tsto./dist/index.d.ts - Change the
modulefield from./dist/es/index.jsto./dist/index.js - Remove the scripts fields
prepare,build:watch,reset,change,bump,pre,change-status,gen-release-note,release,new,upgrade - Change the script
buildfrommodern buildtorslib build - Change the script
devfrommodern devtorslib build --watch - Change the script
lintname tocheckand keep the value - Add a new script
formatwith the valuebiome format --write - Add the script
testwith the valuevitest run - Add the field
exports(object)- Add the field
"."(object) - Add the fields
"types": "./dist/index.d.ts"and"import": "./dist/index.js"
- Add the field
- Add the field
fileswith the value["dist"] - Depending on your configuration and use-case the
devDependenciescan vary- It is important to replace
@modern-js/module-toolswith@rslib/core - We do not need
rimraf,lint-stagedandsimple-git-hooksanymore for starters
- It is important to replace
- Copy over your required
dependenciesandpeerDependenciesif needed
Your package.json should look something like this:
Adapt bundler config
Now we have a clean slate to work with. We will continue with the Rslib configuration. It follows the same pattern as all Rs* projects. Since this step is very unique for every environment, below is an basic example:
Replace your modern.config.ts with a rslib.config.ts:
TypeScript declaration
If you use TypeScript in your Modern.js Module and need to generate declaration files, add the following changes:
React
If you use React in your Modern.js Module, add the following changes:
In addition, you have to install the @rsbuild/plugin-react package as devDependencies.
Sass
If you use Sass in your Modern.js Module, add the following changes:
In addition, you have to install the @rsbuild/plugin-sass package as devDependencies.
If you run TypeScript together with Sass, you might run into declaration files generation errors. This can be resolved by adding a env.d.ts file in your /src directory.
or
CSS Modules
If you use CSS Modules in your Modern.js Module, add the following changes:
Contents supplement
This migration doc is contributed by community user YanPes. Much appreciation for his contribution!
