diff --git a/modern-js/module-tools/api/config/build-config.html b/modern-js/module-tools/api/config/build-config.html index d3d53177a8..ebb50032b6 100644 --- a/modern-js/module-tools/api/config/build-config.html +++ b/modern-js/module-tools/api/config/build-config.html @@ -8,7 +8,7 @@ } })() -

buildConfig

+

buildConfig

buildConfig 是一个用来描述如何编译、生成构建产物的配置项,它包含了构建的所有配置。

  • 类型:object | object[]
  • diff --git a/modern-js/module-tools/api/config/build-preset.html b/modern-js/module-tools/api/config/build-preset.html index b5eb935e34..a49b9586a9 100644 --- a/modern-js/module-tools/api/config/build-preset.html +++ b/modern-js/module-tools/api/config/build-preset.html @@ -8,7 +8,7 @@ } })() -

    buildPreset

    +

    buildPreset

    构建的预设字符串或者预设函数。提供开箱即用的构建配置。

    • diff --git a/modern-js/module-tools/api/config/dev.html b/modern-js/module-tools/api/config/dev.html index 7565c7c65d..e1869c104a 100644 --- a/modern-js/module-tools/api/config/dev.html +++ b/modern-js/module-tools/api/config/dev.html @@ -8,7 +8,7 @@ } })() -

      dev

      +

      dev

      本章节描述了 Modern.js Module 关于调试工具相关的所有配置。

      export default {
         dev: {
      diff --git a/modern-js/module-tools/api/config/plugins.html b/modern-js/module-tools/api/config/plugins.html
      index b8b313062b..4d63e5f653 100644
      --- a/modern-js/module-tools/api/config/plugins.html
      +++ b/modern-js/module-tools/api/config/plugins.html
      @@ -8,7 +8,7 @@
         }
       })()
       
      -

      plugins

      +

      plugins

      本章介绍注册 Modern.js Module 插件的配置。

      • 类型:ModuleToolsPlugin[]
      • diff --git a/modern-js/module-tools/api/config/testing.html b/modern-js/module-tools/api/config/testing.html index 2b127963a7..4ef0ef486c 100644 --- a/modern-js/module-tools/api/config/testing.html +++ b/modern-js/module-tools/api/config/testing.html @@ -8,7 +8,7 @@ } })() -

        testing

        +

        testing

        本章描述了测试相关的配置。

        TIP

        需要先通过 pnpm run new 启用 单元测试 功能。

        diff --git a/modern-js/module-tools/api/index.html b/modern-js/module-tools/api/index.html index 20ee169841..aa37c3e4ed 100644 --- a/modern-js/module-tools/api/index.html +++ b/modern-js/module-tools/api/index.html @@ -8,4 +8,4 @@ } })() -
        \ No newline at end of file +
        \ No newline at end of file diff --git a/modern-js/module-tools/api/plugin-api/plugin-hooks.html b/modern-js/module-tools/api/plugin-api/plugin-hooks.html index 961e983573..d2c17c9eb4 100644 --- a/modern-js/module-tools/api/plugin-api/plugin-hooks.html +++ b/modern-js/module-tools/api/plugin-api/plugin-hooks.html @@ -8,7 +8,7 @@ } })() -

        Plugin Hooks

        +

        Plugin Hooks

        本章介绍关于 Modern.js Module 支持的生命周期钩子。

        目前主要包含两类生命周期钩子:

          diff --git a/modern-js/module-tools/components/faq-build-exception.html b/modern-js/module-tools/components/faq-build-exception.html index f28a1ddd0c..68a5ad61a4 100644 --- a/modern-js/module-tools/components/faq-build-exception.html +++ b/modern-js/module-tools/components/faq-build-exception.html @@ -8,4 +8,4 @@ } })() -
          \ No newline at end of file +
          \ No newline at end of file diff --git a/modern-js/module-tools/components/faq-build-other.html b/modern-js/module-tools/components/faq-build-other.html index b4f9f7dda1..53fe02b68d 100644 --- a/modern-js/module-tools/components/faq-build-other.html +++ b/modern-js/module-tools/components/faq-build-other.html @@ -8,4 +8,4 @@ } })() -
          \ No newline at end of file +
          \ No newline at end of file diff --git a/modern-js/module-tools/components/faq-build-product.html b/modern-js/module-tools/components/faq-build-product.html index d5be40c07c..68f1f1c4c0 100644 --- a/modern-js/module-tools/components/faq-build-product.html +++ b/modern-js/module-tools/components/faq-build-product.html @@ -8,4 +8,4 @@ } })() -
          \ No newline at end of file +
          \ No newline at end of file diff --git a/modern-js/module-tools/components/faq-storybook.html b/modern-js/module-tools/components/faq-storybook.html index dafda7963a..1f5cb8524f 100644 --- a/modern-js/module-tools/components/faq-storybook.html +++ b/modern-js/module-tools/components/faq-storybook.html @@ -8,4 +8,4 @@ } })() -
          \ No newline at end of file +
          \ No newline at end of file diff --git a/modern-js/module-tools/components/faq-test.html b/modern-js/module-tools/components/faq-test.html index ccc8fc2a93..394f5a4a0b 100644 --- a/modern-js/module-tools/components/faq-test.html +++ b/modern-js/module-tools/components/faq-test.html @@ -8,4 +8,4 @@ } })() -
          \ No newline at end of file +
          \ No newline at end of file diff --git a/modern-js/module-tools/components/register-esbuild-plugin.html b/modern-js/module-tools/components/register-esbuild-plugin.html index c12870249b..5720773aa1 100644 --- a/modern-js/module-tools/components/register-esbuild-plugin.html +++ b/modern-js/module-tools/components/register-esbuild-plugin.html @@ -8,7 +8,7 @@ } })() -
          modern.config.ts
          import { myEsbuildPlugin } from './myEsbuildPlugin';
          +
          modern.config.ts
          import { myEsbuildPlugin } from './myEsbuildPlugin';
           
           export default defineConfig({
             buildConfig: {
          diff --git a/modern-js/module-tools/en/api/config/build-config.html b/modern-js/module-tools/en/api/config/build-config.html
          index 2397478c65..051c9264c8 100644
          --- a/modern-js/module-tools/en/api/config/build-config.html
          +++ b/modern-js/module-tools/en/api/config/build-config.html
          @@ -8,7 +8,7 @@
             }
           })()
           
          -

          buildConfig

          +

          buildConfig

          buildConfig is a configuration option that describes how to compile and generate build artifacts. It contains all the configurations related to the build process.

          • Type: object | object[]
          • diff --git a/modern-js/module-tools/en/api/config/build-preset.html b/modern-js/module-tools/en/api/config/build-preset.html index fee7d289d0..07aef455e6 100644 --- a/modern-js/module-tools/en/api/config/build-preset.html +++ b/modern-js/module-tools/en/api/config/build-preset.html @@ -8,7 +8,7 @@ } })() -

            buildPreset

            +

            buildPreset

            A build preset string or preset function. Provides out-of-the-box build configuration

            • Type: string | Function
            • diff --git a/modern-js/module-tools/en/api/config/dev.html b/modern-js/module-tools/en/api/config/dev.html index c1f0447665..df4df52d9a 100644 --- a/modern-js/module-tools/en/api/config/dev.html +++ b/modern-js/module-tools/en/api/config/dev.html @@ -8,7 +8,7 @@ } })() -

              dev

              +

              dev

              This section describes all configuration of Modern.js Module related to debugging tools.

              export default {
                 dev: {
              diff --git a/modern-js/module-tools/en/api/config/plugins.html b/modern-js/module-tools/en/api/config/plugins.html
              index 75d6b68e9e..021c2deec5 100644
              --- a/modern-js/module-tools/en/api/config/plugins.html
              +++ b/modern-js/module-tools/en/api/config/plugins.html
              @@ -8,7 +8,7 @@
                 }
               })()
               
              -

              plugins

              +

              plugins

              This chapter describes the configuration of the registered Modern.js Module plugin.

              • Type: ModuleToolsPlugin[]
              • diff --git a/modern-js/module-tools/en/api/config/testing.html b/modern-js/module-tools/en/api/config/testing.html index fe883b57bc..ca6a839ea2 100644 --- a/modern-js/module-tools/en/api/config/testing.html +++ b/modern-js/module-tools/en/api/config/testing.html @@ -8,7 +8,7 @@ } })() -

                testing

                +

                testing

                This chapter describes the test-related configuration

                TIP

                You need to enable the unit testing feature with pnpm run new first.

                diff --git a/modern-js/module-tools/en/api/index.html b/modern-js/module-tools/en/api/index.html index 59c6ab24fb..383ea14354 100644 --- a/modern-js/module-tools/en/api/index.html +++ b/modern-js/module-tools/en/api/index.html @@ -8,4 +8,4 @@ } })() -
                \ No newline at end of file +
                \ No newline at end of file diff --git a/modern-js/module-tools/en/api/plugin-api/plugin-hooks.html b/modern-js/module-tools/en/api/plugin-api/plugin-hooks.html index a37f9a4acb..045760cee8 100644 --- a/modern-js/module-tools/en/api/plugin-api/plugin-hooks.html +++ b/modern-js/module-tools/en/api/plugin-api/plugin-hooks.html @@ -8,7 +8,7 @@ } })() -

                Plugin Hooks

                +

                Plugin Hooks

                This chapter describes the lifecycle hooks supported by module-tools.

                Currently there are two main types of lifecycle hooks.

                  diff --git a/modern-js/module-tools/en/components/faq-build-exception.html b/modern-js/module-tools/en/components/faq-build-exception.html index 7265e8ce50..b6727af2f2 100644 --- a/modern-js/module-tools/en/components/faq-build-exception.html +++ b/modern-js/module-tools/en/components/faq-build-exception.html @@ -8,4 +8,4 @@ } })() -
                  \ No newline at end of file +
                  \ No newline at end of file diff --git a/modern-js/module-tools/en/components/faq-build-other.html b/modern-js/module-tools/en/components/faq-build-other.html index b04d4a19a4..39864925cb 100644 --- a/modern-js/module-tools/en/components/faq-build-other.html +++ b/modern-js/module-tools/en/components/faq-build-other.html @@ -8,4 +8,4 @@ } })() -
                  \ No newline at end of file +
                  \ No newline at end of file diff --git a/modern-js/module-tools/en/components/faq-build-product.html b/modern-js/module-tools/en/components/faq-build-product.html index d729369766..dc4399a1b2 100644 --- a/modern-js/module-tools/en/components/faq-build-product.html +++ b/modern-js/module-tools/en/components/faq-build-product.html @@ -8,4 +8,4 @@ } })() -
                  \ No newline at end of file +
                  \ No newline at end of file diff --git a/modern-js/module-tools/en/components/faq-storybook.html b/modern-js/module-tools/en/components/faq-storybook.html index f592711b0e..b4e1786d25 100644 --- a/modern-js/module-tools/en/components/faq-storybook.html +++ b/modern-js/module-tools/en/components/faq-storybook.html @@ -8,4 +8,4 @@ } })() -
                  \ No newline at end of file +
                  \ No newline at end of file diff --git a/modern-js/module-tools/en/components/faq-test.html b/modern-js/module-tools/en/components/faq-test.html index 4cee1bb7d9..11c5d7c63c 100644 --- a/modern-js/module-tools/en/components/faq-test.html +++ b/modern-js/module-tools/en/components/faq-test.html @@ -8,4 +8,4 @@ } })() -
                  \ No newline at end of file +
                  \ No newline at end of file diff --git a/modern-js/module-tools/en/components/register-esbuild-plugin.html b/modern-js/module-tools/en/components/register-esbuild-plugin.html index d80dc3a779..c1c6491f75 100644 --- a/modern-js/module-tools/en/components/register-esbuild-plugin.html +++ b/modern-js/module-tools/en/components/register-esbuild-plugin.html @@ -8,7 +8,7 @@ } })() -
                  modern.config.ts
                  import { myEsbuildPlugin } from './myEsbuildPlugin';
                  +
                  modern.config.ts
                  import { myEsbuildPlugin } from './myEsbuildPlugin';
                   
                   export default defineConfig({
                     buildConfig: {
                  diff --git a/modern-js/module-tools/en/guide/advance/asset.html b/modern-js/module-tools/en/guide/advance/asset.html
                  index 6ede52de63..cf8361f668 100644
                  --- a/modern-js/module-tools/en/guide/advance/asset.html
                  +++ b/modern-js/module-tools/en/guide/advance/asset.html
                  @@ -8,7 +8,7 @@
                     }
                   })()
                   
                  -

                  Handle static assets

                  +

                  Handle static assets

                  Modern.js Module will handle static assets used in the code. If configuration is required, then the buildConfig.asset API can be used.

                  Default behavior

                  By default, Modern.js Module handles the following static assets:

                  diff --git a/modern-js/module-tools/en/guide/advance/build-umd.html b/modern-js/module-tools/en/guide/advance/build-umd.html index 46cd0bdef6..e7fe4b7623 100644 --- a/modern-js/module-tools/en/guide/advance/build-umd.html +++ b/modern-js/module-tools/en/guide/advance/build-umd.html @@ -8,7 +8,7 @@ } })() -

                  Build umd artifacts

                  +

                  Build umd artifacts

                  The full name of umd is Universal Module Definition, and JS files in this format can run in multiple runtime environments: the

                  • Browser environment: module loading based on AMD specification
                  • diff --git a/modern-js/module-tools/en/guide/advance/copy.html b/modern-js/module-tools/en/guide/advance/copy.html index 24222b6f21..549d6d4496 100644 --- a/modern-js/module-tools/en/guide/advance/copy.html +++ b/modern-js/module-tools/en/guide/advance/copy.html @@ -8,7 +8,7 @@ } })() -

                    Use the Copy Tools

                    +

                    Use the Copy Tools

                    Modern.js Module provides the Copy utility for copying already existing individual files or entire directories into the output directory. Next we learn how to use it.

                    Understanding the Copy API

                    We can use the Copy tool via the buildConfig.copy API, which contains the following two main configurations.

                    diff --git a/modern-js/module-tools/en/guide/advance/external-dependency.html b/modern-js/module-tools/en/guide/advance/external-dependency.html index 2097268bec..2870ecfe93 100644 --- a/modern-js/module-tools/en/guide/advance/external-dependency.html +++ b/modern-js/module-tools/en/guide/advance/external-dependency.html @@ -8,7 +8,7 @@ } })() -

                    Handle third-party dependencies

                    +

                    Handle third-party dependencies

                    Generally, third-party dependencies required by a project can be installed via the install command in the package manager. After the third-party dependencies are successfully installed, they will generally appear under dependencies and devDependencies in the project package.json.

                    pacakge.json
                    {
                       "dependencies": {},
                    diff --git a/modern-js/module-tools/en/guide/advance/in-depth-about-build.html b/modern-js/module-tools/en/guide/advance/in-depth-about-build.html
                    index 5fb28c810d..9353036695 100644
                    --- a/modern-js/module-tools/en/guide/advance/in-depth-about-build.html
                    +++ b/modern-js/module-tools/en/guide/advance/in-depth-about-build.html
                    @@ -8,7 +8,7 @@
                       }
                     })()
                     
                    -

                    In-depth understanding of build

                    +

                    In-depth understanding of build

                    In the "Basic Usage" section, we already knew that you can modify the output files of a project through the buildConfig configuration. buildConfig not only describes some of the features of the product, but also provides some functionality for building the product.

                    TIP

                    If you are not familiar with buildConfig, please read modify-output-product.

                    diff --git a/modern-js/module-tools/en/guide/advance/in-depth-about-dev-command.html b/modern-js/module-tools/en/guide/advance/in-depth-about-dev-command.html index 5d6a9ebf63..835fcda00a 100644 --- a/modern-js/module-tools/en/guide/advance/in-depth-about-dev-command.html +++ b/modern-js/module-tools/en/guide/advance/in-depth-about-dev-command.html @@ -8,7 +8,7 @@ } })() -

                    In-depth understanding of the dev command

                    +

                    In-depth understanding of the dev command

                    The dev command provided by the Modern.js Module is mainly used for debugging the code.

                    The overall flow of the command run

                      diff --git a/modern-js/module-tools/en/guide/basic/before-getting-started.html b/modern-js/module-tools/en/guide/basic/before-getting-started.html index 47950d8139..160f16111c 100644 --- a/modern-js/module-tools/en/guide/basic/before-getting-started.html +++ b/modern-js/module-tools/en/guide/basic/before-getting-started.html @@ -8,7 +8,7 @@ } })() -

                      Before you start

                      +

                      Before you start

                      Environment preparation

                      In order to use the Modern.js Module, you first need NodeJS engine, we recommend the latest LTS version, and make sure the Node version is >=14.18.0. because non-stable NodeJS releases frequently have bugs. You might consider installing via nvm-windows and nvm (Mac / Linux), so you can easily switch to different NodeJS versions that might be required for different projects that you work on.

                      Getting Started with npm

                      diff --git a/modern-js/module-tools/en/guide/basic/command-preview.html b/modern-js/module-tools/en/guide/basic/command-preview.html index 86065cb929..94ea3b500c 100644 --- a/modern-js/module-tools/en/guide/basic/command-preview.html +++ b/modern-js/module-tools/en/guide/basic/command-preview.html @@ -8,7 +8,7 @@ } })() -

                      CLI Commands

                      +

                      CLI Commands

                      CLI Commands available for Modern.js Module projects are as follows:

                      modern build

                      Usage: modern build [options]
                      diff --git a/modern-js/module-tools/en/guide/basic/modify-output-product.html b/modern-js/module-tools/en/guide/basic/modify-output-product.html
                      index 0c8b3e6c82..eabd1c5405 100644
                      --- a/modern-js/module-tools/en/guide/basic/modify-output-product.html
                      +++ b/modern-js/module-tools/en/guide/basic/modify-output-product.html
                      @@ -8,7 +8,7 @@
                         }
                       })()
                       
                      -

                      Modify the output product

                      +

                      Modify the output product

                      Default output products

                      When you use the modern build command in an initialized project, Modern.js Module will generate corresponding build artifacts based on the current configuration.

                      The default configuration is as follows:

                      diff --git a/modern-js/module-tools/en/guide/basic/publish-your-project.html b/modern-js/module-tools/en/guide/basic/publish-your-project.html index 10d53b9222..d293415ca2 100644 --- a/modern-js/module-tools/en/guide/basic/publish-your-project.html +++ b/modern-js/module-tools/en/guide/basic/publish-your-project.html @@ -8,7 +8,7 @@ } })() -

                      Versioning and Publishing

                      +

                      Versioning and Publishing

                      An npm-type module project release process consists of two phases.

                      • The first phase is during development, where the developer needs to provide a change file to record changes that need to be released.
                      • diff --git a/modern-js/module-tools/en/guide/basic/test-your-project.html b/modern-js/module-tools/en/guide/basic/test-your-project.html index 3dd41db004..73e082f8d0 100644 --- a/modern-js/module-tools/en/guide/basic/test-your-project.html +++ b/modern-js/module-tools/en/guide/basic/test-your-project.html @@ -8,7 +8,7 @@ } })() -

                        Testing Projects

                        +

                        Testing Projects

                        This chapter will describe how to test modules.

                        Prerequisites and conventions

                        To use the testing features of the project, you need to make sure that the project contains the dependency: "@modern-js/plugin-testing" , which can be done with modern new.

                        diff --git a/modern-js/module-tools/en/guide/basic/use-micro-generator.html b/modern-js/module-tools/en/guide/basic/use-micro-generator.html index ae10e831a3..a18aa81550 100644 --- a/modern-js/module-tools/en/guide/basic/use-micro-generator.html +++ b/modern-js/module-tools/en/guide/basic/use-micro-generator.html @@ -8,7 +8,7 @@ } })() -

                        Using the Microgenerator

                        +

                        Using the Microgenerator

                        Modern.js Module provides the Microgenerator tool, which allows for the current project to.

                        • add new directories and files
                        • diff --git a/modern-js/module-tools/en/guide/basic/using-storybook.html b/modern-js/module-tools/en/guide/basic/using-storybook.html index ee8f5777aa..4dec84336b 100644 --- a/modern-js/module-tools/en/guide/basic/using-storybook.html +++ b/modern-js/module-tools/en/guide/basic/using-storybook.html @@ -8,7 +8,7 @@ } })() -

                          Using Storybook

                          +

                          Using Storybook

                          First of all, if you haven't read the following, take a few minutes to understand it first.

                          • use micro-generator to enable Storybook debugging
                          • diff --git a/modern-js/module-tools/en/guide/best-practices/components.html b/modern-js/module-tools/en/guide/best-practices/components.html index ccceebb5e2..39b157d932 100644 --- a/modern-js/module-tools/en/guide/best-practices/components.html +++ b/modern-js/module-tools/en/guide/best-practices/components.html @@ -8,7 +8,7 @@ } })() -

                            Developing Components

                            +

                            Developing Components

                            This chapter will describe how to develop component projects using the Modern.js Module.

                            Initialize the project

                              diff --git a/modern-js/module-tools/en/guide/best-practices/use-tailwindcss.html b/modern-js/module-tools/en/guide/best-practices/use-tailwindcss.html index 323e2a6cf9..b29762bf88 100644 --- a/modern-js/module-tools/en/guide/best-practices/use-tailwindcss.html +++ b/modern-js/module-tools/en/guide/best-practices/use-tailwindcss.html @@ -8,7 +8,7 @@ } })() -

                              Using Tailwind CSS

                              +

                              Using Tailwind CSS

                              Tailwind CSS is a CSS framework and design system based on Utility Class, which can quickly add common styles to components, and support flexible extension of theme styles.

                              Modern.js Module supports developing component styles using Tailwind CSS.

                              Enabling Tailwind CSS

                              diff --git a/modern-js/module-tools/en/guide/faq/build.html b/modern-js/module-tools/en/guide/faq/build.html index 809652b905..198a803092 100644 --- a/modern-js/module-tools/en/guide/faq/build.html +++ b/modern-js/module-tools/en/guide/faq/build.html @@ -8,7 +8,7 @@ } })() -

                              Build FAQ

                              +

                              Build FAQ

                              Product FAQ

                              diff --git a/modern-js/module-tools/en/guide/faq/index.html b/modern-js/module-tools/en/guide/faq/index.html index 49a35a1b54..98633f4825 100644 --- a/modern-js/module-tools/en/guide/faq/index.html +++ b/modern-js/module-tools/en/guide/faq/index.html @@ -8,7 +8,7 @@ } })() -

                              FAQ

                              +

                              FAQ

                              Here is a list of all frequently asked questions about Modern.js Module.

                              • Build FAQ
                              • diff --git a/modern-js/module-tools/en/guide/faq/storybook.html b/modern-js/module-tools/en/guide/faq/storybook.html index f1ddc92ff1..6454ef80d8 100644 --- a/modern-js/module-tools/en/guide/faq/storybook.html +++ b/modern-js/module-tools/en/guide/faq/storybook.html @@ -8,7 +8,7 @@ } })() -

                                Storybook FAQ

                                +

                                Storybook FAQ

                                Storybook v7 Support

                                diff --git a/modern-js/module-tools/en/guide/faq/test.html b/modern-js/module-tools/en/guide/faq/test.html index baf485a031..ba4a6326ee 100644 --- a/modern-js/module-tools/en/guide/faq/test.html +++ b/modern-js/module-tools/en/guide/faq/test.html @@ -8,7 +8,7 @@ } })() -

                                Test FAQ

                                +

                                Test FAQ

                                Execute test command with an error TypeError: Cannot read property 'testEnvironmentOptions' of undefined

                                diff --git a/modern-js/module-tools/en/guide/intro/getting-started.html b/modern-js/module-tools/en/guide/intro/getting-started.html index 19771d89c3..ebb52e6e66 100644 --- a/modern-js/module-tools/en/guide/intro/getting-started.html +++ b/modern-js/module-tools/en/guide/intro/getting-started.html @@ -8,7 +8,7 @@ } })() -

                                Quick Start

                                +

                                Quick Start

                                3 minute demo

                                Want to experience Modern.js Module in action? The only prerequisite you need is Node.js LTS and make sure your Node version is >= 14.18.0.We recommend using the LTS version of Node.js 18.

                                Create new project

                                diff --git a/modern-js/module-tools/en/guide/intro/welcome.html b/modern-js/module-tools/en/guide/intro/welcome.html index 15bf15750b..11f9b4263d 100644 --- a/modern-js/module-tools/en/guide/intro/welcome.html +++ b/modern-js/module-tools/en/guide/intro/welcome.html @@ -8,7 +8,7 @@ } })() -

                                Welcome to Modern.js Module

                                +

                                Welcome to Modern.js Module

                                Modern.js Module is a modules engineering solution for Modern.js, as well as a core dependency. It allows developers to build, debug, and publish module type project more easily. A module type project can mostly be thought of as an npm package type project, which may be a component, component library or tool library project.

                                If you are planning to develop a project of the npm package type, then you came to the right place! Modern.js provides a professional Modern.js Module. It gives you:

                                  diff --git a/modern-js/module-tools/en/guide/intro/why-module-engineering-solution.html b/modern-js/module-tools/en/guide/intro/why-module-engineering-solution.html index 8deeafdd86..73f1a9ee61 100644 --- a/modern-js/module-tools/en/guide/intro/why-module-engineering-solution.html +++ b/modern-js/module-tools/en/guide/intro/why-module-engineering-solution.html @@ -8,7 +8,7 @@ } })() -

                                  Why you need Modern.js Module

                                  +

                                  Why you need Modern.js Module

                                  You've probably all experienced it: when developing a component library or tool library from scratch, we have to consider not only how to write the code logic of the project itself, but also how to build, debug, test, format the code, and other things that have nothing to do with the code logic.

                                  For example, when we consider which builder is used to build the code for a module project, we might previously consider webpack or Rollup, but now we might also consider esbuild or SWC.

                                  Regardless of which builder is chosen, this is going to be a costly learning curve for developers who are not skilled in the use of these build tools. Even if you want to use them quickly, it will take a lot of time and effort.

                                  diff --git a/modern-js/module-tools/en/index.html b/modern-js/module-tools/en/index.html index cd70a8988a..131b6099c3 100644 --- a/modern-js/module-tools/en/index.html +++ b/modern-js/module-tools/en/index.html @@ -8,4 +8,4 @@ } })() -

                                  Modern.js Module

                                  Module engineering solutions

                                  simple, powerful, high-performance modern npm package development solution

                                  🚀

                                  esbuild: The High Performance JS Bundler

                                  Built on esbuild, the build is extremely fast and gives you the ultimate development experience.

                                  Two build modes

                                  Both bundle and bundleless build modes are supported.

                                  🛠️

                                  Out of the box

                                  Develop your npm packages without too much configuration, with built-in presets covering a wide range of scenarios.

                                  🎨

                                  Extensible: Provides a powerful plugin mechanism

                                  With its plugin extension mechanism, you can easily extend the capabilities of Modern.js Module.

                                  📦

                                  Storybook: The community popular UI development tool

                                  Integrated with Storybook, you can use it to debug UI.

                                  📐

                                  Jest: Delightful Testing Framework

                                  Jest integration makes it easier to test code。

                                  Copyright © 2023 ByteDance.
                                  \ No newline at end of file +

                                  Modern.js Module

                                  Module engineering solutions

                                  simple, powerful, high-performance modern npm package development solution

                                  🚀

                                  esbuild: The High Performance JS Bundler

                                  Built on esbuild, the build is extremely fast and gives you the ultimate development experience.

                                  Two build modes

                                  Both bundle and bundleless build modes are supported.

                                  🛠️

                                  Out of the box

                                  Develop your npm packages without too much configuration, with built-in presets covering a wide range of scenarios.

                                  🎨

                                  Extensible: Provides a powerful plugin mechanism

                                  With its plugin extension mechanism, you can easily extend the capabilities of Modern.js Module.

                                  📦

                                  Storybook: The community popular UI development tool

                                  Integrated with Storybook, you can use it to debug UI.

                                  📐

                                  Jest: Delightful Testing Framework

                                  Jest integration makes it easier to test code。

                                  Copyright © 2023 ByteDance.
                                  \ No newline at end of file diff --git a/modern-js/module-tools/en/plugins/guide/getting-started.html b/modern-js/module-tools/en/plugins/guide/getting-started.html index 845d6ccdba..e14cd24abf 100644 --- a/modern-js/module-tools/en/plugins/guide/getting-started.html +++ b/modern-js/module-tools/en/plugins/guide/getting-started.html @@ -8,7 +8,7 @@ } })() -

                                  Quick Start

                                  +

                                  Quick Start

                                  Modern.js Module not only provides a rich set of features, but also supports extending the capabilities of the current project by way of plugins.

                                  We can quickly see how to write a Modern.js Module plugin by using the following example.

                                    diff --git a/modern-js/module-tools/en/plugins/guide/plugin-object.html b/modern-js/module-tools/en/plugins/guide/plugin-object.html index 5578edf73b..a1f195a330 100644 --- a/modern-js/module-tools/en/plugins/guide/plugin-object.html +++ b/modern-js/module-tools/en/plugins/guide/plugin-object.html @@ -8,7 +8,7 @@ } })() -

                                    Plugin Object

                                    +

                                    Plugin Object

                                    The Modern.js Module plugin is an object, and the object contains the following properties.

                                    • name: The name of the plugin, a unique identifier.
                                    • diff --git a/modern-js/module-tools/en/plugins/guide/setup-function.html b/modern-js/module-tools/en/plugins/guide/setup-function.html index 7aaca53df4..5ddd514a1b 100644 --- a/modern-js/module-tools/en/plugins/guide/setup-function.html +++ b/modern-js/module-tools/en/plugins/guide/setup-function.html @@ -8,7 +8,7 @@ } })() -

                                      Setup function

                                      +

                                      Setup function

                                      In the "Plugin object" section we know that the plugin object contains a setup function that not only contains an api object parameter, but also returns a Hooks object.

                                      Plugin API objects

                                      The setup function of the plugin will provide an api object parameter, and you can call some of the methods provided on this object to get information about the configuration, project context, etc.

                                      diff --git a/modern-js/module-tools/en/plugins/official-list/overview.html b/modern-js/module-tools/en/plugins/official-list/overview.html index 1323414452..4633d532b7 100644 --- a/modern-js/module-tools/en/plugins/official-list/overview.html +++ b/modern-js/module-tools/en/plugins/official-list/overview.html @@ -8,7 +8,7 @@ } })() -

                                      Overview

                                      +

                                      Overview

                                      Official Plugin

                                      • @modern-js/plugin-module-import:Use SWC to provide the same ability as babel-plugin-import.
                                      • diff --git a/modern-js/module-tools/en/plugins/official-list/plugin-babel.html b/modern-js/module-tools/en/plugins/official-list/plugin-babel.html index bd41ce15cc..84966304f2 100644 --- a/modern-js/module-tools/en/plugins/official-list/plugin-babel.html +++ b/modern-js/module-tools/en/plugins/official-list/plugin-babel.html @@ -8,7 +8,7 @@ } })() -

                                        Babel Plugin

                                        +

                                        Babel Plugin

                                        TIP

                                        Normally, we don't need to use Babel to transform our code, this plugin is only used as a downgrade.

                                        Quick start

                                        Install

                                        @@ -22,6 +22,27 @@

                                        Registerexport default defineConfig({ plugins: [moduleTools(), modulePluginBabel()], });

                      +

                      You can also configure the registration via hooks, for example, +if you need to bundle two files A and B at the same time and only need to use babel when bundle A:

                      +
                      import { moduleTools, defineConfig } from '@modern-js/module-tools';
                      +import { getBabelHook } from '@modern-js/plugin-module-babel';
                      +
                      +const babelHook = getBabelHook({
                      +  // babel options
                      +});
                      +
                      +export default defineConfig({
                      +  plugins: [moduleTools()],
                      +  buildConfig: [
                      +    {
                      +      hooks: [babelHook],
                      +      input: ['src/a.ts'],
                      +    },
                      +    {
                      +      input: ['src/b.ts'],
                      +    },
                      +  ],
                      +});

                      Config

                      See babel options.

                      Here is an example with @babel/preset-env configured

                      diff --git a/modern-js/module-tools/en/plugins/official-list/plugin-banner.html b/modern-js/module-tools/en/plugins/official-list/plugin-banner.html index 4313b48387..671d138eb5 100644 --- a/modern-js/module-tools/en/plugins/official-list/plugin-banner.html +++ b/modern-js/module-tools/en/plugins/official-list/plugin-banner.html @@ -8,7 +8,7 @@ } })() -

                      Banner Plugin

                      +

                      Banner Plugin

                      Provide the ability to inject content at the top and bottom of each JS and CSS file.

                      Quick Start

                      Install

                      diff --git a/modern-js/module-tools/en/plugins/official-list/plugin-import.html b/modern-js/module-tools/en/plugins/official-list/plugin-import.html index 686c3bda88..c0830e8a68 100644 --- a/modern-js/module-tools/en/plugins/official-list/plugin-import.html +++ b/modern-js/module-tools/en/plugins/official-list/plugin-import.html @@ -8,7 +8,7 @@ } })() -

                      Import Plugin

                      +

                      Import Plugin

                      Using SWC provides the same ability and configuration as babel-plugin-import.

                      TIP

                      Since @modern-js/module-tools version >= v2.16.0, this plugin functionality is built into Modern.js Module and is provided by transformImport.

                      diff --git a/modern-js/module-tools/en/plugins/official-list/plugin-node-polyfill.html b/modern-js/module-tools/en/plugins/official-list/plugin-node-polyfill.html index 85199eb4c1..9d00eaabda 100644 --- a/modern-js/module-tools/en/plugins/official-list/plugin-node-polyfill.html +++ b/modern-js/module-tools/en/plugins/official-list/plugin-node-polyfill.html @@ -8,7 +8,7 @@ } })() -

                      Node Polyfill Plugin

                      +

                      Node Polyfill Plugin

                      About Node Polyfill

                      Normally, we don't need to use Node libs on the browser side. However, it is possible to use some Node libs when the code will run on both the Node side and the browser side, and Node Polyfill provides browser versions of polyfills for these Node libs.

                      By using the Node Polyfill plugin, Node core libs polyfills are automatically injected into the browser-side, allowing you to use these modules on the browser side with confidence.

                      Quick Start

                      diff --git a/modern-js/module-tools/en/plugins/official-list/plugin-polyfill.html b/modern-js/module-tools/en/plugins/official-list/plugin-polyfill.html index 72f94faf93..7177247487 100644 --- a/modern-js/module-tools/en/plugins/official-list/plugin-polyfill.html +++ b/modern-js/module-tools/en/plugins/official-list/plugin-polyfill.html @@ -8,7 +8,7 @@ } })() -

                      Polyfill Plugin

                      +

                      Polyfill Plugin

                      TIP

                      Normally, we don't need to inject polyfill for npm packages, this step should be done on the web application framework side, but in some scenarios we need to inject polyfill in order to make our library run directly in low version browsers.

                      Note that this plugin does not transform your code syntax, it only injects polyfill for unsupported functions used in your code, importing them as normal functions instead of polluting the global. You need to install the core-js-pure dependency.

                      @@ -24,6 +24,25 @@

                      Registerexport default defineConfig({ plugins: [moduleTools(), modulePluginPolyfill()], });

                    +

                    You can also configure registration via hooks, for example, +if you have multiple build configurations at the same time and only need to inject the polyfill when bundle:

                    +
                    import { moduleTools, defineConfig } from '@modern-js/module-tools';
                    +import { getPolyfillHook } from '@modern-js/plugin-module-polyfill';
                    +
                    +const polyfillHook = getPolyfillHook();
                    +
                    +export default defineConfig({
                    +  plugins: [moduleTools()],
                    +  buildConfig: [
                    +    {
                    +      buildType: 'bundle',
                    +      hooks: [polyfillHook],
                    +    },
                    +    {
                    +      buildType: 'bundleless',
                    +    },
                    +  ],
                    +});

                    Config

                    • Type
                    • diff --git a/modern-js/module-tools/guide/advance/asset.html b/modern-js/module-tools/guide/advance/asset.html index 1dbb46dbea..5cb9aed383 100644 --- a/modern-js/module-tools/guide/advance/asset.html +++ b/modern-js/module-tools/guide/advance/asset.html @@ -8,7 +8,7 @@ } })() -

                      处理静态资源

                      +

                      处理静态资源

                      Modern.js Module 会对代码中使用的静态资源进行处理。如果需要配置,则可以使用 buildConfig.asset API。

                      默认行为

                      默认情况下,Modern.js Module 会处理以下静态资源:

                      diff --git a/modern-js/module-tools/guide/advance/build-umd.html b/modern-js/module-tools/guide/advance/build-umd.html index a0e8baad87..1f409a9bf9 100644 --- a/modern-js/module-tools/guide/advance/build-umd.html +++ b/modern-js/module-tools/guide/advance/build-umd.html @@ -8,7 +8,7 @@ } })() -

                      构建 umd 产物

                      +

                      构建 umd 产物

                      umd 全称为 Universal Module Definition,这种格式的 JS 文件可以运行在多个运行环境:

                      • 浏览器环境:基于 AMD 规范进行模块加载
                      • diff --git a/modern-js/module-tools/guide/advance/copy.html b/modern-js/module-tools/guide/advance/copy.html index e5a1777473..03b6613d66 100644 --- a/modern-js/module-tools/guide/advance/copy.html +++ b/modern-js/module-tools/guide/advance/copy.html @@ -8,7 +8,7 @@ } })() -

                        使用 Copy 工具

                        +

                        使用 Copy 工具

                        Modern.js Module 提供了 Copy 工具用于将已经存在的单个文件或整个目录复制到产物目录中。接下来我们学习如何使用它。

                        了解 Copy API

                        我们可以通过 buildConfig.copy API 来使用 Copy 工具,它包含以下两个主要配置:

                        diff --git a/modern-js/module-tools/guide/advance/external-dependency.html b/modern-js/module-tools/guide/advance/external-dependency.html index 18d5f8df73..8b76d3411d 100644 --- a/modern-js/module-tools/guide/advance/external-dependency.html +++ b/modern-js/module-tools/guide/advance/external-dependency.html @@ -8,7 +8,7 @@ } })() -

                        处理三方依赖

                        +

                        处理三方依赖

                        一般来说,项目所需要的第三方依赖可以通过包管理器的 install 命令安装,在安装第三方依赖成功后,这些第三方依赖一般会出现在项目 package.jsondependenciesdevDependencies 下。

                        pacakge.json
                        {
                           "dependencies": {},
                        diff --git a/modern-js/module-tools/guide/advance/in-depth-about-build.html b/modern-js/module-tools/guide/advance/in-depth-about-build.html
                        index 44ecec8206..95e550e88a 100644
                        --- a/modern-js/module-tools/guide/advance/in-depth-about-build.html
                        +++ b/modern-js/module-tools/guide/advance/in-depth-about-build.html
                        @@ -8,7 +8,7 @@
                           }
                         })()
                         
                        -

                        深入理解构建

                        +

                        深入理解构建

                        在 "基础使用" 的部分,我们已经知道可以通过 buildConfig 配置对项目的输出产物进行修改。buildConfig 不仅描述了产物的一些特性,同时还为构建产物提供了一些功能。

                        TIP

                        如果你还不了解 buildConfig 的作用,请先阅读 修改输出产物

                        diff --git a/modern-js/module-tools/guide/advance/in-depth-about-dev-command.html b/modern-js/module-tools/guide/advance/in-depth-about-dev-command.html index 5b92819b1f..7fdd26d4df 100644 --- a/modern-js/module-tools/guide/advance/in-depth-about-dev-command.html +++ b/modern-js/module-tools/guide/advance/in-depth-about-dev-command.html @@ -8,7 +8,7 @@ } })() -

                        深入理解 dev 命令

                        +

                        深入理解 dev 命令

                        Modern.js Module 提供的 dev 命令主要用于代码的调试。

                        命令运行的整体流程

                          diff --git a/modern-js/module-tools/guide/basic/before-getting-started.html b/modern-js/module-tools/guide/basic/before-getting-started.html index ece635b8f5..ac6976fea2 100644 --- a/modern-js/module-tools/guide/basic/before-getting-started.html +++ b/modern-js/module-tools/guide/basic/before-getting-started.html @@ -8,7 +8,7 @@ } })() -

                          开始之前

                          +

                          开始之前

                          环境准备

                          为了使用 Modern.js Module,首先需要 NodeJS,我们推荐最新的长期维护版本,并确保 Node 版本大于等于 14.18.0。因为非稳定的 NodeJS 时常有一些 Bug,你可以使用 nvm-windowsnvm(Mac / Linux)安装,这样你就可以方便地切换到不同的 NodeJS 版本,这些版本可能会用于不同的项目。

                          初识 npm

                          diff --git a/modern-js/module-tools/guide/basic/command-preview.html b/modern-js/module-tools/guide/basic/command-preview.html index f90b0904bb..800020393a 100644 --- a/modern-js/module-tools/guide/basic/command-preview.html +++ b/modern-js/module-tools/guide/basic/command-preview.html @@ -8,7 +8,7 @@ } })() -

                          CLI 命令

                          +

                          CLI 命令

                          Modern.js Module 项目可以使用的 CLI 命令如下:

                          modern build

                          Usage: modern build [options]
                          diff --git a/modern-js/module-tools/guide/basic/modify-output-product.html b/modern-js/module-tools/guide/basic/modify-output-product.html
                          index ddf145e042..c205bf225d 100644
                          --- a/modern-js/module-tools/guide/basic/modify-output-product.html
                          +++ b/modern-js/module-tools/guide/basic/modify-output-product.html
                          @@ -8,7 +8,7 @@
                             }
                           })()
                           
                          -

                          修改输出产物

                          +

                          修改输出产物

                          默认输出产物

                          当你在初始化的项目里使用 modern build 命令的时候,Modern.js Module 会根据当前配置内容,生成相应的构建产物。

                          模板创建的默认配置内容如下:

                          diff --git a/modern-js/module-tools/guide/basic/publish-your-project.html b/modern-js/module-tools/guide/basic/publish-your-project.html index bbe69ba9ae..b1cace3ac3 100644 --- a/modern-js/module-tools/guide/basic/publish-your-project.html +++ b/modern-js/module-tools/guide/basic/publish-your-project.html @@ -8,7 +8,7 @@ } })() -

                          版本管理与发布

                          +

                          版本管理与发布

                          一个 npm 类型的模块项目发布流程包含了两个阶段:

                          • 第一阶段是在开发期间,开发者需要提供变更文件,该文件记录了在发布期间需要的变更内容;
                          • diff --git a/modern-js/module-tools/guide/basic/test-your-project.html b/modern-js/module-tools/guide/basic/test-your-project.html index f9e892cc5d..05e33d57fb 100644 --- a/modern-js/module-tools/guide/basic/test-your-project.html +++ b/modern-js/module-tools/guide/basic/test-your-project.html @@ -8,7 +8,7 @@ } })() -

                            测试项目

                            +

                            测试项目

                            本章将要介绍如何测试可复用模块。

                            先决条件和约定

                            想要使用项目的测试功能,需要确保项目中包含依赖:"@modern-js/plugin-testing",以及按照类似下面的内容进行配置:

                            diff --git a/modern-js/module-tools/guide/basic/use-micro-generator.html b/modern-js/module-tools/guide/basic/use-micro-generator.html index 2a3e9bcfef..c3653cbe53 100644 --- a/modern-js/module-tools/guide/basic/use-micro-generator.html +++ b/modern-js/module-tools/guide/basic/use-micro-generator.html @@ -8,7 +8,7 @@ } })() -

                            使用微生成器

                            +

                            使用微生成器

                            Modern.js Module 提供了微生成器工具,它可以为当前项目:

                            • 新增目录和文件
                            • diff --git a/modern-js/module-tools/guide/basic/using-storybook.html b/modern-js/module-tools/guide/basic/using-storybook.html index ab266b5a17..61491fddb7 100644 --- a/modern-js/module-tools/guide/basic/using-storybook.html +++ b/modern-js/module-tools/guide/basic/using-storybook.html @@ -8,7 +8,7 @@ } })() -

                              使用 Storybook

                              +

                              使用 Storybook

                              首先如果没有看过以下内容的话,可以先花几分钟先了解一下:

                              • 使用微生成器开启 Storybook 调试
                              • diff --git a/modern-js/module-tools/guide/best-practices/components.html b/modern-js/module-tools/guide/best-practices/components.html index a8684b0167..8d9b40e650 100644 --- a/modern-js/module-tools/guide/best-practices/components.html +++ b/modern-js/module-tools/guide/best-practices/components.html @@ -8,7 +8,7 @@ } })() -

                                开发组件

                                +

                                开发组件

                                本章将要介绍如何使用 Modern.js Module 开发组件项目。

                                初始化项目

                                  diff --git a/modern-js/module-tools/guide/best-practices/use-tailwindcss.html b/modern-js/module-tools/guide/best-practices/use-tailwindcss.html index eb4afdacb7..c17767ea98 100644 --- a/modern-js/module-tools/guide/best-practices/use-tailwindcss.html +++ b/modern-js/module-tools/guide/best-practices/use-tailwindcss.html @@ -8,7 +8,7 @@ } })() -

                                  使用 Tailwind CSS

                                  +

                                  使用 Tailwind CSS

                                  Tailwind CSS 是一个以 Utility Class 为基础的 CSS 框架和设计系统,可以快速地为组件添加常用样式,同时支持主题样式的灵活扩展。

                                  Modern.js Module 支持使用 Tailwind CSS 开发组件样式。

                                  启用 Tailwind CSS

                                  diff --git a/modern-js/module-tools/guide/faq/build.html b/modern-js/module-tools/guide/faq/build.html index 42aae163c9..17e50b3f3d 100644 --- a/modern-js/module-tools/guide/faq/build.html +++ b/modern-js/module-tools/guide/faq/build.html @@ -8,7 +8,7 @@ } })() -

                                  构建相关问题

                                  +

                                  构建相关问题

                                  产物问题

                                  diff --git a/modern-js/module-tools/guide/faq/index.html b/modern-js/module-tools/guide/faq/index.html index 8eb732d514..493745cbe2 100644 --- a/modern-js/module-tools/guide/faq/index.html +++ b/modern-js/module-tools/guide/faq/index.html @@ -8,7 +8,7 @@ } })() -

                                  常见问题

                                  +

                                  常见问题

                                  这里是 Modern.js Module 常见问题分类列表:

                                  • 代码构建相关的问题
                                  • diff --git a/modern-js/module-tools/guide/faq/storybook.html b/modern-js/module-tools/guide/faq/storybook.html index 0951b5040b..2d16e4f54d 100644 --- a/modern-js/module-tools/guide/faq/storybook.html +++ b/modern-js/module-tools/guide/faq/storybook.html @@ -8,7 +8,7 @@ } })() -

                                    Storybook 相关问题

                                    +

                                    Storybook 相关问题

                                    支持 Storybook v7

                                    diff --git a/modern-js/module-tools/guide/faq/test.html b/modern-js/module-tools/guide/faq/test.html index d9ca46181d..30724dcda8 100644 --- a/modern-js/module-tools/guide/faq/test.html +++ b/modern-js/module-tools/guide/faq/test.html @@ -8,7 +8,7 @@ } })() -

                                    测试相关问题

                                    +

                                    测试相关问题

                                    执行 test 命令报错 TypeError: Cannot read property 'testEnvironmentOptions' of undefined

                                    diff --git a/modern-js/module-tools/guide/intro/getting-started.html b/modern-js/module-tools/guide/intro/getting-started.html index f50e0e87f5..698197efa2 100644 --- a/modern-js/module-tools/guide/intro/getting-started.html +++ b/modern-js/module-tools/guide/intro/getting-started.html @@ -8,7 +8,7 @@ } })() -

                                    快速开始

                                    +

                                    快速开始

                                    三分钟快速上手

                                    想要实际体验 Modern.js Module?首先你需要安装 Node.js LTS,并确保 Node 版本大于等于 14.18.0。我们推荐使用 Node.js 18 的 LTS 版本。

                                    创建新项目

                                    diff --git a/modern-js/module-tools/guide/intro/welcome.html b/modern-js/module-tools/guide/intro/welcome.html index ae237889b8..d654dc3adf 100644 --- a/modern-js/module-tools/guide/intro/welcome.html +++ b/modern-js/module-tools/guide/intro/welcome.html @@ -8,7 +8,7 @@ } })() -

                                    欢迎使用

                                    +

                                    欢迎使用

                                    Modern.js Module 是 Modern.js 的模块工程解决方案,同时也是核心依赖。它可以让开发者更轻松地构建、调试、发布模块类型的项目。模块类型的项目大多数情况可以认为是 npm 包类型的项目,它可能是一个组件、组件库或者工具库项目。

                                    如果你正打算开发一个 npm 包类型的项目,那么你就来对地方了!Modern.js 提供了专业的模块工程解决方案。它带来了:

                                      diff --git a/modern-js/module-tools/guide/intro/why-module-engineering-solution.html b/modern-js/module-tools/guide/intro/why-module-engineering-solution.html index a61a2a7488..e65dd3028d 100644 --- a/modern-js/module-tools/guide/intro/why-module-engineering-solution.html +++ b/modern-js/module-tools/guide/intro/why-module-engineering-solution.html @@ -8,7 +8,7 @@ } })() -

                                      为什么需要 Modern.js Module

                                      +

                                      为什么需要 Modern.js Module

                                      大家可能都经历过:从零开始开发一个组件库或者工具库的过程中,我们不仅要考虑项目本身的代码逻辑如何编写,还要考虑项目的构建、调试、测试、代码格式化等等和代码逻辑无关的事情。

                                      比如说,当我们考虑构建模块项目的代码是使用什么构建工具的时候,在之前我们可能会考虑使用 webpack 还是 Rollup,然而现在的话,也许还会考虑是使用 esbuild 还是 SWC

                                      无论选择哪个构建工具,这对于没有熟练掌握这些构建工具使用方式的开发者来说,是需要一定的成本去学习的。即使想要快速使用,也会需要花费大量的时间和精力。

                                      diff --git a/modern-js/module-tools/index.html b/modern-js/module-tools/index.html index 600dce55e3..7ad2a693b6 100644 --- a/modern-js/module-tools/index.html +++ b/modern-js/module-tools/index.html @@ -8,4 +8,4 @@ } })() -

                                      Modern.js Module

                                      模块工程解决方案

                                      简单、强大、高性能的现代化 npm 包开发方案

                                      🚀

                                      esbuild: 高性能的 JS Bundler

                                      基于 esbuild 构建,构建速度极快,带给你极致的开发体验。

                                      双构建模式

                                      支持 Bundle 和 Bundleless 两种构建模式。

                                      🛠️

                                      开箱即用

                                      无需过多配置即可开发你的 npm 包,内置预设覆盖多种场景。

                                      🎨

                                      扩展性强: 提供强大的插件机制

                                      通过其插件扩展机制,你可以轻松的扩展 Modern.js Module 的各项能力。

                                      📦

                                      Storybook: 社区流行的 UI 开发工具

                                      集成了 Storybook,你可以使用它调试 UI。

                                      📐

                                      Jest: 令人愉快的测试框架

                                      集成了 Jest,使得代码测试更加容易。

                                      Copyright © 2023 ByteDance.
                                      \ No newline at end of file +

                                      Modern.js Module

                                      模块工程解决方案

                                      简单、强大、高性能的现代化 npm 包开发方案

                                      🚀

                                      esbuild: 高性能的 JS Bundler

                                      基于 esbuild 构建,构建速度极快,带给你极致的开发体验。

                                      双构建模式

                                      支持 Bundle 和 Bundleless 两种构建模式。

                                      🛠️

                                      开箱即用

                                      无需过多配置即可开发你的 npm 包,内置预设覆盖多种场景。

                                      🎨

                                      扩展性强: 提供强大的插件机制

                                      通过其插件扩展机制,你可以轻松的扩展 Modern.js Module 的各项能力。

                                      📦

                                      Storybook: 社区流行的 UI 开发工具

                                      集成了 Storybook,你可以使用它调试 UI。

                                      📐

                                      Jest: 令人愉快的测试框架

                                      集成了 Jest,使得代码测试更加容易。

                                      Copyright © 2023 ByteDance.
                                      \ No newline at end of file diff --git a/modern-js/module-tools/plugins/guide/getting-started.html b/modern-js/module-tools/plugins/guide/getting-started.html index d23ac6ab7d..9358ff026f 100644 --- a/modern-js/module-tools/plugins/guide/getting-started.html +++ b/modern-js/module-tools/plugins/guide/getting-started.html @@ -8,7 +8,7 @@ } })() -

                                      快速开始

                                      +

                                      快速开始

                                      Modern.js Module 不仅提供了丰富的功能,同时也支持通过插件的方式为当前项目扩展能力。

                                      我们可以通过下面的例子来快速了解如何编写一个 Modern.js Module 插件:

                                        diff --git a/modern-js/module-tools/plugins/guide/plugin-object.html b/modern-js/module-tools/plugins/guide/plugin-object.html index 25fef7d944..2253690a96 100644 --- a/modern-js/module-tools/plugins/guide/plugin-object.html +++ b/modern-js/module-tools/plugins/guide/plugin-object.html @@ -8,7 +8,7 @@ } })() -

                                        插件对象

                                        +

                                        插件对象

                                        Modern.js Module 的插件是一个对象,对象包含以下属性:

                                        • name:插件的名称,唯一标识符。
                                        • diff --git a/modern-js/module-tools/plugins/guide/setup-function.html b/modern-js/module-tools/plugins/guide/setup-function.html index 049f72d716..250a9b77d2 100644 --- a/modern-js/module-tools/plugins/guide/setup-function.html +++ b/modern-js/module-tools/plugins/guide/setup-function.html @@ -8,7 +8,7 @@ } })() -

                                          Setup 函数

                                          +

                                          Setup 函数

                                          「插件对象」 部分我们知道插件对象包含了一个 setup 函数,该函数不仅包含了一个 api 对象参数,同时还可以返回一个 Hooks 对象。

                                          插件 API 对象

                                          插件的 setup 函数会提供一个 api 对象参数,你可以调用该对象上提供的一些方法来获取到配置、项目上下文等信息。

                                          diff --git a/modern-js/module-tools/plugins/official-list/overview.html b/modern-js/module-tools/plugins/official-list/overview.html index e8b99c1dff..2db5f574eb 100644 --- a/modern-js/module-tools/plugins/official-list/overview.html +++ b/modern-js/module-tools/plugins/official-list/overview.html @@ -8,7 +8,7 @@ } })() -

                                          总览

                                          +

                                          总览

                                          官方插件

                                          • @modern-js/plugin-module-import:使用 SWC 提供与 babel-plugin-import 一样的能力。
                                          • diff --git a/modern-js/module-tools/plugins/official-list/plugin-babel.html b/modern-js/module-tools/plugins/official-list/plugin-babel.html index a0cffafc1d..750c07a046 100644 --- a/modern-js/module-tools/plugins/official-list/plugin-babel.html +++ b/modern-js/module-tools/plugins/official-list/plugin-babel.html @@ -8,7 +8,7 @@ } })() -

                                            Babel 插件

                                            +

                                            Babel 插件

                                            TIP

                                            通常情况下,我们无需使用 Babel 转换我们的代码,此插件仅作为一种降级方式。

                                            快速开始

                                            安装

                                            @@ -22,6 +22,26 @@

                                            注册插 export default defineConfig({ plugins: [moduleTools(), modulePluginBabel()], });

                          +

                          你也可以通过 hooks 配置注册,例如你同时需要打包 A,B 两个文件,并只需要在打包 A 时使用 babel:

                          +
                          import { moduleTools, defineConfig } from '@modern-js/module-tools';
                          +import { getBabelHook } from '@modern-js/plugin-module-babel';
                          +
                          +const babelHook = getBabelHook({
                          +  // babel options
                          +});
                          +
                          +export default defineConfig({
                          +  plugins: [moduleTools()],
                          +  buildConfig: [
                          +    {
                          +      hooks: [babelHook],
                          +      input: ['src/a.ts'],
                          +    },
                          +    {
                          +      input: ['src/b.ts'],
                          +    },
                          +  ],
                          +});

                          配置

                          See Babel options

                          下面是一个配置了@babel/preset-env的例子:

                          diff --git a/modern-js/module-tools/plugins/official-list/plugin-banner.html b/modern-js/module-tools/plugins/official-list/plugin-banner.html index b1553c401c..a3f73d17a8 100644 --- a/modern-js/module-tools/plugins/official-list/plugin-banner.html +++ b/modern-js/module-tools/plugins/official-list/plugin-banner.html @@ -8,7 +8,7 @@ } })() -

                          Banner 插件

                          +

                          Banner 插件

                          提供为每个 JS 和 CSS 文件的顶部和底部注入内容的能力。

                          TIP

                          @modern-js/module-tools v2.36.0 版本开始,该插件功能内置在 Modern.js Module 中,由 bannerfooter 配置提供。 diff --git a/modern-js/module-tools/plugins/official-list/plugin-import.html b/modern-js/module-tools/plugins/official-list/plugin-import.html index aafeec98be..2a35e5a78a 100644 --- a/modern-js/module-tools/plugins/official-list/plugin-import.html +++ b/modern-js/module-tools/plugins/official-list/plugin-import.html @@ -8,7 +8,7 @@ } })() -

                          Import 插件

                          +

                          Import 插件

                          提供与 babel-plugin-import 等价的能力和配置,基于 SWC 实现。

                          TIP

                          @modern-js/module-tools v2.16.0 版本开始,该插件功能内置在 Modern.js Module 中,由 transformImport 配置提供。 diff --git a/modern-js/module-tools/plugins/official-list/plugin-node-polyfill.html b/modern-js/module-tools/plugins/official-list/plugin-node-polyfill.html index e96b9c99b3..a7d9aa2969 100644 --- a/modern-js/module-tools/plugins/official-list/plugin-node-polyfill.html +++ b/modern-js/module-tools/plugins/official-list/plugin-node-polyfill.html @@ -8,7 +8,7 @@ } })() -

                          Node Polyfill 插件

                          +

                          Node Polyfill 插件

                          Node Polyfill 介绍

                          通常情况下,我们不会在浏览器端使用 Node 模块。但在当前代码需要同时在 Node 端和浏览器端运行时,用到一些 Node 模块是有可能的。Node Polyfill 为这些 Node 模块提供了浏览器版本的 polyfills。

                          通过使用 Node Polyfill 插件,会自动注入 Node 核心模块在浏览器端的 polyfills,让你可以在浏览器端放心使用这些模块。

                          快速开始

                          diff --git a/modern-js/module-tools/plugins/official-list/plugin-polyfill.html b/modern-js/module-tools/plugins/official-list/plugin-polyfill.html index 43e76fa7da..b2dabe83c2 100644 --- a/modern-js/module-tools/plugins/official-list/plugin-polyfill.html +++ b/modern-js/module-tools/plugins/official-list/plugin-polyfill.html @@ -8,7 +8,7 @@ } })() -

                          Polyfill 插件

                          +

                          Polyfill 插件

                          TIP

                          通常情况下,我们不需要为 npm 包注入 polyfill,这一步应该在 Web 应用的框架侧完成,但是在某些场景,为了让我们的库能够直接运行在低版本浏览器里,我们需要注入 polyfill。

                          请注意,此插件并不会转化你的代码语法,只会为你的代码中使用到的不支持的功能注入 polyfill,把它们作为普通函数导入而不是污染全局。你需要安装 core-js-pure 依赖

                          @@ -24,6 +24,24 @@

                          注册插 export default defineConfig({ plugins: [moduleTools(), modulePluginPolyfill()], });

                        +

                        你也可以通过 hooks 配置注册,例如你同时具有多份构建配置,并只需要在 bundle 构建时注入 polyfill:

                        +
                        import { moduleTools, defineConfig } from '@modern-js/module-tools';
                        +import { getPolyfillHook } from '@modern-js/plugin-module-polyfill';
                        +
                        +const polyfillHook = getPolyfillHook();
                        +
                        +export default defineConfig({
                        +  plugins: [moduleTools()],
                        +  buildConfig: [
                        +    {
                        +      buildType: 'bundle',
                        +      hooks: [polyfillHook],
                        +    },
                        +    {
                        +      buildType: 'bundleless',
                        +    },
                        +  ],
                        +});

                        配置

                        • 类型:
                        • diff --git a/modern-js/module-tools/static/js/7396.b2bc4a2b.js b/modern-js/module-tools/static/js/7396.630e7410.js similarity index 90% rename from modern-js/module-tools/static/js/7396.b2bc4a2b.js rename to modern-js/module-tools/static/js/7396.630e7410.js index ccab87f104..656bbc145e 100644 --- a/modern-js/module-tools/static/js/7396.b2bc4a2b.js +++ b/modern-js/module-tools/static/js/7396.630e7410.js @@ -1 +1 @@ -(self.webpackChunk_modern_js_module_tools_docs=self.webpackChunk_modern_js_module_tools_docs||[]).push([["7396"],{74007:function(e,t,n){"use strict";n.r(t),n.d(t,{disableBodyScroll:function(){return x},clearAllBodyScrollLocks:function(){return v}});var r=!1;if("undefined"!=typeof window){var i={get passive(){r=!0;return}};window.addEventListener("testPassive",null,i),window.removeEventListener("testPassive",null,i)}var o="undefined"!=typeof window&&window.navigator&&window.navigator.platform&&(/iP(ad|hone|od)/.test(window.navigator.platform)||"MacIntel"===window.navigator.platform&&window.navigator.maxTouchPoints>1),a=[],l=!1,s=-1,c=void 0,u=void 0,d=void 0,p=function(e){return a.some(function(t){return!!(t.options.allowTouchMove&&t.options.allowTouchMove(e))||!1})},h=function(e){var t=e||window.event;return!!p(t.target)||!!(t.touches.length>1)||(t.preventDefault&&t.preventDefault(),!1)},f=function(e){if(void 0===d){var t=!!e&&!0===e.reserveScrollBarGap,n=window.innerWidth-document.documentElement.clientWidth;if(t&&n>0){var r=parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"),10);d=document.body.style.paddingRight,document.body.style.paddingRight=r+n+"px"}}void 0===c&&(c=document.body.style.overflow,document.body.style.overflow="hidden")},m=function(){void 0!==d&&(document.body.style.paddingRight=d,d=void 0),void 0!==c&&(document.body.style.overflow=c,c=void 0)},g=function(){if(void 0!==u){var e=-parseInt(document.body.style.top,10),t=-parseInt(document.body.style.left,10);document.body.style.position=u.position,document.body.style.top=u.top,document.body.style.left=u.left,window.scrollTo(t,e),u=void 0}},b=function(e,t){var n,r=e.targetTouches[0].clientY-s;if(p(e.target))return!1;if(t&&0===t.scrollTop&&r>0)return h(e);return(n=t)&&n.scrollHeight-n.scrollTop<=n.clientHeight&&r<0?h(e):(e.stopPropagation(),!0)},x=function(e,t){if(!e){console.error("disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.");return}!a.some(function(t){return t.targetElement===e})&&(a=[].concat(function(e){if(!Array.isArray(e))return Array.from(e);for(var t=0,n=Array(e.length);t=r&&(document.body.style.top=-(t+e))})},300)}}):f(t),o&&(e.ontouchstart=function(e){1===e.targetTouches.length&&(s=e.targetTouches[0].clientY)},e.ontouchmove=function(t){1===t.targetTouches.length&&b(t,e)},!l&&(document.addEventListener("touchmove",h,r?{passive:!1}:void 0),l=!0)))},v=function(){o&&(a.forEach(function(e){e.targetElement.ontouchstart=null,e.targetElement.ontouchmove=null}),l&&(document.removeEventListener("touchmove",h,r?{passive:!1}:void 0),l=!1),s=-1),o?g():m(),a=[]}},40926:function(e,t,n){"use strict";t.parse=function(e){for(var t,n=[],i=String(e||o),a=i.indexOf(r),l=0,s=!1;!s;)-1===a&&(a=i.length,s=!0),((t=i.slice(l,a).trim())||!s)&&n.push(t),l=a+1,a=i.indexOf(r,l);return n},t.stringify=function(e,t){var n=t||{},a=!1===n.padLeft?o:i,l=n.padRight?i:o;return e[e.length-1]===o&&(e=e.concat(o)),e.join(l+r+a).trim()};var r=",",i=" ",o=""},53274:function(e,t,n){"use strict";var r=function(e){var t=(/mac os x/i.test(navigator.userAgent)?"\u2318":"Ctrl")+"+C";return e.replace(/#{\s*key\s*}/g,t)},i=n("23072"),o={"text/plain":"Text","text/html":"Url",default:"Text"},a="Copy to clipboard: #{key}, Enter";e.exports=function(e,t){var n,l,s,c,u,d,p=!1;!t&&(t={}),n=t.debug||!1;try{if(s=i(),c=document.createRange(),u=document.getSelection(),(d=document.createElement("span")).textContent=e,d.ariaHidden="true",d.style.all="unset",d.style.position="fixed",d.style.top=0,d.style.clip="rect(0, 0, 0, 0)",d.style.whiteSpace="pre",d.style.webkitUserSelect="text",d.style.MozUserSelect="text",d.style.msUserSelect="text",d.style.userSelect="text",d.addEventListener("copy",function(r){if(r.stopPropagation(),t.format){if(r.preventDefault(),void 0===r.clipboardData){n&&console.warn("unable to use e.clipboardData"),n&&console.warn("trying IE specific stuff"),window.clipboardData.clearData();var i=o[t.format]||o.default;window.clipboardData.setData(i,e)}else r.clipboardData.clearData(),r.clipboardData.setData(t.format,e)}t.onCopy&&(r.preventDefault(),t.onCopy(r.clipboardData))}),document.body.appendChild(d),c.selectNodeContents(d),u.addRange(c),!document.execCommand("copy"))throw Error("copy command was unsuccessful");p=!0}catch(i){n&&console.error("unable to copy using execCommand: ",i),n&&console.warn("trying IE specific stuff");try{window.clipboardData.setData(t.format||"text",e),t.onCopy&&t.onCopy(window.clipboardData),p=!0}catch(i){n&&console.error("unable to copy using clipboardData: ",i),n&&console.error("falling back to prompt"),l=r("message"in t?t.message:a),window.prompt(l,e)}}finally{u&&("function"==typeof u.removeRange?u.removeRange(c):u.removeAllRanges()),d&&document.body.removeChild(d),s()}return p}},61932:function(e,t,n){"use strict";var r,i,o,a,l,s;o="FlexSearch",a=function e(t){var n,r,i,o,a,l,s,c,u,d,p,h,f,m,g,b,x,v,y,w,j,P,O=function(e,t){var n=t?t.id:e&&e.id;this.id=n||0===n?n:K++,this.init(e,t),_(this,"index",function(){return this.a?Object.keys(this.a.index[this.a.keys[0]].c):Object.keys(this.c)}),_(this,"length",function(){return this.index.length})},k=function(e,t,n,r){return this.u!==this.g&&(this.o=this.o.concat(n),this.u++,r&&this.o.length>=r&&(this.u=this.g),this.u===this.g&&(this.cache&&this.j.set(t,this.o),this.F&&this.F(this.o))),this},I=function(e,t){for(var n=e.length,r=F(t),i=[],o=0,a=0;o=a&&((e=(e=e[l-(i+.5>>0)])[n]||(e[n]=[]))[e.length]=r),i)},N=function(e){for(var t="",n="",r="",i=0;i(e=e.length-t.length)?1:e?-1:0},T=function(e,t){return e=e[P],e<(t=t[P])?-1:e>t?1:0},D=function(e,t){for(var n=P.length,r=0;rt?1:0},L=function(e,t,n){return e?{page:e,next:t?""+t:null,result:n}:n},M=function(e,t,n,r,i,o,a){var l,s=[];if(!0===n){n="0";var c=""}else c=n&&n.split(":");var u=e.length;if(1a&&(c=0),(l=(c=c||0)+t)=this.m.length&&(this.C=0),this.m[this.C].postMessage({add:!0,id:e,content:t}),this.c[o]=""+this.C,n&&n(),this;if(!i){if(this.async&&"function"!=typeof importScripts){var a=this;return(o=new Promise(function(n){setTimeout(function(){a.add(e,t,null,r,!0),a=null,n()})}),n)?(o.then(n),this):o}if(n)return this.add(e,t,null,r,!0),n(),this}if(!(t=this.encode(t)).length)return this;i=F(n=this.f)?n(t):t.split(this.split),this.filter&&(i=I(i,this.filter));var l=U();l._ctx=U();for(var s=i.length,c=this.threshold,u=this.depth,d=this.b,p=this.i,h=this.D,f=0;fv;w--)z(p,l,x=m.substring(v,w),e,y,b,c,d-1)}break;default:if(g=z(p,l,m,e,1,b,c,d-1),u&&1=c)for(g=l._ctx[m]||(l._ctx[m]=U()),m=this.h[m]||(this.h[m]=q(d-(c||0))),0>(b=f-u)&&(b=0),(x=f+u+1)>s&&(x=s);bi;n--)a=o[n-1],o[n]=a,r[a]=n;o[i]=e,r[e]=i}}}return t},j);return O}((r={},i="undefined"!=typeof Blob&&"undefined"!=typeof URL&&URL.createObjectURL,function(e,t,n,o,a){return n=i?URL.createObjectURL(new Blob(["("+n.toString()+")()"],{type:"text/javascript"})):e+".min.js",r[e+="-"+t]||(r[e]=[]),r[e][a]=new Worker(n),r[e][a].onmessage=o,r[e][a]})),l=this,(s=l.define)&&s.amd?s([],function(){return a}):(s=l.modules)?s[o.toLowerCase()]=a:"object"==typeof t?e.exports=a:l[o]=a},8569:function(e,t,n){"use strict";e.exports=function(e,t){for(var n,i,o,a=e||"",l=t||"div",s={},c=0;c=97&&t<=122||t>=65&&t<=90}},99215:function(e,t,n){"use strict";var r=n("21076"),i=n("48935");e.exports=function(e){return r(e)||i(e)}},48935:function(e,t,n){"use strict";e.exports=function(e){var t="string"==typeof e?e.charCodeAt(0):e;return t>=48&&t<=57}},55181:function(e,t,n){"use strict";e.exports=function(e){var t="string"==typeof e?e.charCodeAt(0):e;return t>=97&&t<=102||t>=65&&t<=70||t>=48&&t<=57}},41989:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return p}});var r=n("20891"),i=Object.assign||function(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:{},o=window.Promise||function(e){var t=function(){};e(t,t)},p=function(){for(var e=arguments.length,t=Array(e),n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.target,n=function(){var e={width:document.documentElement.clientWidth,height:document.documentElement.clientHeight,left:0,top:0,right:0,bottom:0},t=void 0,n=void 0;if(y.container){if((0,r._)(y.container,Object))t=(e=i({},e,y.container)).width-e.left-e.right-2*y.margin,n=e.height-e.top-e.bottom-2*y.margin;else{var o=(a(y.container)?y.container:document.querySelector(y.container)).getBoundingClientRect();e=i({},e,{width:o.width,height:o.height,left:o.left,top:o.top})}}t=t||e.width-2*y.margin,n=n||e.height-2*y.margin;var s=w.zoomedHd||w.original,c=l(s)?t:s.naturalWidth||t,u=l(s)?n:s.naturalHeight||n,d=s.getBoundingClientRect(),p=d.top,h=d.left,f=d.width,m=d.height,g=Math.min(Math.min(Math.max(f,c),t)/f,Math.min(Math.max(m,u),n)/m),b=(-h+(t-f)/2+y.margin+e.left)/g,x=(-p+(n-m)/2+y.margin+e.top)/g,v="scale("+g+") translate3d("+b+"px, "+x+"px, 0)";w.zoomed.style.transform=v,w.zoomedHd&&(w.zoomedHd.style.transform=v)};return new o(function(e){if(t&&-1===g.indexOf(t)){e(P);return}if(w.zoomed){e(P);return}if(t)w.original=t;else if(g.length>0){var r=g;w.original=r[0]}else{e(P);return}if(w.original.dispatchEvent(d("medium-zoom:open",{detail:{zoom:P}})),v=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0,x=!0,w.zoomed=u(w.original),document.body.appendChild(j),y.template){var i=a(y.template)?y.template:document.querySelector(y.template);w.template=document.createElement("div"),w.template.appendChild(i.content.cloneNode(!0)),document.body.appendChild(w.template)}if(w.original.parentElement&&"PICTURE"===w.original.parentElement.tagName&&w.original.currentSrc&&(w.zoomed.src=w.original.currentSrc),document.body.appendChild(w.zoomed),window.requestAnimationFrame(function(){document.body.classList.add("medium-zoom--opened")}),w.original.classList.add("medium-zoom-image--hidden"),w.zoomed.classList.add("medium-zoom-image--opened"),w.zoomed.addEventListener("click",f),w.zoomed.addEventListener("transitionend",function t(){x=!1,w.zoomed.removeEventListener("transitionend",t),w.original.dispatchEvent(d("medium-zoom:opened",{detail:{zoom:P}})),e(P)}),w.original.getAttribute("data-zoom-src")){w.zoomedHd=w.zoomed.cloneNode(),w.zoomedHd.removeAttribute("srcset"),w.zoomedHd.removeAttribute("sizes"),w.zoomedHd.removeAttribute("loading"),w.zoomedHd.src=w.zoomed.getAttribute("data-zoom-src"),w.zoomedHd.onerror=function(){clearInterval(o),console.warn("Unable to reach the zoom image target "+w.zoomedHd.src),w.zoomedHd=null,n()};var o=setInterval(function(){w.zoomedHd.complete&&(clearInterval(o),w.zoomedHd.classList.add("medium-zoom-image--opened"),w.zoomedHd.addEventListener("click",f),document.body.appendChild(w.zoomedHd),n())},10)}else if(w.original.hasAttribute("srcset")){w.zoomedHd=w.zoomed.cloneNode(),w.zoomedHd.removeAttribute("sizes"),w.zoomedHd.removeAttribute("loading");var l=w.zoomedHd.addEventListener("load",function(){w.zoomedHd.removeEventListener("load",l),w.zoomedHd.classList.add("medium-zoom-image--opened"),w.zoomedHd.addEventListener("click",f),document.body.appendChild(w.zoomedHd),n()})}else n()})},f=function(){return new o(function(e){if(x||!w.original){e(P);return}x=!0,document.body.classList.remove("medium-zoom--opened"),w.zoomed.style.transform="",w.zoomedHd&&(w.zoomedHd.style.transform=""),w.template&&(w.template.style.transition="opacity 150ms",w.template.style.opacity=0),w.original.dispatchEvent(d("medium-zoom:close",{detail:{zoom:P}})),w.zoomed.addEventListener("transitionend",function t(){w.original.classList.remove("medium-zoom-image--hidden"),document.body.removeChild(w.zoomed),w.zoomedHd&&document.body.removeChild(w.zoomedHd),document.body.removeChild(j),w.zoomed.classList.remove("medium-zoom-image--opened"),w.template&&document.body.removeChild(w.template),x=!1,w.zoomed.removeEventListener("transitionend",t),w.original.dispatchEvent(d("medium-zoom:closed",{detail:{zoom:P}})),w.original=null,w.zoomed=null,w.zoomedHd=null,w.template=null,e(P)})})},m=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.target;return w.original?f():h({target:t})},g=[],b=[],x=!1,v=0,y=n,w={original:null,zoomed:null,zoomedHd:null,template:null};"[object Object]"===Object.prototype.toString.call(t)?y=t:(t||"string"==typeof t)&&p(t);var j=c((y=i({margin:0,background:"#fff",scrollOffset:40,container:null,template:null},y)).background);document.addEventListener("click",function(e){var t=e.target;if(t===j){f();return}-1!==g.indexOf(t)&&m({target:t})}),document.addEventListener("keyup",function(e){var t=e.key||e.keyCode;("Escape"===t||"Esc"===t||27===t)&&f()}),document.addEventListener("scroll",function(){if(!x&&w.original){var e=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0;Math.abs(v-e)>y.scrollOffset&&setTimeout(f,150)}}),window.addEventListener("resize",f);var P={open:h,close:f,toggle:m,update:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e.background&&(j.style.background=e.background),e.container&&(0,r._)(e.container,Object)&&(e.container=i({},y.container,e.container)),e.template){var t=a(e.template)?e.template:document.querySelector(e.template);e.template=t}return y=i({},y,e),g.forEach(function(e){e.dispatchEvent(d("medium-zoom:update",{detail:{zoom:P}}))}),P},clone:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return e(i({},y,t))},attach:p,detach:function(){for(var e=arguments.length,t=Array(e),n=0;n0?t.reduce(function(e,t){return[].concat(e,s(t))},[]):g;return r.forEach(function(e){e.classList.remove("medium-zoom-image"),e.dispatchEvent(d("medium-zoom:detach",{detail:{zoom:P}}))}),g=g.filter(function(e){return -1===r.indexOf(e)}),P},on:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return g.forEach(function(r){r.addEventListener("medium-zoom:"+e,t,n)}),b.push({type:"medium-zoom:"+e,listener:t,options:n}),P},off:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return g.forEach(function(r){r.removeEventListener("medium-zoom:"+e,t,n)}),b=b.filter(function(n){return!(n.type==="medium-zoom:"+e&&n.listener.toString()===t.toString())}),P},getOptions:function(){return y},getImages:function(){return g},getZoomedImage:function(){return w.original}};return P}},42256:function(e,t,n){var r,i;r=this,i=function(){var e,t,n,r,i,o,a,l,s=function(e,t,n){return en?n:e},c=function(e){return(-1+e)*100},u=function(e,t,n){var r;return(r="translate3d"===b.positionUsing?{transform:"translate3d("+c(e)+"%,0,0)"}:"translate"===b.positionUsing?{transform:"translate("+c(e)+"%,0)"}:{"margin-left":c(e)+"%"}).transition="all "+t+"ms "+n,r},d=function(e,t){return("string"==typeof e?e:f(e)).indexOf(" "+t+" ")>=0},p=function(e,t){var n=f(e),r=n+t;!d(n,t)&&(e.className=r.substring(1))},h=function(e,t){var n,r=f(e);d(e,t)&&(n=r.replace(" "+t+" "," "),e.className=n.substring(1,n.length-1))},f=function(e){return(" "+(e.className||"")+" ").replace(/\s+/gi," ")},m=function(e){e&&e.parentNode&&e.parentNode.removeChild(e)},g={};g.version="0.2.0";var b=g.settings={minimum:.08,easing:"ease",positionUsing:"",speed:200,trickle:!0,trickleRate:.02,trickleSpeed:800,showSpinner:!0,barSelector:'[role="bar"]',spinnerSelector:'[role="spinner"]',parent:"body",template:'
                          '};g.configure=function(e){var t,n;for(t in e)void 0!==(n=e[t])&&e.hasOwnProperty(t)&&(b[t]=n);return this},g.status=null,g.set=function(e){var t=g.isStarted();e=s(e,b.minimum,1),g.status=1===e?null:e;var n=g.render(!t),r=n.querySelector(b.barSelector),i=b.speed,o=b.easing;return n.offsetWidth,x(function(t){""===b.positionUsing&&(b.positionUsing=g.getPositioningCSS()),v(r,u(e,i,o)),1===e?(v(n,{transition:"none",opacity:1}),n.offsetWidth,setTimeout(function(){v(n,{transition:"all "+i+"ms linear",opacity:0}),setTimeout(function(){g.remove(),t()},i)},i)):setTimeout(t,i)}),this},g.isStarted=function(){return"number"==typeof g.status},g.start=function(){!g.status&&g.set(0);var e=function(){setTimeout(function(){g.status&&(g.trickle(),e())},b.trickleSpeed)};return b.trickle&&e(),this},g.done=function(e){return e||g.status?g.inc(.3+.5*Math.random()).set(1):this},g.inc=function(e){var t=g.status;return t?("number"!=typeof e&&(e=(1-t)*s(Math.random()*t,.1,.95)),t=s(t+e,0,.994),g.set(t)):g.start()},g.trickle=function(){return g.inc(Math.random()*b.trickleRate)},e=0,t=0,g.promise=function(n){return n&&"resolved"!==n.state()?(0===t&&g.start(),e++,t++,n.always(function(){0==--t?(e=0,g.done()):g.set((e-t)/e)}),this):this},g.render=function(e){if(g.isRendered())return document.getElementById("nprogress");p(document.documentElement,"nprogress-busy");var t=document.createElement("div");t.id="nprogress",t.innerHTML=b.template;var n,r=t.querySelector(b.barSelector),i=e?"-100":c(g.status||0),o=document.querySelector(b.parent);return v(r,{transition:"all 0 linear",transform:"translate3d("+i+"%,0,0)"}),!b.showSpinner&&(n=t.querySelector(b.spinnerSelector))&&m(n),o!=document.body&&p(o,"nprogress-custom-parent"),o.appendChild(t),t},g.remove=function(){h(document.documentElement,"nprogress-busy"),h(document.querySelector(b.parent),"nprogress-custom-parent");var e=document.getElementById("nprogress");e&&m(e)},g.isRendered=function(){return!!document.getElementById("nprogress")},g.getPositioningCSS=function(){var e=document.body.style,t="WebkitTransform"in e?"Webkit":"MozTransform"in e?"Moz":"msTransform"in e?"ms":"OTransform"in e?"O":"";return t+"Perspective" in e?"translate3d":t+"Transform" in e?"translate":"margin"};var x=(n=[],function(e){n.push(e),1==n.length&&!function e(){var t=n.shift();t&&t(e)}()});var v=(r=function(e){var t=document.body.style;if(e in t)return e;for(var n,r=a.length,i=e.charAt(0).toUpperCase()+e.slice(1);r--;)if((n=a[r]+i)in t)return n;return e},i=function(e){return l[e=e.replace(/^-ms-/,"ms-").replace(/-([\da-z])/gi,function(e,t){return t.toUpperCase()})]||(l[e]=r(e))},o=function(e,t,n){t=i(t),e.style[t]=n},a=["Webkit","O","Moz","ms"],l={},function(e,t){var n,r,i=arguments;if(2==i.length)for(n in t)void 0!==(r=t[n])&&t.hasOwnProperty(n)&&o(e,n,r);else o(e,i[1],i[2])});return g},"function"==typeof define&&define.amd?define(i):"object"==typeof t?e.exports=i():r.NProgress=i()},54178:function(e,t,n){"use strict";var r,i=59;e.exports=function(e){var t,n="&"+e+";";return(r=r||document.createElement("i")).innerHTML=n,((t=r.textContent).charCodeAt(t.length-1)!==i||"semi"===e)&&t!==n&&t}},63716:function(e,t,n){"use strict";var r=function(e,t){var n,r,s,c,m,H,W,q,U,$,G,V,Z,Y,X,K,Q,J,ee,et=t.additional,en=t.nonTerminated,er=t.text,ei=t.reference,eo=t.warning,ea=t.textContext,el=t.referenceContext,es=t.warningContext,ec=t.position,eu=t.indent||[],ed=e.length,ep=0,eh=-1,ef=ec.column||1,em=ec.line||1,eg="",eb=[];for("string"==typeof et&&(et=et.charCodeAt(0)),K=ex(),q=eo?function(e,t){var n=ex();n.column+=t,n.offset+=t,eo.call(es,F[e],n,e)}:f,ep--,ed++;++ep65535&&(H-=65536,$+=h(H>>>10|55296),H=56320|1023&H),H=$+h(H))):Y!==_&&q(L,J);H?(ev(),K=ex(),ep=ee-1,ef+=ee-Z+1,eb.push(H),Q=ex(),Q.offset++,ei&&ei.call(el,H,{start:K,end:Q},e.slice(Z-1,ee)),K=Q):(c=e.slice(Z-1,ee),eg+=c,ef+=c.length,ep=ee-1)}else 10===m&&(em++,eh++,ef=0),m==m?(eg+=h(m),ef++):ev();return eb.join("");function ex(){return{line:em,column:ef,offset:ep+(ec.offset||0)}}function ev(){eg&&(eb.push(eg),er&&er.call(ea,eg,{start:K,end:ex()}),eg="")}},i=function(e){return e>=55296&&e<=57343||e>1114111},o=function(e){return e>=1&&e<=8||11===e||e>=13&&e<=31||e>=127&&e<=159||e>=64976&&e<=65007||(65535&e)==65535||(65535&e)==65534},a=n("66428"),l=n("20165"),s=n("48935"),c=n("55181"),u=n("99215"),d=n("54178");e.exports=function(e,t){var n,i,o={};for(i in!t&&(t={}),m)n=t[i],o[i]=null==n?m[i]:n;return(o.position.indent||o.position.start)&&(o.indent=o.position.indent||[],o.position=o.position.start),r(e,o)};var p={}.hasOwnProperty,h=String.fromCharCode,f=Function.prototype,m={warning:null,reference:null,text:null,warningContext:null,referenceContext:null,textContext:null,position:{},additional:null,attribute:!1,nonTerminated:!0},g=9,b=10,x=12,v=32,y=38,w=59,j=60,P=61,O=35,k=88,I=120,S=65533,_="named",E="hexadecimal",C="decimal",z={};z[E]=16,z[C]=10;var N={};N[_]=u,N[C]=s,N[E]=c;var A=1,T=2,D=3,L=4,M=5,R=6,B=7,F={};F[1]="Named character references must be terminated by a semicolon",F[T]="Numeric character references must be terminated by a semicolon",F[D]="Named character references cannot be empty",F[L]="Numeric character references cannot be empty",F[M]="Named character references must be known",F[R]="Numeric character references cannot be disallowed",F[B]="Numeric character references cannot be outside the permissible Unicode range"},62920:function(e,t,n){e=n.nmd(e);var r=n("20891"),i=function(e){var t=function(e,t,n,r){this.type=e,this.content=t,this.alias=n,this.length=0|(r||"").length},n=function(e,t,n,r){e.lastIndex=t;var i=e.exec(n);if(i&&r&&i[1]){var o=i[1].length;i.index+=o,i[0]=i[0].slice(o)}return i},i=function(){var e={value:null,prev:null,next:null},t={value:null,prev:e,next:null};e.next=t,this.head=e,this.tail=t,this.length=0},o=function(e,t,n){var r=t.next,i={value:n,prev:t,next:r};return t.next=i,r.prev=i,e.length++,i},a=function(e,t,n){for(var r=t.next,i=0;i=d.reach));O+=P.value.length,P=P.next){var k,I=P.value;if(l.length>i.length)return;if(!r._(I,t)){var S=1;if(v){if(!(k=n(j,O,i,x))||k.index>=i.length)break;var _=k.index,E=k.index+k[0].length,C=O;for(C+=P.value.length;_>=C;)C+=(P=P.next).value.length;if(C-=P.value.length,O=C,r._(P.value,t))continue;for(var z=P;z!==l.tail&&(Cd.reach&&(d.reach=D);var L=P.prev;if(A&&(L=o(l,L,A),O+=A.length),a(l,L,S),P=o(l,L,new t(h,b?p.tokenize(N,b):N,y,N)),T&&o(l,P,T),S>1){var M={cause:h+","+m,reach:D};e(i,l,s,P.prev,O,M),d&&M.reach>d.reach&&(d.reach=M.reach)}}}}}}(e,d,s,d.head,0),l(d)},hooks:{all:{},add:function(e,t){var n=p.hooks.all;n[e]=n[e]||[],n[e].push(t)},run:function(e,t){var n=p.hooks.all[e];if(n&&n.length)for(var r,i=0;r=n[i++];)r(t)}},Token:t};e.Prism=p,t.stringify=function e(t,n){if("string"==typeof t)return t;if(Array.isArray(t)){var r="";return t.forEach(function(t){r+=e(t,n)}),r}var i={type:t.type,content:e(t.content,n),tag:"span",classes:["token",t.type],attributes:{},language:n},o=t.alias;o&&(Array.isArray(o)?Array.prototype.push.apply(i.classes,o):i.classes.push(o)),p.hooks.run("wrap",i);var a="";for(var l in i.attributes)a+=" "+l+'="'+(i.attributes[l]||"").replace(/"/g,""")+'"';return"<"+i.tag+' class="'+i.classes.join(" ")+'"'+a+">"+i.content+""};if(!e.document)return e.addEventListener?(!p.disableWorkerMessageHandler&&e.addEventListener("message",function(t){var n=JSON.parse(t.data),r=n.language,i=n.code,o=n.immediateClose;e.postMessage(p.highlight(i,p.languages[r],r)),o&&e.close()},!1),p):p;var h=p.util.currentScript();if(h&&(p.filename=h.src,h.hasAttribute("data-manual")&&(p.manual=!0)),!p.manual){var f=document.readyState;"loading"===f||"interactive"===f&&h&&h.defer?document.addEventListener("DOMContentLoaded",s):window.requestAnimationFrame?window.requestAnimationFrame(s):window.setTimeout(s,16)}return p}("undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&r._(self,WorkerGlobalScope)?self:{});void 0!==e&&e.exports&&(e.exports=i),void 0!==n.g&&(n.g.Prism=i)},88154:function(e,t,n){"use strict";var r=function(){},i=function(){},o=n("11585");i.resetWarningCache=r,e.exports=function(){var e=function(e,t,n,r,i,a){if(a!==o){var l=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw l.name="Invariant Violation",l}},t=function(){return e};e.isRequired=e;var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:r};return n.PropTypes=n,n}},47459:function(e,t,n){e.exports=n("88154")()},11585:function(e,t,n){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},31368:function(e,t,n){"use strict";var r=function(e){var t=e.slice(5).replace(p,a);return u+t.charAt(0).toUpperCase()+t.slice(1)},i=function(e){var t=e.slice(4);return p.test(t)?e:("-"!==(t=t.replace(h,o)).charAt(0)&&(t="-"+t),u+t)},o=function(e){return"-"+e.toLowerCase()},a=function(e){return e.charAt(1).toUpperCase()},l=n("95322"),s=n("52987"),c=n("82558"),u="data";e.exports=function(e,t){var n=l(t),o=t,a=c;return n in e.normal?e.property[e.normal[n]]:(n.length>4&&n.slice(0,4)===u&&d.test(t)&&("-"===t.charAt(4)?o=r(t):t=i(t),a=s),new a(o,t))};var d=/^data[-\w.:]+$/i,p=/-[a-z]/g,h=/[A-Z]/g},71236:function(e,t,n){"use strict";var r=n("70541"),i=n("87043"),o=n("96690"),a=n("26605"),l=n("40096"),s=n("40051");e.exports=r([o,i,a,l,s])},40096:function(e,t,n){"use strict";var r=n("8532"),i=n("49402"),o=r.booleanish,a=r.number,l=r.spaceSeparated;e.exports=i({transform:function(e,t){return"role"===t?t:"aria-"+t.slice(4).toLowerCase()},properties:{ariaActiveDescendant:null,ariaAtomic:o,ariaAutoComplete:null,ariaBusy:o,ariaChecked:o,ariaColCount:a,ariaColIndex:a,ariaColSpan:a,ariaControls:l,ariaCurrent:null,ariaDescribedBy:l,ariaDetails:null,ariaDisabled:o,ariaDropEffect:l,ariaErrorMessage:null,ariaExpanded:o,ariaFlowTo:l,ariaGrabbed:o,ariaHasPopup:null,ariaHidden:o,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:l,ariaLevel:a,ariaLive:null,ariaModal:o,ariaMultiLine:o,ariaMultiSelectable:o,ariaOrientation:null,ariaOwns:l,ariaPlaceholder:null,ariaPosInSet:a,ariaPressed:o,ariaReadOnly:o,ariaRelevant:null,ariaRequired:o,ariaRoleDescription:l,ariaRowCount:a,ariaRowIndex:a,ariaRowSpan:a,ariaSelected:o,ariaSetSize:a,ariaSort:null,ariaValueMax:a,ariaValueMin:a,ariaValueNow:a,ariaValueText:null,role:null}})},40051:function(e,t,n){"use strict";var r=n("8532"),i=n("49402"),o=n("14890"),a=r.boolean,l=r.overloadedBoolean,s=r.booleanish,c=r.number,u=r.spaceSeparated,d=r.commaSeparated;e.exports=i({space:"html",attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},transform:o,mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:d,acceptCharset:u,accessKey:u,action:null,allow:null,allowFullScreen:a,allowPaymentRequest:a,allowUserMedia:a,alt:null,as:null,async:a,autoCapitalize:null,autoComplete:u,autoFocus:a,autoPlay:a,capture:a,charSet:null,checked:a,cite:null,className:u,cols:c,colSpan:null,content:null,contentEditable:s,controls:a,controlsList:u,coords:c|d,crossOrigin:null,data:null,dateTime:null,decoding:null,default:a,defer:a,dir:null,dirName:null,disabled:a,download:l,draggable:s,encType:null,enterKeyHint:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:a,formTarget:null,headers:u,height:c,hidden:a,high:c,href:null,hrefLang:null,htmlFor:u,httpEquiv:u,id:null,imageSizes:null,imageSrcSet:d,inputMode:null,integrity:null,is:null,isMap:a,itemId:null,itemProp:u,itemRef:u,itemScope:a,itemType:u,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:a,low:c,manifest:null,max:null,maxLength:c,media:null,method:null,min:null,minLength:c,multiple:a,muted:a,name:null,nonce:null,noModule:a,noValidate:a,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforePrint:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextMenu:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:a,optimum:c,pattern:null,ping:u,placeholder:null,playsInline:a,poster:null,preload:null,readOnly:a,referrerPolicy:null,rel:u,required:a,reversed:a,rows:c,rowSpan:c,sandbox:u,scope:null,scoped:a,seamless:a,selected:a,shape:null,size:c,sizes:null,slot:null,span:c,spellCheck:s,src:null,srcDoc:null,srcLang:null,srcSet:d,start:c,step:null,style:null,tabIndex:c,target:null,title:null,translate:null,type:null,typeMustMatch:a,useMap:null,value:s,width:c,wrap:null,align:null,aLink:null,archive:u,axis:null,background:null,bgColor:null,border:c,borderColor:null,bottomMargin:c,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:a,declare:a,event:null,face:null,frame:null,frameBorder:null,hSpace:c,leftMargin:c,link:null,longDesc:null,lowSrc:null,marginHeight:c,marginWidth:c,noResize:a,noHref:a,noShade:a,noWrap:a,object:null,profile:null,prompt:null,rev:null,rightMargin:c,rules:null,scheme:null,scrolling:s,standby:null,summary:null,text:null,topMargin:c,valueType:null,version:null,vAlign:null,vLink:null,vSpace:c,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:a,disableRemotePlayback:a,prefix:null,property:null,results:c,security:null,unselectable:null}})},14890:function(e,t,n){"use strict";var r=n("83379");e.exports=function(e,t){return r(e,t.toLowerCase())}},83379:function(e,t,n){"use strict";e.exports=function(e,t){return t in e?e[t]:t}},49402:function(e,t,n){"use strict";var r=n("95322"),i=n("23707"),o=n("52987");e.exports=function(e){var t,n,a=e.space,l=e.mustUseProperty||[],s=e.attributes||{},c=e.properties,u=e.transform,d={},p={};for(t in c)n=new o(t,u(s,t),c[t],a),-1!==l.indexOf(t)&&(n.mustUseProperty=!0),d[t]=n,p[r(t)]=t,p[r(n.attribute)]=t;return new i(d,p,a)}},52987:function(e,t,n){"use strict";var r=function(e,t,n,r){var c,u=-1;for(i(this,"space",r),o.call(this,e,t);++u=0||(i[n]=e[n]);return i}var k={BASE:"base",BODY:"body",HEAD:"head",HTML:"html",LINK:"link",META:"meta",NOSCRIPT:"noscript",SCRIPT:"script",STYLE:"style",TITLE:"title",FRAGMENT:"Symbol(react.fragment)"},I={rel:["amphtml","canonical","alternate"]},S={type:["application/ld+json"]},_={charset:"",name:["robots","description"],property:["og:type","og:title","og:url","og:image","og:image:alt","og:description","twitter:url","twitter:title","twitter:description","twitter:image","twitter:image:alt","twitter:card","twitter:site"]},E=Object.keys(k).map(function(e){return k[e]}),C={accesskey:"accessKey",charset:"charSet",class:"className",contenteditable:"contentEditable",contextmenu:"contextMenu","http-equiv":"httpEquiv",itemprop:"itemProp",tabindex:"tabIndex"},z=Object.keys(C).reduce(function(e,t){return e[C[t]]=t,e},{}),N=function(e,t){for(var n=e.length-1;n>=0;n-=1){var r=e[n];if(Object.prototype.hasOwnProperty.call(r,t))return r[t]}return null},A=function(e){var t=N(e,k.TITLE),n=N(e,"titleTemplate");if(Array.isArray(t)&&(t=t.join("")),n&&t)return n.replace(/%s/g,function(){return t});var r=N(e,"defaultTitle");return t||r||void 0},T=function(e,t){return t.filter(function(t){return void 0!==t[e]}).map(function(t){return t[e]}).reduce(function(e,t){return w({},e,t)},{})},D=function(e,t,n){var r={};return n.filter(function(t){return!!Array.isArray(t[e])||(void 0!==t[e]&&console&&"function"==typeof console.warn&&console.warn("Helmet: "+e+' should be of type "Array". Instead found type "'+(0,u._)(t[e])+'"'),!1)}).map(function(t){return t[e]}).reverse().reduce(function(e,n){var i={};n.filter(function(e){for(var n,o=Object.keys(e),a=0;a/g,">").replace(/"/g,""").replace(/'/g,"'")},W=function(e){return Object.keys(e).reduce(function(t,n){var r=void 0!==e[n]?n+'="'+e[n]+'"':""+n;return t?t+" "+r:r},"")},q=function(e,t){return void 0===t&&(t={}),Object.keys(e).reduce(function(t,n){return t[C[n]||n]=e[n],t},t)},U=function(e,t){return t.map(function(t,n){var r,i=((r={key:n})["data-rh"]=!0,r);return Object.keys(t).forEach(function(e){var n=C[e]||e;"innerHTML"===n||"cssText"===n?i.dangerouslySetInnerHTML={__html:t.innerHTML||t.cssText}:i[n]=t[e]}),p.createElement(e,i)})},$=function(e,t,n){switch(e){case k.TITLE:return{toComponent:function(){var e,n,r,i;return n=t.titleAttributes,(r={key:e=t.title})["data-rh"]=!0,i=q(n,r),[p.createElement(k.TITLE,i,e)]},toString:function(){var r,i,o,a,l,s;return r=e,i=t.title,o=t.titleAttributes,a=n,l=W(o),s=M(i),l?"<"+r+' data-rh="true" '+l+">"+H(s,a)+"":"<"+r+' data-rh="true">'+H(s,a)+""}};case"bodyAttributes":case"htmlAttributes":return{toComponent:function(){return q(t)},toString:function(){return W(t)}};default:return{toComponent:function(){return U(e,t)},toString:function(){var r,i,o;return r=e,i=t,o=n,i.reduce(function(e,t){var n=Object.keys(t).filter(function(e){return!("innerHTML"===e||"cssText"===e)}).reduce(function(e,n){var r=void 0===t[n]?n:n+'="'+H(t[n],o)+'"';return e?e+" "+r:r},""),i=t.innerHTML||t.cssText||"",a=-1===F.indexOf(r);return e+"<"+r+' data-rh="true" '+n+(a?"/>":">"+i+"")},"")}}}},G=function(e){var t=e.baseTag,n=e.bodyAttributes,r=e.encode,i=e.htmlAttributes,o=e.noscriptTags,a=e.styleTags,l=e.title,s=e.titleAttributes,c=e.linkTags,u=e.metaTags,d=e.scriptTags,p={toComponent:function(){},toString:function(){return""}};if(e.prioritizeSeoTags){var h,f,m,g,b,x,v,y=(f=(h=e).linkTags,m=h.scriptTags,g=h.encode,b=R(h.metaTags,_),x=R(f,I),v=R(m,S),{priorityMethods:{toComponent:function(){return[].concat(U(k.META,b.priority),U(k.LINK,x.priority),U(k.SCRIPT,v.priority))},toString:function(){return $(k.META,b.priority,g)+" "+$(k.LINK,x.priority,g)+" "+$(k.SCRIPT,v.priority,g)}},metaTags:b.default,linkTags:x.default,scriptTags:v.default});p=y.priorityMethods,c=y.linkTags,u=y.metaTags,d=y.scriptTags}return{priority:p,base:$(k.BASE,t,r),bodyAttributes:$("bodyAttributes",n,r),htmlAttributes:$("htmlAttributes",i,r),link:$(k.LINK,c,r),meta:$(k.META,u,r),noscript:$(k.NOSCRIPT,o,r),script:$(k.SCRIPT,d,r),style:$(k.STYLE,a,r),title:$(k.TITLE,{title:void 0===l?"":l,titleAttributes:s},r)}},V=[],Z=function(e,t){var n=this;void 0===t&&(t="undefined"!=typeof document),this.instances=[],this.value={setHelmet:function(e){n.context.helmet=e},helmetInstances:{get:function(){return n.canUseDOM?V:n.instances},add:function(e){(n.canUseDOM?V:n.instances).push(e)},remove:function(e){var t=(n.canUseDOM?V:n.instances).indexOf(e);(n.canUseDOM?V:n.instances).splice(t,1)}}},this.context=e,this.canUseDOM=t,t||(e.helmet=G({baseTag:[],bodyAttributes:{},encodeSpecialCharacters:!0,htmlAttributes:{},linkTags:[],metaTags:[],noscriptTags:[],scriptTags:[],styleTags:[],title:"",titleAttributes:{}}))},Y=p.createContext({}),X=f.shape({setHelmet:f.func,helmetInstances:f.shape({get:f.func,add:f.func,remove:f.func})}),K="undefined"!=typeof document,Q=function(e){function t(n){var r;return(r=e.call(this,n)||this).helmetData=new Z(r.props.context,t.canUseDOM),r}return j(t,e),t.prototype.render=function(){return p.createElement(Y.Provider,{value:this.helmetData.value},this.props.children)},t}(d.Component);Q.canUseDOM=K,Q.propTypes={context:f.shape({helmet:f.shape()}),children:f.node.isRequired},Q.defaultProps={context:{}},Q.displayName="HelmetProvider";var J=function(e,t){var n,r=document.head||document.querySelector(k.HEAD),i=r.querySelectorAll(e+"[data-rh]"),o=[].slice.call(i),a=[];return t&&t.length&&t.forEach(function(t){var r=document.createElement(e);for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&("innerHTML"===i?r.innerHTML=t.innerHTML:"cssText"===i?r.styleSheet?r.styleSheet.cssText=t.cssText:r.appendChild(document.createTextNode(t.cssText)):r.setAttribute(i,void 0===t[i]?"":t[i]));r.setAttribute("data-rh","true"),o.some(function(e,t){return n=t,r.isEqualNode(e)})?o.splice(n,1):a.push(r)}),o.forEach(function(e){return e.parentNode.removeChild(e)}),a.forEach(function(e){return r.appendChild(e)}),{oldTags:o,newTags:a}},ee=function(e,t){var n=document.getElementsByTagName(e)[0];if(n){for(var r=n.getAttribute("data-rh"),i=r?r.split(","):[],o=[].concat(i),a=Object.keys(t),l=0;l=0;d-=1)n.removeAttribute(o[d]);i.length===o.length?n.removeAttribute("data-rh"):n.getAttribute("data-rh")!==a.join(",")&&n.setAttribute("data-rh",a.join(","))}},et=function(e,t){var n,r,i=e.baseTag,o=e.htmlAttributes,a=e.linkTags,l=e.metaTags,s=e.noscriptTags,c=e.onChangeClientState,u=e.scriptTags,d=e.styleTags,p=e.title,h=e.titleAttributes;ee(k.BODY,e.bodyAttributes),ee(k.HTML,o),n=p,r=h,void 0!==n&&document.title!==n&&(document.title=M(n)),ee(k.TITLE,r);var f={baseTag:J(k.BASE,i),linkTags:J(k.LINK,a),metaTags:J(k.META,l),noscriptTags:J(k.NOSCRIPT,s),scriptTags:J(k.SCRIPT,u),styleTags:J(k.STYLE,d)},m={},g={};Object.keys(f).forEach(function(e){var t=f[e],n=t.newTags,r=t.oldTags;n.length&&(m[e]=n),r.length&&(g[e]=f[e].oldTags)}),t&&t(),c(e,m,g)},en=null,er=(r=d.Component,j(i=function(){for(var e,t=arguments.length,n=Array(t),i=0;i elements are self-closing and can not contain children. Refer to our API for more information.")}},s.flattenArrayTypeChildren=function(e){var t,n=e.child,r=e.arrayTypeChildren;return w({},r,((t={})[n.type]=[].concat(r[n.type]||[],[w({},e.newChildProps,this.mapNestedChildrenToProps(n,e.nestedChildren))]),t))},s.mapObjectTypeChildren=function(e){var t,n,r=e.child,i=e.newProps,o=e.newChildProps,a=e.nestedChildren;switch(r.type){case k.TITLE:return w({},i,((t={})[r.type]=a,t.titleAttributes=w({},o),t));case k.BODY:return w({},i,{bodyAttributes:w({},o)});case k.HTML:return w({},i,{htmlAttributes:w({},o)});default:return w({},i,((n={})[r.type]=w({},o),n))}},s.mapArrayTypeChildrenToProps=function(e,t){var n=w({},t);return Object.keys(e).forEach(function(t){var r;n=w({},n,((r={})[t]=e[t],r))}),n},s.warnOnInvalidChildren=function(e,t){return x(E.some(function(t){return e.type===t}),"function"==typeof e.type?"You may be attempting to nest components within each other, which is not allowed. Refer to our API for more information.":"Only elements types "+E.join(", ")+" are allowed. Helmet does not support rendering <"+e.type+"> elements. Refer to our API for more information."),x(!t||"string"==typeof t||Array.isArray(t)&&!t.some(function(e){return"string"!=typeof e}),"Helmet expects a string as a child of <"+e.type+">. Did you forget to wrap your children in braces? ( <"+e.type+">{``} ) Refer to our API for more information."),!0},s.mapChildrenToProps=function(e,t){var n=this,r={};return p.Children.forEach(e,function(e){if(e&&e.props){var i=e.props,o=i.children,a=O(i,ei),l=Object.keys(a).reduce(function(e,t){return e[z[t]||t]=a[t],e},{}),s=e.type;switch("symbol"==(void 0===s?"undefined":(0,u._)(s))?s=s.toString():n.warnOnInvalidChildren(e,o),s){case k.FRAGMENT:t=n.mapChildrenToProps(o,t);break;case k.LINK:case k.META:case k.NOSCRIPT:case k.SCRIPT:case k.STYLE:r=n.flattenArrayTypeChildren({child:e,arrayTypeChildren:r,newChildProps:l,nestedChildren:o});break;default:t=n.mapObjectTypeChildren({child:e,newProps:t,newChildProps:l,nestedChildren:o})}}}),this.mapArrayTypeChildrenToProps(r,t)},s.render=function(){var e=this.props,t=e.children,n=O(e,eo),r=w({},n),i=n.helmetData;return t&&(r=this.mapChildrenToProps(t,r)),!i||(0,c._)(i,Z)||(i=new Z(i.context,i.instances)),i?p.createElement(er,w({},r,{context:i.value,helmetData:void 0})):p.createElement(Y.Consumer,null,function(e){return p.createElement(er,w({},r,{context:e}))})},l);ea.propTypes={base:f.object,bodyAttributes:f.object,children:f.oneOfType([f.arrayOf(f.node),f.node]),defaultTitle:f.string,defer:f.bool,encodeSpecialCharacters:f.bool,htmlAttributes:f.object,link:f.arrayOf(f.object),meta:f.arrayOf(f.object),noscript:f.arrayOf(f.object),onChangeClientState:f.func,script:f.arrayOf(f.object),style:f.arrayOf(f.object),title:f.string,titleAttributes:f.object,titleTemplate:f.string,prioritizeSeoTags:f.bool,helmetData:f.object},ea.defaultProps={defer:!0,encodeSpecialCharacters:!0,prioritizeSeoTags:!1},ea.displayName="Helmet"},89440:function(e,t,n){"use strict";var r=function(e){var t,n,r=(0,i.lazy)(e),o=(0,i.forwardRef)(function(e,n){var o=(0,i.useRef)(null!=t?t:r);return(0,i.createElement)(o.current,Object.assign(n?{ref:n}:{},e))});return o.preload=function(){return!n&&(n=e().then(function(e){return t=e.default})),n},o};Object.defineProperty(t,"__esModule",{value:!0}),t.lazyWithPreload=void 0;var i=n("57814");t.lazyWithPreload=r,t.default=r},10606:function(e,t,n){"use strict";function r(e,t){return -1!==e.listLanguages().indexOf(t)}n.r(t),n.d(t,{default:function(){return r}})},7873:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return d}});var r=n("44358"),i=n("71257"),o=n("57814"),a=n.n(o);function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function s(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;return(function(e){if(0===e.length||1===e.length)return e;var t,n,r=e.join(".");if(!c[r]){;c[r]=0===(n=(t=e).length)||1===n?t:2===n?[t[0],t[1],"".concat(t[0],".").concat(t[1]),"".concat(t[1],".").concat(t[0])]:3===n?[t[0],t[1],t[2],"".concat(t[0],".").concat(t[1]),"".concat(t[0],".").concat(t[2]),"".concat(t[1],".").concat(t[0]),"".concat(t[1],".").concat(t[2]),"".concat(t[2],".").concat(t[0]),"".concat(t[2],".").concat(t[1]),"".concat(t[0],".").concat(t[1],".").concat(t[2]),"".concat(t[0],".").concat(t[2],".").concat(t[1]),"".concat(t[1],".").concat(t[0],".").concat(t[2]),"".concat(t[1],".").concat(t[2],".").concat(t[0]),"".concat(t[2],".").concat(t[0],".").concat(t[1]),"".concat(t[2],".").concat(t[1],".").concat(t[0])]:n>=4?[t[0],t[1],t[2],t[3],"".concat(t[0],".").concat(t[1]),"".concat(t[0],".").concat(t[2]),"".concat(t[0],".").concat(t[3]),"".concat(t[1],".").concat(t[0]),"".concat(t[1],".").concat(t[2]),"".concat(t[1],".").concat(t[3]),"".concat(t[2],".").concat(t[0]),"".concat(t[2],".").concat(t[1]),"".concat(t[2],".").concat(t[3]),"".concat(t[3],".").concat(t[0]),"".concat(t[3],".").concat(t[1]),"".concat(t[3],".").concat(t[2]),"".concat(t[0],".").concat(t[1],".").concat(t[2]),"".concat(t[0],".").concat(t[1],".").concat(t[3]),"".concat(t[0],".").concat(t[2],".").concat(t[1]),"".concat(t[0],".").concat(t[2],".").concat(t[3]),"".concat(t[0],".").concat(t[3],".").concat(t[1]),"".concat(t[0],".").concat(t[3],".").concat(t[2]),"".concat(t[1],".").concat(t[0],".").concat(t[2]),"".concat(t[1],".").concat(t[0],".").concat(t[3]),"".concat(t[1],".").concat(t[2],".").concat(t[0]),"".concat(t[1],".").concat(t[2],".").concat(t[3]),"".concat(t[1],".").concat(t[3],".").concat(t[0]),"".concat(t[1],".").concat(t[3],".").concat(t[2]),"".concat(t[2],".").concat(t[0],".").concat(t[1]),"".concat(t[2],".").concat(t[0],".").concat(t[3]),"".concat(t[2],".").concat(t[1],".").concat(t[0]),"".concat(t[2],".").concat(t[1],".").concat(t[3]),"".concat(t[2],".").concat(t[3],".").concat(t[0]),"".concat(t[2],".").concat(t[3],".").concat(t[1]),"".concat(t[3],".").concat(t[0],".").concat(t[1]),"".concat(t[3],".").concat(t[0],".").concat(t[2]),"".concat(t[3],".").concat(t[1],".").concat(t[0]),"".concat(t[3],".").concat(t[1],".").concat(t[2]),"".concat(t[3],".").concat(t[2],".").concat(t[0]),"".concat(t[3],".").concat(t[2],".").concat(t[1]),"".concat(t[0],".").concat(t[1],".").concat(t[2],".").concat(t[3]),"".concat(t[0],".").concat(t[1],".").concat(t[3],".").concat(t[2]),"".concat(t[0],".").concat(t[2],".").concat(t[1],".").concat(t[3]),"".concat(t[0],".").concat(t[2],".").concat(t[3],".").concat(t[1]),"".concat(t[0],".").concat(t[3],".").concat(t[1],".").concat(t[2]),"".concat(t[0],".").concat(t[3],".").concat(t[2],".").concat(t[1]),"".concat(t[1],".").concat(t[0],".").concat(t[2],".").concat(t[3]),"".concat(t[1],".").concat(t[0],".").concat(t[3],".").concat(t[2]),"".concat(t[1],".").concat(t[2],".").concat(t[0],".").concat(t[3]),"".concat(t[1],".").concat(t[2],".").concat(t[3],".").concat(t[0]),"".concat(t[1],".").concat(t[3],".").concat(t[0],".").concat(t[2]),"".concat(t[1],".").concat(t[3],".").concat(t[2],".").concat(t[0]),"".concat(t[2],".").concat(t[0],".").concat(t[1],".").concat(t[3]),"".concat(t[2],".").concat(t[0],".").concat(t[3],".").concat(t[1]),"".concat(t[2],".").concat(t[1],".").concat(t[0],".").concat(t[3]),"".concat(t[2],".").concat(t[1],".").concat(t[3],".").concat(t[0]),"".concat(t[2],".").concat(t[3],".").concat(t[0],".").concat(t[1]),"".concat(t[2],".").concat(t[3],".").concat(t[1],".").concat(t[0]),"".concat(t[3],".").concat(t[0],".").concat(t[1],".").concat(t[2]),"".concat(t[3],".").concat(t[0],".").concat(t[2],".").concat(t[1]),"".concat(t[3],".").concat(t[1],".").concat(t[0],".").concat(t[2]),"".concat(t[3],".").concat(t[1],".").concat(t[2],".").concat(t[0]),"".concat(t[3],".").concat(t[2],".").concat(t[0],".").concat(t[1]),"".concat(t[3],".").concat(t[2],".").concat(t[1],".").concat(t[0])]:void 0}return c[r]})(e.filter(function(e){return"token"!==e})).reduce(function(e,t){return s(s({},e),n[t])},t)}(u.className,Object.assign({},u.style,void 0===i?{}:i),n)})}else x=s(s({},u),{},{className:u.className.join(" ")});var P=v(t.children);return a.createElement(h,(0,r.default)({key:l},x),P)}}},3197:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return y}});var r=n("23093"),i=n("77165"),o=n("71257"),a=n("57814"),l=n.n(a),s=n("7873"),c=n("10606"),u=["language","children","style","customStyle","codeTagProps","useInlineStyles","showLineNumbers","showInlineLineNumbers","startingLineNumber","lineNumberContainerStyle","lineNumberStyle","wrapLines","wrapLongLines","lineProps","renderer","PreTag","CodeTag","code","astGenerator"];function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function p(e){for(var t=1;t2&&void 0!==arguments[2]?arguments[2]:[];return b({children:e,lineNumber:t,lineNumberStyle:s,largestLineNumber:l,showInlineLineNumbers:o,lineProps:n,className:i,showLineNumbers:r,wrapLongLines:c})},p=function(e,t){if(r&&t&&o){var n=g(s,t,l);e.unshift(m(t,n))}return e},f=function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return t||r.length>0?d(e,n,r):p(e,n)},x=function e(t){for(var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],o=0;o>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,punctuation:/\(\(?|\)\)?|,|;/}},{pattern:/\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,greedy:!0,inside:{variable:/^\$\(|^`|\)$|`$/}},{pattern:/\$\{[^}]+\}/,greedy:!0,inside:{operator:/:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,punctuation:/[\[\]]/,environment:{pattern:RegExp("(\\{)"+t),lookbehind:!0,alias:"constant"}}},/\$(?:\w+|[#?*!@$])/],entity:/\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{1,2})/};e.languages.bash={shebang:{pattern:/^#!\s*\/.*/,alias:"important"},comment:{pattern:/(^|[^"{\\$])#.*/,lookbehind:!0},"function-name":[{pattern:/(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,lookbehind:!0,alias:"function"},{pattern:/\b[\w-]+(?=\s*\(\s*\)\s*\{)/,alias:"function"}],"for-or-select":{pattern:/(\b(?:for|select)\s+)\w+(?=\s+in\s)/,alias:"variable",lookbehind:!0},"assign-left":{pattern:/(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,inside:{environment:{pattern:RegExp("(^|[\\s;|&]|[<>]\\()"+t),lookbehind:!0,alias:"constant"}},alias:"variable",lookbehind:!0},string:[{pattern:/((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/,lookbehind:!0,greedy:!0,inside:r},{pattern:/((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,lookbehind:!0,greedy:!0,inside:{bash:n}},{pattern:/(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,lookbehind:!0,greedy:!0,inside:r},{pattern:/(^|[^$\\])'[^']*'/,lookbehind:!0,greedy:!0},{pattern:/\$'(?:[^'\\]|\\[\s\S])*'/,greedy:!0,inside:{entity:r.entity}}],environment:{pattern:RegExp("\\$?"+t),alias:"constant"},variable:r.variable,function:{pattern:/(^|[\s;|&]|[<>]\()(?:add|apropos|apt|apt-cache|apt-get|aptitude|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|docker|docker-compose|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|node|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|podman|podman-compose|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vcpkg|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,lookbehind:!0},keyword:{pattern:/(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/,lookbehind:!0},builtin:{pattern:/(^|[\s;|&]|[<>]\()(?:\.|:|alias|bind|break|builtin|caller|cd|command|continue|declare|echo|enable|eval|exec|exit|export|getopts|hash|help|let|local|logout|mapfile|printf|pwd|read|readarray|readonly|return|set|shift|shopt|source|test|times|trap|type|typeset|ulimit|umask|unalias|unset)(?=$|[)\s;|&])/,lookbehind:!0,alias:"class-name"},boolean:{pattern:/(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/,lookbehind:!0},"file-descriptor":{pattern:/\B&\d\b/,alias:"important"},operator:{pattern:/\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/,inside:{"file-descriptor":{pattern:/^\d/,alias:"important"}}},punctuation:/\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,number:{pattern:/(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,lookbehind:!0}},n.inside=e.languages.bash;for(var i=["comment","function-name","for-or-select","assign-left","string","environment","function","keyword","builtin","boolean","file-descriptor","operator","punctuation","number"],o=r.variable[1].inside,a=0;a]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/}};e.exports=r,r.displayName="clike",r.aliases=[]},5340:function(e,t,n){"use strict";var r=function(e){var t,n,r;n=/(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/,(t=e).languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:/@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,lookbehind:!0,alias:"selector"},keyword:{pattern:/(^|[^\w-])(?:and|not|only|or)(?![\w-])/,lookbehind:!0}}},url:{pattern:RegExp("\\burl\\((?:"+n.source+"|"+/(?:[^\\\r\n()"']|\\[\s\S])*/.source+")\\)","i"),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/,string:{pattern:RegExp("^"+n.source+"$"),alias:"url"}}},selector:{pattern:RegExp("(^|[{}\\s])[^{}\\s](?:[^{};\"'\\s]|\\s+(?![\\s{])|"+n.source+")*(?=\\s*\\{)"),lookbehind:!0},string:{pattern:n,greedy:!0},property:{pattern:/(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,lookbehind:!0},important:/!important\b/i,function:{pattern:/(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,lookbehind:!0},punctuation:/[(){};:,]/},t.languages.css.atrule.inside.rest=t.languages.css,(r=t.languages.markup)&&(r.tag.addInlined("style","css"),r.tag.addAttribute("style","css"))};e.exports=r,r.displayName="css",r.aliases=[]},69870:function(e,t,n){"use strict";var r=function(e){var t,n;(t=e).languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]},Object.keys(n={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"}).forEach(function(e){var r=n[e],i=[];!/^\w+$/.test(e)&&i.push(/\w+/.exec(e)[0]),"diff"===e&&i.push("bold"),t.languages.diff[e]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(e)[0]}}}}),Object.defineProperty(t.languages.diff,"PREFIXES",{value:n})};e.exports=r,r.displayName="diff",r.aliases=[]},84641:function(e,t,n){"use strict";var r=function(e){e.languages.javascript=e.languages.extend("clike",{"class-name":[e.languages.clike["class-name"],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:{pattern:RegExp(/(^|[^\w$])/.source+"(?:"+(/NaN|Infinity/.source+"|"+/0[bB][01]+(?:_[01]+)*n?/.source+"|"+/0[oO][0-7]+(?:_[0-7]+)*n?/.source+"|"+/0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source+"|"+/\d+(?:_\d+)*n/.source+"|")+/(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source+")"+/(?![\w$])/.source),lookbehind:!0},operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),e.languages.javascript["class-name"][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,e.languages.insertBefore("javascript","keyword",{regex:{pattern:/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:"language-regex",inside:e.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:"function"},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:e.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:e.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:e.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:e.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),e.languages.insertBefore("javascript","string",{hashbang:{pattern:/^#!.*/,greedy:!0,alias:"comment"},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:"string"},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:"punctuation"},rest:e.languages.javascript}},string:/[\s\S]+/}},"string-property":{pattern:/((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,lookbehind:!0,greedy:!0,alias:"property"}}),e.languages.insertBefore("javascript","operator",{"literal-property":{pattern:/((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,lookbehind:!0,alias:"property"}}),e.languages.markup&&(e.languages.markup.tag.addInlined("script","javascript"),e.languages.markup.tag.addAttribute(/on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,"javascript")),e.languages.js=e.languages.javascript};e.exports=r,r.displayName="javascript",r.aliases=["js"]},62178:function(e,t,n){"use strict";var r=function(e){e.languages.json={property:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,lookbehind:!0,greedy:!0},string:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,lookbehind:!0,greedy:!0},comment:{pattern:/\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},number:/-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,punctuation:/[{}[\],]/,operator:/:/,boolean:/\b(?:false|true)\b/,null:{pattern:/\bnull\b/,alias:"keyword"}},e.languages.webmanifest=e.languages.json};e.exports=r,r.displayName="json",r.aliases=["webmanifest"]},18055:function(e,t,n){"use strict";var r=function(e){!function(e){var t=e.util.clone(e.languages.javascript),n=/(?:\s|\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))\*\/)/.source,r=/(?:\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])*\})/.source,i=/(?:\{*\.{3}(?:[^{}]|)*\})/.source;function o(e,t){return RegExp(e=e.replace(//g,function(){return n}).replace(//g,function(){return r}).replace(//g,function(){return i}),t)}i=o(i).source,e.languages.jsx=e.languages.extend("markup",t),e.languages.jsx.tag.pattern=o(/<\/?(?:[\w.:-]+(?:+(?:[\w.:$-]+(?:=(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s{'"/>=]+|))?|))**\/?)?>/.source),e.languages.jsx.tag.inside.tag.pattern=/^<\/?[^\s>\/]*/,e.languages.jsx.tag.inside["attr-value"].pattern=/=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/,e.languages.jsx.tag.inside.tag.inside["class-name"]=/^[A-Z]\w*(?:\.[A-Z]\w*)*$/,e.languages.jsx.tag.inside.comment=t.comment,e.languages.insertBefore("inside","attr-name",{spread:{pattern:o(//.source),inside:e.languages.jsx}},e.languages.jsx.tag),e.languages.insertBefore("inside","special-attr",{script:{pattern:o(/=/.source),alias:"language-javascript",inside:{"script-punctuation":{pattern:/^=(?=\{)/,alias:"punctuation"},rest:e.languages.jsx}}},e.languages.jsx.tag);var a=function(e){return e?"string"==typeof e?e:"string"==typeof e.content?e.content:e.content.map(a).join(""):""},l=function(t){for(var n=[],r=0;r0&&n[n.length-1].tagName===a(i.content[0].content[1])&&n.pop():"/>"===i.content[i.content.length-1].content||n.push({tagName:a(i.content[0].content[1]),openedBraces:0}):n.length>0&&"punctuation"===i.type&&"{"===i.content?n[n.length-1].openedBraces++:n.length>0&&n[n.length-1].openedBraces>0&&"punctuation"===i.type&&"}"===i.content?n[n.length-1].openedBraces--:o=!0),(o||"string"==typeof i)&&n.length>0&&0===n[n.length-1].openedBraces){var s=a(i);r0&&("string"==typeof t[r-1]||"plain-text"===t[r-1].type)&&(s=a(t[r-1])+s,t.splice(r-1,1),r--),t[r]=new e.Token("plain-text",s,null,s)}i.content&&"string"!=typeof i.content&&l(i.content)}};e.hooks.add("after-tokenize",function(e){("jsx"===e.language||"tsx"===e.language)&&l(e.tokens)})}(e)};e.exports=r,r.displayName="jsx",r.aliases=[]},75271:function(e,t,n){"use strict";var r=function(e){e.languages.less=e.languages.extend("css",{comment:[/\/\*[\s\S]*?\*\//,{pattern:/(^|[^\\])\/\/.*/,lookbehind:!0}],atrule:{pattern:/@[\w-](?:\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};\s]|\s+(?!\s))*?(?=\s*\{)/,inside:{punctuation:/[:()]/}},selector:{pattern:/(?:@\{[\w-]+\}|[^{};\s@])(?:@\{[\w-]+\}|\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};@\s]|\s+(?!\s))*?(?=\s*\{)/,inside:{variable:/@+[\w-]+/}},property:/(?:@\{[\w-]+\}|[\w-])+(?:\+_?)?(?=\s*:)/,operator:/[+\-*\/]/}),e.languages.insertBefore("less","property",{variable:[{pattern:/@[\w-]+\s*:/,inside:{punctuation:/:/}},/@@?[\w-]+/],"mixin-usage":{pattern:/([{;]\s*)[.#](?!\d)[\w-].*?(?=[(;])/,lookbehind:!0,alias:"function"}})};e.exports=r,r.displayName="less",r.aliases=[]},24667:function(e,t,n){"use strict";var r=function(e){!function(e){var t=/(?:\\.|[^\\\n\r]|(?:\n|\r\n?)(?![\r\n]))/.source;function n(e){return e=e.replace(//g,function(){return t}),RegExp(/((?:^|[^\\])(?:\\{2})*)/.source+"(?:"+e+")")}var r=/(?:\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\|\r\n`])+/.source,i=/\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|(?![\s\S]))/.source.replace(/__/g,function(){return r}),o=/\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\n|\r\n?)/.source;e.languages.markdown=e.languages.extend("markup",{}),e.languages.insertBefore("markdown","prolog",{"front-matter-block":{pattern:/(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,lookbehind:!0,greedy:!0,inside:{punctuation:/^---|---$/,"front-matter":{pattern:/\S+(?:\s+\S+)*/,alias:["yaml","language-yaml"],inside:e.languages.yaml}}},blockquote:{pattern:/^>(?:[\t ]*>)*/m,alias:"punctuation"},table:{pattern:RegExp("^"+i+o+"(?:"+i+")*","m"),inside:{"table-data-rows":{pattern:RegExp("^("+i+o+")(?:"+i+")*$"),lookbehind:!0,inside:{"table-data":{pattern:RegExp(r),inside:e.languages.markdown},punctuation:/\|/}},"table-line":{pattern:RegExp("^("+i+")"+o+"$"),lookbehind:!0,inside:{punctuation:/\||:?-{3,}:?/}},"table-header-row":{pattern:RegExp("^"+i+"$"),inside:{"table-header":{pattern:RegExp(r),alias:"important",inside:e.languages.markdown},punctuation:/\|/}}}},code:[{pattern:/((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,lookbehind:!0,alias:"keyword"},{pattern:/^```[\s\S]*?^```$/m,greedy:!0,inside:{"code-block":{pattern:/^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,lookbehind:!0},"code-language":{pattern:/^(```).+/,lookbehind:!0},punctuation:/```/}}],title:[{pattern:/\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,alias:"important",inside:{punctuation:/==+$|--+$/}},{pattern:/(^\s*)#.+/m,lookbehind:!0,alias:"important",inside:{punctuation:/^#+|#+$/}}],hr:{pattern:/(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,lookbehind:!0,alias:"punctuation"},list:{pattern:/(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,lookbehind:!0,alias:"punctuation"},"url-reference":{pattern:/!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,inside:{variable:{pattern:/^(!?\[)[^\]]+/,lookbehind:!0},string:/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,punctuation:/^[\[\]!:]|[<>]/},alias:"url"},bold:{pattern:n(/\b__(?:(?!_)|_(?:(?!_))+_)+__\b|\*\*(?:(?!\*)|\*(?:(?!\*))+\*)+\*\*/.source),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^..)[\s\S]+(?=..$)/,lookbehind:!0,inside:{}},punctuation:/\*\*|__/}},italic:{pattern:n(/\b_(?:(?!_)|__(?:(?!_))+__)+_\b|\*(?:(?!\*)|\*\*(?:(?!\*))+\*\*)+\*/.source),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^.)[\s\S]+(?=.$)/,lookbehind:!0,inside:{}},punctuation:/[*_]/}},strike:{pattern:n(/(~~?)(?:(?!~))+\2/.source),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^~~?)[\s\S]+(?=\1$)/,lookbehind:!0,inside:{}},punctuation:/~~?/}},"code-snippet":{pattern:/(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/,lookbehind:!0,greedy:!0,alias:["code","keyword"]},url:{pattern:n(/!?\[(?:(?!\]))+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)|[ \t]?\[(?:(?!\]))+\])/.source),lookbehind:!0,greedy:!0,inside:{operator:/^!/,content:{pattern:/(^\[)[^\]]+(?=\])/,lookbehind:!0,inside:{}},variable:{pattern:/(^\][ \t]?\[)[^\]]+(?=\]$)/,lookbehind:!0},url:{pattern:/(^\]\()[^\s)]+/,lookbehind:!0},string:{pattern:/(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,lookbehind:!0}}}}),["url","bold","italic","strike"].forEach(function(t){["url","bold","italic","strike","code-snippet"].forEach(function(n){t!==n&&(e.languages.markdown[t].inside.content.inside[n]=e.languages.markdown[n])})}),e.hooks.add("after-tokenize",function(e){("markdown"===e.language||"md"===e.language)&&function e(t){if(t&&"string"!=typeof t)for(var n=0,r=t.length;n",quot:'"'},s=String.fromCodePoint||String.fromCharCode;e.languages.md=e.languages.markdown}(e)};e.exports=r,r.displayName="markdown",r.aliases=["md"]},61976:function(e,t,n){"use strict";var r=function(e){e.languages.markup={comment:{pattern://,greedy:!0},prolog:{pattern:/<\?[\s\S]+?\?>/,greedy:!0},doctype:{pattern:/"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(^[^\[]*\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^$|[[\]]/,"doctype-tag":/^DOCTYPE/i,name:/[^\s<>'"]+/}},cdata:{pattern://i,greedy:!0},tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:"named-entity"},/&#x?[\da-f]{1,8};/i]},e.languages.markup.tag.inside["attr-value"].inside.entity=e.languages.markup.entity,e.languages.markup.doctype.inside["internal-subset"].inside=e.languages.markup,e.hooks.add("wrap",function(e){"entity"===e.type&&(e.attributes.title=e.content.value.replace(/&/,"&"))}),Object.defineProperty(e.languages.markup.tag,"addInlined",{value:function(t,n){var r={};r["language-"+n]={pattern:/(^$)/i,lookbehind:!0,inside:e.languages[n]},r.cdata=/^$/i;var i={"included-cdata":{pattern://i,inside:r}};i["language-"+n]={pattern:/[\s\S]+/,inside:e.languages[n]};var o={};o[t]={pattern:RegExp(/(<__[^>]*>)(?:))*\]\]>|(?!)/.source.replace(/__/g,function(){return t}),"i"),lookbehind:!0,greedy:!0,inside:i},e.languages.insertBefore("markup","cdata",o)}}),Object.defineProperty(e.languages.markup.tag,"addAttribute",{value:function(t,n){e.languages.markup.tag.inside["special-attr"].push({pattern:RegExp(/(^|["'\s])/.source+"(?:"+t+")"+/\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,"i"),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[n,"language-"+n],inside:e.languages[n]},punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}}}})}}),e.languages.html=e.languages.markup,e.languages.mathml=e.languages.markup,e.languages.svg=e.languages.markup,e.languages.xml=e.languages.extend("markup",{}),e.languages.ssml=e.languages.xml,e.languages.atom=e.languages.xml,e.languages.rss=e.languages.xml};e.exports=r,r.displayName="markup",r.aliases=["html","mathml","svg","xml","ssml","atom","rss"]},49317:function(e,t,n){"use strict";var r=function(e){e.languages.scss=e.languages.extend("css",{comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},atrule:{pattern:/@[\w-](?:\([^()]+\)|[^()\s]|\s+(?!\s))*?(?=\s+[{;])/,inside:{rule:/@[\w-]+/}},url:/(?:[-a-z]+-)?url(?=\()/i,selector:{pattern:/(?=\S)[^@;{}()]?(?:[^@;{}()\s]|\s+(?!\s)|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}][^:{}]*[:{][^}]))/,inside:{parent:{pattern:/&/,alias:"important"},placeholder:/%[-\w]+/,variable:/\$[-\w]+|#\{\$[-\w]+\}/}},property:{pattern:/(?:[-\w]|\$[-\w]|#\{\$[-\w]+\})+(?=\s*:)/,inside:{variable:/\$[-\w]+|#\{\$[-\w]+\}/}}}),e.languages.insertBefore("scss","atrule",{keyword:[/@(?:content|debug|each|else(?: if)?|extend|for|forward|function|if|import|include|mixin|return|use|warn|while)\b/i,{pattern:/( )(?:from|through)(?= )/,lookbehind:!0}]}),e.languages.insertBefore("scss","important",{variable:/\$[-\w]+|#\{\$[-\w]+\}/}),e.languages.insertBefore("scss","function",{"module-modifier":{pattern:/\b(?:as|hide|show|with)\b/i,alias:"keyword"},placeholder:{pattern:/%[-\w]+/,alias:"selector"},statement:{pattern:/\B!(?:default|optional)\b/i,alias:"keyword"},boolean:/\b(?:false|true)\b/,null:{pattern:/\bnull\b/,alias:"keyword"},operator:{pattern:/(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|not|or)(?=\s)/,lookbehind:!0}}),e.languages.scss.atrule.inside.rest=e.languages.scss};e.exports=r,r.displayName="scss",r.aliases=[]},35944:function(e,t,n){"use strict";var r=function(e){var t,n,r;e.register(i),e.register(o),n=(t=e).util.clone(t.languages.typescript),t.languages.tsx=t.languages.extend("jsx",n),delete t.languages.tsx.parameter,delete t.languages.tsx["literal-property"],(r=t.languages.tsx.tag).pattern=RegExp(/(^|[^\w$]|(?=<\/))/.source+"(?:"+r.pattern.source+")",r.pattern.flags),r.lookbehind=!0},i=n("18055"),o=n("73987");e.exports=r,r.displayName="tsx",r.aliases=[]},73987:function(e,t,n){"use strict";var r=function(e){var t,n;(t=e).languages.typescript=t.languages.extend("javascript",{"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,lookbehind:!0,greedy:!0,inside:null},builtin:/\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/}),t.languages.typescript.keyword.push(/\b(?:abstract|declare|is|keyof|readonly|require)\b/,/\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,/\btype\b(?=\s*(?:[\{*]|$))/),delete t.languages.typescript.parameter,delete t.languages.typescript["literal-property"],n=t.languages.extend("typescript",{}),delete n["class-name"],t.languages.typescript["class-name"].inside=n,t.languages.insertBefore("typescript","function",{decorator:{pattern:/@[$\w\xA0-\uFFFF]+/,inside:{at:{pattern:/^@/,alias:"operator"},function:/^[\s\S]+/}},"generic-function":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,greedy:!0,inside:{function:/^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,generic:{pattern:/<[\s\S]+/,alias:"class-name",inside:n}}}}),t.languages.ts=t.languages.typescript};e.exports=r,r.displayName="typescript",r.aliases=["ts"]},93871:function(e,t,n){"use strict";var r=function(e){!function(e){function t(t,n){e.languages[t]&&e.languages.insertBefore(t,"comment",{"doc-comment":n})}var n=e.languages.markup.tag,r={pattern:/\/\/\/.*/,greedy:!0,alias:"comment",inside:{tag:n}};t("csharp",r),t("fsharp",r),t("vbnet",{pattern:/'''.*/,greedy:!0,alias:"comment",inside:{tag:n}})}(e)};e.exports=r,r.displayName="xmlDoc",r.aliases=[]},94369:function(e,t,n){"use strict";var r=function(e){!function(e){var t=/[*&][^\s[\]{},]+/,n=/!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/,r="(?:"+n.source+"(?:[ ]+"+t.source+")?|"+t.source+"(?:[ ]+"+n.source+")?)",i=/(?:[^\s\x00-\x08\x0e-\x1f!"#%&'*,\-:>?@[\]`{|}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]|[?:-])(?:[ \t]*(?:(?![#:])|:))*/.source.replace(//g,function(){return/[^\s\x00-\x08\x0e-\x1f,[\]{}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]/.source}),o=/"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'/.source;function a(e,t){return t=(t||"").replace(/m/g,"")+"m",RegExp(/([:\-,[{]\s*(?:\s<>[ \t]+)?)(?:<>)(?=[ \t]*(?:$|,|\]|\}|(?:[\r\n]\s*)?#))/.source.replace(/<>/g,function(){return r}).replace(/<>/g,function(){return e}),t)}e.languages.yaml={scalar:{pattern:RegExp(/([\-:]\s*(?:\s<>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)\S[^\r\n]*(?:\2[^\r\n]+)*)/.source.replace(/<>/g,function(){return r})),lookbehind:!0,alias:"string"},comment:/#.*/,key:{pattern:RegExp(/((?:^|[:\-,[{\r\n?])[ \t]*(?:<>[ \t]+)?)<>(?=\s*:\s)/.source.replace(/<>/g,function(){return r}).replace(/<>/g,function(){return"(?:"+i+"|"+o+")"})),lookbehind:!0,greedy:!0,alias:"atrule"},directive:{pattern:/(^[ \t]*)%.+/m,lookbehind:!0,alias:"important"},datetime:{pattern:a(/\d{4}-\d\d?-\d\d?(?:[tT]|[ \t]+)\d\d?:\d{2}:\d{2}(?:\.\d*)?(?:[ \t]*(?:Z|[-+]\d\d?(?::\d{2})?))?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(?::\d{2}(?:\.\d*)?)?/.source),lookbehind:!0,alias:"number"},boolean:{pattern:a(/false|true/.source,"i"),lookbehind:!0,alias:"important"},null:{pattern:a(/null|~/.source,"i"),lookbehind:!0,alias:"important"},string:{pattern:a(o),lookbehind:!0,greedy:!0},number:{pattern:a(/[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/.source,"i"),lookbehind:!0},tag:n,important:t,punctuation:/---|[:[\]{}\-,|>?]|\.\.\./},e.languages.yml=e.languages.yaml}(e)};e.exports=r,r.displayName="yaml",r.aliases=["yml"]},28722:function(e,t,n){e.exports=function(e,t,n,r){var i=n?n.call(r,e,t):void 0;if(void 0!==i)return!!i;if(e===t)return!0;if("object"!=typeof e||!e||"object"!=typeof t||!t)return!1;var o=Object.keys(e),a=Object.keys(t);if(o.length!==a.length)return!1;for(var l=Object.prototype.hasOwnProperty.bind(t),s=0;s0&&void 0!==arguments[0]?arguments[0]:"/";return(0,i.withBase)(e,r.default.base)}function l(e){return(0,i.removeBase)(e,r.default.base)}function s(e,t){return a(c(e))===a(c(t))}function c(e){var t,n,o=!!(null===(n=r.default)||void 0===n?void 0:null===(t=n.route)||void 0===t?void 0:t.cleanUrls);return(0,i.normalizeHref)(e,o)}},86126:function(e,t,n){"use strict";n.r(t),n.d(t,{Button:function(){return eM},HomeFooter:function(){return nS},HomeLayout:function(){return e$},Layout:function(){return eD},Link:function(){return eh},Nav:function(){return tg},NotFoundLayout:function(){return V},PackageManagerTabs:function(){return nF},Search:function(){return nI},SearchPanel:function(){return nk},Tab:function(){return tO},Tabs:function(){return tP},Toc:function(){return nE},bindingAsideScroll:function(){return ee},default:function(){return rl},getCustomMDXComponent:function(){return ra},getLogoUrl:function(){return eo},isActive:function(){return er},isExternalHref:function(){return ei},isMobileDevice:function(){return ea},scrollToTarget:function(){return J},setup:function(){return et},useEditLink:function(){return Q},useLocaleSiteData:function(){return Z},usePathUtils:function(){return en},usePrevNextPage:function(){return K},useSidebarData:function(){return X}});var r,i,o,a=n("20469"),l=n("33888"),s=n("37599"),c=n("28003"),u=n("93160"),d=n("73706"),p=n("9880"),h=n("85464");n("57520");var f=n("57814"),m=n("78585"),g=n("19730"),b=n("80061"),x=n("60421"),v=n("23169"),y=n("97150"),w=n("1765"),j=n("42256"),P=n("76819"),O=n("74007"),k=n("88273"),I=n("31952"),S=n("53816"),_=n("11167"),E=n("84404"),C=n("61932"),z=n("75208"),N=n("72858"),A=n("73846"),T=n("4249"),D=n("14917"),L=n("57077"),M=n("54466"),R=n("81130"),B=n("64227"),F=n("68448"),H=n("73513"),W=n("43184"),q=n("33204"),U=n("97575"),$=n("29385"),G=n("53274");function V(){var e=(0,h.usePageData)().siteData,t=e.lang;if(!(t&&"undefined"!=typeof window&&location.pathname.includes("/".concat(t,"/"))))return(0,p.jsxs)("div",{className:"m-auto mt-50 p-16 sm:p-8 sm:pt-24 sm:pb-40 text-center flex-center flex-col",children:[(0,p.jsx)("p",{className:"text-6xl font-semibold",children:"404"}),(0,p.jsx)("h1",{className:"leading-5 pt-3 text-xl font-bold",children:"PAGE NOT FOUND"}),(0,p.jsx)("div",{style:{height:"1px"},className:"mt-6 mx-auto mb-4.5 w-16 bg-gray-light-1"}),(0,p.jsx)("div",{className:"pt-5",children:(0,p.jsx)("a",{className:"py-2 px-4 rounded-2xl inline-block border-solid border-brand text-brand font-medium hover:border-brand-dark hover:text-brand-dark transition-colors duration-300",href:e.base,"aria-label":"go to home",children:"Take me home"})})]});var n=location.pathname.replace("/".concat(t,"/"),"/");return window.location.replace(n),(0,p.jsx)(p.Fragment,{})}function Z(){var e,t,n,r,i,o=(0,h.usePageData)(),a=o.page.lang,l=null!==(r=null==o?void 0:null===(n=o.siteData)||void 0===n?void 0:n.themeConfig)&&void 0!==r?r:{},s=null!==(i=o.siteData.lang)&&void 0!==i?i:"",c=null==l?void 0:l.locales;if(!c||0===c.length)return{nav:l.nav,sidebar:l.sidebar,prevPageText:l.prevPageText,nextPageText:l.nextPageText};return e=function(e){for(var t=1;t span'));o&&(r&&r.classList.remove("aside-active"),(r=o).classList.add("aside-active"))}},a=(0,y.default)(function(){if(document.documentElement.scrollTop+window.innerHeight>=document.documentElement.scrollHeight)o(n,n.length-1);else for(var e=0;e=a&&i2&&void 0!==arguments[2]&&arguments[2],r=null;try{r=e.classList.contains("header-anchor")?e:document.getElementById(decodeURIComponent(t.slice(1)))}catch(e){console.warn(e)}r&&J(r,n)},window.addEventListener("click",function(t){var n=t.target.closest("a");if(n){var r=n.origin,i=n.hash,o=n.target,a=n.pathname,l=n.search,s=window.location;i&&"_blank"!==o&&r===s.origin&&(a===s.pathname&&l===s.search&&i&&n.classList.contains("header-anchor")?(t.preventDefault(),history.pushState(null,"",i),e(n,i,!0),window.dispatchEvent(new Event("hashchange"))):window.addEventListener("RspressReloadContent",function(){location.hash.length>1&&J(document.getElementById(location.hash.slice(1)),!1)}))}},{capture:!0}),window.addEventListener("hashchange",function(e){e.preventDefault()})}}function en(){var e=(0,h.useLang)(),t=(0,h.useVersion)(),n=(0,h.usePageData)(),r=n.siteData.lang,i=n.siteData.multiVersion.default;return{normalizeLinkHref:function(n){var o=n;if(!r&&!i||(0,w.isExternalUrl)(o)||o.startsWith("#"))return o;var a=(o=(0,h.removeBase)(o)).split("/").filter(Boolean),l="",s="",c="";return i&&(t!==i?(l=t,a[0]===t&&a.shift()):a[0]===i&&a.shift()),r&&(e!==r?(s=e,a[0]===e&&a.shift()):a[0]===r&&a.shift()),c=a.join("/"),(0,h.normalizeHrefInRuntime)((0,h.withBase)([l,s,c].filter(Boolean).join("/")))}}}function er(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return!!t&&(n?(0,h.isEqualPath)(e,t):(0,h.isEqualPath)(e,t)||e.startsWith(t))}function ei(e){return/^https?:\/\//.test(e)}function eo(e,t){return"string"==typeof e?e:"dark"===t?e.dark:e.light}function ea(){return window.innerWidth<768}function el(e){var t,n=e.headers,r=n.length>0,i=(0,f.useRef)(null),o=(null===(t=n[0])||void 0===t?void 0:t.depth)||2;return(0,f.useEffect)(function(){i.current&&(i.current.style.opacity="0"),setTimeout(function(){e=ee()},100);var e,t=decodeURIComponent(window.location.hash);if(t){var n=document.getElementById(t.slice(1));n&&J(n,!1)}else window.scrollTo(0,0);return function(){e&&e()}},[n]),(0,p.jsx)("div",{className:"flex flex-col",children:(0,p.jsx)("div",{className:r?"0?[{name:e_,items:n.map(e)}]:[]))},[o]);return(0,p.jsxs)("div",{className:"overview-index mx-auto px-8",children:[(0,p.jsx)("div",{className:"flex items-center justify-between",children:(0,p.jsx)("h1",{children:"Overview"})}),a.map(function(e){return(0,p.jsxs)("div",{className:"mb-16",children:[e.name===e_&&1===a.length?(0,p.jsx)("h2",{style:{paddingTop:0}}):(0,p.jsx)("h2",{children:e.name}),(0,p.jsx)("div",{className:eS.overviewGroups,children:e.items.map(function(e){var t;return(0,p.jsxs)("div",{className:eS.overviewGroup,children:[(0,p.jsx)("div",{className:"flex",children:(0,p.jsx)("h3",{style:{marginBottom:8},children:(0,p.jsx)(eh,{href:(0,h.normalizeHrefInRuntime)(e.link),children:e.text})})}),(0,p.jsx)("ul",{className:"list-none",children:null===(t=e.headers)||void 0===t?void 0:t.map(function(t){return(0,p.jsx)("li",{className:"".concat(eS.overviewGroupLi," ").concat(eS["level".concat(t.depth)]," first:mt-2"),children:(0,p.jsx)(eh,{href:"".concat((0,h.normalizeHrefInRuntime)(e.link),"#").concat(t.id),children:t.text})},t.id)})})]},e.link)})})]},e.name)})]})}var eC=(0,f.createContext)({}),ez={asideContainer:"aside-container_feeda",docLayout:"docLayout_feeda",content:"content_feeda"};function eN(e){for(var t=1;t0,T=(null==S?void 0:S.outlineTitle)||(null==I?void 0:I.outlineTitle)||"ON THIS PAGE",D=null!==(r=null==w?void 0:w.overview)&&void 0!==r&&r,L=null===(i=null==w?void 0:w.footer)||void 0===i||i,M=function(){var e,t,n="undefined"==typeof window||window.top===window.self;return(null!==(t=null!==(e=null==w?void 0:w.outline)&&void 0!==e?e:null==I?void 0:I.outline)&&void 0!==t?t:n)&&k.length>0},R=(0,c._)((0,f.useState)(M()),2),B=R[0],F=R[1];return(0,f.useEffect)(function(){F(M())},[b,m]),(0,p.jsxs)("div",{className:"".concat(ez.docLayout," pt-0"),style:eN({},N?{marginTop:0}:{}),children:[a,A?(0,p.jsx)(eI,{pathname:E,langRoutePrefix:z,sidebarData:C}):null,(0,p.jsxs)("div",{className:"".concat(ez.content," rspress-doc-container flex flex-shrink-0"),children:[(0,p.jsx)("div",{className:"w-full",children:D?(0,p.jsx)(eE,{}):(0,p.jsxs)("div",{children:[(0,p.jsx)("div",{className:"rspress-doc",children:(0,p.jsx)(eC.Provider,{value:{tabData:P,setTabData:O},children:(0,p.jsx)(v.MDXProvider,{components:(0,g.getCustomMDXComponent)(),children:(0,p.jsx)(h.Content,{})})})}),(0,p.jsxs)("div",{className:"rspress-doc-footer",children:[o,L&&(0,p.jsx)(em,{})]})]})}),B?(0,p.jsx)("div",{className:ez.asideContainer,style:eN({maxHeight:"calc(100vh - (var(--rp-nav-height) + 32px))",overflow:"scroll"},N?{marginTop:0,paddingTop:"32px"}:{}),children:(0,p.jsxs)("div",{children:[s,(0,p.jsx)(el,{headers:k,outlineTitle:T}),u]})}):null]}),l]})}function eT(e){for(var t=1;t3,r=[],i=[];t.forEach(function(e,t){t<3?r.push(e):i.push(e)});var o=(0,c._)((0,f.useState)(!1),2),a=o[0],l=o[1];return(0,p.jsxs)("div",{className:"social-links ".concat(e5.menuItem," flex-center relative"),onMouseLeave:function(){return l(!1)},children:[(0,p.jsx)(e9,{links:r,moreIconVisible:n,mouseEnter:function(){return l(!0)}}),a?(0,p.jsx)(te,{links:i}):null]})},tn={navScreen:"navScreen_8624f",active:"active_8624f",container:"container_8624f",navMenu:"navMenu_8624f",navMenuItem:"navMenuItem_8624f",navAppearance:"navAppearance_8624f"};function tr(e){for(var t=1;t1,m=i.nav||[],g=!1!==o.themeConfig.darkMode,b=(null==o?void 0:null===(t=o.themeConfig)||void 0===t?void 0:t.socialLinks)||[],x=b.length>0,v=u.map(function(e){return e.lang||"zh"})||[],y=o.base,w=o.logo,j=d?{text:(0,p.jsx)(e3,{style:{width:"18px",height:"18px"}}),items:u.map(function(e){return{text:null==e?void 0:e.label,link:"/".concat(e.lang)}}),activeValue:null===(n=u.find(function(e){return e.lang===i.lang}))||void 0===n?void 0:n.label}:null;return(0,f.useEffect)(function(){return s.current&&r&&(0,O.disableBodyScroll)(s.current,{reserveScrollBarGap:!0}),function(){(0,O.clearAllBodyScrollLocks)()}},[r]),(0,p.jsx)("div",{className:"".concat(tn.navScreen," ").concat(r?tn.active:""),ref:s,id:"navScreen",children:(0,p.jsxs)("div",{className:tn.container,children:[(0,p.jsx)(function(e){var t=e.menuItems;return(0,p.jsx)("div",{className:tn.navMenu,children:t.map(function(e,t){var n,r;return(0,p.jsx)("div",{className:"".concat(tn.navMenuItem," w-full"),children:"link"in e?(0,p.jsx)(eX,tr({pathname:a,base:y,langs:v},e),t):(0,p.jsx)("div",{className:"mx-3 last:mr-0",children:(0,p.jsx)(eZ,(n=tr({},e),r=(r={items:"items"in e?e.items:e},r),Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(r)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(r)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(r,e))}),n))},t)},t)})})},{menuItems:m}),(0,p.jsxs)("div",{className:"flex-center flex-col gap-2",children:[g&&(0,p.jsx)(function(){return(0,p.jsx)("div",{className:"mt-2 ".concat(tn.navAppearance," flex justify-center"),children:(0,p.jsx)(h.NoSSR,{children:(0,p.jsx)(e2,{onClick:function(){l(eo(w,"dark"===c?"light":"dark"))}})})})},{}),d&&(0,p.jsx)(ti,{translationMenuData:j}),x&&(0,p.jsx)(tt,{socialLinks:b})]})]})})}var ta=function(e){var t,n;return(0,p.jsxs)("svg",(t=function(e){for(var t=1;t=768&&n()},o=(i=(0,c._)((0,f.useState)(!1),2))[0],a=i[1],{isScreenOpen:o,openScreen:t,closeScreen:n,toggleScreen:function(){o?n():t()}}),m=h.isScreenOpen,g=h.toggleScreen;return(0,p.jsxs)(f.Fragment,{children:[(0,p.jsx)(to,{isScreenOpen:m,localeData:l,siteData:s,pathname:u,setLogo:d}),(0,p.jsx)("button",{onClick:g,className:"".concat(m?tl.active:""," ").concat(tl.navHamburger," text-gray-500"),children:(0,p.jsx)(ta,{fill:"currentColor"})})]})}function tc(e){var t=e.item;return(0,p.jsxs)("div",{className:"rounded-2xl my-1 flex",style:{padding:"0.4rem 1.5rem 0.4rem 0.75rem"},children:[t.tag&&(0,p.jsx)(eb,{tag:t.tag}),(0,p.jsx)("span",{className:"text-brand",children:t.text})]},t.link)}function tu(e){var t=e.item;return(0,p.jsx)("div",{className:"font-medium my-1",children:(0,p.jsx)(eh,{href:t.link,children:(0,p.jsx)("div",{className:"rounded-2xl hover:bg-mute",style:{padding:"0.4rem 1.5rem 0.4rem 0.75rem"},children:(0,p.jsxs)("div",{className:"flex",children:[t.tag&&(0,p.jsx)(eb,{tag:t.tag}),(0,p.jsx)("span",{children:t.text})]})})})},t.link)}function td(e){var t,n,r=e.activeValue,i=e.isTranslation,o=e.items,a=e.base,l=void 0===a?"":a,s=e.link,u=e.pathname,d=void 0===u?"":u,h=(0,c._)((0,f.useState)(!1),2),m=h[0],g=h[1],b=function(e){var t=new RegExp(e.activeMatch||e.link).test((0,w.withoutBase)(d,l));return r===e.text||!r&&t?(0,p.jsx)(tc,{item:e},e.link):(0,p.jsx)(tu,{item:e},e.link)};return(0,p.jsxs)("div",{className:"relative flex-center h-14",onMouseLeave:function(){return g(!1)},children:[(0,p.jsx)("button",{onMouseEnter:function(){return g(!0)},className:"nav-menu-group-button flex-center items-center font-medium text-sm text-text-1 hover:text-text-2 transition-colors duration-200",children:(void 0===s?"":s)?(0,p.jsx)(eX,(t=function(e){for(var t=1;t1,E=u.themeConfig.socialLinks||[],C=E.length>0,z=u.lang||"",N=u.multiVersion.default||"",A=d.lang,T=S.map(function(e){return e.lang||""})||[],D=(0,c._)((0,f.useState)(eo(m,y)),2),L=D[0],M=D[1],R=_?{items:S.map(function(e){return{text:null==e?void 0:e.label,link:(0,w.replaceLang)(v,{current:A,target:e.lang,default:z},{current:P,default:N},b)}}),activeValue:null===(t=S.find(function(e){return A===e.lang}))||void 0===t?void 0:t.label}:null;(0,f.useEffect)(function(){M(eo(m,y))},[y]),(0,f.useEffect)(function(){I(ea())},[]);var B=function(e){var t=e.menuItems;return(0,p.jsx)("div",{className:"rspress-nav-menu menu h-14",children:t.map(function(e){return"items"in e||Array.isArray(e)?(0,p.jsx)("div",{className:"mx-3 last:mr-0",children:(0,p.jsx)(td,th(tp({},e),{base:b,pathname:v,langs:T,items:"items"in e?e.items:e}))},e.text):(0,p.jsx)(eX,tp({pathname:v,langs:T,base:b},e),e.link)})})},F=j.nav||[],H=function(e){return null!==(r=e.position)&&void 0!==r?r:"right"},W=F.filter(function(e){return"left"===H(e)}),q=F.filter(function(e){return"right"===H(e)}),U=(null==u?void 0:null===(n=u.themeConfig)||void 0===n?void 0:n.search)!==!1,$=null!==(i=j.title)&&void 0!==i?i:u.title,G=!1!==u.themeConfig.darkMode;return(0,p.jsxs)("header",{className:"top-0 left-0 md:fixed w-full",style:{zIndex:"var(--rp-z-index-nav)",background:"var(--rp-c-bg)"},children:[l,(0,p.jsx)("div",{className:"".concat(eY.navContainer," rspress-nav px-6"),children:(0,p.jsxs)("div",{className:"".concat(eY.container," flex justify-between items-center h-full"),children:[o,(0,p.jsx)(tf,{title:$,langRoutePrefix:j.langRoutePrefix||"/",logo:L}),a,(0,p.jsxs)("div",{className:"".concat(eY.content," flex flex-1 justify-end items-center"),children:[W.length>0?(0,p.jsx)("div",{className:eY.leftNav,children:(0,p.jsx)(B,{menuItems:W})}):null,(0,p.jsxs)("div",{className:eY.rightNav,children:[U&&(0,p.jsx)("div",{className:"flex sm:flex-1 items-center sm:pl-4 sm:pr-2",children:(0,p.jsx)(g.Search,{})}),(0,p.jsx)(B,{menuItems:q}),(0,p.jsxs)("div",{className:"flex-center flex-row",children:[_&&(0,p.jsx)(tm,{translationMenuData:R}),G&&(0,p.jsx)("div",{className:"mx-2",children:(0,p.jsx)(e2,{})}),C&&(0,p.jsx)(tt,{socialLinks:E})]})]}),(0,p.jsxs)("div",{className:eY.mobileNavMenu,children:[k&&(0,p.jsx)(g.Search,{}),(0,p.jsx)(ts,{localeData:j,siteData:u,pathname:v,setLogo:M})]})]})]})})]})}var tb=function(e){var t,n;return(0,p.jsx)("svg",(t=function(e){for(var t=1;t=0)&&(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0))Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}}return i}(e,["children"]);return(0,p.jsx)("div",tw(ty({},n),{className:"rounded px-2",children:t}))}var tk=function(e){var t,n;return(0,p.jsx)("svg",(t=function(e){for(var t=1;t255?3:1}function tz(e,t){for(var n=0,r=0,i=0;i=t);i++)r+=tC(e.charAt(i)),n++;return n}function tN(e){for(var t=0,n=0;n1&&void 0!==arguments[1]?arguments[1]:7,n=this;return t2(function(){var r,i,o,a;return(0,d._)(this,function(l){switch(l.label){case 0:return[4,null===(r=t5(n,nn))||void 0===r?void 0:r.search({keyword:e,limit:t})];case 1:return i=l.sent(),o=t_(e),a=(null==i?void 0:i.find(function(e){return t8(n,ns,nm).call(n,e.index)}))||{index:tS,hits:[]},[2,{current:t8(n,nr,nu).call(n,o,a),others:((null==i?void 0:i.filter(function(e){return!t8(n,ns,nm).call(n,e.index)}))||[]).map(function(e){return{index:e.index,items:t8(n,nr,nu).call(n,o,e)}})}]}})})()}}]),e}();function nu(e,t){var n=this,r=[];return null==t||t.hits.forEach(function(t){t8(n,ni,nd).call(n,t,e,r),!t8(n,no,np).call(n,t,e,r)&&t8(n,na,nh).call(n,t,e,r)}),r}function nd(e,t,n){var r=e.title,i=void 0===r?"":r,o=t_(i);return!!o.includes(t)&&(n.push({type:"title",title:i,header:i,link:"".concat(e.domain).concat((0,h.normalizeHrefInRuntime)(e.routePath)),query:t,highlightInfoList:[{start:o.indexOf(t),length:tN(t)}],group:t5(this,ne).extractGroupName(e.routePath)}),!0)}function np(e,t,n){var r=e.toc,i=void 0===r?[]:r,o=e.domain,a=void 0===o?"":o,l=e.title,s=void 0===l?"":l,u=!0,d=!1,p=void 0;try{for(var f,m=i.entries()[Symbol.iterator]();!(u=(f=m.next()).done);u=!0){var g=(0,c._)(f.value,2),b=g[0],x=g[1];if(t_(x.text).includes(t)){var v=(function(e,t){for(var n=e[t],r=t,i=[n];n&&n.depth>2;){for(var o=!1,a=r-1;a>=0;a--){var l=e[a];if(l.depth>1&&l.depth===n.depth-1){n=l,r=a,i.unshift(n),o=!0;break}}if(!o)break}return i})(i,b).map(function(e){return e.text}).join(" > "),y=t_(v).indexOf(t),w="".concat(s," > ");return n.push({type:"header",title:e.title,header:"".concat(w).concat(v),highlightInfoList:[{start:y+w.length,length:tN(t)}],link:"".concat(a).concat((0,h.normalizeHrefInRuntime)(e.routePath),"#").concat(x.id),query:t,group:t5(this,ne).extractGroupName(e.routePath)}),!0}}}catch(e){d=!0,p=e}finally{try{!u&&null!=m.return&&m.return()}finally{if(d)throw p}}return!1}function nh(e,t,n){var r=e.content,i=e.toc,o=e.domain;if(r.length){var a=t_(r),l=a.indexOf(t),s=i.map(function(e){return e.charIndex}),c=function(e){return i[s.findIndex(function(t,n){if(!(n=e)return!0;return!1})]};if(-1===l){var u,d,p=null===(u=e._matchesPosition)||void 0===u?void 0:u.content;if(!(null==p?void 0:p.length))return;var f=e._matchesPosition.content[0].start,m=c(f),g=tz(r,f),b=tz(r,f+100),x=r.slice(g,b),v=e._matchesPosition.content.filter(function(e){return e.start>=f&&e.start+e.length<=f+100}).map(function(e){return{start:tz(r,e.start)-g+3,length:e.length}});n.push({type:"content",title:e.title,header:null!==(d=null==m?void 0:m.text)&&void 0!==d?d:e.title,link:"".concat(o).concat((0,h.normalizeHrefInRuntime)(e.routePath)).concat(m?"#".concat(m.id):""),query:t,highlightInfoList:v,group:t5(this,ne).extractGroupName(e.routePath),statement:"...".concat(x,"...")});return}for(;-1!==l;){var y,w=c(l),j=r.slice(0,l).lastIndexOf("\n");j=-1===j?0:j;var P=r.indexOf("\n\n",l+t.length),O=r.slice(j,P);O.length>100&&(O=t8(this,nl,nf).call(this,O,t));var k=t_(O).indexOf(t),I=[{start:k,length:tN(t)}];n.push({type:"content",title:e.title,header:null!==(y=null==w?void 0:w.text)&&void 0!==y?y:e.title,statement:O,highlightInfoList:I,link:"".concat(o).concat((0,h.normalizeHrefInRuntime)(e.routePath)).concat(w?"#".concat(w.id):""),query:t,group:t5(this,ne).extractGroupName(e.routePath)}),l=a.indexOf(t,l+O.length-k)}}}function nf(e,t){var n=t_(e).indexOf(t_(t)),r=Math.floor((100-t.length)/2),i=e.slice(0,n);i.length>r&&(i="...".concat(e.slice(n-r+3,n)));var o=e.slice(n+t.length);return o.length>r&&(o="".concat(e.slice(n+t.length,n+r-3),"...")),i+t+o}function nm(e){return e===t5(this,nt)||e===tS}var ng=function(e){var t,n;return(0,p.jsx)("svg",(t=function(e){for(var t=1;tt+n);a++){;i>t&&(r+=e.charAt(a))}return r}(c.slice(u),0,d));n.push(g),n.push((0,p.jsx)("span",{className:tx.mark,children:b},f)),r=f+b.length}}catch(e){o=!0,a=e}finally{try{!i&&null!=s.return&&s.return()}finally{if(o)throw a}}return r=0){var t=T[j];j1)||void 0===arguments[1]||arguments[1];if(0===e.length&&!v)return(0,p.jsx)("div",{className:"mt-4 flex-center",children:(0,p.jsx)("div",{className:"p-2 font-bold text-md",style:{color:"#2c3e50"},children:"No results found"})});var r=(t=e,(0,S.default)(t,"group"));return(0,p.jsx)("ul",{className:tx.suggestList,children:Object.keys(r).map(function(e){var t=r[e]||[];return(0,p.jsxs)("li",{children:[n&&(0,p.jsx)("h2",{className:tx.groupTitle,children:e}),(0,p.jsx)("ul",{className:"pb-2",children:t.map(function(e){var t=++R;return(0,p.jsx)(nx,{suggestion:e,isCurrent:t===j,setCurrentSuggestionIndex:function(){P(t)},closeSearch:function(){return i(!1)},inCurrentDocIndex:t0,r=e.others.map(function(e){if(!t||"remote"!==t.mode)return e;return(t.searchIndexes||[]).map(function(e){return"string"==typeof e?{value:e,label:e}:e}).find(function(t){return t.value===e.index}).label});return(0,p.jsxs)("div",{children:[B(e.current),n&&(0,p.jsx)("h2",{className:tx.groupTitle,children:nO[z]}),(0,p.jsx)("div",{style:{marginTop:"-12px"},children:(0,p.jsx)(tP,{values:r,tabContainerClassName:tx.tabClassName,children:e.others.map(function(e){return(0,p.jsx)(tO,{children:B(e.items,!1)},e.index)})})})]})}(m,A)}):null,v&&(0,p.jsx)("div",{className:"flex-center",children:(0,p.jsx)("div",{className:"p-2 text-sm",children:(0,p.jsx)(tk,{})})})]})}),document.getElementById("search-container"))})}function nI(){var e=(0,c._)((0,f.useState)(!1),2),t=e[0],n=e[1];return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)("div",{className:tx.navSearchButton,onClick:function(){return n(!0)},children:(0,p.jsxs)("button",{children:[(0,p.jsx)(tb,{width:"18",hight:"18"}),(0,p.jsx)("p",{className:tx.searchWord,children:"Search Docs"}),(0,p.jsxs)("div",{children:[(0,p.jsx)("span",{children:"\u2318"}),(0,p.jsx)("span",{children:"K"})]})]})}),(0,p.jsx)("div",{className:tx.mobileNavSearchButton,onClick:function(){return n(!0)},children:(0,p.jsx)(tb,{})}),(0,p.jsx)(nk,{focused:t,setFocused:n})]})}function nS(){var e=((0,h.usePageData)().siteData.themeConfig.footer||{}).message;return(0,p.jsx)("footer",{className:"absolute bottom-0 mt-12 py-8 px-6 sm:p-8 w-full border-t border-solid border-divider-light",children:(0,p.jsx)("div",{className:"m-auto w-full text-center",children:e&&(0,p.jsx)("div",{className:"font-meduim text-sm text-text-2",children:e})})})}var n_=function(e){return(0,p.jsx)("li",{className:"py-1",children:(0,p.jsx)("a",{href:"#".concat(e.id),className:"toc-link transition-all duration-300 hover:text-text-1 text-text-2 block underline underline-offset-2",style:{marginLeft:12*e.depth},onClick:function(t){t.preventDefault(),window.location.hash=e.id;var n=document.getElementById(e.id);n&&J(n,!1)},children:(0,p.jsx)("span",{className:"toc-link-text block",children:e.text})})},e.id)};function nE(){var e=(0,h.usePageData)().page;return(0,p.jsx)("ul",{children:e.toc.map(function(e){return(0,p.jsx)(n_,function(e){for(var t=1;t0,lineProps:function(e){var t=u.includes(e);return{className:t?"line highlighted":"",style:{backgroundColor:t?"var(--rp-code-line-highlight-color)":"",display:"block",padding:"0 1.25rem"}}},children:t}),(0,p.jsx)("button",{className:"copy",onClick:function(){var e=G(t),n=r.current;if(e&&n){n.classList.add("copied"),clearTimeout(nA.get(n));var i=setTimeout(function(){n.classList.remove("copied"),n.blur(),nA.delete(n)},2e3);nA.set(n,i)}},ref:r})]})}function nD(e){var t,n;return(0,p.jsxs)("svg",(t=function(e){for(var t=1;t-1},v.prototype.set=function(e,t){var n=this.__data__,r=b(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this};var y="object"==typeof global&&global&&global.Object===Object&&global,w="object"==typeof self&&self&&self.Object===Object&&self,j=y||w||Function("return this")(),P=j.Symbol,O=Object.prototype,k=O.hasOwnProperty,I=O.toString,S=P?P.toStringTag:void 0,_=function(e){var t=k.call(e,S),n=e[S];try{e[S]=void 0;var r=!0}catch(e){}var i=I.call(e);return r&&(t?e[S]=n:delete e[S]),i},E=Object.prototype.toString,C=P?P.toStringTag:void 0,z=function(e){var t;if(null==e)return void 0===e?"[object Undefined]":"[object Null]";return C&&C in Object(e)?_(e):(t=e,E.call(t))},N=function(e){var t=void 0===e?"undefined":(0,m._)(e);return null!=e&&("object"==t||"function"==t)},A=function(e){if(!N(e))return!1;var t=z(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t},T=j["__core-js_shared__"];var D=(r=/[^.]+$/.exec(T&&T.keys&&T.keys.IE_PROTO||""))?"Symbol(src)_1."+r:"",L=Function.prototype.toString,M=function(e){if(null!=e){try{return L.call(e)}catch(e){}try{return e+""}catch(e){}}return""},R=/^\[object .+?Constructor\]$/,B=Object.prototype,F=Function.prototype.toString,H=B.hasOwnProperty,W=RegExp("^"+F.call(H).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),q=function(e){var t;return!!N(e)&&(t=e,!D||!(D in t))&&(A(e)?W:R).test(M(e))},U=function(e,t){var n,r,i=(n=e,r=t,null==n?void 0:n[r]);return q(i)?i:void 0},$=U(j,"Map"),G=U(Object,"create"),V=Object.prototype.hasOwnProperty,Z=Object.prototype.hasOwnProperty;function Y(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t-1&&e%1==0&&e<=9007199254740991},eI=function(e){return null!=e&&ek(e.length)&&!A(e)},eS="object"==typeof exports&&exports&&!exports.nodeType&&exports,e_=eS&&"object"==typeof module&&module&&!module.nodeType&&module,eE=e_&&e_.exports===eS?j.Buffer:void 0,eC=eE?eE.isBuffer:void 0,ez=eC||function(){return!1},eN=Object.prototype,eA=Function.prototype.toString,eT=eN.hasOwnProperty,eD=eA.call(Object),eL=function(e){if(!ex(e)||"[object Object]"!=z(e))return!1;var t=em(e);if(null===t)return!0;var n=eT.call(t,"constructor")&&t.constructor;return"function"==typeof n&&(0,h._)(n,n)&&eA.call(n)==eD},eM={};eM["[object Float32Array]"]=eM["[object Float64Array]"]=eM["[object Int8Array]"]=eM["[object Int16Array]"]=eM["[object Int32Array]"]=eM["[object Uint8Array]"]=eM["[object Uint8ClampedArray]"]=eM["[object Uint16Array]"]=eM["[object Uint32Array]"]=!0,eM["[object Arguments]"]=eM["[object Array]"]=eM["[object ArrayBuffer]"]=eM["[object Boolean]"]=eM["[object DataView]"]=eM["[object Date]"]=eM["[object Error]"]=eM["[object Function]"]=eM["[object Map]"]=eM["[object Number]"]=eM["[object Object]"]=eM["[object RegExp]"]=eM["[object Set]"]=eM["[object String]"]=eM["[object WeakMap]"]=!1;var eR="object"==typeof exports&&exports&&!exports.nodeType&&exports,eB=eR&&"object"==typeof module&&module&&!module.nodeType&&module,eF=eB&&eB.exports===eR&&y.process,eH=function(){try{var e=eB&&eB.require&&eB.require("util").types;if(e)return e;return eF&&eF.binding&&eF.binding("util")}catch(e){}}(),eW=eH&&eH.isTypedArray;var eq=eW?(s=eW,function(e){return s(e)}):function(e){return ex(e)&&ek(e.length)&&!!eM[z(e)]},eU=function(e,t){if("constructor"!==t||"function"!=typeof e[t]){if("__proto__"!=t)return e[t]}},e$=Object.prototype.hasOwnProperty,eG=function(e,t,n){var r=e[t];(!(e$.call(e,t)&&g(r,n))||void 0===n&&!(t in e))&&et(e,t,n)},eV=function(e,t,n,r){var i=!n;n||(n={});for(var o=-1,a=t.length;++o-1&&e%1==0&&e0){if(++u>=800)return arguments[0]}else u=0;return c.apply(void 0,arguments)}),tt=function(e,t){var n,r,i;return te((n=e,r=t,i=e5,r=e7(void 0===r?n.length-1:r,0),function(){for(var e=arguments,t=-1,o=e7(e.length-r,0),a=Array(o);++t1?t[r-1]:void 0,o=r>2?t[2]:void 0;for(i=p.length>3&&"function"==typeof i?(r--,i):void 0,o&&tn(t[0],t[1],o)&&(i=r<3?void 0:i,r=1),e=Object(e);++n0&&".."!==i[i.length-1]?i.pop():n&&i.push(".."):i.push(u)}}catch(e){a=!0,l=e}finally{try{!o&&null!=c.return&&c.return()}finally{if(a)throw l}}var d=i.join("/");return n&&(d="/".concat(d)),d}(e))).charAt(t.length-1)?t.slice(0,-1):t}function tp(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("mailto:")||e.startsWith("tel:")}function th(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",i=tx(e,r);!i&&(i="/index.html");var o="",a="",l="",s=i.split("/").filter(Boolean);return n.current&&n.current!==n.default&&(o=s.shift()||""),t.target!==t.default?(a=t.target,t.current!==t.default&&s.shift()):s.shift(),l=s.join("/")||"",(o||a)&&!l&&(l="index.html"),tb(tu([o,a,l].filter(Boolean).join("/")),r)}var tf=function(e){var t=(0,f._)(e.split("#"),2),n=t[0],r=t[1];return{url:n,hash:void 0===r?"":r}};function tm(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!e)return"/";if(tp(e))return e;var n=tf(decodeURIComponent(e)),r=n.url,i=n.hash;return e.startsWith("mailto:")||e.startsWith("tel:")?e:(!t&&!r.endsWith(".html")&&(r.endsWith("/")?r+="index.html":r+=".html"),tu(i?"".concat(r,"#").concat(i):r))}function tg(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return tu(e).replace(td(t),"")}function tb(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=tu(e),r=td(t);return n.startsWith(r)?n:"".concat(r).concat(n)}function tx(e,t){return tu(e).replace(td(t),"")}},88273:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return r}});var r={title:"Modern.js Module",description:"",icon:"https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/logo-1x-0104.png",themeConfig:{footer:{message:"Copyright \xa9 2023 ByteDance."},socialLinks:[{icon:"github",mode:"link",content:"https://github.com/web-infra-dev/modern.js/tree/main/packages/solutions/module-tools"}],locales:[{lang:"zh",label:"\u7B80\u4F53\u4E2D\u6587",nav:[{text:"\u6307\u5357",link:"/guide/intro/welcome",activeMatch:"^/guide/"},{text:"API",link:"/api/",activeMatch:"^/api/"},{text:"\u63D2\u4EF6",link:"/plugins/guide/getting-started",activeMatch:"^/plugins/"},{text:"v2.35.1",items:[{text:"\u66F4\u65B0\u65E5\u5FD7",link:"https://github.com/web-infra-dev/modern.js/tree/main/packages/solutions/module-tools/CHANGELOG.md"},{text:"\u8D21\u732E\u6307\u5357",link:"https://modernjs.dev/en/community/contributing-guide.html"}]}],title:"Modern.js Module",outlineTitle:"\u76EE\u5F55",prevPageText:"\u4E0A\u4E00\u9875",nextPageText:"\u4E0B\u4E00\u9875",description:"\u6A21\u5757\u5DE5\u7A0B\u89E3\u51B3\u65B9\u6848",sidebar:{"/api/":[{text:"\u6982\u89C8",link:"/module-tools/api/"},{text:"\u914D\u7F6E\u9879",collapsed:!1,collapsible:!0,items:[{text:"buildConfig",link:"/module-tools/api/config/build-config"},{text:"buildPreset",link:"/module-tools/api/config/build-preset"},{text:"dev",link:"/module-tools/api/config/dev"},{text:"plugins",link:"/module-tools/api/config/plugins"},{text:"testing",link:"/module-tools/api/config/testing"}]},{text:"Plugin API",collapsed:!1,collapsible:!0,items:[{text:"Plugin Hooks",link:"/module-tools/api/plugin-api/plugin-hooks"}]}],"/guide/":[{text:"\u4ECB\u7ECD",collapsed:!1,collapsible:!0,items:[{text:"\u6B22\u8FCE\u4F7F\u7528",link:"/module-tools/guide/intro/welcome"},{text:"\u4E3A\u4EC0\u4E48\u9700\u8981 Modern.js Module",link:"/module-tools/guide/intro/why-module-engineering-solution"},{text:"\u5FEB\u901F\u5F00\u59CB",link:"/module-tools/guide/intro/getting-started"}]},{text:"\u57FA\u7840\u4F7F\u7528",collapsed:!1,collapsible:!0,items:[{text:"\u5F00\u59CB\u4E4B\u524D",link:"/module-tools/guide/basic/before-getting-started"},{text:"CLI \u547D\u4EE4",link:"/module-tools/guide/basic/command-preview"},{text:"\u4FEE\u6539\u8F93\u51FA\u4EA7\u7269",link:"/module-tools/guide/basic/modify-output-product"},{text:"\u4F7F\u7528\u5FAE\u751F\u6210\u5668",link:"/module-tools/guide/basic/use-micro-generator"},{text:"\u4F7F\u7528 Storybook",link:"/module-tools/guide/basic/using-storybook"},{text:"\u6D4B\u8BD5\u9879\u76EE",link:"/module-tools/guide/basic/test-your-project"},{text:"\u7248\u672C\u7BA1\u7406\u4E0E\u53D1\u5E03",link:"/module-tools/guide/basic/publish-your-project"}]},{text:"\u8FDB\u9636\u6307\u5357",collapsed:!1,collapsible:!0,items:[{text:"\u6DF1\u5165\u7406\u89E3\u6784\u5EFA",link:"/module-tools/guide/advance/in-depth-about-build"},{text:"\u6DF1\u5165\u7406\u89E3 dev \u547D\u4EE4",link:"/module-tools/guide/advance/in-depth-about-dev-command"},{text:"\u4F7F\u7528 Copy \u5DE5\u5177",link:"/module-tools/guide/advance/copy"},{text:"\u5904\u7406\u4E09\u65B9\u4F9D\u8D56",link:"/module-tools/guide/advance/external-dependency"},{text:"\u6784\u5EFA umd \u4EA7\u7269",link:"/module-tools/guide/advance/build-umd"},{text:"\u5904\u7406\u9759\u6001\u8D44\u6E90",link:"/module-tools/guide/advance/asset"}]},{text:"\u6700\u4F73\u5B9E\u8DF5",collapsed:!1,collapsible:!0,items:[{text:"\u5F00\u53D1\u7EC4\u4EF6",link:"/module-tools/guide/best-practices/components"},{text:"\u4F7F\u7528 Tailwind CSS",link:"/module-tools/guide/best-practices/use-tailwindcss"}]},{text:"\u5E38\u89C1\u95EE\u9898",link:"/module-tools/guide/faq/",collapsed:!1,collapsible:!0,items:[{text:"\u6784\u5EFA\u76F8\u5173\u95EE\u9898",link:"/module-tools/guide/faq/build"},{text:"Storybook \u76F8\u5173\u95EE\u9898",link:"/module-tools/guide/faq/storybook"},{text:"\u6D4B\u8BD5\u76F8\u5173\u95EE\u9898",link:"/module-tools/guide/faq/test"}]}],"/plugins/":[{text:"\u6307\u5357",collapsed:!1,collapsible:!0,items:[{text:"\u5FEB\u901F\u5F00\u59CB",link:"/module-tools/plugins/guide/getting-started"},{text:"\u63D2\u4EF6\u5BF9\u8C61",link:"/module-tools/plugins/guide/plugin-object"},{text:"Setup \u51FD\u6570",link:"/module-tools/plugins/guide/setup-function"}]},{text:"\u63D2\u4EF6\u5217\u8868",collapsed:!1,collapsible:!0,items:[{text:"\u603B\u89C8",link:"/module-tools/plugins/official-list/overview"},{text:"Babel \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-babel"},{text:"Banner \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-banner"},{text:"Import \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-import"},{text:"Node Polyfill \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-node-polyfill"},{text:"Polyfill \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-polyfill"}]}]}},{lang:"en",label:"English",nav:[{text:"Guide",link:"/en/guide/intro/welcome",activeMatch:"^/guide/"},{text:"API",link:"/en/api/",activeMatch:"^/api/"},{text:"Plugins",link:"/en/plugins/guide/getting-started",activeMatch:"^/plugins/"},{text:"v2.35.1",items:[{text:"Changelog",link:"https://github.com/web-infra-dev/modern.js/tree/main/packages/solutions/module-tools/CHANGELOG.md"},{text:"Contributing",link:"https://modernjs.dev/en/community/contributing-guide.html"}]}],title:"Modern.js Module",description:"Module Engineering Solutions",sidebar:{"/en/api/":[{text:"Overview",link:"/module-tools/en/api/"},{text:"Config",collapsed:!1,collapsible:!0,items:[{text:"buildConfig",link:"/module-tools/en/api/config/build-config"},{text:"buildPreset",link:"/module-tools/en/api/config/build-preset"},{text:"dev",link:"/module-tools/en/api/config/dev"},{text:"plugins",link:"/module-tools/en/api/config/plugins"},{text:"testing",link:"/module-tools/en/api/config/testing"}]},{text:"Plugin API",collapsed:!1,collapsible:!0,items:[{text:"Plugin Hooks",link:"/module-tools/en/api/plugin-api/plugin-hooks"}]}],"/en/guide/":[{text:"Introduction",collapsed:!1,collapsible:!0,items:[{text:"Welcome to Modern.js Module",link:"/module-tools/en/guide/intro/welcome"},{text:"Why you need Modern.js Module",link:"/module-tools/en/guide/intro/why-module-engineering-solution"},{text:"Quick Start",link:"/module-tools/en/guide/intro/getting-started"}]},{text:"Basic Guide",collapsed:!1,collapsible:!0,items:[{text:"Before you start",link:"/module-tools/en/guide/basic/before-getting-started"},{text:"CLI Commands",link:"/module-tools/en/guide/basic/command-preview"},{text:"Modify the output product",link:"/module-tools/en/guide/basic/modify-output-product"},{text:"Using the Microgenerator",link:"/module-tools/en/guide/basic/use-micro-generator"},{text:"Using Storybook",link:"/module-tools/en/guide/basic/using-storybook"},{text:"Testing Projects",link:"/module-tools/en/guide/basic/test-your-project"},{text:"Versioning and Publishing",link:"/module-tools/en/guide/basic/publish-your-project"}]},{text:"Advanced Guide",collapsed:!1,collapsible:!0,items:[{text:"In-depth understanding of build",link:"/module-tools/en/guide/advance/in-depth-about-build"},{text:"In-depth understanding of the dev command",link:"/module-tools/en/guide/advance/in-depth-about-dev-command"},{text:"Use the Copy Tools",link:"/module-tools/en/guide/advance/copy"},{text:"Handle third-party dependencies",link:"/module-tools/en/guide/advance/external-dependency"},{text:"Build umd artifacts",link:"/module-tools/en/guide/advance/build-umd"},{text:"Handle static assets",link:"/module-tools/en/guide/advance/asset"}]},{text:"Best practices",collapsed:!1,collapsible:!0,items:[{text:"Developing Components",link:"/module-tools/en/guide/best-practices/components"},{text:"Using Tailwind CSS",link:"/module-tools/en/guide/best-practices/use-tailwindcss"}]},{text:"FAQ",link:"/module-tools/en/guide/faq/",collapsed:!1,collapsible:!0,items:[{text:"Build FAQ",link:"/module-tools/en/guide/faq/build"},{text:"Storybook FAQ",link:"/module-tools/en/guide/faq/storybook"},{text:"Test FAQ",link:"/module-tools/en/guide/faq/test"}]}],"/en/plugins/":[{text:"Guide",collapsed:!1,collapsible:!0,items:[{text:"Quick Start",link:"/module-tools/en/plugins/guide/getting-started"},{text:"Plugin Object",link:"/module-tools/en/plugins/guide/plugin-object"},{text:"Setup function",link:"/module-tools/en/plugins/guide/setup-function"}]},{text:"Plugins List",collapsed:!1,collapsible:!0,items:[{text:"Overview",link:"/module-tools/en/plugins/official-list/overview"},{text:"Babel Plugin",link:"/module-tools/en/plugins/official-list/plugin-babel"},{text:"Banner Plugin",link:"/module-tools/en/plugins/official-list/plugin-banner"},{text:"Import Plugin",link:"/module-tools/en/plugins/official-list/plugin-import"},{text:"Node Polyfill Plugin",link:"/module-tools/en/plugins/official-list/plugin-node-polyfill"},{text:"Polyfill Plugin",link:"/module-tools/en/plugins/official-list/plugin-polyfill"}]}]}}],editLink:{docRepoBaseUrl:"https://github.com/web-infra-dev/modern.js/tree/main/packages/document/module-doc/docs",text:"Edit this page on GitHub"}},base:"/module-tools/",lang:"zh",locales:[{lang:"zh",label:"\u7B80\u4F53\u4E2D\u6587",nav:[{text:"\u6307\u5357",link:"/guide/intro/welcome",activeMatch:"^/guide/"},{text:"API",link:"/api/",activeMatch:"^/api/"},{text:"\u63D2\u4EF6",link:"/plugins/guide/getting-started",activeMatch:"^/plugins/"},{text:"v2.35.1",items:[{text:"\u66F4\u65B0\u65E5\u5FD7",link:"https://github.com/web-infra-dev/modern.js/tree/main/packages/solutions/module-tools/CHANGELOG.md"},{text:"\u8D21\u732E\u6307\u5357",link:"https://modernjs.dev/en/community/contributing-guide.html"}]}],title:"Modern.js Module",outlineTitle:"\u76EE\u5F55",prevPageText:"\u4E0A\u4E00\u9875",nextPageText:"\u4E0B\u4E00\u9875",description:"\u6A21\u5757\u5DE5\u7A0B\u89E3\u51B3\u65B9\u6848",sidebar:{"/api/":[{text:"\u6982\u89C8",link:"/module-tools/api/"},{text:"\u914D\u7F6E\u9879",collapsed:!1,collapsible:!0,items:[{text:"buildConfig",link:"/module-tools/api/config/build-config"},{text:"buildPreset",link:"/module-tools/api/config/build-preset"},{text:"dev",link:"/module-tools/api/config/dev"},{text:"plugins",link:"/module-tools/api/config/plugins"},{text:"testing",link:"/module-tools/api/config/testing"}]},{text:"Plugin API",collapsed:!1,collapsible:!0,items:[{text:"Plugin Hooks",link:"/module-tools/api/plugin-api/plugin-hooks"}]}],"/guide/":[{text:"\u4ECB\u7ECD",collapsed:!1,collapsible:!0,items:[{text:"\u6B22\u8FCE\u4F7F\u7528",link:"/module-tools/guide/intro/welcome"},{text:"\u4E3A\u4EC0\u4E48\u9700\u8981 Modern.js Module",link:"/module-tools/guide/intro/why-module-engineering-solution"},{text:"\u5FEB\u901F\u5F00\u59CB",link:"/module-tools/guide/intro/getting-started"}]},{text:"\u57FA\u7840\u4F7F\u7528",collapsed:!1,collapsible:!0,items:[{text:"\u5F00\u59CB\u4E4B\u524D",link:"/module-tools/guide/basic/before-getting-started"},{text:"CLI \u547D\u4EE4",link:"/module-tools/guide/basic/command-preview"},{text:"\u4FEE\u6539\u8F93\u51FA\u4EA7\u7269",link:"/module-tools/guide/basic/modify-output-product"},{text:"\u4F7F\u7528\u5FAE\u751F\u6210\u5668",link:"/module-tools/guide/basic/use-micro-generator"},{text:"\u4F7F\u7528 Storybook",link:"/module-tools/guide/basic/using-storybook"},{text:"\u6D4B\u8BD5\u9879\u76EE",link:"/module-tools/guide/basic/test-your-project"},{text:"\u7248\u672C\u7BA1\u7406\u4E0E\u53D1\u5E03",link:"/module-tools/guide/basic/publish-your-project"}]},{text:"\u8FDB\u9636\u6307\u5357",collapsed:!1,collapsible:!0,items:[{text:"\u6DF1\u5165\u7406\u89E3\u6784\u5EFA",link:"/module-tools/guide/advance/in-depth-about-build"},{text:"\u6DF1\u5165\u7406\u89E3 dev \u547D\u4EE4",link:"/module-tools/guide/advance/in-depth-about-dev-command"},{text:"\u4F7F\u7528 Copy \u5DE5\u5177",link:"/module-tools/guide/advance/copy"},{text:"\u5904\u7406\u4E09\u65B9\u4F9D\u8D56",link:"/module-tools/guide/advance/external-dependency"},{text:"\u6784\u5EFA umd \u4EA7\u7269",link:"/module-tools/guide/advance/build-umd"},{text:"\u5904\u7406\u9759\u6001\u8D44\u6E90",link:"/module-tools/guide/advance/asset"}]},{text:"\u6700\u4F73\u5B9E\u8DF5",collapsed:!1,collapsible:!0,items:[{text:"\u5F00\u53D1\u7EC4\u4EF6",link:"/module-tools/guide/best-practices/components"},{text:"\u4F7F\u7528 Tailwind CSS",link:"/module-tools/guide/best-practices/use-tailwindcss"}]},{text:"\u5E38\u89C1\u95EE\u9898",link:"/module-tools/guide/faq/",collapsed:!1,collapsible:!0,items:[{text:"\u6784\u5EFA\u76F8\u5173\u95EE\u9898",link:"/module-tools/guide/faq/build"},{text:"Storybook \u76F8\u5173\u95EE\u9898",link:"/module-tools/guide/faq/storybook"},{text:"\u6D4B\u8BD5\u76F8\u5173\u95EE\u9898",link:"/module-tools/guide/faq/test"}]}],"/plugins/":[{text:"\u6307\u5357",collapsed:!1,collapsible:!0,items:[{text:"\u5FEB\u901F\u5F00\u59CB",link:"/module-tools/plugins/guide/getting-started"},{text:"\u63D2\u4EF6\u5BF9\u8C61",link:"/module-tools/plugins/guide/plugin-object"},{text:"Setup \u51FD\u6570",link:"/module-tools/plugins/guide/setup-function"}]},{text:"\u63D2\u4EF6\u5217\u8868",collapsed:!1,collapsible:!0,items:[{text:"\u603B\u89C8",link:"/module-tools/plugins/official-list/overview"},{text:"Babel \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-babel"},{text:"Banner \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-banner"},{text:"Import \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-import"},{text:"Node Polyfill \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-node-polyfill"},{text:"Polyfill \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-polyfill"}]}]}},{lang:"en",label:"English",nav:[{text:"Guide",link:"/en/guide/intro/welcome",activeMatch:"^/guide/"},{text:"API",link:"/en/api/",activeMatch:"^/api/"},{text:"Plugins",link:"/en/plugins/guide/getting-started",activeMatch:"^/plugins/"},{text:"v2.35.1",items:[{text:"Changelog",link:"https://github.com/web-infra-dev/modern.js/tree/main/packages/solutions/module-tools/CHANGELOG.md"},{text:"Contributing",link:"https://modernjs.dev/en/community/contributing-guide.html"}]}],title:"Modern.js Module",description:"Module Engineering Solutions",sidebar:{"/en/api/":[{text:"Overview",link:"/module-tools/en/api/"},{text:"Config",collapsed:!1,collapsible:!0,items:[{text:"buildConfig",link:"/module-tools/en/api/config/build-config"},{text:"buildPreset",link:"/module-tools/en/api/config/build-preset"},{text:"dev",link:"/module-tools/en/api/config/dev"},{text:"plugins",link:"/module-tools/en/api/config/plugins"},{text:"testing",link:"/module-tools/en/api/config/testing"}]},{text:"Plugin API",collapsed:!1,collapsible:!0,items:[{text:"Plugin Hooks",link:"/module-tools/en/api/plugin-api/plugin-hooks"}]}],"/en/guide/":[{text:"Introduction",collapsed:!1,collapsible:!0,items:[{text:"Welcome to Modern.js Module",link:"/module-tools/en/guide/intro/welcome"},{text:"Why you need Modern.js Module",link:"/module-tools/en/guide/intro/why-module-engineering-solution"},{text:"Quick Start",link:"/module-tools/en/guide/intro/getting-started"}]},{text:"Basic Guide",collapsed:!1,collapsible:!0,items:[{text:"Before you start",link:"/module-tools/en/guide/basic/before-getting-started"},{text:"CLI Commands",link:"/module-tools/en/guide/basic/command-preview"},{text:"Modify the output product",link:"/module-tools/en/guide/basic/modify-output-product"},{text:"Using the Microgenerator",link:"/module-tools/en/guide/basic/use-micro-generator"},{text:"Using Storybook",link:"/module-tools/en/guide/basic/using-storybook"},{text:"Testing Projects",link:"/module-tools/en/guide/basic/test-your-project"},{text:"Versioning and Publishing",link:"/module-tools/en/guide/basic/publish-your-project"}]},{text:"Advanced Guide",collapsed:!1,collapsible:!0,items:[{text:"In-depth understanding of build",link:"/module-tools/en/guide/advance/in-depth-about-build"},{text:"In-depth understanding of the dev command",link:"/module-tools/en/guide/advance/in-depth-about-dev-command"},{text:"Use the Copy Tools",link:"/module-tools/en/guide/advance/copy"},{text:"Handle third-party dependencies",link:"/module-tools/en/guide/advance/external-dependency"},{text:"Build umd artifacts",link:"/module-tools/en/guide/advance/build-umd"},{text:"Handle static assets",link:"/module-tools/en/guide/advance/asset"}]},{text:"Best practices",collapsed:!1,collapsible:!0,items:[{text:"Developing Components",link:"/module-tools/en/guide/best-practices/components"},{text:"Using Tailwind CSS",link:"/module-tools/en/guide/best-practices/use-tailwindcss"}]},{text:"FAQ",link:"/module-tools/en/guide/faq/",collapsed:!1,collapsible:!0,items:[{text:"Build FAQ",link:"/module-tools/en/guide/faq/build"},{text:"Storybook FAQ",link:"/module-tools/en/guide/faq/storybook"},{text:"Test FAQ",link:"/module-tools/en/guide/faq/test"}]}],"/en/plugins/":[{text:"Guide",collapsed:!1,collapsible:!0,items:[{text:"Quick Start",link:"/module-tools/en/plugins/guide/getting-started"},{text:"Plugin Object",link:"/module-tools/en/plugins/guide/plugin-object"},{text:"Setup function",link:"/module-tools/en/plugins/guide/setup-function"}]},{text:"Plugins List",collapsed:!1,collapsible:!0,items:[{text:"Overview",link:"/module-tools/en/plugins/official-list/overview"},{text:"Babel Plugin",link:"/module-tools/en/plugins/official-list/plugin-babel"},{text:"Banner Plugin",link:"/module-tools/en/plugins/official-list/plugin-banner"},{text:"Import Plugin",link:"/module-tools/en/plugins/official-list/plugin-import"},{text:"Node Polyfill Plugin",link:"/module-tools/en/plugins/official-list/plugin-node-polyfill"},{text:"Polyfill Plugin",link:"/module-tools/en/plugins/official-list/plugin-polyfill"}]}]}}],logo:"",multiVersion:{default:"",versions:[]},search:{mode:"local"},pages:[{title:"buildConfig",routePath:"/module-tools/en/api/config/build-config",lang:"en",toc:[{text:"alias",id:"alias",depth:2,charIndex:378},{text:"asset",id:"asset",depth:2,charIndex:1394},{text:"asset.path",id:"assetpath",depth:2,charIndex:1453},{text:"asset.limit",id:"assetlimit",depth:2,charIndex:1557},{text:"asset.publicPath",id:"assetpublicpath",depth:2,charIndex:2123},{text:"asset.svgr",id:"assetsvgr",depth:2,charIndex:2406},{text:"asset.svgr.include",id:"assetsvgrinclude",depth:2,charIndex:3027},{text:"asset.svgr.exclude",id:"assetsvgrexclude",depth:2,charIndex:3145},{text:"autoExternal",id:"autoexternal",depth:2,charIndex:3262},{text:"autoExternal.dependencies",id:"autoexternaldependencies",depth:2,charIndex:3992},{text:"autoExternal.peerDependencies",id:"autoexternalpeerdependencies",depth:2,charIndex:4128},{text:"banner",id:"banner",depth:2,charIndex:4259},{text:"buildType",id:"buildtype",depth:2,charIndex:4876},{text:"copy",id:"copy",depth:2,charIndex:5036},{text:"copy.patterns",id:"copypatterns",depth:2,charIndex:5301},{text:"copy.options",id:"copyoptions",depth:2,charIndex:5474},{text:"define",id:"define",depth:2,charIndex:5771},{text:"dts",id:"dts",depth:2,charIndex:7136},{text:"dts.abortOnError",id:"dtsabortonerror",depth:2,charIndex:7318},{text:"dts.distPath",id:"dtsdistpath",depth:2,charIndex:7903},{text:"dts.only",id:"dtsonly",depth:2,charIndex:8166},{text:"dts.tsconfigPath",id:"dtstsconfigpath",depth:2,charIndex:8414},{text:"dts.respectExternal",id:"dtsrespectexternal",depth:2,charIndex:8662},{text:"esbuildOptions",id:"esbuildoptions",depth:2,charIndex:9198},{text:"externalHelpers",id:"externalhelpers",depth:2,charIndex:10723},{text:"externals",id:"externals",depth:2,charIndex:11689},{text:"footer",id:"footer",depth:2,charIndex:12025},{text:"format",id:"format",depth:2,charIndex:12121},{text:"format: esm",id:"format-esm",depth:3,charIndex:12308},{text:"format: cjs",id:"format-cjs",depth:3,charIndex:12523},{text:"format: iife",id:"format-iife",depth:3,charIndex:12794},{text:"format: umd",id:"format-umd",depth:3,charIndex:13164},{text:"hooks",id:"hooks",depth:2,charIndex:13542},{text:"input",id:"input",depth:2,charIndex:14500},{text:"jsx",id:"jsx",depth:2,charIndex:16089},{text:"metafile",id:"metafile",depth:2,charIndex:16702},{text:"minify",id:"minify",depth:2,charIndex:17232},{text:"outDir",id:"outdir",depth:2,charIndex:17493},{text:"platform",id:"platform",depth:2,charIndex:17669},{text:"redirect",id:"redirect",depth:2,charIndex:17947},{text:"resolve",id:"resolve",depth:2,charIndex:18639},{text:"resolve.mainFields",id:"resolvemainfields",depth:3,charIndex:18684},{text:"resolve.jsExtentions",id:"resolvejsextentions",depth:3,charIndex:19307},{text:"sideEffects",id:"sideeffects",depth:2,charIndex:19885},{text:"sourceDir",id:"sourcedir",depth:2,charIndex:21098},{text:"sourceMap",id:"sourcemap",depth:2,charIndex:21331},{text:"sourceType",id:"sourcetype",depth:2,charIndex:21442},{text:"splitting",id:"splitting",depth:2,charIndex:21669},{text:"style",id:"style",depth:2,charIndex:21752},{text:"style.less",id:"styleless",depth:2,charIndex:21800},{text:"style.less.lessOptions",id:"stylelesslessoptions",depth:2,charIndex:21842},{text:"style.less.additionalData",id:"stylelessadditionaldata",depth:2,charIndex:21967},{text:"style.less.implementation",id:"stylelessimplementation",depth:2,charIndex:22222},{text:"style.sass",id:"stylesass",depth:2,charIndex:22827},{text:"style.sass.sassOptions",id:"stylesasssassoptions",depth:2,charIndex:22870},{text:"style.sass.additionalData",id:"stylesassadditionaldata",depth:2,charIndex:22976},{text:"style.sass.implementation",id:"stylesassimplementation",depth:2,charIndex:23291},{text:"style.postcss",id:"stylepostcss",depth:2,charIndex:23891},{text:"style.inject",id:"styleinject",depth:2,charIndex:24893},{text:"style.autoModules",id:"styleautomodules",depth:2,charIndex:26353},{text:"style.modules",id:"stylemodules",depth:2,charIndex:26700},{text:"style.tailwindcss",id:"styletailwindcss",depth:2,charIndex:27160},{text:"Enabling Tailwind CSS",id:"enabling-tailwind-css",depth:3,charIndex:27413},{text:"Type",id:"type",depth:3,charIndex:27622},{text:"Notes",id:"notes",depth:3,charIndex:27927},{text:"target",id:"target",depth:2,charIndex:28510},{text:"transformImport",id:"transformimport",depth:2,charIndex:29101},{text:"transformLodash",id:"transformlodash",depth:2,charIndex:29655},{text:"tsconfig",id:"tsconfig",depth:2,charIndex:30260},{text:"umdGlobals",id:"umdglobals",depth:2,charIndex:30457},{text:"umdModuleName",id:"umdmodulename",depth:2,charIndex:30888}],frontmatter:{sidebar_position:1},version:"",_relativePath:"en/api/config/build-config.mdx"},{title:"buildPreset",routePath:"/module-tools/en/api/config/build-preset",lang:"en",toc:[{text:"npm-library",id:"npm-library",depth:3,charIndex:118},{text:"npm-library-with-umd",id:"npm-library-with-umd",depth:3,charIndex:827},{text:"npm-component",id:"npm-component",depth:3,charIndex:1685},{text:"npm-component-with-umd",id:"npm-component-with-umd",depth:3,charIndex:2617},{text:"npm-library-{es5...esnext}",id:"npm-library-es5esnext",depth:3,charIndex:3476},{text:"string / function",id:"string--function",depth:2,charIndex:3911}],frontmatter:{sidebar_position:2},version:"",_relativePath:"en/api/config/build-preset.mdx"},{title:"dev",routePath:"/module-tools/en/api/config/dev",lang:"en",toc:[{text:"storybook",id:"storybook",depth:2,charIndex:182},{text:"storybook.webpack",id:"storybookwebpack",depth:3,charIndex:440},{text:"Configure Manager App",id:"configure-manager-app",depth:4,charIndex:821},{text:"storybook.webpackChain",id:"storybookwebpackchain",depth:3,charIndex:1194}],frontmatter:{sidebar_position:3},version:"",_relativePath:"en/api/config/dev.md"},{title:"plugins",routePath:"/module-tools/en/api/config/plugins",lang:"en",toc:[{text:"Plugin Execution Order",id:"plugin-execution-order",depth:2,charIndex:140},{text:"Developing Plugins",id:"developing-plugins",depth:2,charIndex:584},{text:"Example",id:"example",depth:2,charIndex:680},{text:"Using Plugins from npm",id:"using-plugins-from-npm",depth:3,charIndex:691},{text:"Using Local Plugins",id:"using-local-plugins",depth:4,charIndex:898},{text:"Plugin Configuration",id:"plugin-configuration",depth:3,charIndex:1082}],frontmatter:{sidebar_position:4},version:"",_relativePath:"en/api/config/plugins.md"},{title:"testing",routePath:"/module-tools/en/api/config/testing",lang:"en",toc:[{text:"jest",id:"jest",depth:2,charIndex:133},{text:"transformer",id:"transformer",depth:2,charIndex:736}],frontmatter:{sidebar_position:5},version:"",_relativePath:"en/api/config/testing.md"},{title:"Overview",routePath:"/module-tools/en/api/",lang:"en",toc:[],frontmatter:{overview:!0,sidebar_label:"Overview",sidebar_position:1},version:"",_relativePath:"en/api/index.md"},{title:"Plugin Hooks",routePath:"/module-tools/en/api/plugin-api/plugin-hooks",lang:"en",toc:[{text:"build hooks",id:"build-hooks",depth:2,charIndex:424},{text:"beforeBuild",id:"beforebuild",depth:3,charIndex:586},{text:"beforeBuildTask",id:"beforebuildtask",depth:3,charIndex:1223},{text:"afterBuildTask",id:"afterbuildtask",depth:3,charIndex:1699},{text:"afterBuild",id:"afterbuild",depth:3,charIndex:2103},{text:"buildPlatform hooks",id:"buildplatform-hooks",depth:2,charIndex:2558},{text:"registerBuildPlatform",id:"registerbuildplatform",depth:3,charIndex:3057},{text:"beforeBuildPlatform",id:"beforebuildplatform",depth:3,charIndex:3779},{text:"buildPlatform",id:"buildplatform",depth:3,charIndex:4503},{text:"afterBuildPlatform",id:"afterbuildplatform",depth:3,charIndex:4998},{text:"Dev Hooks",id:"dev-hooks",depth:2,charIndex:5702},{text:"registerDev.",id:"registerdev",depth:3,charIndex:6177},{text:"beforeDev",id:"beforedev",depth:3,charIndex:7287},{text:"(before|after)DevMenu",id:"beforeafterdevmenu",depth:3,charIndex:7889},{text:"beforeDevTask",id:"beforedevtask",depth:3,charIndex:9070},{text:"afterDev",id:"afterdev",depth:3,charIndex:9640}],frontmatter:{},version:"",_relativePath:"en/api/plugin-api/plugin-hooks.md"},{title:"",routePath:"/module-tools/en/components/faq-build-exception",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/components/faq-build-exception.mdx"},{title:"",routePath:"/module-tools/en/components/faq-build-other",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/components/faq-build-other.mdx"},{title:"",routePath:"/module-tools/en/components/faq-build-product",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/components/faq-build-product.mdx"},{title:"",routePath:"/module-tools/en/components/faq-storybook",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/components/faq-storybook.mdx"},{title:"",routePath:"/module-tools/en/components/faq-test",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/components/faq-test.mdx"},{title:"",routePath:"/module-tools/en/components/register-esbuild-plugin",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/components/register-esbuild-plugin.mdx"},{title:"Handle static assets",routePath:"/module-tools/en/guide/advance/asset",lang:"en",toc:[{text:"Default behavior",id:"default-behavior",depth:2,charIndex:139},{text:"Example",id:"example",depth:2,charIndex:571}],frontmatter:{sidebar_position:6},version:"",_relativePath:"en/guide/advance/asset.mdx"},{title:"Build umd artifacts",routePath:"/module-tools/en/guide/advance/build-umd",lang:"en",toc:[{text:"Third-party dependency handling for umd artifacts",id:"third-party-dependency-handling-for-umd-artifacts",depth:2,charIndex:487},{text:"Example",id:"example",depth:3,charIndex:791},{text:"Global variable names of third-party dependencies",id:"global-variable-names-of-third-party-dependencies",depth:3,charIndex:2178},{text:"Changing the name of a global variable in a project",id:"changing-the-name-of-a-global-variable-in-a-project",depth:2,charIndex:3607}],frontmatter:{sidebar_position:5},version:"",_relativePath:"en/guide/advance/build-umd.mdx"},{title:"Use the Copy Tools",routePath:"/module-tools/en/guide/advance/copy",lang:"en",toc:[{text:"Understanding the Copy API",id:"understanding-the-copy-api",depth:2,charIndex:171},{text:"API Description",id:"api-description",depth:2,charIndex:335},{text:"Examples of Different Scenarios",id:"examples-of-different-scenarios",depth:2,charIndex:2449},{text:"Copying Files",id:"copying-files",depth:3,charIndex:2484},{text:"Copying Files to a Directory",id:"copying-files-to-a-directory",depth:3,charIndex:2834},{text:"Copying from Directory to Directory",id:"copying-from-directory-to-directory",depth:3,charIndex:3192},{text:"Copying from Directory to File",id:"copying-from-directory-to-file",depth:3,charIndex:3613},{text:"Using Glob",id:"using-glob",depth:3,charIndex:4042}],frontmatter:{sidebar_position:3},version:"",_relativePath:"en/guide/advance/copy.md"},{title:"Handle third-party dependencies",routePath:"/module-tools/en/guide/advance/external-dependency",lang:"en",toc:[{text:"Default handling of third-party dependencies",id:"default-handling-of-third-party-dependencies",depth:2,charIndex:861},{text:"Example",id:"example",depth:3,charIndex:1423},{text:"Exclude specified third-party dependencies",id:"exclude-specified-third-party-dependencies",depth:2,charIndex:1840}],frontmatter:{sidebar_position:4},version:"",_relativePath:"en/guide/advance/external-dependency.mdx"},{title:"In-depth understanding of build",routePath:"/module-tools/en/guide/advance/in-depth-about-build",lang:"en",toc:[{text:"bundle / bundleless",id:"bundle--bundleless",depth:2,charIndex:497},{text:"input / sourceDir",id:"input--sourcedir",depth:2,charIndex:1630},{text:"use swc",id:"use-swc",depth:2,charIndex:2902},{text:"Using Hooks to Intervene in the Build Process",id:"using-hooks-to-intervene-in-the-build-process",depth:2,charIndex:3852},{text:"Hook type",id:"hook-type",depth:3,charIndex:4232},{text:"AsyncSeriesBailHook",id:"asyncseriesbailhook",depth:4,charIndex:4244},{text:"AsyncSeriesWaterFallHooks",id:"asyncserieswaterfallhooks",depth:4,charIndex:4383},{text:"Hook API",id:"hook-api",depth:3,charIndex:4480},{text:"load",id:"load",depth:4,charIndex:4491},{text:"transform",id:"transform",depth:4,charIndex:5185},{text:"renderChunk",id:"renderchunk",depth:4,charIndex:5696},{text:"dts",id:"dts",depth:2,charIndex:6675},{text:"Turn off type generation",id:"turn-off-type-generation",depth:3,charIndex:6758},{text:"Build type files",id:"build-type-files",depth:3,charIndex:7035},{text:"Alias Conversion",id:"alias-conversion",depth:3,charIndex:7729},{text:"Some examples of the use of dts",id:"some-examples-of-the-use-of-dts",depth:3,charIndex:8305},{text:"Build process",id:"build-process",depth:2,charIndex:9002},{text:"Build errors",id:"build-errors",depth:2,charIndex:9295},{text:"Debug mode",id:"debug-mode",depth:2,charIndex:10045}],frontmatter:{sidebar_position:1},version:"",_relativePath:"en/guide/advance/in-depth-about-build.md"},{title:"In-depth understanding of the dev command",routePath:"/module-tools/en/guide/advance/in-depth-about-dev-command",lang:"en",toc:[{text:"The overall flow of the command run",id:"the-overall-flow-of-the-command-run",depth:2,charIndex:92},{text:"Extending the dev command",id:"extending-the-dev-command",depth:2,charIndex:805}],frontmatter:{sidebar_position:2},version:"",_relativePath:"en/guide/advance/in-depth-about-dev-command.md"},{title:"Before you start",routePath:"/module-tools/en/guide/basic/before-getting-started",lang:"en",toc:[{text:"Environment preparation",id:"environment-preparation",depth:2,charIndex:3},{text:"Getting Started with npm",id:"getting-started-with-npm",depth:2,charIndex:425},{text:"npm package type project",id:"npm-package-type-project",depth:2,charIndex:907},{text:"Using third-party npm packages",id:"using-third-party-npm-packages",depth:2,charIndex:2127},{text:"Other npm bits and pieces to know",id:"other-npm-bits-and-pieces-to-know",depth:2,charIndex:3994},{text:"Program entry for npm packages",id:"program-entry-for-npm-packages",depth:3,charIndex:4031},{text:"scripts",id:"scripts",depth:3,charIndex:4916},{text:"npm install",id:"npm-install",depth:4,charIndex:5729},{text:"npm publish",id:"npm-publish",depth:4,charIndex:6090},{text:"peerDependencies",id:"peerdependencies",depth:3,charIndex:6360},{text:"npm package manager",id:"npm-package-manager",depth:2,charIndex:7062},{text:"Modern.js Module configuration file",id:"modernjs-module-configuration-file",depth:2,charIndex:7347}],frontmatter:{sidebar_position:1},version:"",_relativePath:"en/guide/basic/before-getting-started.md"},{title:"CLI Commands",routePath:"/module-tools/en/guide/basic/command-preview",lang:"en",toc:[{text:"modern build",id:"modern-build",depth:2,charIndex:73},{text:"modern new",id:"modern-new",depth:2,charIndex:2087},{text:"modern dev",id:"modern-dev",depth:2,charIndex:2866},{text:"modern test",id:"modern-test",depth:2,charIndex:3439},{text:"modern lint",id:"modern-lint",depth:2,charIndex:3747},{text:"modern change",id:"modern-change",depth:2,charIndex:4183},{text:"modern pre",id:"modern-pre",depth:2,charIndex:4511},{text:"modern bump",id:"modern-bump",depth:2,charIndex:4742},{text:"modern release",id:"modern-release",depth:2,charIndex:5261},{text:"modern gen-release-note",id:"modern-gen-release-note",depth:2,charIndex:5741},{text:"modern upgrade",id:"modern-upgrade",depth:2,charIndex:6237}],frontmatter:{sidebar_position:2},version:"",_relativePath:"en/guide/basic/command-preview.md"},{title:"Modify the output product",routePath:"/module-tools/en/guide/basic/modify-output-product",lang:"en",toc:[{text:"Default output products",id:"default-output-products",depth:2,charIndex:3},{text:"buildPreset",id:"buildpreset",depth:2,charIndex:1002},{text:"buildConfig",id:"buildconfig",depth:2,charIndex:1823},{text:"Combining Configuration and Presets",id:"combining-configuration-and-presets",depth:2,charIndex:4571}],frontmatter:{sidebar_position:3},version:"",_relativePath:"en/guide/basic/modify-output-product.md"},{title:"Versioning and Publishing",routePath:"/module-tools/en/guide/basic/publish-your-project",lang:"en",toc:[{text:"Tracking changes",id:"tracking-changes",depth:2,charIndex:406},{text:"Version update",id:"version-update",depth:2,charIndex:1748},{text:"Publish",id:"publish",depth:2,charIndex:2227},{text:"Pre-releases",id:"pre-releases",depth:2,charIndex:2941}],frontmatter:{sidebar_position:7},version:"",_relativePath:"en/guide/basic/publish-your-project.md"},{title:"Testing Projects",routePath:"/module-tools/en/guide/basic/test-your-project",lang:"en",toc:[{text:"Prerequisites and conventions",id:"prerequisites-and-conventions",depth:2,charIndex:52},{text:"Run the tests",id:"run-the-tests",depth:2,charIndex:745},{text:"Usage Configuration",id:"usage-configuration",depth:2,charIndex:1015},{text:"Test example",id:"test-example",depth:2,charIndex:1160},{text:"Common modules",id:"common-modules",depth:3,charIndex:1176},{text:"Components",id:"components",depth:3,charIndex:1781}],frontmatter:{sidebar_position:6},version:"",_relativePath:"en/guide/basic/test-your-project.mdx"},{title:"Using the Microgenerator",routePath:"/module-tools/en/guide/basic/use-micro-generator",lang:"en",toc:[{text:"Test",id:"test",depth:2,charIndex:431},{text:"Storybook",id:"storybook",depth:2,charIndex:908},{text:"Tailwind CSS Support",id:"tailwind-css-support",depth:2,charIndex:1544},{text:"Modern.js Runtime API",id:"modernjs-runtime-api",depth:2,charIndex:1829}],frontmatter:{sidebar_position:4},version:"",_relativePath:"en/guide/basic/use-micro-generator.md"},{title:"Using Storybook",routePath:"/module-tools/en/guide/basic/using-storybook",lang:"en",toc:[{text:"Debugging code",id:"debugging-code",depth:2,charIndex:682},{text:"Referencing component products",id:"referencing-component-products",depth:3,charIndex:1322},{text:"Referencing component source code",id:"referencing-component-source-code",depth:3,charIndex:3382},{text:"Configure Storybook",id:"configure-storybook",depth:2,charIndex:4225},{text:"Building Storybook Products",id:"building-storybook-products",depth:2,charIndex:5155},{text:"Use Tailwind CSS with Storybook",id:"use-tailwind-css-with-storybook",depth:2,charIndex:5542}],frontmatter:{sidebar_position:5},version:"",_relativePath:"en/guide/basic/using-storybook.mdx"},{title:"Developing Components",routePath:"/module-tools/en/guide/best-practices/components",lang:"en",toc:[{text:"Initialize the project",id:"initialize-the-project",depth:2,charIndex:93},{text:"Debugging code with Storybook",id:"debugging-code-with-storybook",depth:2,charIndex:881},{text:"Developing Styles",id:"developing-styles",depth:2,charIndex:980},{text:"CSS/PostCSS",id:"csspostcss",depth:3,charIndex:1186},{text:"Less",id:"less",depth:3,charIndex:1831},{text:"Sass/Scss",id:"sassscss",depth:3,charIndex:2144},{text:"Tailwind CSS",id:"tailwind-css",depth:3,charIndex:2486},{text:"CSS Modules",id:"css-modules",depth:3,charIndex:2560},{text:"Configuring build products",id:"configuring-build-products",depth:2,charIndex:2999},{text:"Testing components",id:"testing-components",depth:2,charIndex:3933},{text:"Releasing components",id:"releasing-components",depth:2,charIndex:4036}],frontmatter:{sidebar_position:1},version:"",_relativePath:"en/guide/best-practices/components.mdx"},{title:"Using Tailwind CSS",routePath:"/module-tools/en/guide/best-practices/use-tailwindcss",lang:"en",toc:[{text:"Enabling Tailwind CSS",id:"enabling-tailwind-css",depth:2,charIndex:252},{text:"Configuring Tailwind CSS",id:"configuring-tailwind-css",depth:2,charIndex:1573},{text:"Tailwind CSS Autocomplete",id:"tailwind-css-autocomplete",depth:3,charIndex:2541},{text:"Build Modes",id:"build-modes",depth:2,charIndex:3112},{text:"Bundle Mode",id:"bundle-mode",depth:3,charIndex:3380},{text:"Bundleless Mode",id:"bundleless-mode",depth:3,charIndex:4149},{text:"Class Name Prefix",id:"class-name-prefix",depth:2,charIndex:4450},{text:"Usage Guide",id:"usage-guide",depth:2,charIndex:5064},{text:"HTML Class Names",id:"html-class-names",depth:3,charIndex:5126},{text:"@apply",id:"apply",depth:3,charIndex:5562},{text:"Sass",id:"sass",depth:4,charIndex:5866},{text:"Less",id:"less",depth:4,charIndex:6157},{text:"About designSystem config",id:"about-designsystem-config",depth:2,charIndex:6796}],frontmatter:{sidebar_position:2},version:"",_relativePath:"en/guide/best-practices/use-tailwindcss.mdx"},{title:"Build FAQ",routePath:"/module-tools/en/guide/faq/build",lang:"en",toc:[{text:"Product FAQ",id:"product-faq",depth:2,charIndex:3},{text:"Initialization of Class Fields",id:"initialization-of-class-fields",depth:3,charIndex:18},{text:"babel-plugin-lodash treats the introduced lodash as undefined",id:"babel-plugin-lodash-treats-the-introduced-lodash-as-undefined",depth:3,charIndex:2081},{text:"Exceptions FAQ",id:"exceptions-faq",depth:2,charIndex:2772},{text:'Dynamic require of \\"react\\" is not supported',id:"dynamic-require-of-react-is-not-supported",depth:3,charIndex:-1},{text:"Problem Description",id:"problem-description",depth:4,charIndex:2836},{text:"Solution",id:"solution",depth:4,charIndex:3139},{text:"Reference Links",id:"reference-links",depth:4,charIndex:3735},{text:"During compilation, an error was reported in the less file of a component library:\\'Operation on an invalid type\\'",id:"during-compilation-an-error-was-reported-in-the-less-file-of-a-component-libraryoperation-on-an-invalid-type",depth:3,charIndex:-1},{text:"Bundle DTS failed",id:"bundle-dts-failed",depth:3,charIndex:5274},{text:'Error reported for defineConfig function type: If there is no reference to \\"...\\" then the inferred type of \\"default\\" cannot be named',id:"error-reported-for-defineconfig-function-type-if-there-is-no-reference-to--then-the-inferred-type-of-default-cannot-be-named",depth:3,charIndex:-1},{text:"Other FAQ",id:"other-faq",depth:2,charIndex:6300},{text:"Add additional compilation feature",id:"add-additional-compilation-feature",depth:3,charIndex:6313},{text:"Support for generating TypeScript declaration files for CSS Modules",id:"support-for-generating-typescript-declaration-files-for-css-modules",depth:3,charIndex:7224}],frontmatter:{},version:"",_relativePath:"en/guide/faq/build.mdx"},{title:"FAQ",routePath:"/module-tools/en/guide/faq/",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/guide/faq/index.md"},{title:"Storybook FAQ",routePath:"/module-tools/en/guide/faq/storybook",lang:"en",toc:[{text:"Storybook v7 Support",id:"storybook-v7-support",depth:2,charIndex:3},{text:"Using Storybook Addon or other configurations does not work",id:"using-storybook-addon-or-other-configurations-does-not-work",depth:2,charIndex:186},{text:"Cannot find module \\'react-dom/package.json",id:"cannot-find-module-react-dompackagejson",depth:2,charIndex:-1},{text:"Unable to locate the specific error message",id:"unable-to-locate-the-specific-error-message",depth:2,charIndex:880},{text:"Can`t find any stories is your Storybook",id:"cant-find-any-stories-is-your-storybook",depth:2,charIndex:1653},{text:"Storybook Adds Proxy Functionality",id:"storybook-adds-proxy-functionality",depth:2,charIndex:1953},{text:"Modify the directory where the Story file exists",id:"modify-the-directory-where-the-story-file-exists",depth:2,charIndex:2800}],frontmatter:{},version:"",_relativePath:"en/guide/faq/storybook.mdx"},{title:"Test FAQ",routePath:"/module-tools/en/guide/faq/test",lang:"en",toc:[{text:"Execute test command with an error TypeError: Cannot read property \\'testEnvironmentOptions\\' of undefined",id:"execute-test-command-with-an-error-typeerror-cannot-read-property-testenvironmentoptions-of-undefined",depth:3,charIndex:-1}],frontmatter:{},version:"",_relativePath:"en/guide/faq/test.mdx"},{title:"Quick Start",routePath:"/module-tools/en/guide/intro/getting-started",lang:"en",toc:[{text:"3 minute demo",id:"3-minute-demo",depth:2,charIndex:3},{text:"Create new project",id:"create-new-project",depth:3,charIndex:210},{text:"Add to an existing project",id:"add-to-an-existing-project",depth:3,charIndex:1097},{text:"Core npm Package",id:"core-npm-package",depth:3,charIndex:1934},{text:"View official example",id:"view-official-example",depth:3,charIndex:2693},{text:"Let\\'s get started",id:"lets-get-started",depth:2,charIndex:-1}],frontmatter:{sidebar_position:3},version:"",_relativePath:"en/guide/intro/getting-started.mdx"},{title:"Welcome to Modern.js Module",routePath:"/module-tools/en/guide/intro/welcome",lang:"en",toc:[],frontmatter:{sidebar_position:1},version:"",_relativePath:"en/guide/intro/welcome.md"},{title:"Why you need Modern.js Module",routePath:"/module-tools/en/guide/intro/why-module-engineering-solution",lang:"en",toc:[],frontmatter:{sidebar_position:2},version:"",_relativePath:"en/guide/intro/why-module-engineering-solution.md"},{title:"index",routePath:"/module-tools/en/",lang:"en",toc:[],frontmatter:{pageType:"home",hero:{name:"Modern.js Module",text:"Module engineering solutions",tagline:"simple, powerful, high-performance modern npm package development solution",actions:[{theme:"brand",text:"Welcome",link:"/en/guide/intro/welcome"},{theme:"alt",text:"Quick Start",link:"/en/guide/intro/getting-started"}]},features:[{title:"esbuild: The High Performance JS Bundler",details:"Built on esbuild, the build is extremely fast and gives you the ultimate development experience.",icon:"\uD83D\uDE80"},{title:"Two build modes",details:"Both bundle and bundleless build modes are supported.",icon:"\u2728"},{title:"Out of the box",details:"Develop your npm packages without too much configuration, with built-in presets covering a wide range of scenarios.",icon:"\uD83D\uDEE0\uFE0F"},{title:"Extensible: Provides a powerful plugin mechanism",details:"With its plugin extension mechanism, you can easily extend the capabilities of Modern.js Module.",icon:"\uD83C\uDFA8"},{title:"Storybook: The community popular UI development tool",details:"Integrated with Storybook, you can use it to debug UI.",icon:"\uD83D\uDCE6"},{title:"Jest: Delightful Testing Framework",details:"Jest integration makes it easier to test code\u3002",icon:"\uD83D\uDCD0"}]},version:"",_relativePath:"en/index.md"},{title:"Quick Start",routePath:"/module-tools/en/plugins/guide/getting-started",lang:"en",toc:[],frontmatter:{sidebar_position:1},version:"",_relativePath:"en/plugins/guide/getting-started.mdx"},{title:"Plugin Object",routePath:"/module-tools/en/plugins/guide/plugin-object",lang:"en",toc:[{text:"Plugin type definitions",id:"plugin-type-definitions",depth:2,charIndex:805},{text:"Plugin configuration options",id:"plugin-configuration-options",depth:2,charIndex:1163}],frontmatter:{sidebar_position:2},version:"",_relativePath:"en/plugins/guide/plugin-object.mdx"},{title:"Setup function",routePath:"/module-tools/en/plugins/guide/setup-function",lang:"en",toc:[{text:"Plugin API objects",id:"plugin-api-objects",depth:2,charIndex:173},{text:"api.useAppContext",id:"apiuseappcontext",depth:3,charIndex:783},{text:"api.useResolvedConfigContext",id:"apiuseresolvedconfigcontext",depth:3,charIndex:1343},{text:"api.useHookRunners",id:"apiusehookrunners",depth:3,charIndex:1811},{text:"Asynchronous setup",id:"asynchronous-setup",depth:2,charIndex:2132},{text:"Life cycle hooks",id:"life-cycle-hooks",depth:2,charIndex:2694}],frontmatter:{sidebar_position:3},version:"",_relativePath:"en/plugins/guide/setup-function.mdx"},{title:"Overview",routePath:"/module-tools/en/plugins/official-list/overview",lang:"en",toc:[{text:"Official Plugin",id:"official-plugin",depth:2,charIndex:3}],frontmatter:{},version:"",_relativePath:"en/plugins/official-list/overview.md"},{title:"Babel Plugin",routePath:"/module-tools/en/plugins/official-list/plugin-babel",lang:"en",toc:[{text:"Quick start",id:"quick-start",depth:2,charIndex:110},{text:"Install",id:"install",depth:3,charIndex:125},{text:"Register",id:"register",depth:3,charIndex:136},{text:"Config",id:"config",depth:2,charIndex:292}],frontmatter:{},version:"",_relativePath:"en/plugins/official-list/plugin-babel.mdx"},{title:"Banner Plugin",routePath:"/module-tools/en/plugins/official-list/plugin-banner",lang:"en",toc:[{text:"Quick Start",id:"quick-start",depth:2,charIndex:89},{text:"Install",id:"install",depth:3,charIndex:104},{text:"Register",id:"register",depth:3,charIndex:115},{text:"Example",id:"example",depth:2,charIndex:456},{text:"Add copyright information at the top of a JS file",id:"add-copyright-information-at-the-top-of-a-js-file",depth:3,charIndex:467},{text:"Configuration",id:"configuration",depth:2,charIndex:967},{text:"banner",id:"banner",depth:3,charIndex:1126},{text:"footer",id:"footer",depth:3,charIndex:1266}],frontmatter:{},version:"",_relativePath:"en/plugins/official-list/plugin-banner.mdx"},{title:"Import Plugin",routePath:"/module-tools/en/plugins/official-list/plugin-import",lang:"en",toc:[{text:"Quick Start",id:"quick-start",depth:2,charIndex:231},{text:"Install",id:"install",depth:3,charIndex:246},{text:"Register",id:"register",depth:3,charIndex:257},{text:"Configurations",id:"configurations",depth:2,charIndex:627},{text:"pluginImport",id:"pluginimport",depth:3,charIndex:708},{text:"Notes",id:"notes",depth:2,charIndex:1127}],frontmatter:{},version:"",_relativePath:"en/plugins/official-list/plugin-import.mdx"},{title:"Node Polyfill Plugin",routePath:"/module-tools/en/plugins/official-list/plugin-node-polyfill",lang:"en",toc:[{text:"Quick Start",id:"quick-start",depth:2,charIndex:460},{text:"Install",id:"install",depth:3,charIndex:475},{text:"Register",id:"register",depth:3,charIndex:486},{text:"Configurations",id:"configurations",depth:2,charIndex:662},{text:"exclude",id:"exclude",depth:3,charIndex:768},{text:"overrides",id:"overrides",depth:3,charIndex:965},{text:"Node Polyfills",id:"node-polyfills",depth:2,charIndex:1211},{text:"Globals",id:"globals",depth:3,charIndex:1229},{text:"Modules",id:"modules",depth:3,charIndex:1420},{text:"Fallbacks",id:"fallbacks",depth:3,charIndex:1921}],frontmatter:{},version:"",_relativePath:"en/plugins/official-list/plugin-node-polyfill.mdx"},{title:"Polyfill Plugin",routePath:"/module-tools/en/plugins/official-list/plugin-polyfill",lang:"en",toc:[{text:"Quick start",id:"quick-start",depth:2,charIndex:497},{text:"Install",id:"install",depth:3,charIndex:512},{text:"Register",id:"register",depth:3,charIndex:523},{text:"Config",id:"config",depth:2,charIndex:695},{text:"targets",id:"targets",depth:3,charIndex:765}],frontmatter:{},version:"",_relativePath:"en/plugins/official-list/plugin-polyfill.mdx"},{title:"buildConfig",routePath:"/module-tools/api/config/build-config",lang:"zh",toc:[{text:"alias",id:"alias",depth:2,charIndex:141},{text:"asset",id:"asset",depth:2,charIndex:862},{text:"asset.path",id:"assetpath",depth:2,charIndex:885},{text:"asset.limit",id:"assetlimit",depth:2,charIndex:956},{text:"asset.publicPath",id:"assetpublicpath",depth:2,charIndex:1276},{text:"asset.svgr",id:"assetsvgr",depth:2,charIndex:1493},{text:"asset.svgr.include",id:"assetsvgrinclude",depth:2,charIndex:1889},{text:"asset.svgr.exclude",id:"assetsvgrexclude",depth:2,charIndex:1988},{text:"autoExternal",id:"autoexternal",depth:2,charIndex:2089},{text:"autoExternal.dependencies",id:"autoexternaldependencies",depth:2,charIndex:2588},{text:"autoExternal.peerDependencies",id:"autoexternalpeerdependencies",depth:2,charIndex:2676},{text:"banner",id:"banner",depth:2,charIndex:2772},{text:"buildType",id:"buildtype",depth:2,charIndex:3278},{text:"copy",id:"copy",depth:2,charIndex:3381},{text:"copy.patterns",id:"copypatterns",depth:2,charIndex:3549},{text:"copy.options",id:"copyoptions",depth:2,charIndex:3716},{text:"define",id:"define",depth:2,charIndex:3949},{text:"dts",id:"dts",depth:2,charIndex:4761},{text:"dts.abortOnError",id:"dtsabortonerror",depth:2,charIndex:4882},{text:"dts.distPath",id:"dtsdistpath",depth:2,charIndex:5216},{text:"dts.only",id:"dtsonly",depth:2,charIndex:5416},{text:"dts.respectExternal",id:"dtsrespectexternal",depth:2,charIndex:5588},{text:"dts.tsconfigPath",id:"dtstsconfigpath",depth:2,charIndex:5911},{text:"esbuildOptions",id:"esbuildoptions",depth:2,charIndex:6102},{text:"externalHelpers",id:"externalhelpers",depth:2,charIndex:6954},{text:"externals",id:"externals",depth:2,charIndex:7553},{text:"footer",id:"footer",depth:2,charIndex:7807},{text:"format",id:"format",depth:2,charIndex:7845},{text:"format: esm",id:"format-esm",depth:3,charIndex:7970},{text:"format: cjs",id:"format-cjs",depth:3,charIndex:8124},{text:"format: iife",id:"format-iife",depth:3,charIndex:8297},{text:"format: umd",id:"format-umd",depth:3,charIndex:8474},{text:"hooks",id:"hooks",depth:2,charIndex:8702},{text:"input",id:"input",depth:2,charIndex:9321},{text:"jsx",id:"jsx",depth:2,charIndex:10360},{text:"metafile",id:"metafile",depth:2,charIndex:10761},{text:"minify",id:"minify",depth:2,charIndex:11100},{text:"outDir",id:"outdir",depth:2,charIndex:11352},{text:"platform",id:"platform",depth:2,charIndex:11488},{text:"redirect",id:"redirect",depth:2,charIndex:11679},{text:"resolve",id:"resolve",depth:2,charIndex:12046},{text:"resolve.mainFields",id:"resolvemainfields",depth:3,charIndex:12068},{text:"resolve.jsExtentions",id:"resolvejsextentions",depth:3,charIndex:12513},{text:"sideEffects",id:"sideeffects",depth:2,charIndex:12883},{text:"sourceDir",id:"sourcedir",depth:2,charIndex:13689},{text:"sourceMap",id:"sourcemap",depth:2,charIndex:13785},{text:"sourceType",id:"sourcetype",depth:2,charIndex:13872},{text:"splitting",id:"splitting",depth:2,charIndex:14030},{text:"style",id:"style",depth:2,charIndex:14084},{text:"style.less",id:"styleless",depth:2,charIndex:14105},{text:"style.less.lessOptions",id:"stylelesslessoptions",depth:2,charIndex:14131},{text:"style.less.additionalData",id:"stylelessadditionaldata",depth:2,charIndex:14222},{text:"style.less.implementation",id:"stylelessimplementation",depth:2,charIndex:14454},{text:"sass",id:"sass",depth:2,charIndex:14917},{text:"style.sass.sassOptions",id:"stylesasssassoptions",depth:2,charIndex:14937},{text:"style.sass.additionalData",id:"stylesassadditionaldata",depth:2,charIndex:15007},{text:"style.sass.implementation",id:"stylesassimplementation",depth:2,charIndex:15299},{text:"style.postcss",id:"stylepostcss",depth:2,charIndex:15763},{text:"style.inject",id:"styleinject",depth:2,charIndex:16502},{text:"style.autoModules",id:"styleautomodules",depth:2,charIndex:17446},{text:"style.modules",id:"stylemodules",depth:2,charIndex:17680},{text:"style.tailwindcss",id:"styletailwindcss",depth:2,charIndex:18033},{text:"\u542F\u7528 Tailwind CSS",id:"\u542F\u7528-tailwind-css",depth:3,charIndex:18254},{text:"\u7C7B\u578B",id:"\u7C7B\u578B",depth:3,charIndex:18374},{text:"\u6CE8\u610F\u4E8B\u9879",id:"\u6CE8\u610F\u4E8B\u9879",depth:3,charIndex:18505},{text:"target",id:"target",depth:2,charIndex:18795},{text:"transformImport",id:"transformimport",depth:2,charIndex:19188},{text:"transformLodash",id:"transformlodash",depth:2,charIndex:19578},{text:"tsconfig",id:"tsconfig",depth:2,charIndex:19924},{text:"umdGlobals",id:"umdglobals",depth:2,charIndex:20104},{text:"umdModuleName",id:"umdmodulename",depth:2,charIndex:20398}],frontmatter:{sidebar_position:1},version:"",_relativePath:"zh/api/config/build-config.mdx"},{title:"buildPreset",routePath:"/module-tools/api/config/build-preset",lang:"zh",toc:[{text:"npm-library",id:"npm-library",depth:2,charIndex:76},{text:"npm-library-with-umd",id:"npm-library-with-umd",depth:2,charIndex:655},{text:"npm-component",id:"npm-component",depth:2,charIndex:1376},{text:"npm-component-with-umd",id:"npm-component-with-umd",depth:2,charIndex:2027},{text:"npm-library-{es5...esnext}",id:"npm-library-es5esnext",depth:2,charIndex:2784},{text:"string / function",id:"string--function",depth:2,charIndex:3082}],frontmatter:{sidebar_position:2},version:"",_relativePath:"zh/api/config/build-preset.mdx"},{title:"dev",routePath:"/module-tools/api/config/dev",lang:"zh",toc:[{text:"storybook",id:"storybook",depth:2,charIndex:132},{text:"storybook.webpack",id:"storybookwebpack",depth:3,charIndex:295},{text:"\u914D\u7F6E Manager App",id:"\u914D\u7F6E-manager-app",depth:4,charIndex:605},{text:"storybook.webpackChain",id:"storybookwebpackchain",depth:3,charIndex:901}],frontmatter:{sidebar_position:3},version:"",_relativePath:"zh/api/config/dev.md"},{title:"plugins",routePath:"/module-tools/api/config/plugins",lang:"zh",toc:[{text:"\u63D2\u4EF6\u6267\u884C\u987A\u5E8F",id:"\u63D2\u4EF6\u6267\u884C\u987A\u5E8F",depth:2,charIndex:79},{text:"\u5F00\u53D1\u63D2\u4EF6",id:"\u5F00\u53D1\u63D2\u4EF6",depth:2,charIndex:221},{text:"\u793A\u4F8B",id:"\u793A\u4F8B",depth:2,charIndex:253},{text:"\u4F7F\u7528 npm \u4E0A\u7684\u63D2\u4EF6",id:"\u4F7F\u7528-npm-\u4E0A\u7684\u63D2\u4EF6",depth:3,charIndex:259},{text:"\u4F7F\u7528\u672C\u5730\u63D2\u4EF6",id:"\u4F7F\u7528\u672C\u5730\u63D2\u4EF6",depth:4,charIndex:377},{text:"\u63D2\u4EF6\u914D\u7F6E\u9879",id:"\u63D2\u4EF6\u914D\u7F6E\u9879",depth:3,charIndex:486}],frontmatter:{sidebar_position:4},version:"",_relativePath:"zh/api/config/plugins.md"},{title:"testing",routePath:"/module-tools/api/config/testing",lang:"zh",toc:[{text:"jest",id:"jest",depth:2,charIndex:55},{text:"transformer",id:"transformer",depth:2,charIndex:457}],frontmatter:{sidebar_position:5},version:"",_relativePath:"zh/api/config/testing.md"},{title:"\u6982\u89C8",routePath:"/module-tools/api/",lang:"zh",toc:[],frontmatter:{overview:!0,sidebar_label:"\u6982\u89C8",sidebar_position:1},version:"",_relativePath:"zh/api/index.md"},{title:"Plugin Hooks",routePath:"/module-tools/api/plugin-api/plugin-hooks",lang:"zh",toc:[{text:"\u6784\u5EFA\u94A9\u5B50",id:"\u6784\u5EFA\u94A9\u5B50",depth:2,charIndex:172},{text:"beforeBuild",id:"beforebuild",depth:3,charIndex:281},{text:"beforeBuildTask",id:"beforebuildtask",depth:3,charIndex:831},{text:"afterBuildTask",id:"afterbuildtask",depth:3,charIndex:1163},{text:"afterBuild",id:"afterbuild",depth:3,charIndex:1513},{text:"buildPlatform \u94A9\u5B50",id:"buildplatform-\u94A9\u5B50",depth:2,charIndex:1905},{text:"registerBuildPlatform",id:"registerbuildplatform",depth:3,charIndex:2244},{text:"beforeBuildPlatform",id:"beforebuildplatform",depth:3,charIndex:2851},{text:"buildPlatform",id:"buildplatform",depth:3,charIndex:3432},{text:"afterBuildPlatform",id:"afterbuildplatform",depth:3,charIndex:3807},{text:"\u8C03\u8BD5\u94A9\u5B50",id:"\u8C03\u8BD5\u94A9\u5B50",depth:2,charIndex:4385},{text:"registerDev",id:"registerdev",depth:3,charIndex:4614},{text:"beforeDev",id:"beforedev",depth:3,charIndex:5460},{text:"(before|after)DevMenu",id:"beforeafterdevmenu",depth:3,charIndex:5972},{text:"beforeDevTask",id:"beforedevtask",depth:3,charIndex:7008},{text:"afterDev",id:"afterdev",depth:3,charIndex:7517}],frontmatter:{},version:"",_relativePath:"zh/api/plugin-api/plugin-hooks.md"},{title:"",routePath:"/module-tools/components/faq-build-exception",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/components/faq-build-exception.mdx"},{title:"",routePath:"/module-tools/components/faq-build-other",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/components/faq-build-other.mdx"},{title:"",routePath:"/module-tools/components/faq-build-product",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/components/faq-build-product.mdx"},{title:"",routePath:"/module-tools/components/faq-storybook",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/components/faq-storybook.mdx"},{title:"",routePath:"/module-tools/components/faq-test",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/components/faq-test.mdx"},{title:"",routePath:"/module-tools/components/register-esbuild-plugin",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/components/register-esbuild-plugin.mdx"},{title:"\u5904\u7406\u9759\u6001\u8D44\u6E90",routePath:"/module-tools/guide/advance/asset",lang:"zh",toc:[{text:"\u9ED8\u8BA4\u884C\u4E3A",id:"\u9ED8\u8BA4\u884C\u4E3A",depth:2,charIndex:74},{text:"\u793A\u4F8B",id:"\u793A\u4F8B",depth:2,charIndex:355}],frontmatter:{sidebar_position:7},version:"",_relativePath:"zh/guide/advance/asset.mdx"},{title:"\u6784\u5EFA umd \u4EA7\u7269",routePath:"/module-tools/guide/advance/build-umd",lang:"zh",toc:[{text:"umd \u4EA7\u7269\u7684\u7B2C\u4E09\u65B9\u4F9D\u8D56\u5904\u7406",id:"umd-\u4EA7\u7269\u7684\u7B2C\u4E09\u65B9\u4F9D\u8D56\u5904\u7406",depth:2,charIndex:256},{text:"\u793A\u4F8B",id:"\u793A\u4F8B",depth:3,charIndex:377},{text:"\u4E09\u65B9\u4F9D\u8D56\u7684\u5168\u5C40\u53D8\u91CF\u540D\u79F0",id:"\u4E09\u65B9\u4F9D\u8D56\u7684\u5168\u5C40\u53D8\u91CF\u540D\u79F0",depth:3,charIndex:1563},{text:"\u66F4\u6539\u9879\u76EE\u7684\u5168\u5C40\u53D8\u91CF\u540D\u79F0",id:"\u66F4\u6539\u9879\u76EE\u7684\u5168\u5C40\u53D8\u91CF\u540D\u79F0",depth:2,charIndex:2612}],frontmatter:{sidebar_position:5},version:"",_relativePath:"zh/guide/advance/build-umd.mdx"},{title:"\u4F7F\u7528 Copy \u5DE5\u5177",routePath:"/module-tools/guide/advance/copy",lang:"zh",toc:[{text:"\u4E86\u89E3 Copy API",id:"\u4E86\u89E3-copy-api",depth:2,charIndex:72},{text:"API \u8BE6\u89E3",id:"api-\u8BE6\u89E3",depth:2,charIndex:165},{text:"\u4E0D\u540C\u573A\u666F\u4F7F\u7528\u793A\u4F8B",id:"\u4E0D\u540C\u573A\u666F\u4F7F\u7528\u793A\u4F8B",depth:2,charIndex:1492},{text:"\u5C06\u6587\u4EF6\u590D\u5236\u6587\u4EF6",id:"\u5C06\u6587\u4EF6\u590D\u5236\u6587\u4EF6",depth:3,charIndex:1504},{text:"\u5C06\u6587\u4EF6\u590D\u5236\u5230\u76EE\u5F55",id:"\u5C06\u6587\u4EF6\u590D\u5236\u5230\u76EE\u5F55",depth:3,charIndex:1848},{text:"\u4ECE\u76EE\u5F55\u590D\u5236\u5230\u76EE\u5F55",id:"\u4ECE\u76EE\u5F55\u590D\u5236\u5230\u76EE\u5F55",depth:3,charIndex:2186},{text:"\u4ECE\u76EE\u5F55\u5230\u6587\u4EF6",id:"\u4ECE\u76EE\u5F55\u5230\u6587\u4EF6",depth:3,charIndex:2580},{text:"\u4F7F\u7528 Glob",id:"\u4F7F\u7528-glob",depth:3,charIndex:2985}],frontmatter:{sidebar_position:3},version:"",_relativePath:"zh/guide/advance/copy.md"},{title:"\u5904\u7406\u4E09\u65B9\u4F9D\u8D56",routePath:"/module-tools/guide/advance/external-dependency",lang:"zh",toc:[{text:"\u7B2C\u4E09\u65B9\u4F9D\u8D56\u7684\u9ED8\u8BA4\u5904\u7406",id:"\u7B2C\u4E09\u65B9\u4F9D\u8D56\u7684\u9ED8\u8BA4\u5904\u7406",depth:2,charIndex:314},{text:"\u793A\u4F8B",id:"\u793A\u4F8B",depth:3,charIndex:571},{text:"\u6392\u9664\u6307\u5B9A\u7B2C\u4E09\u65B9\u4F9D\u8D56",id:"\u6392\u9664\u6307\u5B9A\u7B2C\u4E09\u65B9\u4F9D\u8D56",depth:2,charIndex:849}],frontmatter:{sidebar_position:4},version:"",_relativePath:"zh/guide/advance/external-dependency.mdx"},{title:"\u6DF1\u5165\u7406\u89E3\u6784\u5EFA",routePath:"/module-tools/guide/advance/in-depth-about-build",lang:"zh",toc:[{text:"bundle / bundleless",id:"bundle--bundleless",depth:2,charIndex:195},{text:"input / sourceDir",id:"input--sourcedir",depth:2,charIndex:715},{text:"\u4F7F\u7528 swc",id:"\u4F7F\u7528-swc",depth:2,charIndex:1372},{text:"\u4F7F\u7528 Hook \u4ECB\u5165\u6784\u5EFA\u6D41\u7A0B",id:"\u4F7F\u7528-hook-\u4ECB\u5165\u6784\u5EFA\u6D41\u7A0B",depth:2,charIndex:1851},{text:"Hook \u7C7B\u578B",id:"hook-\u7C7B\u578B",depth:3,charIndex:2025},{text:"AsyncSeriesBailHook",id:"asyncseriesbailhook",depth:4,charIndex:2035},{text:"AsyncSeriesWaterFallHooks",id:"asyncserieswaterfallhooks",depth:4,charIndex:2137},{text:"Hook API",id:"hook-api",depth:3,charIndex:2206},{text:"load",id:"load",depth:4,charIndex:2217},{text:"transform",id:"transform",depth:4,charIndex:2824},{text:"renderChunk",id:"renderchunk",depth:4,charIndex:3246},{text:"\u7C7B\u578B\u6587\u4EF6\u751F\u6210",id:"\u7C7B\u578B\u6587\u4EF6\u751F\u6210",depth:2,charIndex:4134},{text:"\u5173\u95ED\u7C7B\u578B\u751F\u6210",id:"\u5173\u95ED\u7C7B\u578B\u751F\u6210",depth:3,charIndex:4176},{text:"\u6253\u5305\u7C7B\u578B\u6587\u4EF6",id:"\u6253\u5305\u7C7B\u578B\u6587\u4EF6",depth:3,charIndex:4327},{text:"\u522B\u540D\u8F6C\u6362",id:"\u522B\u540D\u8F6C\u6362",depth:3,charIndex:4624},{text:"\u4E00\u4E9B\u793A\u4F8B",id:"\u4E00\u4E9B\u793A\u4F8B",depth:3,charIndex:4909},{text:"\u6784\u5EFA\u8FC7\u7A0B",id:"\u6784\u5EFA\u8FC7\u7A0B",depth:2,charIndex:5480},{text:"\u6784\u5EFA\u62A5\u9519",id:"\u6784\u5EFA\u62A5\u9519",depth:2,charIndex:5654},{text:"\u8C03\u8BD5\u6A21\u5F0F",id:"\u8C03\u8BD5\u6A21\u5F0F",depth:2,charIndex:6052}],frontmatter:{sidebar_position:1},version:"",_relativePath:"zh/guide/advance/in-depth-about-build.md"},{title:"\u6DF1\u5165\u7406\u89E3 dev \u547D\u4EE4",routePath:"/module-tools/guide/advance/in-depth-about-dev-command",lang:"zh",toc:[{text:"\u547D\u4EE4\u8FD0\u884C\u7684\u6574\u4F53\u6D41\u7A0B",id:"\u547D\u4EE4\u8FD0\u884C\u7684\u6574\u4F53\u6D41\u7A0B",depth:2,charIndex:42},{text:"\u6269\u5C55 dev \u547D\u4EE4",id:"\u6269\u5C55-dev-\u547D\u4EE4",depth:2,charIndex:339}],frontmatter:{sidebar_position:2},version:"",_relativePath:"zh/guide/advance/in-depth-about-dev-command.md"},{title:"\u5F00\u59CB\u4E4B\u524D",routePath:"/module-tools/guide/basic/before-getting-started",lang:"zh",toc:[{text:"\u73AF\u5883\u51C6\u5907",id:"\u73AF\u5883\u51C6\u5907",depth:2,charIndex:3},{text:"\u521D\u8BC6 npm",id:"\u521D\u8BC6-npm",depth:2,charIndex:189},{text:"npm \u5305\u7C7B\u578B\u9879\u76EE",id:"npm-\u5305\u7C7B\u578B\u9879\u76EE",depth:2,charIndex:392},{text:"\u4F7F\u7528\u7B2C\u4E09\u65B9 npm \u5305",id:"\u4F7F\u7528\u7B2C\u4E09\u65B9-npm-\u5305",depth:2,charIndex:1023},{text:"\u8FD8\u9700\u8981\u4E86\u89E3\u7684 npm \u96F6\u788E\u77E5\u8BC6",id:"\u8FD8\u9700\u8981\u4E86\u89E3\u7684-npm-\u96F6\u788E\u77E5\u8BC6",depth:2,charIndex:1990},{text:"npm \u5305\u7684\u7A0B\u5E8F\u5165\u53E3",id:"npm-\u5305\u7684\u7A0B\u5E8F\u5165\u53E3",depth:3,charIndex:2009},{text:'\\"scripts\\"',id:"scripts",depth:3,charIndex:-1},{text:"npm install",id:"npm-install",depth:4,charIndex:2878},{text:"npm publish",id:"npm-publish",depth:4,charIndex:3142},{text:"peerDependencies",id:"peerdependencies",depth:3,charIndex:3302},{text:"npm \u5305\u7BA1\u7406\u5668",id:"npm-\u5305\u7BA1\u7406\u5668",depth:2,charIndex:3616},{text:"Modern.js Module \u914D\u7F6E\u6587\u4EF6",id:"modernjs-module-\u914D\u7F6E\u6587\u4EF6",depth:2,charIndex:3744}],frontmatter:{sidebar_position:1},version:"",_relativePath:"zh/guide/basic/before-getting-started.md"},{title:"CLI \u547D\u4EE4",routePath:"/module-tools/guide/basic/command-preview",lang:"zh",toc:[{text:"modern build",id:"modern-build",depth:2,charIndex:39},{text:"modern new",id:"modern-new",depth:2,charIndex:1090},{text:"modern dev",id:"modern-dev",depth:2,charIndex:1549},{text:"modern test",id:"modern-test",depth:2,charIndex:1925},{text:"modern lint",id:"modern-lint",depth:2,charIndex:2129},{text:"modern change",id:"modern-change",depth:2,charIndex:2422},{text:"modern pre",id:"modern-pre",depth:2,charIndex:2662},{text:"modern bump",id:"modern-bump",depth:2,charIndex:2808},{text:"modern release",id:"modern-release",depth:2,charIndex:3151},{text:"modern gen-release-note",id:"modern-gen-release-note",depth:2,charIndex:3502},{text:"modern upgrade",id:"modern-upgrade",depth:2,charIndex:3832}],frontmatter:{sidebar_position:2},version:"",_relativePath:"zh/guide/basic/command-preview.md"},{title:"\u4FEE\u6539\u8F93\u51FA\u4EA7\u7269",routePath:"/module-tools/guide/basic/modify-output-product",lang:"zh",toc:[{text:"\u9ED8\u8BA4\u8F93\u51FA\u4EA7\u7269",id:"\u9ED8\u8BA4\u8F93\u51FA\u4EA7\u7269",depth:2,charIndex:3},{text:"\u6784\u5EFA\u9884\u8BBE",id:"\u6784\u5EFA\u9884\u8BBE",depth:2,charIndex:486},{text:"\u6784\u5EFA\u914D\u7F6E",id:"\u6784\u5EFA\u914D\u7F6E",depth:2,charIndex:804},{text:"\u7ED3\u5408\u914D\u7F6E\u4E0E\u9884\u8BBE",id:"\u7ED3\u5408\u914D\u7F6E\u4E0E\u9884\u8BBE",depth:2,charIndex:2092}],frontmatter:{sidebar_position:3},version:"",_relativePath:"zh/guide/basic/modify-output-product.md"},{title:"\u7248\u672C\u7BA1\u7406\u4E0E\u53D1\u5E03",routePath:"/module-tools/guide/basic/publish-your-project",lang:"zh",toc:[{text:"\u8DDF\u8E2A\u53D8\u66F4",id:"\u8DDF\u8E2A\u53D8\u66F4",depth:2,charIndex:156},{text:"\u7248\u672C\u66F4\u65B0",id:"\u7248\u672C\u66F4\u65B0",depth:2,charIndex:1050},{text:"\u53D1\u5E03",id:"\u53D1\u5E03",depth:2,charIndex:1313},{text:"\u9884\u53D1\u5E03",id:"\u9884\u53D1\u5E03",depth:2,charIndex:1651}],frontmatter:{sidebar_position:7},version:"",_relativePath:"zh/guide/basic/publish-your-project.md"},{title:"\u6D4B\u8BD5\u9879\u76EE",routePath:"/module-tools/guide/basic/test-your-project",lang:"zh",toc:[{text:"\u5148\u51B3\u6761\u4EF6\u548C\u7EA6\u5B9A",id:"\u5148\u51B3\u6761\u4EF6\u548C\u7EA6\u5B9A",depth:2,charIndex:21},{text:"\u8FD0\u884C\u6D4B\u8BD5",id:"\u8FD0\u884C\u6D4B\u8BD5",depth:2,charIndex:417},{text:"\u4F7F\u7528\u914D\u7F6E",id:"\u4F7F\u7528\u914D\u7F6E",depth:2,charIndex:551},{text:"\u6D4B\u8BD5\u793A\u4F8B",id:"\u6D4B\u8BD5\u793A\u4F8B",depth:2,charIndex:633},{text:"\u666E\u901A\u6A21\u5757",id:"\u666E\u901A\u6A21\u5757",depth:3,charIndex:641},{text:"\u7EC4\u4EF6",id:"\u7EC4\u4EF6",depth:3,charIndex:1057}],frontmatter:{sidebar_position:6},version:"",_relativePath:"zh/guide/basic/test-your-project.mdx"},{title:"\u4F7F\u7528\u5FAE\u751F\u6210\u5668",routePath:"/module-tools/guide/basic/use-micro-generator",lang:"zh",toc:[{text:"Test \u6D4B\u8BD5",id:"test-\u6D4B\u8BD5",depth:2,charIndex:166},{text:"Storybook \u8C03\u8BD5",id:"storybook-\u8C03\u8BD5",depth:2,charIndex:407},{text:"Tailwind CSS \u652F\u6301",id:"tailwind-css-\u652F\u6301",depth:2,charIndex:751},{text:"Modern.js Runtime API \u652F\u6301",id:"modernjs-runtime-api-\u652F\u6301",depth:2,charIndex:899}],frontmatter:{sidebar_position:4},version:"",_relativePath:"zh/guide/basic/use-micro-generator.md"},{title:"\u4F7F\u7528 Storybook",routePath:"/module-tools/guide/basic/using-storybook",lang:"zh",toc:[{text:"\u8C03\u8BD5\u4EE3\u7801",id:"\u8C03\u8BD5\u4EE3\u7801",depth:2,charIndex:292},{text:"\u5F15\u7528\u7EC4\u4EF6\u4EA7\u7269",id:"\u5F15\u7528\u7EC4\u4EF6\u4EA7\u7269",depth:3,charIndex:491},{text:"\u5F15\u7528\u7EC4\u4EF6\u6E90\u7801",id:"\u5F15\u7528\u7EC4\u4EF6\u6E90\u7801",depth:3,charIndex:1862},{text:"\u914D\u7F6E Storybook",id:"\u914D\u7F6E-storybook",depth:2,charIndex:2277},{text:"\u6784\u5EFA Storybook \u4EA7\u7269",id:"\u6784\u5EFA-storybook-\u4EA7\u7269",depth:2,charIndex:2686},{text:"\u7ED3\u5408 Tailwind CSS \u4F7F\u7528",id:"\u7ED3\u5408-tailwind-css-\u4F7F\u7528",depth:2,charIndex:2901}],frontmatter:{sidebar_position:5},version:"",_relativePath:"zh/guide/basic/using-storybook.mdx"},{title:"\u5F00\u53D1\u7EC4\u4EF6",routePath:"/module-tools/guide/best-practices/components",lang:"zh",toc:[{text:"\u521D\u59CB\u5316\u9879\u76EE",id:"\u521D\u59CB\u5316\u9879\u76EE",depth:2,charIndex:40},{text:"\u4F7F\u7528 Storybook \u8C03\u8BD5\u4EE3\u7801",id:"\u4F7F\u7528-storybook-\u8C03\u8BD5\u4EE3\u7801",depth:2,charIndex:513},{text:"\u5F00\u53D1\u6837\u5F0F",id:"\u5F00\u53D1\u6837\u5F0F",depth:2,charIndex:574},{text:"CSS/PostCSS",id:"csspostcss",depth:3,charIndex:682},{text:"Less",id:"less",depth:3,charIndex:1192},{text:"Sass/Scss",id:"sassscss",depth:3,charIndex:1445},{text:"Tailwind CSS",id:"tailwind-css",depth:3,charIndex:1728},{text:"CSS Modules",id:"css-modules",depth:3,charIndex:1776},{text:"\u914D\u7F6E\u6784\u5EFA\u4EA7\u7269",id:"\u914D\u7F6E\u6784\u5EFA\u4EA7\u7269",depth:2,charIndex:2090},{text:"\u6D4B\u8BD5\u7EC4\u4EF6",id:"\u6D4B\u8BD5\u7EC4\u4EF6",depth:2,charIndex:2571},{text:"\u53D1\u5E03\u7EC4\u4EF6",id:"\u53D1\u5E03\u7EC4\u4EF6",depth:2,charIndex:2605}],frontmatter:{sidebar_position:1},version:"",_relativePath:"zh/guide/best-practices/components.mdx"},{title:"\u4F7F\u7528 Tailwind CSS",routePath:"/module-tools/guide/best-practices/use-tailwindcss",lang:"zh",toc:[{text:"\u542F\u7528 Tailwind CSS",id:"\u542F\u7528-tailwind-css",depth:2,charIndex:127},{text:"\u914D\u7F6E Tailwind CSS",id:"\u914D\u7F6E-tailwind-css",depth:2,charIndex:962},{text:"Tailwind CSS \u81EA\u52A8\u8865\u5168",id:"tailwind-css-\u81EA\u52A8\u8865\u5168",depth:2,charIndex:1608},{text:"\u6784\u5EFA\u6A21\u5F0F",id:"\u6784\u5EFA\u6A21\u5F0F",depth:2,charIndex:1921},{text:"Bundle \u6A21\u5F0F",id:"bundle-\u6A21\u5F0F",depth:3,charIndex:2038},{text:"Bundleless \u6A21\u5F0F",id:"bundleless-\u6A21\u5F0F",depth:3,charIndex:2627},{text:"\u7C7B\u540D\u524D\u7F00",id:"\u7C7B\u540D\u524D\u7F00",depth:2,charIndex:2837},{text:"\u7528\u6CD5\u4ECB\u7ECD",id:"\u7528\u6CD5\u4ECB\u7ECD",depth:2,charIndex:3222},{text:"HTML \u7C7B\u540D",id:"html-\u7C7B\u540D",depth:3,charIndex:3257},{text:"@apply",id:"apply",depth:3,charIndex:3568},{text:"Sass",id:"sass",depth:4,charIndex:3756},{text:"Less",id:"less",depth:4,charIndex:3953},{text:"\u5173\u4E8E designSystem \u914D\u7F6E",id:"\u5173\u4E8E-designsystem-\u914D\u7F6E",depth:2,charIndex:4467}],frontmatter:{sidebar_position:2},version:"",_relativePath:"zh/guide/best-practices/use-tailwindcss.mdx"},{title:"\u6784\u5EFA\u76F8\u5173\u95EE\u9898",routePath:"/module-tools/guide/faq/build",lang:"zh",toc:[{text:"\u4EA7\u7269\u95EE\u9898",id:"\u4EA7\u7269\u95EE\u9898",depth:2,charIndex:3},{text:"Class Fields \u7684\u521D\u59CB\u5316\u5904\u7406",id:"class-fields-\u7684\u521D\u59CB\u5316\u5904\u7406",depth:3,charIndex:11},{text:"babel-plugin-lodash \u5C06\u5F15\u5165\u7684 lodash \u5904\u7406\u6210 undefined",id:"babel-plugin-lodash-\u5C06\u5F15\u5165\u7684-lodash-\u5904\u7406\u6210-undefined",depth:3,charIndex:1315},{text:"\u5F02\u5E38\u7C7B\u95EE\u9898",id:"\u5F02\u5E38\u7C7B\u95EE\u9898",depth:2,charIndex:1722},{text:'Dynamic require of \\"react\\" is not supported',id:"dynamic-require-of-react-is-not-supported",depth:3,charIndex:-1},{text:"\u95EE\u9898\u63CF\u8FF0",id:"\u95EE\u9898\u63CF\u8FF0",depth:4,charIndex:1777},{text:"\u89E3\u51B3\u529E\u6CD5",id:"\u89E3\u51B3\u529E\u6CD5",depth:4,charIndex:1952},{text:"\u53C2\u8003\u94FE\u63A5",id:"\u53C2\u8003\u94FE\u63A5",depth:4,charIndex:2246},{text:"\u7F16\u8BD1\u8FC7\u7A0B\u4E2D\uFF0C\u56E0\u4E3A\u67D0\u4E2A\u7EC4\u4EF6\u5E93\u7684 less \u6587\u4EF6\u62A5\u9519\uFF1A\\'Operation on an invalid type\\'",id:"\u7F16\u8BD1\u8FC7\u7A0B\u4E2D\u56E0\u4E3A\u67D0\u4E2A\u7EC4\u4EF6\u5E93\u7684-less-\u6587\u4EF6\u62A5\u9519operation-on-an-invalid-type",depth:3,charIndex:-1},{text:"Bundle DTS failed",id:"bundle-dts-failed",depth:3,charIndex:3439},{text:'defineConfig \u51FD\u6570\u7C7B\u578B\u62A5\u9519\uFF1A\u5982\u679C\u6CA1\u6709\u5F15\u7528 \\"...\\"\uFF0C\u5219\u65E0\u6CD5\u547D\u540D \\"default\\" \u7684\u63A8\u65AD\u7C7B\u578B',id:"defineconfig-\u51FD\u6570\u7C7B\u578B\u62A5\u9519\u5982\u679C\u6CA1\u6709\u5F15\u7528-\u5219\u65E0\u6CD5\u547D\u540D-default-\u7684\u63A8\u65AD\u7C7B\u578B",depth:3,charIndex:-1},{text:"\u5176\u4ED6",id:"\u5176\u4ED6",depth:2,charIndex:3873},{text:"\u589E\u52A0\u989D\u5916\u7684\u7F16\u8BD1\u80FD\u529B",id:"\u589E\u52A0\u989D\u5916\u7684\u7F16\u8BD1\u80FD\u529B",depth:3,charIndex:3879},{text:"\u652F\u6301\u751F\u6210 CSS Modules \u7684 TypeScript \u58F0\u660E\u6587\u4EF6",id:"\u652F\u6301\u751F\u6210-css-modules-\u7684-typescript-\u58F0\u660E\u6587\u4EF6",depth:3,charIndex:4370}],frontmatter:{},version:"",_relativePath:"zh/guide/faq/build.mdx"},{title:"\u5E38\u89C1\u95EE\u9898",routePath:"/module-tools/guide/faq/",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/guide/faq/index.md"},{title:"Storybook \u76F8\u5173\u95EE\u9898",routePath:"/module-tools/guide/faq/storybook",lang:"zh",toc:[{text:"\u652F\u6301 Storybook v7",id:"\u652F\u6301-storybook-v7",depth:2,charIndex:3},{text:"\u4F7F\u7528 Storybook Addon \u6216\u8005\u5176\u4ED6\u914D\u7F6E\u4E0D\u751F\u6548",id:"\u4F7F\u7528-storybook-addon-\u6216\u8005\u5176\u4ED6\u914D\u7F6E\u4E0D\u751F\u6548",depth:2,charIndex:102},{text:"Cannot find module \\'react-dom/package.json",id:"cannot-find-module-react-dompackagejson",depth:2,charIndex:-1},{text:"\u62A5\u9519\u540E\uFF0C\u770B\u4E0D\u5230\u5177\u4F53\u62A5\u9519\u4FE1\u606F",id:"\u62A5\u9519\u540E\u770B\u4E0D\u5230\u5177\u4F53\u62A5\u9519\u4FE1\u606F",depth:2,charIndex:534},{text:"Couldn\\'t find any stories is your Storybook",id:"couldnt-find-any-stories-is-your-storybook",depth:2,charIndex:-1},{text:"Storybook \u6DFB\u52A0 Proxy \u529F\u80FD",id:"storybook-\u6DFB\u52A0-proxy-\u529F\u80FD",depth:2,charIndex:1411},{text:"\u4FEE\u6539\u5B58\u5728 Story \u6587\u4EF6\u7684\u76EE\u5F55",id:"\u4FEE\u6539\u5B58\u5728-story-\u6587\u4EF6\u7684\u76EE\u5F55",depth:2,charIndex:2095}],frontmatter:{},version:"",_relativePath:"zh/guide/faq/storybook.mdx"},{title:"\u6D4B\u8BD5\u76F8\u5173\u95EE\u9898",routePath:"/module-tools/guide/faq/test",lang:"zh",toc:[{text:"\u6267\u884C test \u547D\u4EE4\u62A5\u9519 TypeError: Cannot read property \\'testEnvironmentOptions\\' of undefined",id:"\u6267\u884C-test-\u547D\u4EE4\u62A5\u9519-typeerror-cannot-read-property-testenvironmentoptions-of-undefined",depth:2,charIndex:-1}],frontmatter:{},version:"",_relativePath:"zh/guide/faq/test.mdx"},{title:"\u5FEB\u901F\u5F00\u59CB",routePath:"/module-tools/guide/intro/getting-started",lang:"zh",toc:[{text:"\u4E09\u5206\u949F\u5FEB\u901F\u4E0A\u624B",id:"\u4E09\u5206\u949F\u5FEB\u901F\u4E0A\u624B",depth:2,charIndex:3},{text:"\u521B\u5EFA\u65B0\u9879\u76EE",id:"\u521B\u5EFA\u65B0\u9879\u76EE",depth:3,charIndex:111},{text:"\u63A5\u5165\u5DF2\u6709\u9879\u76EE",id:"\u63A5\u5165\u5DF2\u6709\u9879\u76EE",depth:3,charIndex:516},{text:"\u6838\u5FC3 npm \u5305",id:"\u6838\u5FC3-npm-\u5305",depth:3,charIndex:1013},{text:"\u67E5\u770B\u5B98\u65B9\u793A\u4F8B",id:"\u67E5\u770B\u5B98\u65B9\u793A\u4F8B",depth:3,charIndex:1411},{text:"\u8BA9\u6211\u4EEC\u5F00\u59CB\u5427",id:"\u8BA9\u6211\u4EEC\u5F00\u59CB\u5427",depth:2,charIndex:1669}],frontmatter:{sidebar_position:3},version:"",_relativePath:"zh/guide/intro/getting-started.mdx"},{title:"\u6B22\u8FCE\u4F7F\u7528",routePath:"/module-tools/guide/intro/welcome",lang:"zh",toc:[],frontmatter:{sidebar_position:1},version:"",_relativePath:"zh/guide/intro/welcome.md"},{title:"\u4E3A\u4EC0\u4E48\u9700\u8981 Modern.js Module",routePath:"/module-tools/guide/intro/why-module-engineering-solution",lang:"zh",toc:[],frontmatter:{sidebar_position:2},version:"",_relativePath:"zh/guide/intro/why-module-engineering-solution.md"},{title:"index",routePath:"/module-tools/",lang:"zh",toc:[],frontmatter:{pageType:"home",hero:{name:"Modern.js Module",text:"\u6A21\u5757\u5DE5\u7A0B\u89E3\u51B3\u65B9\u6848",tagline:"\u7B80\u5355\u3001\u5F3A\u5927\u3001\u9AD8\u6027\u80FD\u7684\u73B0\u4EE3\u5316 npm \u5305\u5F00\u53D1\u65B9\u6848",actions:[{theme:"brand",text:"\u6B22\u8FCE\u4F7F\u7528",link:"/guide/intro/welcome"},{theme:"alt",text:"\u5FEB\u901F\u4E0A\u624B",link:"/guide/intro/getting-started"}]},features:[{title:"esbuild: \u9AD8\u6027\u80FD\u7684 JS Bundler",details:"\u57FA\u4E8E esbuild \u6784\u5EFA\uFF0C\u6784\u5EFA\u901F\u5EA6\u6781\u5FEB\uFF0C\u5E26\u7ED9\u4F60\u6781\u81F4\u7684\u5F00\u53D1\u4F53\u9A8C\u3002",icon:"\uD83D\uDE80"},{title:"\u53CC\u6784\u5EFA\u6A21\u5F0F",details:"\u652F\u6301 Bundle \u548C Bundleless \u4E24\u79CD\u6784\u5EFA\u6A21\u5F0F\u3002",icon:"\u2728"},{title:"\u5F00\u7BB1\u5373\u7528",details:"\u65E0\u9700\u8FC7\u591A\u914D\u7F6E\u5373\u53EF\u5F00\u53D1\u4F60\u7684 npm \u5305\uFF0C\u5185\u7F6E\u9884\u8BBE\u8986\u76D6\u591A\u79CD\u573A\u666F\u3002",icon:"\uD83D\uDEE0\uFE0F"},{title:"\u6269\u5C55\u6027\u5F3A: \u63D0\u4F9B\u5F3A\u5927\u7684\u63D2\u4EF6\u673A\u5236",details:"\u901A\u8FC7\u5176\u63D2\u4EF6\u6269\u5C55\u673A\u5236\uFF0C\u4F60\u53EF\u4EE5\u8F7B\u677E\u7684\u6269\u5C55 Modern.js Module \u7684\u5404\u9879\u80FD\u529B\u3002",icon:"\uD83C\uDFA8"},{title:"Storybook: \u793E\u533A\u6D41\u884C\u7684 UI \u5F00\u53D1\u5DE5\u5177",details:"\u96C6\u6210\u4E86 Storybook\uFF0C\u4F60\u53EF\u4EE5\u4F7F\u7528\u5B83\u8C03\u8BD5 UI\u3002",icon:"\uD83D\uDCE6"},{title:"Jest: \u4EE4\u4EBA\u6109\u5FEB\u7684\u6D4B\u8BD5\u6846\u67B6",details:"\u96C6\u6210\u4E86 Jest\uFF0C\u4F7F\u5F97\u4EE3\u7801\u6D4B\u8BD5\u66F4\u52A0\u5BB9\u6613\u3002",icon:"\uD83D\uDCD0"}]},version:"",_relativePath:"zh/index.md"},{title:"\u5FEB\u901F\u5F00\u59CB",routePath:"/module-tools/plugins/guide/getting-started",lang:"zh",toc:[],frontmatter:{sidebar_position:1},version:"",_relativePath:"zh/plugins/guide/getting-started.mdx"},{title:"\u63D2\u4EF6\u5BF9\u8C61",routePath:"/module-tools/plugins/guide/plugin-object",lang:"zh",toc:[{text:"\u63D2\u4EF6\u7C7B\u578B\u5B9A\u4E49",id:"\u63D2\u4EF6\u7C7B\u578B\u5B9A\u4E49",depth:2,charIndex:480},{text:"\u63D2\u4EF6\u914D\u7F6E\u9879",id:"\u63D2\u4EF6\u914D\u7F6E\u9879",depth:2,charIndex:745}],frontmatter:{sidebar_position:2},version:"",_relativePath:"zh/plugins/guide/plugin-object.mdx"},{title:"Setup \u51FD\u6570",routePath:"/module-tools/plugins/guide/setup-function",lang:"zh",toc:[{text:"\u63D2\u4EF6 API \u5BF9\u8C61",id:"\u63D2\u4EF6-api-\u5BF9\u8C61",depth:2,charIndex:77},{text:"api.useAppContext",id:"apiuseappcontext",depth:3,charIndex:441},{text:"api.useResolvedConfigContext",id:"apiuseresolvedconfigcontext",depth:3,charIndex:823},{text:"api.useHookRunners",id:"apiusehookrunners",depth:3,charIndex:1198},{text:"\u5F02\u6B65 setup",id:"\u5F02\u6B65-setup",depth:2,charIndex:1461},{text:"\u751F\u547D\u5468\u671F\u94A9\u5B50",id:"\u751F\u547D\u5468\u671F\u94A9\u5B50",depth:2,charIndex:1731}],frontmatter:{sidebar_position:3},version:"",_relativePath:"zh/plugins/guide/setup-function.mdx"},{title:"\u603B\u89C8",routePath:"/module-tools/plugins/official-list/overview",lang:"zh",toc:[{text:"\u5B98\u65B9\u63D2\u4EF6",id:"\u5B98\u65B9\u63D2\u4EF6",depth:2,charIndex:3}],frontmatter:{},version:"",_relativePath:"zh/plugins/official-list/overview.md"},{title:"Babel \u63D2\u4EF6",routePath:"/module-tools/plugins/official-list/plugin-babel",lang:"zh",toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2,charIndex:50},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3,charIndex:58},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3,charIndex:64},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2,charIndex:197}],frontmatter:{},version:"",_relativePath:"zh/plugins/official-list/plugin-babel.mdx"},{title:"Banner \u63D2\u4EF6",routePath:"/module-tools/plugins/official-list/plugin-banner",lang:"zh",toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2,charIndex:133},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3,charIndex:141},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3,charIndex:147},{text:"\u793A\u4F8B",id:"\u793A\u4F8B",depth:2,charIndex:426},{text:"\u5728 JS \u6587\u4EF6\u9876\u90E8\u589E\u52A0\u7248\u6743\u4FE1\u606F",id:"\u5728-js-\u6587\u4EF6\u9876\u90E8\u589E\u52A0\u7248\u6743\u4FE1\u606F",depth:3,charIndex:432},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2,charIndex:898},{text:"banner",id:"banner",depth:3,charIndex:1045},{text:"footer",id:"footer",depth:3,charIndex:1124}],frontmatter:{},version:"",_relativePath:"zh/plugins/official-list/plugin-banner.mdx"},{title:"Import \u63D2\u4EF6",routePath:"/module-tools/plugins/official-list/plugin-import",lang:"zh",toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2,charIndex:145},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3,charIndex:153},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3,charIndex:159},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2,charIndex:459},{text:"pluginImport",id:"pluginimport",depth:3,charIndex:526},{text:"\u6CE8\u610F\u4E8B\u9879",id:"\u6CE8\u610F\u4E8B\u9879",depth:2,charIndex:878}],frontmatter:{},version:"",_relativePath:"zh/plugins/official-list/plugin-import.mdx"},{title:"Node Polyfill \u63D2\u4EF6",routePath:"/module-tools/plugins/official-list/plugin-node-polyfill",lang:"zh",toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2,charIndex:213},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3,charIndex:221},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3,charIndex:227},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2,charIndex:367},{text:"exclude",id:"exclude",depth:3,charIndex:459},{text:"overrides",id:"overrides",depth:3,charIndex:636},{text:"Node Polyfills",id:"node-polyfills",depth:2,charIndex:866},{text:"Globals",id:"globals",depth:3,charIndex:884},{text:"Modules",id:"modules",depth:3,charIndex:1007},{text:"Fallbacks",id:"fallbacks",depth:3,charIndex:1445}],frontmatter:{},version:"",_relativePath:"zh/plugins/official-list/plugin-node-polyfill.mdx"},{title:"Polyfill \u63D2\u4EF6",routePath:"/module-tools/plugins/official-list/plugin-polyfill",lang:"zh",toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2,charIndex:197},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3,charIndex:205},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3,charIndex:211},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2,charIndex:347},{text:"targets",id:"targets",depth:3,charIndex:412}],frontmatter:{},version:"",_relativePath:"zh/plugins/official-list/plugin-polyfill.mdx"}],markdown:{showLineNumbers:!1}}},66428:function(e,t,n){e.exports={AElig:"\xc6",AMP:"&",Aacute:"\xc1",Acirc:"\xc2",Agrave:"\xc0",Aring:"\xc5",Atilde:"\xc3",Auml:"\xc4",COPY:"\xa9",Ccedil:"\xc7",ETH:"\xd0",Eacute:"\xc9",Ecirc:"\xca",Egrave:"\xc8",Euml:"\xcb",GT:">",Iacute:"\xcd",Icirc:"\xce",Igrave:"\xcc",Iuml:"\xcf",LT:"<",Ntilde:"\xd1",Oacute:"\xd3",Ocirc:"\xd4",Ograve:"\xd2",Oslash:"\xd8",Otilde:"\xd5",Ouml:"\xd6",QUOT:'"',REG:"\xae",THORN:"\xde",Uacute:"\xda",Ucirc:"\xdb",Ugrave:"\xd9",Uuml:"\xdc",Yacute:"\xdd",aacute:"\xe1",acirc:"\xe2",acute:"\xb4",aelig:"\xe6",agrave:"\xe0",amp:"&",aring:"\xe5",atilde:"\xe3",auml:"\xe4",brvbar:"\xa6",ccedil:"\xe7",cedil:"\xb8",cent:"\xa2",copy:"\xa9",curren:"\xa4",deg:"\xb0",divide:"\xf7",eacute:"\xe9",ecirc:"\xea",egrave:"\xe8",eth:"\xf0",euml:"\xeb",frac12:"\xbd",frac14:"\xbc",frac34:"\xbe",gt:">",iacute:"\xed",icirc:"\xee",iexcl:"\xa1",igrave:"\xec",iquest:"\xbf",iuml:"\xef",laquo:"\xab",lt:"<",macr:"\xaf",micro:"\xb5",middot:"\xb7",nbsp:"\xa0",not:"\xac",ntilde:"\xf1",oacute:"\xf3",ocirc:"\xf4",ograve:"\xf2",ordf:"\xaa",ordm:"\xba",oslash:"\xf8",otilde:"\xf5",ouml:"\xf6",para:"\xb6",plusmn:"\xb1",pound:"\xa3",quot:'"',raquo:"\xbb",reg:"\xae",sect:"\xa7",shy:"\xad",sup1:"\xb9",sup2:"\xb2",sup3:"\xb3",szlig:"\xdf",thorn:"\xfe",times:"\xd7",uacute:"\xfa",ucirc:"\xfb",ugrave:"\xf9",uml:"\xa8",uuml:"\xfc",yacute:"\xfd",yen:"\xa5",yuml:"\xff"}},20165:function(e,t,n){e.exports={0:"\uFFFD",128:"\u20AC",130:"\u201A",131:"\u0192",132:"\u201E",133:"\u2026",134:"\u2020",135:"\u2021",136:"\u02C6",137:"\u2030",138:"\u0160",139:"\u2039",140:"\u0152",142:"\u017D",145:"\u2018",146:"\u2019",147:"\u201C",148:"\u201D",149:"\u2022",150:"\u2013",151:"\u2014",152:"\u02DC",153:"\u2122",154:"\u0161",155:"\u203A",156:"\u0153",158:"\u017E",159:"\u0178"}},15467:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return a}});var r=n("99462"),i=n("41989"),o=n("57814");function a(e){var t=(0,r.useLocation)().pathname,n=e.selector,a=void 0===n?".rspress-doc img":n,l=e.options,s=void 0===l?{}:l;return(0,o.useEffect)(function(){var e=document.querySelectorAll(a);(0,i.default)(e,s)},[t]),null}n("49857")},88916:function(e,t,n){"use strict";n.r(t);var r=n("85464");n.es(r,t)},56885:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return r.default}});var r=n("48589");n.es(r,t)},99462:function(e,t,n){"use strict";n.r(t);var r=n("88916");n.es(r,t)},53868:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return r.default}});var r=n("56885");n.es(r,t)},84404:function(e,t,n){"use strict";n.r(t),n.d(t,{onSearch:function(){return r}});var r=function(){}}}]); \ No newline at end of file +(self.webpackChunk_modern_js_module_tools_docs=self.webpackChunk_modern_js_module_tools_docs||[]).push([["7396"],{74007:function(e,t,n){"use strict";n.r(t),n.d(t,{disableBodyScroll:function(){return x},clearAllBodyScrollLocks:function(){return v}});var r=!1;if("undefined"!=typeof window){var i={get passive(){r=!0;return}};window.addEventListener("testPassive",null,i),window.removeEventListener("testPassive",null,i)}var o="undefined"!=typeof window&&window.navigator&&window.navigator.platform&&(/iP(ad|hone|od)/.test(window.navigator.platform)||"MacIntel"===window.navigator.platform&&window.navigator.maxTouchPoints>1),a=[],l=!1,s=-1,c=void 0,u=void 0,d=void 0,p=function(e){return a.some(function(t){return!!(t.options.allowTouchMove&&t.options.allowTouchMove(e))||!1})},h=function(e){var t=e||window.event;return!!p(t.target)||!!(t.touches.length>1)||(t.preventDefault&&t.preventDefault(),!1)},f=function(e){if(void 0===d){var t=!!e&&!0===e.reserveScrollBarGap,n=window.innerWidth-document.documentElement.clientWidth;if(t&&n>0){var r=parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"),10);d=document.body.style.paddingRight,document.body.style.paddingRight=r+n+"px"}}void 0===c&&(c=document.body.style.overflow,document.body.style.overflow="hidden")},m=function(){void 0!==d&&(document.body.style.paddingRight=d,d=void 0),void 0!==c&&(document.body.style.overflow=c,c=void 0)},g=function(){if(void 0!==u){var e=-parseInt(document.body.style.top,10),t=-parseInt(document.body.style.left,10);document.body.style.position=u.position,document.body.style.top=u.top,document.body.style.left=u.left,window.scrollTo(t,e),u=void 0}},b=function(e,t){var n,r=e.targetTouches[0].clientY-s;if(p(e.target))return!1;if(t&&0===t.scrollTop&&r>0)return h(e);return(n=t)&&n.scrollHeight-n.scrollTop<=n.clientHeight&&r<0?h(e):(e.stopPropagation(),!0)},x=function(e,t){if(!e){console.error("disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.");return}!a.some(function(t){return t.targetElement===e})&&(a=[].concat(function(e){if(!Array.isArray(e))return Array.from(e);for(var t=0,n=Array(e.length);t=r&&(document.body.style.top=-(t+e))})},300)}}):f(t),o&&(e.ontouchstart=function(e){1===e.targetTouches.length&&(s=e.targetTouches[0].clientY)},e.ontouchmove=function(t){1===t.targetTouches.length&&b(t,e)},!l&&(document.addEventListener("touchmove",h,r?{passive:!1}:void 0),l=!0)))},v=function(){o&&(a.forEach(function(e){e.targetElement.ontouchstart=null,e.targetElement.ontouchmove=null}),l&&(document.removeEventListener("touchmove",h,r?{passive:!1}:void 0),l=!1),s=-1),o?g():m(),a=[]}},40926:function(e,t,n){"use strict";t.parse=function(e){for(var t,n=[],i=String(e||o),a=i.indexOf(r),l=0,s=!1;!s;)-1===a&&(a=i.length,s=!0),((t=i.slice(l,a).trim())||!s)&&n.push(t),l=a+1,a=i.indexOf(r,l);return n},t.stringify=function(e,t){var n=t||{},a=!1===n.padLeft?o:i,l=n.padRight?i:o;return e[e.length-1]===o&&(e=e.concat(o)),e.join(l+r+a).trim()};var r=",",i=" ",o=""},53274:function(e,t,n){"use strict";var r=function(e){var t=(/mac os x/i.test(navigator.userAgent)?"\u2318":"Ctrl")+"+C";return e.replace(/#{\s*key\s*}/g,t)},i=n("23072"),o={"text/plain":"Text","text/html":"Url",default:"Text"},a="Copy to clipboard: #{key}, Enter";e.exports=function(e,t){var n,l,s,c,u,d,p=!1;!t&&(t={}),n=t.debug||!1;try{if(s=i(),c=document.createRange(),u=document.getSelection(),(d=document.createElement("span")).textContent=e,d.ariaHidden="true",d.style.all="unset",d.style.position="fixed",d.style.top=0,d.style.clip="rect(0, 0, 0, 0)",d.style.whiteSpace="pre",d.style.webkitUserSelect="text",d.style.MozUserSelect="text",d.style.msUserSelect="text",d.style.userSelect="text",d.addEventListener("copy",function(r){if(r.stopPropagation(),t.format){if(r.preventDefault(),void 0===r.clipboardData){n&&console.warn("unable to use e.clipboardData"),n&&console.warn("trying IE specific stuff"),window.clipboardData.clearData();var i=o[t.format]||o.default;window.clipboardData.setData(i,e)}else r.clipboardData.clearData(),r.clipboardData.setData(t.format,e)}t.onCopy&&(r.preventDefault(),t.onCopy(r.clipboardData))}),document.body.appendChild(d),c.selectNodeContents(d),u.addRange(c),!document.execCommand("copy"))throw Error("copy command was unsuccessful");p=!0}catch(i){n&&console.error("unable to copy using execCommand: ",i),n&&console.warn("trying IE specific stuff");try{window.clipboardData.setData(t.format||"text",e),t.onCopy&&t.onCopy(window.clipboardData),p=!0}catch(i){n&&console.error("unable to copy using clipboardData: ",i),n&&console.error("falling back to prompt"),l=r("message"in t?t.message:a),window.prompt(l,e)}}finally{u&&("function"==typeof u.removeRange?u.removeRange(c):u.removeAllRanges()),d&&document.body.removeChild(d),s()}return p}},61932:function(e,t,n){"use strict";var r,i,o,a,l,s;o="FlexSearch",a=function e(t){var n,r,i,o,a,l,s,c,u,d,p,h,f,m,g,b,x,v,y,w,j,P,O=function(e,t){var n=t?t.id:e&&e.id;this.id=n||0===n?n:K++,this.init(e,t),_(this,"index",function(){return this.a?Object.keys(this.a.index[this.a.keys[0]].c):Object.keys(this.c)}),_(this,"length",function(){return this.index.length})},k=function(e,t,n,r){return this.u!==this.g&&(this.o=this.o.concat(n),this.u++,r&&this.o.length>=r&&(this.u=this.g),this.u===this.g&&(this.cache&&this.j.set(t,this.o),this.F&&this.F(this.o))),this},I=function(e,t){for(var n=e.length,r=F(t),i=[],o=0,a=0;o=a&&((e=(e=e[l-(i+.5>>0)])[n]||(e[n]=[]))[e.length]=r),i)},N=function(e){for(var t="",n="",r="",i=0;i(e=e.length-t.length)?1:e?-1:0},T=function(e,t){return e=e[P],e<(t=t[P])?-1:e>t?1:0},D=function(e,t){for(var n=P.length,r=0;rt?1:0},L=function(e,t,n){return e?{page:e,next:t?""+t:null,result:n}:n},M=function(e,t,n,r,i,o,a){var l,s=[];if(!0===n){n="0";var c=""}else c=n&&n.split(":");var u=e.length;if(1a&&(c=0),(l=(c=c||0)+t)=this.m.length&&(this.C=0),this.m[this.C].postMessage({add:!0,id:e,content:t}),this.c[o]=""+this.C,n&&n(),this;if(!i){if(this.async&&"function"!=typeof importScripts){var a=this;return(o=new Promise(function(n){setTimeout(function(){a.add(e,t,null,r,!0),a=null,n()})}),n)?(o.then(n),this):o}if(n)return this.add(e,t,null,r,!0),n(),this}if(!(t=this.encode(t)).length)return this;i=F(n=this.f)?n(t):t.split(this.split),this.filter&&(i=I(i,this.filter));var l=U();l._ctx=U();for(var s=i.length,c=this.threshold,u=this.depth,d=this.b,p=this.i,h=this.D,f=0;fv;w--)z(p,l,x=m.substring(v,w),e,y,b,c,d-1)}break;default:if(g=z(p,l,m,e,1,b,c,d-1),u&&1=c)for(g=l._ctx[m]||(l._ctx[m]=U()),m=this.h[m]||(this.h[m]=q(d-(c||0))),0>(b=f-u)&&(b=0),(x=f+u+1)>s&&(x=s);bi;n--)a=o[n-1],o[n]=a,r[a]=n;o[i]=e,r[e]=i}}}return t},j);return O}((r={},i="undefined"!=typeof Blob&&"undefined"!=typeof URL&&URL.createObjectURL,function(e,t,n,o,a){return n=i?URL.createObjectURL(new Blob(["("+n.toString()+")()"],{type:"text/javascript"})):e+".min.js",r[e+="-"+t]||(r[e]=[]),r[e][a]=new Worker(n),r[e][a].onmessage=o,r[e][a]})),l=this,(s=l.define)&&s.amd?s([],function(){return a}):(s=l.modules)?s[o.toLowerCase()]=a:"object"==typeof t?e.exports=a:l[o]=a},8569:function(e,t,n){"use strict";e.exports=function(e,t){for(var n,i,o,a=e||"",l=t||"div",s={},c=0;c=97&&t<=122||t>=65&&t<=90}},99215:function(e,t,n){"use strict";var r=n("21076"),i=n("48935");e.exports=function(e){return r(e)||i(e)}},48935:function(e,t,n){"use strict";e.exports=function(e){var t="string"==typeof e?e.charCodeAt(0):e;return t>=48&&t<=57}},55181:function(e,t,n){"use strict";e.exports=function(e){var t="string"==typeof e?e.charCodeAt(0):e;return t>=97&&t<=102||t>=65&&t<=70||t>=48&&t<=57}},41989:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return p}});var r=n("20891"),i=Object.assign||function(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:{},o=window.Promise||function(e){var t=function(){};e(t,t)},p=function(){for(var e=arguments.length,t=Array(e),n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.target,n=function(){var e={width:document.documentElement.clientWidth,height:document.documentElement.clientHeight,left:0,top:0,right:0,bottom:0},t=void 0,n=void 0;if(y.container){if((0,r._)(y.container,Object))t=(e=i({},e,y.container)).width-e.left-e.right-2*y.margin,n=e.height-e.top-e.bottom-2*y.margin;else{var o=(a(y.container)?y.container:document.querySelector(y.container)).getBoundingClientRect();e=i({},e,{width:o.width,height:o.height,left:o.left,top:o.top})}}t=t||e.width-2*y.margin,n=n||e.height-2*y.margin;var s=w.zoomedHd||w.original,c=l(s)?t:s.naturalWidth||t,u=l(s)?n:s.naturalHeight||n,d=s.getBoundingClientRect(),p=d.top,h=d.left,f=d.width,m=d.height,g=Math.min(Math.min(Math.max(f,c),t)/f,Math.min(Math.max(m,u),n)/m),b=(-h+(t-f)/2+y.margin+e.left)/g,x=(-p+(n-m)/2+y.margin+e.top)/g,v="scale("+g+") translate3d("+b+"px, "+x+"px, 0)";w.zoomed.style.transform=v,w.zoomedHd&&(w.zoomedHd.style.transform=v)};return new o(function(e){if(t&&-1===g.indexOf(t)){e(P);return}if(w.zoomed){e(P);return}if(t)w.original=t;else if(g.length>0){var r=g;w.original=r[0]}else{e(P);return}if(w.original.dispatchEvent(d("medium-zoom:open",{detail:{zoom:P}})),v=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0,x=!0,w.zoomed=u(w.original),document.body.appendChild(j),y.template){var i=a(y.template)?y.template:document.querySelector(y.template);w.template=document.createElement("div"),w.template.appendChild(i.content.cloneNode(!0)),document.body.appendChild(w.template)}if(w.original.parentElement&&"PICTURE"===w.original.parentElement.tagName&&w.original.currentSrc&&(w.zoomed.src=w.original.currentSrc),document.body.appendChild(w.zoomed),window.requestAnimationFrame(function(){document.body.classList.add("medium-zoom--opened")}),w.original.classList.add("medium-zoom-image--hidden"),w.zoomed.classList.add("medium-zoom-image--opened"),w.zoomed.addEventListener("click",f),w.zoomed.addEventListener("transitionend",function t(){x=!1,w.zoomed.removeEventListener("transitionend",t),w.original.dispatchEvent(d("medium-zoom:opened",{detail:{zoom:P}})),e(P)}),w.original.getAttribute("data-zoom-src")){w.zoomedHd=w.zoomed.cloneNode(),w.zoomedHd.removeAttribute("srcset"),w.zoomedHd.removeAttribute("sizes"),w.zoomedHd.removeAttribute("loading"),w.zoomedHd.src=w.zoomed.getAttribute("data-zoom-src"),w.zoomedHd.onerror=function(){clearInterval(o),console.warn("Unable to reach the zoom image target "+w.zoomedHd.src),w.zoomedHd=null,n()};var o=setInterval(function(){w.zoomedHd.complete&&(clearInterval(o),w.zoomedHd.classList.add("medium-zoom-image--opened"),w.zoomedHd.addEventListener("click",f),document.body.appendChild(w.zoomedHd),n())},10)}else if(w.original.hasAttribute("srcset")){w.zoomedHd=w.zoomed.cloneNode(),w.zoomedHd.removeAttribute("sizes"),w.zoomedHd.removeAttribute("loading");var l=w.zoomedHd.addEventListener("load",function(){w.zoomedHd.removeEventListener("load",l),w.zoomedHd.classList.add("medium-zoom-image--opened"),w.zoomedHd.addEventListener("click",f),document.body.appendChild(w.zoomedHd),n()})}else n()})},f=function(){return new o(function(e){if(x||!w.original){e(P);return}x=!0,document.body.classList.remove("medium-zoom--opened"),w.zoomed.style.transform="",w.zoomedHd&&(w.zoomedHd.style.transform=""),w.template&&(w.template.style.transition="opacity 150ms",w.template.style.opacity=0),w.original.dispatchEvent(d("medium-zoom:close",{detail:{zoom:P}})),w.zoomed.addEventListener("transitionend",function t(){w.original.classList.remove("medium-zoom-image--hidden"),document.body.removeChild(w.zoomed),w.zoomedHd&&document.body.removeChild(w.zoomedHd),document.body.removeChild(j),w.zoomed.classList.remove("medium-zoom-image--opened"),w.template&&document.body.removeChild(w.template),x=!1,w.zoomed.removeEventListener("transitionend",t),w.original.dispatchEvent(d("medium-zoom:closed",{detail:{zoom:P}})),w.original=null,w.zoomed=null,w.zoomedHd=null,w.template=null,e(P)})})},m=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.target;return w.original?f():h({target:t})},g=[],b=[],x=!1,v=0,y=n,w={original:null,zoomed:null,zoomedHd:null,template:null};"[object Object]"===Object.prototype.toString.call(t)?y=t:(t||"string"==typeof t)&&p(t);var j=c((y=i({margin:0,background:"#fff",scrollOffset:40,container:null,template:null},y)).background);document.addEventListener("click",function(e){var t=e.target;if(t===j){f();return}-1!==g.indexOf(t)&&m({target:t})}),document.addEventListener("keyup",function(e){var t=e.key||e.keyCode;("Escape"===t||"Esc"===t||27===t)&&f()}),document.addEventListener("scroll",function(){if(!x&&w.original){var e=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0;Math.abs(v-e)>y.scrollOffset&&setTimeout(f,150)}}),window.addEventListener("resize",f);var P={open:h,close:f,toggle:m,update:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e.background&&(j.style.background=e.background),e.container&&(0,r._)(e.container,Object)&&(e.container=i({},y.container,e.container)),e.template){var t=a(e.template)?e.template:document.querySelector(e.template);e.template=t}return y=i({},y,e),g.forEach(function(e){e.dispatchEvent(d("medium-zoom:update",{detail:{zoom:P}}))}),P},clone:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return e(i({},y,t))},attach:p,detach:function(){for(var e=arguments.length,t=Array(e),n=0;n0?t.reduce(function(e,t){return[].concat(e,s(t))},[]):g;return r.forEach(function(e){e.classList.remove("medium-zoom-image"),e.dispatchEvent(d("medium-zoom:detach",{detail:{zoom:P}}))}),g=g.filter(function(e){return -1===r.indexOf(e)}),P},on:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return g.forEach(function(r){r.addEventListener("medium-zoom:"+e,t,n)}),b.push({type:"medium-zoom:"+e,listener:t,options:n}),P},off:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return g.forEach(function(r){r.removeEventListener("medium-zoom:"+e,t,n)}),b=b.filter(function(n){return!(n.type==="medium-zoom:"+e&&n.listener.toString()===t.toString())}),P},getOptions:function(){return y},getImages:function(){return g},getZoomedImage:function(){return w.original}};return P}},42256:function(e,t,n){var r,i;r=this,i=function(){var e,t,n,r,i,o,a,l,s=function(e,t,n){return en?n:e},c=function(e){return(-1+e)*100},u=function(e,t,n){var r;return(r="translate3d"===b.positionUsing?{transform:"translate3d("+c(e)+"%,0,0)"}:"translate"===b.positionUsing?{transform:"translate("+c(e)+"%,0)"}:{"margin-left":c(e)+"%"}).transition="all "+t+"ms "+n,r},d=function(e,t){return("string"==typeof e?e:f(e)).indexOf(" "+t+" ")>=0},p=function(e,t){var n=f(e),r=n+t;!d(n,t)&&(e.className=r.substring(1))},h=function(e,t){var n,r=f(e);d(e,t)&&(n=r.replace(" "+t+" "," "),e.className=n.substring(1,n.length-1))},f=function(e){return(" "+(e.className||"")+" ").replace(/\s+/gi," ")},m=function(e){e&&e.parentNode&&e.parentNode.removeChild(e)},g={};g.version="0.2.0";var b=g.settings={minimum:.08,easing:"ease",positionUsing:"",speed:200,trickle:!0,trickleRate:.02,trickleSpeed:800,showSpinner:!0,barSelector:'[role="bar"]',spinnerSelector:'[role="spinner"]',parent:"body",template:'
                          '};g.configure=function(e){var t,n;for(t in e)void 0!==(n=e[t])&&e.hasOwnProperty(t)&&(b[t]=n);return this},g.status=null,g.set=function(e){var t=g.isStarted();e=s(e,b.minimum,1),g.status=1===e?null:e;var n=g.render(!t),r=n.querySelector(b.barSelector),i=b.speed,o=b.easing;return n.offsetWidth,x(function(t){""===b.positionUsing&&(b.positionUsing=g.getPositioningCSS()),v(r,u(e,i,o)),1===e?(v(n,{transition:"none",opacity:1}),n.offsetWidth,setTimeout(function(){v(n,{transition:"all "+i+"ms linear",opacity:0}),setTimeout(function(){g.remove(),t()},i)},i)):setTimeout(t,i)}),this},g.isStarted=function(){return"number"==typeof g.status},g.start=function(){!g.status&&g.set(0);var e=function(){setTimeout(function(){g.status&&(g.trickle(),e())},b.trickleSpeed)};return b.trickle&&e(),this},g.done=function(e){return e||g.status?g.inc(.3+.5*Math.random()).set(1):this},g.inc=function(e){var t=g.status;return t?("number"!=typeof e&&(e=(1-t)*s(Math.random()*t,.1,.95)),t=s(t+e,0,.994),g.set(t)):g.start()},g.trickle=function(){return g.inc(Math.random()*b.trickleRate)},e=0,t=0,g.promise=function(n){return n&&"resolved"!==n.state()?(0===t&&g.start(),e++,t++,n.always(function(){0==--t?(e=0,g.done()):g.set((e-t)/e)}),this):this},g.render=function(e){if(g.isRendered())return document.getElementById("nprogress");p(document.documentElement,"nprogress-busy");var t=document.createElement("div");t.id="nprogress",t.innerHTML=b.template;var n,r=t.querySelector(b.barSelector),i=e?"-100":c(g.status||0),o=document.querySelector(b.parent);return v(r,{transition:"all 0 linear",transform:"translate3d("+i+"%,0,0)"}),!b.showSpinner&&(n=t.querySelector(b.spinnerSelector))&&m(n),o!=document.body&&p(o,"nprogress-custom-parent"),o.appendChild(t),t},g.remove=function(){h(document.documentElement,"nprogress-busy"),h(document.querySelector(b.parent),"nprogress-custom-parent");var e=document.getElementById("nprogress");e&&m(e)},g.isRendered=function(){return!!document.getElementById("nprogress")},g.getPositioningCSS=function(){var e=document.body.style,t="WebkitTransform"in e?"Webkit":"MozTransform"in e?"Moz":"msTransform"in e?"ms":"OTransform"in e?"O":"";return t+"Perspective" in e?"translate3d":t+"Transform" in e?"translate":"margin"};var x=(n=[],function(e){n.push(e),1==n.length&&!function e(){var t=n.shift();t&&t(e)}()});var v=(r=function(e){var t=document.body.style;if(e in t)return e;for(var n,r=a.length,i=e.charAt(0).toUpperCase()+e.slice(1);r--;)if((n=a[r]+i)in t)return n;return e},i=function(e){return l[e=e.replace(/^-ms-/,"ms-").replace(/-([\da-z])/gi,function(e,t){return t.toUpperCase()})]||(l[e]=r(e))},o=function(e,t,n){t=i(t),e.style[t]=n},a=["Webkit","O","Moz","ms"],l={},function(e,t){var n,r,i=arguments;if(2==i.length)for(n in t)void 0!==(r=t[n])&&t.hasOwnProperty(n)&&o(e,n,r);else o(e,i[1],i[2])});return g},"function"==typeof define&&define.amd?define(i):"object"==typeof t?e.exports=i():r.NProgress=i()},54178:function(e,t,n){"use strict";var r,i=59;e.exports=function(e){var t,n="&"+e+";";return(r=r||document.createElement("i")).innerHTML=n,((t=r.textContent).charCodeAt(t.length-1)!==i||"semi"===e)&&t!==n&&t}},63716:function(e,t,n){"use strict";var r=function(e,t){var n,r,s,c,m,H,W,q,U,$,G,V,Z,Y,X,K,Q,J,ee,et=t.additional,en=t.nonTerminated,er=t.text,ei=t.reference,eo=t.warning,ea=t.textContext,el=t.referenceContext,es=t.warningContext,ec=t.position,eu=t.indent||[],ed=e.length,ep=0,eh=-1,ef=ec.column||1,em=ec.line||1,eg="",eb=[];for("string"==typeof et&&(et=et.charCodeAt(0)),K=ex(),q=eo?function(e,t){var n=ex();n.column+=t,n.offset+=t,eo.call(es,F[e],n,e)}:f,ep--,ed++;++ep65535&&(H-=65536,$+=h(H>>>10|55296),H=56320|1023&H),H=$+h(H))):Y!==_&&q(L,J);H?(ev(),K=ex(),ep=ee-1,ef+=ee-Z+1,eb.push(H),Q=ex(),Q.offset++,ei&&ei.call(el,H,{start:K,end:Q},e.slice(Z-1,ee)),K=Q):(c=e.slice(Z-1,ee),eg+=c,ef+=c.length,ep=ee-1)}else 10===m&&(em++,eh++,ef=0),m==m?(eg+=h(m),ef++):ev();return eb.join("");function ex(){return{line:em,column:ef,offset:ep+(ec.offset||0)}}function ev(){eg&&(eb.push(eg),er&&er.call(ea,eg,{start:K,end:ex()}),eg="")}},i=function(e){return e>=55296&&e<=57343||e>1114111},o=function(e){return e>=1&&e<=8||11===e||e>=13&&e<=31||e>=127&&e<=159||e>=64976&&e<=65007||(65535&e)==65535||(65535&e)==65534},a=n("66428"),l=n("20165"),s=n("48935"),c=n("55181"),u=n("99215"),d=n("54178");e.exports=function(e,t){var n,i,o={};for(i in!t&&(t={}),m)n=t[i],o[i]=null==n?m[i]:n;return(o.position.indent||o.position.start)&&(o.indent=o.position.indent||[],o.position=o.position.start),r(e,o)};var p={}.hasOwnProperty,h=String.fromCharCode,f=Function.prototype,m={warning:null,reference:null,text:null,warningContext:null,referenceContext:null,textContext:null,position:{},additional:null,attribute:!1,nonTerminated:!0},g=9,b=10,x=12,v=32,y=38,w=59,j=60,P=61,O=35,k=88,I=120,S=65533,_="named",E="hexadecimal",C="decimal",z={};z[E]=16,z[C]=10;var N={};N[_]=u,N[C]=s,N[E]=c;var A=1,T=2,D=3,L=4,M=5,R=6,B=7,F={};F[1]="Named character references must be terminated by a semicolon",F[T]="Numeric character references must be terminated by a semicolon",F[D]="Named character references cannot be empty",F[L]="Numeric character references cannot be empty",F[M]="Named character references must be known",F[R]="Numeric character references cannot be disallowed",F[B]="Numeric character references cannot be outside the permissible Unicode range"},62920:function(e,t,n){e=n.nmd(e);var r=n("20891"),i=function(e){var t=function(e,t,n,r){this.type=e,this.content=t,this.alias=n,this.length=0|(r||"").length},n=function(e,t,n,r){e.lastIndex=t;var i=e.exec(n);if(i&&r&&i[1]){var o=i[1].length;i.index+=o,i[0]=i[0].slice(o)}return i},i=function(){var e={value:null,prev:null,next:null},t={value:null,prev:e,next:null};e.next=t,this.head=e,this.tail=t,this.length=0},o=function(e,t,n){var r=t.next,i={value:n,prev:t,next:r};return t.next=i,r.prev=i,e.length++,i},a=function(e,t,n){for(var r=t.next,i=0;i=d.reach));O+=P.value.length,P=P.next){var k,I=P.value;if(l.length>i.length)return;if(!r._(I,t)){var S=1;if(v){if(!(k=n(j,O,i,x))||k.index>=i.length)break;var _=k.index,E=k.index+k[0].length,C=O;for(C+=P.value.length;_>=C;)C+=(P=P.next).value.length;if(C-=P.value.length,O=C,r._(P.value,t))continue;for(var z=P;z!==l.tail&&(Cd.reach&&(d.reach=D);var L=P.prev;if(A&&(L=o(l,L,A),O+=A.length),a(l,L,S),P=o(l,L,new t(h,b?p.tokenize(N,b):N,y,N)),T&&o(l,P,T),S>1){var M={cause:h+","+m,reach:D};e(i,l,s,P.prev,O,M),d&&M.reach>d.reach&&(d.reach=M.reach)}}}}}}(e,d,s,d.head,0),l(d)},hooks:{all:{},add:function(e,t){var n=p.hooks.all;n[e]=n[e]||[],n[e].push(t)},run:function(e,t){var n=p.hooks.all[e];if(n&&n.length)for(var r,i=0;r=n[i++];)r(t)}},Token:t};e.Prism=p,t.stringify=function e(t,n){if("string"==typeof t)return t;if(Array.isArray(t)){var r="";return t.forEach(function(t){r+=e(t,n)}),r}var i={type:t.type,content:e(t.content,n),tag:"span",classes:["token",t.type],attributes:{},language:n},o=t.alias;o&&(Array.isArray(o)?Array.prototype.push.apply(i.classes,o):i.classes.push(o)),p.hooks.run("wrap",i);var a="";for(var l in i.attributes)a+=" "+l+'="'+(i.attributes[l]||"").replace(/"/g,""")+'"';return"<"+i.tag+' class="'+i.classes.join(" ")+'"'+a+">"+i.content+""};if(!e.document)return e.addEventListener?(!p.disableWorkerMessageHandler&&e.addEventListener("message",function(t){var n=JSON.parse(t.data),r=n.language,i=n.code,o=n.immediateClose;e.postMessage(p.highlight(i,p.languages[r],r)),o&&e.close()},!1),p):p;var h=p.util.currentScript();if(h&&(p.filename=h.src,h.hasAttribute("data-manual")&&(p.manual=!0)),!p.manual){var f=document.readyState;"loading"===f||"interactive"===f&&h&&h.defer?document.addEventListener("DOMContentLoaded",s):window.requestAnimationFrame?window.requestAnimationFrame(s):window.setTimeout(s,16)}return p}("undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&r._(self,WorkerGlobalScope)?self:{});void 0!==e&&e.exports&&(e.exports=i),void 0!==n.g&&(n.g.Prism=i)},88154:function(e,t,n){"use strict";var r=function(){},i=function(){},o=n("11585");i.resetWarningCache=r,e.exports=function(){var e=function(e,t,n,r,i,a){if(a!==o){var l=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw l.name="Invariant Violation",l}},t=function(){return e};e.isRequired=e;var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:r};return n.PropTypes=n,n}},47459:function(e,t,n){e.exports=n("88154")()},11585:function(e,t,n){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},31368:function(e,t,n){"use strict";var r=function(e){var t=e.slice(5).replace(p,a);return u+t.charAt(0).toUpperCase()+t.slice(1)},i=function(e){var t=e.slice(4);return p.test(t)?e:("-"!==(t=t.replace(h,o)).charAt(0)&&(t="-"+t),u+t)},o=function(e){return"-"+e.toLowerCase()},a=function(e){return e.charAt(1).toUpperCase()},l=n("95322"),s=n("52987"),c=n("82558"),u="data";e.exports=function(e,t){var n=l(t),o=t,a=c;return n in e.normal?e.property[e.normal[n]]:(n.length>4&&n.slice(0,4)===u&&d.test(t)&&("-"===t.charAt(4)?o=r(t):t=i(t),a=s),new a(o,t))};var d=/^data[-\w.:]+$/i,p=/-[a-z]/g,h=/[A-Z]/g},71236:function(e,t,n){"use strict";var r=n("70541"),i=n("87043"),o=n("96690"),a=n("26605"),l=n("40096"),s=n("40051");e.exports=r([o,i,a,l,s])},40096:function(e,t,n){"use strict";var r=n("8532"),i=n("49402"),o=r.booleanish,a=r.number,l=r.spaceSeparated;e.exports=i({transform:function(e,t){return"role"===t?t:"aria-"+t.slice(4).toLowerCase()},properties:{ariaActiveDescendant:null,ariaAtomic:o,ariaAutoComplete:null,ariaBusy:o,ariaChecked:o,ariaColCount:a,ariaColIndex:a,ariaColSpan:a,ariaControls:l,ariaCurrent:null,ariaDescribedBy:l,ariaDetails:null,ariaDisabled:o,ariaDropEffect:l,ariaErrorMessage:null,ariaExpanded:o,ariaFlowTo:l,ariaGrabbed:o,ariaHasPopup:null,ariaHidden:o,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:l,ariaLevel:a,ariaLive:null,ariaModal:o,ariaMultiLine:o,ariaMultiSelectable:o,ariaOrientation:null,ariaOwns:l,ariaPlaceholder:null,ariaPosInSet:a,ariaPressed:o,ariaReadOnly:o,ariaRelevant:null,ariaRequired:o,ariaRoleDescription:l,ariaRowCount:a,ariaRowIndex:a,ariaRowSpan:a,ariaSelected:o,ariaSetSize:a,ariaSort:null,ariaValueMax:a,ariaValueMin:a,ariaValueNow:a,ariaValueText:null,role:null}})},40051:function(e,t,n){"use strict";var r=n("8532"),i=n("49402"),o=n("14890"),a=r.boolean,l=r.overloadedBoolean,s=r.booleanish,c=r.number,u=r.spaceSeparated,d=r.commaSeparated;e.exports=i({space:"html",attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},transform:o,mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:d,acceptCharset:u,accessKey:u,action:null,allow:null,allowFullScreen:a,allowPaymentRequest:a,allowUserMedia:a,alt:null,as:null,async:a,autoCapitalize:null,autoComplete:u,autoFocus:a,autoPlay:a,capture:a,charSet:null,checked:a,cite:null,className:u,cols:c,colSpan:null,content:null,contentEditable:s,controls:a,controlsList:u,coords:c|d,crossOrigin:null,data:null,dateTime:null,decoding:null,default:a,defer:a,dir:null,dirName:null,disabled:a,download:l,draggable:s,encType:null,enterKeyHint:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:a,formTarget:null,headers:u,height:c,hidden:a,high:c,href:null,hrefLang:null,htmlFor:u,httpEquiv:u,id:null,imageSizes:null,imageSrcSet:d,inputMode:null,integrity:null,is:null,isMap:a,itemId:null,itemProp:u,itemRef:u,itemScope:a,itemType:u,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:a,low:c,manifest:null,max:null,maxLength:c,media:null,method:null,min:null,minLength:c,multiple:a,muted:a,name:null,nonce:null,noModule:a,noValidate:a,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforePrint:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextMenu:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:a,optimum:c,pattern:null,ping:u,placeholder:null,playsInline:a,poster:null,preload:null,readOnly:a,referrerPolicy:null,rel:u,required:a,reversed:a,rows:c,rowSpan:c,sandbox:u,scope:null,scoped:a,seamless:a,selected:a,shape:null,size:c,sizes:null,slot:null,span:c,spellCheck:s,src:null,srcDoc:null,srcLang:null,srcSet:d,start:c,step:null,style:null,tabIndex:c,target:null,title:null,translate:null,type:null,typeMustMatch:a,useMap:null,value:s,width:c,wrap:null,align:null,aLink:null,archive:u,axis:null,background:null,bgColor:null,border:c,borderColor:null,bottomMargin:c,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:a,declare:a,event:null,face:null,frame:null,frameBorder:null,hSpace:c,leftMargin:c,link:null,longDesc:null,lowSrc:null,marginHeight:c,marginWidth:c,noResize:a,noHref:a,noShade:a,noWrap:a,object:null,profile:null,prompt:null,rev:null,rightMargin:c,rules:null,scheme:null,scrolling:s,standby:null,summary:null,text:null,topMargin:c,valueType:null,version:null,vAlign:null,vLink:null,vSpace:c,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:a,disableRemotePlayback:a,prefix:null,property:null,results:c,security:null,unselectable:null}})},14890:function(e,t,n){"use strict";var r=n("83379");e.exports=function(e,t){return r(e,t.toLowerCase())}},83379:function(e,t,n){"use strict";e.exports=function(e,t){return t in e?e[t]:t}},49402:function(e,t,n){"use strict";var r=n("95322"),i=n("23707"),o=n("52987");e.exports=function(e){var t,n,a=e.space,l=e.mustUseProperty||[],s=e.attributes||{},c=e.properties,u=e.transform,d={},p={};for(t in c)n=new o(t,u(s,t),c[t],a),-1!==l.indexOf(t)&&(n.mustUseProperty=!0),d[t]=n,p[r(t)]=t,p[r(n.attribute)]=t;return new i(d,p,a)}},52987:function(e,t,n){"use strict";var r=function(e,t,n,r){var c,u=-1;for(i(this,"space",r),o.call(this,e,t);++u=0||(i[n]=e[n]);return i}var k={BASE:"base",BODY:"body",HEAD:"head",HTML:"html",LINK:"link",META:"meta",NOSCRIPT:"noscript",SCRIPT:"script",STYLE:"style",TITLE:"title",FRAGMENT:"Symbol(react.fragment)"},I={rel:["amphtml","canonical","alternate"]},S={type:["application/ld+json"]},_={charset:"",name:["robots","description"],property:["og:type","og:title","og:url","og:image","og:image:alt","og:description","twitter:url","twitter:title","twitter:description","twitter:image","twitter:image:alt","twitter:card","twitter:site"]},E=Object.keys(k).map(function(e){return k[e]}),C={accesskey:"accessKey",charset:"charSet",class:"className",contenteditable:"contentEditable",contextmenu:"contextMenu","http-equiv":"httpEquiv",itemprop:"itemProp",tabindex:"tabIndex"},z=Object.keys(C).reduce(function(e,t){return e[C[t]]=t,e},{}),N=function(e,t){for(var n=e.length-1;n>=0;n-=1){var r=e[n];if(Object.prototype.hasOwnProperty.call(r,t))return r[t]}return null},A=function(e){var t=N(e,k.TITLE),n=N(e,"titleTemplate");if(Array.isArray(t)&&(t=t.join("")),n&&t)return n.replace(/%s/g,function(){return t});var r=N(e,"defaultTitle");return t||r||void 0},T=function(e,t){return t.filter(function(t){return void 0!==t[e]}).map(function(t){return t[e]}).reduce(function(e,t){return w({},e,t)},{})},D=function(e,t,n){var r={};return n.filter(function(t){return!!Array.isArray(t[e])||(void 0!==t[e]&&console&&"function"==typeof console.warn&&console.warn("Helmet: "+e+' should be of type "Array". Instead found type "'+(0,u._)(t[e])+'"'),!1)}).map(function(t){return t[e]}).reverse().reduce(function(e,n){var i={};n.filter(function(e){for(var n,o=Object.keys(e),a=0;a/g,">").replace(/"/g,""").replace(/'/g,"'")},W=function(e){return Object.keys(e).reduce(function(t,n){var r=void 0!==e[n]?n+'="'+e[n]+'"':""+n;return t?t+" "+r:r},"")},q=function(e,t){return void 0===t&&(t={}),Object.keys(e).reduce(function(t,n){return t[C[n]||n]=e[n],t},t)},U=function(e,t){return t.map(function(t,n){var r,i=((r={key:n})["data-rh"]=!0,r);return Object.keys(t).forEach(function(e){var n=C[e]||e;"innerHTML"===n||"cssText"===n?i.dangerouslySetInnerHTML={__html:t.innerHTML||t.cssText}:i[n]=t[e]}),p.createElement(e,i)})},$=function(e,t,n){switch(e){case k.TITLE:return{toComponent:function(){var e,n,r,i;return n=t.titleAttributes,(r={key:e=t.title})["data-rh"]=!0,i=q(n,r),[p.createElement(k.TITLE,i,e)]},toString:function(){var r,i,o,a,l,s;return r=e,i=t.title,o=t.titleAttributes,a=n,l=W(o),s=M(i),l?"<"+r+' data-rh="true" '+l+">"+H(s,a)+"":"<"+r+' data-rh="true">'+H(s,a)+""}};case"bodyAttributes":case"htmlAttributes":return{toComponent:function(){return q(t)},toString:function(){return W(t)}};default:return{toComponent:function(){return U(e,t)},toString:function(){var r,i,o;return r=e,i=t,o=n,i.reduce(function(e,t){var n=Object.keys(t).filter(function(e){return!("innerHTML"===e||"cssText"===e)}).reduce(function(e,n){var r=void 0===t[n]?n:n+'="'+H(t[n],o)+'"';return e?e+" "+r:r},""),i=t.innerHTML||t.cssText||"",a=-1===F.indexOf(r);return e+"<"+r+' data-rh="true" '+n+(a?"/>":">"+i+"")},"")}}}},G=function(e){var t=e.baseTag,n=e.bodyAttributes,r=e.encode,i=e.htmlAttributes,o=e.noscriptTags,a=e.styleTags,l=e.title,s=e.titleAttributes,c=e.linkTags,u=e.metaTags,d=e.scriptTags,p={toComponent:function(){},toString:function(){return""}};if(e.prioritizeSeoTags){var h,f,m,g,b,x,v,y=(f=(h=e).linkTags,m=h.scriptTags,g=h.encode,b=R(h.metaTags,_),x=R(f,I),v=R(m,S),{priorityMethods:{toComponent:function(){return[].concat(U(k.META,b.priority),U(k.LINK,x.priority),U(k.SCRIPT,v.priority))},toString:function(){return $(k.META,b.priority,g)+" "+$(k.LINK,x.priority,g)+" "+$(k.SCRIPT,v.priority,g)}},metaTags:b.default,linkTags:x.default,scriptTags:v.default});p=y.priorityMethods,c=y.linkTags,u=y.metaTags,d=y.scriptTags}return{priority:p,base:$(k.BASE,t,r),bodyAttributes:$("bodyAttributes",n,r),htmlAttributes:$("htmlAttributes",i,r),link:$(k.LINK,c,r),meta:$(k.META,u,r),noscript:$(k.NOSCRIPT,o,r),script:$(k.SCRIPT,d,r),style:$(k.STYLE,a,r),title:$(k.TITLE,{title:void 0===l?"":l,titleAttributes:s},r)}},V=[],Z=function(e,t){var n=this;void 0===t&&(t="undefined"!=typeof document),this.instances=[],this.value={setHelmet:function(e){n.context.helmet=e},helmetInstances:{get:function(){return n.canUseDOM?V:n.instances},add:function(e){(n.canUseDOM?V:n.instances).push(e)},remove:function(e){var t=(n.canUseDOM?V:n.instances).indexOf(e);(n.canUseDOM?V:n.instances).splice(t,1)}}},this.context=e,this.canUseDOM=t,t||(e.helmet=G({baseTag:[],bodyAttributes:{},encodeSpecialCharacters:!0,htmlAttributes:{},linkTags:[],metaTags:[],noscriptTags:[],scriptTags:[],styleTags:[],title:"",titleAttributes:{}}))},Y=p.createContext({}),X=f.shape({setHelmet:f.func,helmetInstances:f.shape({get:f.func,add:f.func,remove:f.func})}),K="undefined"!=typeof document,Q=function(e){function t(n){var r;return(r=e.call(this,n)||this).helmetData=new Z(r.props.context,t.canUseDOM),r}return j(t,e),t.prototype.render=function(){return p.createElement(Y.Provider,{value:this.helmetData.value},this.props.children)},t}(d.Component);Q.canUseDOM=K,Q.propTypes={context:f.shape({helmet:f.shape()}),children:f.node.isRequired},Q.defaultProps={context:{}},Q.displayName="HelmetProvider";var J=function(e,t){var n,r=document.head||document.querySelector(k.HEAD),i=r.querySelectorAll(e+"[data-rh]"),o=[].slice.call(i),a=[];return t&&t.length&&t.forEach(function(t){var r=document.createElement(e);for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&("innerHTML"===i?r.innerHTML=t.innerHTML:"cssText"===i?r.styleSheet?r.styleSheet.cssText=t.cssText:r.appendChild(document.createTextNode(t.cssText)):r.setAttribute(i,void 0===t[i]?"":t[i]));r.setAttribute("data-rh","true"),o.some(function(e,t){return n=t,r.isEqualNode(e)})?o.splice(n,1):a.push(r)}),o.forEach(function(e){return e.parentNode.removeChild(e)}),a.forEach(function(e){return r.appendChild(e)}),{oldTags:o,newTags:a}},ee=function(e,t){var n=document.getElementsByTagName(e)[0];if(n){for(var r=n.getAttribute("data-rh"),i=r?r.split(","):[],o=[].concat(i),a=Object.keys(t),l=0;l=0;d-=1)n.removeAttribute(o[d]);i.length===o.length?n.removeAttribute("data-rh"):n.getAttribute("data-rh")!==a.join(",")&&n.setAttribute("data-rh",a.join(","))}},et=function(e,t){var n,r,i=e.baseTag,o=e.htmlAttributes,a=e.linkTags,l=e.metaTags,s=e.noscriptTags,c=e.onChangeClientState,u=e.scriptTags,d=e.styleTags,p=e.title,h=e.titleAttributes;ee(k.BODY,e.bodyAttributes),ee(k.HTML,o),n=p,r=h,void 0!==n&&document.title!==n&&(document.title=M(n)),ee(k.TITLE,r);var f={baseTag:J(k.BASE,i),linkTags:J(k.LINK,a),metaTags:J(k.META,l),noscriptTags:J(k.NOSCRIPT,s),scriptTags:J(k.SCRIPT,u),styleTags:J(k.STYLE,d)},m={},g={};Object.keys(f).forEach(function(e){var t=f[e],n=t.newTags,r=t.oldTags;n.length&&(m[e]=n),r.length&&(g[e]=f[e].oldTags)}),t&&t(),c(e,m,g)},en=null,er=(r=d.Component,j(i=function(){for(var e,t=arguments.length,n=Array(t),i=0;i elements are self-closing and can not contain children. Refer to our API for more information.")}},s.flattenArrayTypeChildren=function(e){var t,n=e.child,r=e.arrayTypeChildren;return w({},r,((t={})[n.type]=[].concat(r[n.type]||[],[w({},e.newChildProps,this.mapNestedChildrenToProps(n,e.nestedChildren))]),t))},s.mapObjectTypeChildren=function(e){var t,n,r=e.child,i=e.newProps,o=e.newChildProps,a=e.nestedChildren;switch(r.type){case k.TITLE:return w({},i,((t={})[r.type]=a,t.titleAttributes=w({},o),t));case k.BODY:return w({},i,{bodyAttributes:w({},o)});case k.HTML:return w({},i,{htmlAttributes:w({},o)});default:return w({},i,((n={})[r.type]=w({},o),n))}},s.mapArrayTypeChildrenToProps=function(e,t){var n=w({},t);return Object.keys(e).forEach(function(t){var r;n=w({},n,((r={})[t]=e[t],r))}),n},s.warnOnInvalidChildren=function(e,t){return x(E.some(function(t){return e.type===t}),"function"==typeof e.type?"You may be attempting to nest components within each other, which is not allowed. Refer to our API for more information.":"Only elements types "+E.join(", ")+" are allowed. Helmet does not support rendering <"+e.type+"> elements. Refer to our API for more information."),x(!t||"string"==typeof t||Array.isArray(t)&&!t.some(function(e){return"string"!=typeof e}),"Helmet expects a string as a child of <"+e.type+">. Did you forget to wrap your children in braces? ( <"+e.type+">{``} ) Refer to our API for more information."),!0},s.mapChildrenToProps=function(e,t){var n=this,r={};return p.Children.forEach(e,function(e){if(e&&e.props){var i=e.props,o=i.children,a=O(i,ei),l=Object.keys(a).reduce(function(e,t){return e[z[t]||t]=a[t],e},{}),s=e.type;switch("symbol"==(void 0===s?"undefined":(0,u._)(s))?s=s.toString():n.warnOnInvalidChildren(e,o),s){case k.FRAGMENT:t=n.mapChildrenToProps(o,t);break;case k.LINK:case k.META:case k.NOSCRIPT:case k.SCRIPT:case k.STYLE:r=n.flattenArrayTypeChildren({child:e,arrayTypeChildren:r,newChildProps:l,nestedChildren:o});break;default:t=n.mapObjectTypeChildren({child:e,newProps:t,newChildProps:l,nestedChildren:o})}}}),this.mapArrayTypeChildrenToProps(r,t)},s.render=function(){var e=this.props,t=e.children,n=O(e,eo),r=w({},n),i=n.helmetData;return t&&(r=this.mapChildrenToProps(t,r)),!i||(0,c._)(i,Z)||(i=new Z(i.context,i.instances)),i?p.createElement(er,w({},r,{context:i.value,helmetData:void 0})):p.createElement(Y.Consumer,null,function(e){return p.createElement(er,w({},r,{context:e}))})},l);ea.propTypes={base:f.object,bodyAttributes:f.object,children:f.oneOfType([f.arrayOf(f.node),f.node]),defaultTitle:f.string,defer:f.bool,encodeSpecialCharacters:f.bool,htmlAttributes:f.object,link:f.arrayOf(f.object),meta:f.arrayOf(f.object),noscript:f.arrayOf(f.object),onChangeClientState:f.func,script:f.arrayOf(f.object),style:f.arrayOf(f.object),title:f.string,titleAttributes:f.object,titleTemplate:f.string,prioritizeSeoTags:f.bool,helmetData:f.object},ea.defaultProps={defer:!0,encodeSpecialCharacters:!0,prioritizeSeoTags:!1},ea.displayName="Helmet"},89440:function(e,t,n){"use strict";var r=function(e){var t,n,r=(0,i.lazy)(e),o=(0,i.forwardRef)(function(e,n){var o=(0,i.useRef)(null!=t?t:r);return(0,i.createElement)(o.current,Object.assign(n?{ref:n}:{},e))});return o.preload=function(){return!n&&(n=e().then(function(e){return t=e.default})),n},o};Object.defineProperty(t,"__esModule",{value:!0}),t.lazyWithPreload=void 0;var i=n("57814");t.lazyWithPreload=r,t.default=r},10606:function(e,t,n){"use strict";function r(e,t){return -1!==e.listLanguages().indexOf(t)}n.r(t),n.d(t,{default:function(){return r}})},7873:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return d}});var r=n("44358"),i=n("71257"),o=n("57814"),a=n.n(o);function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function s(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;return(function(e){if(0===e.length||1===e.length)return e;var t,n,r=e.join(".");if(!c[r]){;c[r]=0===(n=(t=e).length)||1===n?t:2===n?[t[0],t[1],"".concat(t[0],".").concat(t[1]),"".concat(t[1],".").concat(t[0])]:3===n?[t[0],t[1],t[2],"".concat(t[0],".").concat(t[1]),"".concat(t[0],".").concat(t[2]),"".concat(t[1],".").concat(t[0]),"".concat(t[1],".").concat(t[2]),"".concat(t[2],".").concat(t[0]),"".concat(t[2],".").concat(t[1]),"".concat(t[0],".").concat(t[1],".").concat(t[2]),"".concat(t[0],".").concat(t[2],".").concat(t[1]),"".concat(t[1],".").concat(t[0],".").concat(t[2]),"".concat(t[1],".").concat(t[2],".").concat(t[0]),"".concat(t[2],".").concat(t[0],".").concat(t[1]),"".concat(t[2],".").concat(t[1],".").concat(t[0])]:n>=4?[t[0],t[1],t[2],t[3],"".concat(t[0],".").concat(t[1]),"".concat(t[0],".").concat(t[2]),"".concat(t[0],".").concat(t[3]),"".concat(t[1],".").concat(t[0]),"".concat(t[1],".").concat(t[2]),"".concat(t[1],".").concat(t[3]),"".concat(t[2],".").concat(t[0]),"".concat(t[2],".").concat(t[1]),"".concat(t[2],".").concat(t[3]),"".concat(t[3],".").concat(t[0]),"".concat(t[3],".").concat(t[1]),"".concat(t[3],".").concat(t[2]),"".concat(t[0],".").concat(t[1],".").concat(t[2]),"".concat(t[0],".").concat(t[1],".").concat(t[3]),"".concat(t[0],".").concat(t[2],".").concat(t[1]),"".concat(t[0],".").concat(t[2],".").concat(t[3]),"".concat(t[0],".").concat(t[3],".").concat(t[1]),"".concat(t[0],".").concat(t[3],".").concat(t[2]),"".concat(t[1],".").concat(t[0],".").concat(t[2]),"".concat(t[1],".").concat(t[0],".").concat(t[3]),"".concat(t[1],".").concat(t[2],".").concat(t[0]),"".concat(t[1],".").concat(t[2],".").concat(t[3]),"".concat(t[1],".").concat(t[3],".").concat(t[0]),"".concat(t[1],".").concat(t[3],".").concat(t[2]),"".concat(t[2],".").concat(t[0],".").concat(t[1]),"".concat(t[2],".").concat(t[0],".").concat(t[3]),"".concat(t[2],".").concat(t[1],".").concat(t[0]),"".concat(t[2],".").concat(t[1],".").concat(t[3]),"".concat(t[2],".").concat(t[3],".").concat(t[0]),"".concat(t[2],".").concat(t[3],".").concat(t[1]),"".concat(t[3],".").concat(t[0],".").concat(t[1]),"".concat(t[3],".").concat(t[0],".").concat(t[2]),"".concat(t[3],".").concat(t[1],".").concat(t[0]),"".concat(t[3],".").concat(t[1],".").concat(t[2]),"".concat(t[3],".").concat(t[2],".").concat(t[0]),"".concat(t[3],".").concat(t[2],".").concat(t[1]),"".concat(t[0],".").concat(t[1],".").concat(t[2],".").concat(t[3]),"".concat(t[0],".").concat(t[1],".").concat(t[3],".").concat(t[2]),"".concat(t[0],".").concat(t[2],".").concat(t[1],".").concat(t[3]),"".concat(t[0],".").concat(t[2],".").concat(t[3],".").concat(t[1]),"".concat(t[0],".").concat(t[3],".").concat(t[1],".").concat(t[2]),"".concat(t[0],".").concat(t[3],".").concat(t[2],".").concat(t[1]),"".concat(t[1],".").concat(t[0],".").concat(t[2],".").concat(t[3]),"".concat(t[1],".").concat(t[0],".").concat(t[3],".").concat(t[2]),"".concat(t[1],".").concat(t[2],".").concat(t[0],".").concat(t[3]),"".concat(t[1],".").concat(t[2],".").concat(t[3],".").concat(t[0]),"".concat(t[1],".").concat(t[3],".").concat(t[0],".").concat(t[2]),"".concat(t[1],".").concat(t[3],".").concat(t[2],".").concat(t[0]),"".concat(t[2],".").concat(t[0],".").concat(t[1],".").concat(t[3]),"".concat(t[2],".").concat(t[0],".").concat(t[3],".").concat(t[1]),"".concat(t[2],".").concat(t[1],".").concat(t[0],".").concat(t[3]),"".concat(t[2],".").concat(t[1],".").concat(t[3],".").concat(t[0]),"".concat(t[2],".").concat(t[3],".").concat(t[0],".").concat(t[1]),"".concat(t[2],".").concat(t[3],".").concat(t[1],".").concat(t[0]),"".concat(t[3],".").concat(t[0],".").concat(t[1],".").concat(t[2]),"".concat(t[3],".").concat(t[0],".").concat(t[2],".").concat(t[1]),"".concat(t[3],".").concat(t[1],".").concat(t[0],".").concat(t[2]),"".concat(t[3],".").concat(t[1],".").concat(t[2],".").concat(t[0]),"".concat(t[3],".").concat(t[2],".").concat(t[0],".").concat(t[1]),"".concat(t[3],".").concat(t[2],".").concat(t[1],".").concat(t[0])]:void 0}return c[r]})(e.filter(function(e){return"token"!==e})).reduce(function(e,t){return s(s({},e),n[t])},t)}(u.className,Object.assign({},u.style,void 0===i?{}:i),n)})}else x=s(s({},u),{},{className:u.className.join(" ")});var P=v(t.children);return a.createElement(h,(0,r.default)({key:l},x),P)}}},3197:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return y}});var r=n("23093"),i=n("77165"),o=n("71257"),a=n("57814"),l=n.n(a),s=n("7873"),c=n("10606"),u=["language","children","style","customStyle","codeTagProps","useInlineStyles","showLineNumbers","showInlineLineNumbers","startingLineNumber","lineNumberContainerStyle","lineNumberStyle","wrapLines","wrapLongLines","lineProps","renderer","PreTag","CodeTag","code","astGenerator"];function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function p(e){for(var t=1;t2&&void 0!==arguments[2]?arguments[2]:[];return b({children:e,lineNumber:t,lineNumberStyle:s,largestLineNumber:l,showInlineLineNumbers:o,lineProps:n,className:i,showLineNumbers:r,wrapLongLines:c})},p=function(e,t){if(r&&t&&o){var n=g(s,t,l);e.unshift(m(t,n))}return e},f=function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return t||r.length>0?d(e,n,r):p(e,n)},x=function e(t){for(var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],o=0;o>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,punctuation:/\(\(?|\)\)?|,|;/}},{pattern:/\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,greedy:!0,inside:{variable:/^\$\(|^`|\)$|`$/}},{pattern:/\$\{[^}]+\}/,greedy:!0,inside:{operator:/:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,punctuation:/[\[\]]/,environment:{pattern:RegExp("(\\{)"+t),lookbehind:!0,alias:"constant"}}},/\$(?:\w+|[#?*!@$])/],entity:/\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{1,2})/};e.languages.bash={shebang:{pattern:/^#!\s*\/.*/,alias:"important"},comment:{pattern:/(^|[^"{\\$])#.*/,lookbehind:!0},"function-name":[{pattern:/(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,lookbehind:!0,alias:"function"},{pattern:/\b[\w-]+(?=\s*\(\s*\)\s*\{)/,alias:"function"}],"for-or-select":{pattern:/(\b(?:for|select)\s+)\w+(?=\s+in\s)/,alias:"variable",lookbehind:!0},"assign-left":{pattern:/(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,inside:{environment:{pattern:RegExp("(^|[\\s;|&]|[<>]\\()"+t),lookbehind:!0,alias:"constant"}},alias:"variable",lookbehind:!0},string:[{pattern:/((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/,lookbehind:!0,greedy:!0,inside:r},{pattern:/((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,lookbehind:!0,greedy:!0,inside:{bash:n}},{pattern:/(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,lookbehind:!0,greedy:!0,inside:r},{pattern:/(^|[^$\\])'[^']*'/,lookbehind:!0,greedy:!0},{pattern:/\$'(?:[^'\\]|\\[\s\S])*'/,greedy:!0,inside:{entity:r.entity}}],environment:{pattern:RegExp("\\$?"+t),alias:"constant"},variable:r.variable,function:{pattern:/(^|[\s;|&]|[<>]\()(?:add|apropos|apt|apt-cache|apt-get|aptitude|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|docker|docker-compose|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|node|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|podman|podman-compose|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vcpkg|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,lookbehind:!0},keyword:{pattern:/(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/,lookbehind:!0},builtin:{pattern:/(^|[\s;|&]|[<>]\()(?:\.|:|alias|bind|break|builtin|caller|cd|command|continue|declare|echo|enable|eval|exec|exit|export|getopts|hash|help|let|local|logout|mapfile|printf|pwd|read|readarray|readonly|return|set|shift|shopt|source|test|times|trap|type|typeset|ulimit|umask|unalias|unset)(?=$|[)\s;|&])/,lookbehind:!0,alias:"class-name"},boolean:{pattern:/(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/,lookbehind:!0},"file-descriptor":{pattern:/\B&\d\b/,alias:"important"},operator:{pattern:/\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/,inside:{"file-descriptor":{pattern:/^\d/,alias:"important"}}},punctuation:/\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,number:{pattern:/(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,lookbehind:!0}},n.inside=e.languages.bash;for(var i=["comment","function-name","for-or-select","assign-left","string","environment","function","keyword","builtin","boolean","file-descriptor","operator","punctuation","number"],o=r.variable[1].inside,a=0;a]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/}};e.exports=r,r.displayName="clike",r.aliases=[]},5340:function(e,t,n){"use strict";var r=function(e){var t,n,r;n=/(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/,(t=e).languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:/@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,lookbehind:!0,alias:"selector"},keyword:{pattern:/(^|[^\w-])(?:and|not|only|or)(?![\w-])/,lookbehind:!0}}},url:{pattern:RegExp("\\burl\\((?:"+n.source+"|"+/(?:[^\\\r\n()"']|\\[\s\S])*/.source+")\\)","i"),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/,string:{pattern:RegExp("^"+n.source+"$"),alias:"url"}}},selector:{pattern:RegExp("(^|[{}\\s])[^{}\\s](?:[^{};\"'\\s]|\\s+(?![\\s{])|"+n.source+")*(?=\\s*\\{)"),lookbehind:!0},string:{pattern:n,greedy:!0},property:{pattern:/(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,lookbehind:!0},important:/!important\b/i,function:{pattern:/(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,lookbehind:!0},punctuation:/[(){};:,]/},t.languages.css.atrule.inside.rest=t.languages.css,(r=t.languages.markup)&&(r.tag.addInlined("style","css"),r.tag.addAttribute("style","css"))};e.exports=r,r.displayName="css",r.aliases=[]},69870:function(e,t,n){"use strict";var r=function(e){var t,n;(t=e).languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]},Object.keys(n={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"}).forEach(function(e){var r=n[e],i=[];!/^\w+$/.test(e)&&i.push(/\w+/.exec(e)[0]),"diff"===e&&i.push("bold"),t.languages.diff[e]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(e)[0]}}}}),Object.defineProperty(t.languages.diff,"PREFIXES",{value:n})};e.exports=r,r.displayName="diff",r.aliases=[]},84641:function(e,t,n){"use strict";var r=function(e){e.languages.javascript=e.languages.extend("clike",{"class-name":[e.languages.clike["class-name"],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:{pattern:RegExp(/(^|[^\w$])/.source+"(?:"+(/NaN|Infinity/.source+"|"+/0[bB][01]+(?:_[01]+)*n?/.source+"|"+/0[oO][0-7]+(?:_[0-7]+)*n?/.source+"|"+/0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source+"|"+/\d+(?:_\d+)*n/.source+"|")+/(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source+")"+/(?![\w$])/.source),lookbehind:!0},operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),e.languages.javascript["class-name"][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,e.languages.insertBefore("javascript","keyword",{regex:{pattern:/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:"language-regex",inside:e.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:"function"},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:e.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:e.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:e.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:e.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),e.languages.insertBefore("javascript","string",{hashbang:{pattern:/^#!.*/,greedy:!0,alias:"comment"},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:"string"},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:"punctuation"},rest:e.languages.javascript}},string:/[\s\S]+/}},"string-property":{pattern:/((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,lookbehind:!0,greedy:!0,alias:"property"}}),e.languages.insertBefore("javascript","operator",{"literal-property":{pattern:/((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,lookbehind:!0,alias:"property"}}),e.languages.markup&&(e.languages.markup.tag.addInlined("script","javascript"),e.languages.markup.tag.addAttribute(/on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,"javascript")),e.languages.js=e.languages.javascript};e.exports=r,r.displayName="javascript",r.aliases=["js"]},62178:function(e,t,n){"use strict";var r=function(e){e.languages.json={property:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,lookbehind:!0,greedy:!0},string:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,lookbehind:!0,greedy:!0},comment:{pattern:/\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},number:/-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,punctuation:/[{}[\],]/,operator:/:/,boolean:/\b(?:false|true)\b/,null:{pattern:/\bnull\b/,alias:"keyword"}},e.languages.webmanifest=e.languages.json};e.exports=r,r.displayName="json",r.aliases=["webmanifest"]},18055:function(e,t,n){"use strict";var r=function(e){!function(e){var t=e.util.clone(e.languages.javascript),n=/(?:\s|\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))\*\/)/.source,r=/(?:\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])*\})/.source,i=/(?:\{*\.{3}(?:[^{}]|)*\})/.source;function o(e,t){return RegExp(e=e.replace(//g,function(){return n}).replace(//g,function(){return r}).replace(//g,function(){return i}),t)}i=o(i).source,e.languages.jsx=e.languages.extend("markup",t),e.languages.jsx.tag.pattern=o(/<\/?(?:[\w.:-]+(?:+(?:[\w.:$-]+(?:=(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s{'"/>=]+|))?|))**\/?)?>/.source),e.languages.jsx.tag.inside.tag.pattern=/^<\/?[^\s>\/]*/,e.languages.jsx.tag.inside["attr-value"].pattern=/=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/,e.languages.jsx.tag.inside.tag.inside["class-name"]=/^[A-Z]\w*(?:\.[A-Z]\w*)*$/,e.languages.jsx.tag.inside.comment=t.comment,e.languages.insertBefore("inside","attr-name",{spread:{pattern:o(//.source),inside:e.languages.jsx}},e.languages.jsx.tag),e.languages.insertBefore("inside","special-attr",{script:{pattern:o(/=/.source),alias:"language-javascript",inside:{"script-punctuation":{pattern:/^=(?=\{)/,alias:"punctuation"},rest:e.languages.jsx}}},e.languages.jsx.tag);var a=function(e){return e?"string"==typeof e?e:"string"==typeof e.content?e.content:e.content.map(a).join(""):""},l=function(t){for(var n=[],r=0;r0&&n[n.length-1].tagName===a(i.content[0].content[1])&&n.pop():"/>"===i.content[i.content.length-1].content||n.push({tagName:a(i.content[0].content[1]),openedBraces:0}):n.length>0&&"punctuation"===i.type&&"{"===i.content?n[n.length-1].openedBraces++:n.length>0&&n[n.length-1].openedBraces>0&&"punctuation"===i.type&&"}"===i.content?n[n.length-1].openedBraces--:o=!0),(o||"string"==typeof i)&&n.length>0&&0===n[n.length-1].openedBraces){var s=a(i);r0&&("string"==typeof t[r-1]||"plain-text"===t[r-1].type)&&(s=a(t[r-1])+s,t.splice(r-1,1),r--),t[r]=new e.Token("plain-text",s,null,s)}i.content&&"string"!=typeof i.content&&l(i.content)}};e.hooks.add("after-tokenize",function(e){("jsx"===e.language||"tsx"===e.language)&&l(e.tokens)})}(e)};e.exports=r,r.displayName="jsx",r.aliases=[]},75271:function(e,t,n){"use strict";var r=function(e){e.languages.less=e.languages.extend("css",{comment:[/\/\*[\s\S]*?\*\//,{pattern:/(^|[^\\])\/\/.*/,lookbehind:!0}],atrule:{pattern:/@[\w-](?:\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};\s]|\s+(?!\s))*?(?=\s*\{)/,inside:{punctuation:/[:()]/}},selector:{pattern:/(?:@\{[\w-]+\}|[^{};\s@])(?:@\{[\w-]+\}|\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};@\s]|\s+(?!\s))*?(?=\s*\{)/,inside:{variable:/@+[\w-]+/}},property:/(?:@\{[\w-]+\}|[\w-])+(?:\+_?)?(?=\s*:)/,operator:/[+\-*\/]/}),e.languages.insertBefore("less","property",{variable:[{pattern:/@[\w-]+\s*:/,inside:{punctuation:/:/}},/@@?[\w-]+/],"mixin-usage":{pattern:/([{;]\s*)[.#](?!\d)[\w-].*?(?=[(;])/,lookbehind:!0,alias:"function"}})};e.exports=r,r.displayName="less",r.aliases=[]},24667:function(e,t,n){"use strict";var r=function(e){!function(e){var t=/(?:\\.|[^\\\n\r]|(?:\n|\r\n?)(?![\r\n]))/.source;function n(e){return e=e.replace(//g,function(){return t}),RegExp(/((?:^|[^\\])(?:\\{2})*)/.source+"(?:"+e+")")}var r=/(?:\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\|\r\n`])+/.source,i=/\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|(?![\s\S]))/.source.replace(/__/g,function(){return r}),o=/\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\n|\r\n?)/.source;e.languages.markdown=e.languages.extend("markup",{}),e.languages.insertBefore("markdown","prolog",{"front-matter-block":{pattern:/(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,lookbehind:!0,greedy:!0,inside:{punctuation:/^---|---$/,"front-matter":{pattern:/\S+(?:\s+\S+)*/,alias:["yaml","language-yaml"],inside:e.languages.yaml}}},blockquote:{pattern:/^>(?:[\t ]*>)*/m,alias:"punctuation"},table:{pattern:RegExp("^"+i+o+"(?:"+i+")*","m"),inside:{"table-data-rows":{pattern:RegExp("^("+i+o+")(?:"+i+")*$"),lookbehind:!0,inside:{"table-data":{pattern:RegExp(r),inside:e.languages.markdown},punctuation:/\|/}},"table-line":{pattern:RegExp("^("+i+")"+o+"$"),lookbehind:!0,inside:{punctuation:/\||:?-{3,}:?/}},"table-header-row":{pattern:RegExp("^"+i+"$"),inside:{"table-header":{pattern:RegExp(r),alias:"important",inside:e.languages.markdown},punctuation:/\|/}}}},code:[{pattern:/((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,lookbehind:!0,alias:"keyword"},{pattern:/^```[\s\S]*?^```$/m,greedy:!0,inside:{"code-block":{pattern:/^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,lookbehind:!0},"code-language":{pattern:/^(```).+/,lookbehind:!0},punctuation:/```/}}],title:[{pattern:/\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,alias:"important",inside:{punctuation:/==+$|--+$/}},{pattern:/(^\s*)#.+/m,lookbehind:!0,alias:"important",inside:{punctuation:/^#+|#+$/}}],hr:{pattern:/(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,lookbehind:!0,alias:"punctuation"},list:{pattern:/(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,lookbehind:!0,alias:"punctuation"},"url-reference":{pattern:/!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,inside:{variable:{pattern:/^(!?\[)[^\]]+/,lookbehind:!0},string:/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,punctuation:/^[\[\]!:]|[<>]/},alias:"url"},bold:{pattern:n(/\b__(?:(?!_)|_(?:(?!_))+_)+__\b|\*\*(?:(?!\*)|\*(?:(?!\*))+\*)+\*\*/.source),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^..)[\s\S]+(?=..$)/,lookbehind:!0,inside:{}},punctuation:/\*\*|__/}},italic:{pattern:n(/\b_(?:(?!_)|__(?:(?!_))+__)+_\b|\*(?:(?!\*)|\*\*(?:(?!\*))+\*\*)+\*/.source),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^.)[\s\S]+(?=.$)/,lookbehind:!0,inside:{}},punctuation:/[*_]/}},strike:{pattern:n(/(~~?)(?:(?!~))+\2/.source),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^~~?)[\s\S]+(?=\1$)/,lookbehind:!0,inside:{}},punctuation:/~~?/}},"code-snippet":{pattern:/(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/,lookbehind:!0,greedy:!0,alias:["code","keyword"]},url:{pattern:n(/!?\[(?:(?!\]))+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)|[ \t]?\[(?:(?!\]))+\])/.source),lookbehind:!0,greedy:!0,inside:{operator:/^!/,content:{pattern:/(^\[)[^\]]+(?=\])/,lookbehind:!0,inside:{}},variable:{pattern:/(^\][ \t]?\[)[^\]]+(?=\]$)/,lookbehind:!0},url:{pattern:/(^\]\()[^\s)]+/,lookbehind:!0},string:{pattern:/(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,lookbehind:!0}}}}),["url","bold","italic","strike"].forEach(function(t){["url","bold","italic","strike","code-snippet"].forEach(function(n){t!==n&&(e.languages.markdown[t].inside.content.inside[n]=e.languages.markdown[n])})}),e.hooks.add("after-tokenize",function(e){("markdown"===e.language||"md"===e.language)&&function e(t){if(t&&"string"!=typeof t)for(var n=0,r=t.length;n",quot:'"'},s=String.fromCodePoint||String.fromCharCode;e.languages.md=e.languages.markdown}(e)};e.exports=r,r.displayName="markdown",r.aliases=["md"]},61976:function(e,t,n){"use strict";var r=function(e){e.languages.markup={comment:{pattern://,greedy:!0},prolog:{pattern:/<\?[\s\S]+?\?>/,greedy:!0},doctype:{pattern:/"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(^[^\[]*\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^$|[[\]]/,"doctype-tag":/^DOCTYPE/i,name:/[^\s<>'"]+/}},cdata:{pattern://i,greedy:!0},tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:"named-entity"},/&#x?[\da-f]{1,8};/i]},e.languages.markup.tag.inside["attr-value"].inside.entity=e.languages.markup.entity,e.languages.markup.doctype.inside["internal-subset"].inside=e.languages.markup,e.hooks.add("wrap",function(e){"entity"===e.type&&(e.attributes.title=e.content.value.replace(/&/,"&"))}),Object.defineProperty(e.languages.markup.tag,"addInlined",{value:function(t,n){var r={};r["language-"+n]={pattern:/(^$)/i,lookbehind:!0,inside:e.languages[n]},r.cdata=/^$/i;var i={"included-cdata":{pattern://i,inside:r}};i["language-"+n]={pattern:/[\s\S]+/,inside:e.languages[n]};var o={};o[t]={pattern:RegExp(/(<__[^>]*>)(?:))*\]\]>|(?!)/.source.replace(/__/g,function(){return t}),"i"),lookbehind:!0,greedy:!0,inside:i},e.languages.insertBefore("markup","cdata",o)}}),Object.defineProperty(e.languages.markup.tag,"addAttribute",{value:function(t,n){e.languages.markup.tag.inside["special-attr"].push({pattern:RegExp(/(^|["'\s])/.source+"(?:"+t+")"+/\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,"i"),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[n,"language-"+n],inside:e.languages[n]},punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}}}})}}),e.languages.html=e.languages.markup,e.languages.mathml=e.languages.markup,e.languages.svg=e.languages.markup,e.languages.xml=e.languages.extend("markup",{}),e.languages.ssml=e.languages.xml,e.languages.atom=e.languages.xml,e.languages.rss=e.languages.xml};e.exports=r,r.displayName="markup",r.aliases=["html","mathml","svg","xml","ssml","atom","rss"]},49317:function(e,t,n){"use strict";var r=function(e){e.languages.scss=e.languages.extend("css",{comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},atrule:{pattern:/@[\w-](?:\([^()]+\)|[^()\s]|\s+(?!\s))*?(?=\s+[{;])/,inside:{rule:/@[\w-]+/}},url:/(?:[-a-z]+-)?url(?=\()/i,selector:{pattern:/(?=\S)[^@;{}()]?(?:[^@;{}()\s]|\s+(?!\s)|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}][^:{}]*[:{][^}]))/,inside:{parent:{pattern:/&/,alias:"important"},placeholder:/%[-\w]+/,variable:/\$[-\w]+|#\{\$[-\w]+\}/}},property:{pattern:/(?:[-\w]|\$[-\w]|#\{\$[-\w]+\})+(?=\s*:)/,inside:{variable:/\$[-\w]+|#\{\$[-\w]+\}/}}}),e.languages.insertBefore("scss","atrule",{keyword:[/@(?:content|debug|each|else(?: if)?|extend|for|forward|function|if|import|include|mixin|return|use|warn|while)\b/i,{pattern:/( )(?:from|through)(?= )/,lookbehind:!0}]}),e.languages.insertBefore("scss","important",{variable:/\$[-\w]+|#\{\$[-\w]+\}/}),e.languages.insertBefore("scss","function",{"module-modifier":{pattern:/\b(?:as|hide|show|with)\b/i,alias:"keyword"},placeholder:{pattern:/%[-\w]+/,alias:"selector"},statement:{pattern:/\B!(?:default|optional)\b/i,alias:"keyword"},boolean:/\b(?:false|true)\b/,null:{pattern:/\bnull\b/,alias:"keyword"},operator:{pattern:/(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|not|or)(?=\s)/,lookbehind:!0}}),e.languages.scss.atrule.inside.rest=e.languages.scss};e.exports=r,r.displayName="scss",r.aliases=[]},35944:function(e,t,n){"use strict";var r=function(e){var t,n,r;e.register(i),e.register(o),n=(t=e).util.clone(t.languages.typescript),t.languages.tsx=t.languages.extend("jsx",n),delete t.languages.tsx.parameter,delete t.languages.tsx["literal-property"],(r=t.languages.tsx.tag).pattern=RegExp(/(^|[^\w$]|(?=<\/))/.source+"(?:"+r.pattern.source+")",r.pattern.flags),r.lookbehind=!0},i=n("18055"),o=n("73987");e.exports=r,r.displayName="tsx",r.aliases=[]},73987:function(e,t,n){"use strict";var r=function(e){var t,n;(t=e).languages.typescript=t.languages.extend("javascript",{"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,lookbehind:!0,greedy:!0,inside:null},builtin:/\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/}),t.languages.typescript.keyword.push(/\b(?:abstract|declare|is|keyof|readonly|require)\b/,/\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,/\btype\b(?=\s*(?:[\{*]|$))/),delete t.languages.typescript.parameter,delete t.languages.typescript["literal-property"],n=t.languages.extend("typescript",{}),delete n["class-name"],t.languages.typescript["class-name"].inside=n,t.languages.insertBefore("typescript","function",{decorator:{pattern:/@[$\w\xA0-\uFFFF]+/,inside:{at:{pattern:/^@/,alias:"operator"},function:/^[\s\S]+/}},"generic-function":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,greedy:!0,inside:{function:/^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,generic:{pattern:/<[\s\S]+/,alias:"class-name",inside:n}}}}),t.languages.ts=t.languages.typescript};e.exports=r,r.displayName="typescript",r.aliases=["ts"]},93871:function(e,t,n){"use strict";var r=function(e){!function(e){function t(t,n){e.languages[t]&&e.languages.insertBefore(t,"comment",{"doc-comment":n})}var n=e.languages.markup.tag,r={pattern:/\/\/\/.*/,greedy:!0,alias:"comment",inside:{tag:n}};t("csharp",r),t("fsharp",r),t("vbnet",{pattern:/'''.*/,greedy:!0,alias:"comment",inside:{tag:n}})}(e)};e.exports=r,r.displayName="xmlDoc",r.aliases=[]},94369:function(e,t,n){"use strict";var r=function(e){!function(e){var t=/[*&][^\s[\]{},]+/,n=/!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/,r="(?:"+n.source+"(?:[ ]+"+t.source+")?|"+t.source+"(?:[ ]+"+n.source+")?)",i=/(?:[^\s\x00-\x08\x0e-\x1f!"#%&'*,\-:>?@[\]`{|}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]|[?:-])(?:[ \t]*(?:(?![#:])|:))*/.source.replace(//g,function(){return/[^\s\x00-\x08\x0e-\x1f,[\]{}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]/.source}),o=/"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'/.source;function a(e,t){return t=(t||"").replace(/m/g,"")+"m",RegExp(/([:\-,[{]\s*(?:\s<>[ \t]+)?)(?:<>)(?=[ \t]*(?:$|,|\]|\}|(?:[\r\n]\s*)?#))/.source.replace(/<>/g,function(){return r}).replace(/<>/g,function(){return e}),t)}e.languages.yaml={scalar:{pattern:RegExp(/([\-:]\s*(?:\s<>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)\S[^\r\n]*(?:\2[^\r\n]+)*)/.source.replace(/<>/g,function(){return r})),lookbehind:!0,alias:"string"},comment:/#.*/,key:{pattern:RegExp(/((?:^|[:\-,[{\r\n?])[ \t]*(?:<>[ \t]+)?)<>(?=\s*:\s)/.source.replace(/<>/g,function(){return r}).replace(/<>/g,function(){return"(?:"+i+"|"+o+")"})),lookbehind:!0,greedy:!0,alias:"atrule"},directive:{pattern:/(^[ \t]*)%.+/m,lookbehind:!0,alias:"important"},datetime:{pattern:a(/\d{4}-\d\d?-\d\d?(?:[tT]|[ \t]+)\d\d?:\d{2}:\d{2}(?:\.\d*)?(?:[ \t]*(?:Z|[-+]\d\d?(?::\d{2})?))?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(?::\d{2}(?:\.\d*)?)?/.source),lookbehind:!0,alias:"number"},boolean:{pattern:a(/false|true/.source,"i"),lookbehind:!0,alias:"important"},null:{pattern:a(/null|~/.source,"i"),lookbehind:!0,alias:"important"},string:{pattern:a(o),lookbehind:!0,greedy:!0},number:{pattern:a(/[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/.source,"i"),lookbehind:!0},tag:n,important:t,punctuation:/---|[:[\]{}\-,|>?]|\.\.\./},e.languages.yml=e.languages.yaml}(e)};e.exports=r,r.displayName="yaml",r.aliases=["yml"]},28722:function(e,t,n){e.exports=function(e,t,n,r){var i=n?n.call(r,e,t):void 0;if(void 0!==i)return!!i;if(e===t)return!0;if("object"!=typeof e||!e||"object"!=typeof t||!t)return!1;var o=Object.keys(e),a=Object.keys(t);if(o.length!==a.length)return!1;for(var l=Object.prototype.hasOwnProperty.bind(t),s=0;s0&&void 0!==arguments[0]?arguments[0]:"/";return(0,i.withBase)(e,r.default.base)}function l(e){return(0,i.removeBase)(e,r.default.base)}function s(e,t){return a(c(e))===a(c(t))}function c(e){var t,n,o=!!(null===(n=r.default)||void 0===n?void 0:null===(t=n.route)||void 0===t?void 0:t.cleanUrls);return(0,i.normalizeHref)(e,o)}},86126:function(e,t,n){"use strict";n.r(t),n.d(t,{Button:function(){return eM},HomeFooter:function(){return nS},HomeLayout:function(){return e$},Layout:function(){return eD},Link:function(){return eh},Nav:function(){return tg},NotFoundLayout:function(){return V},PackageManagerTabs:function(){return nF},Search:function(){return nI},SearchPanel:function(){return nk},Tab:function(){return tO},Tabs:function(){return tP},Toc:function(){return nE},bindingAsideScroll:function(){return ee},default:function(){return rl},getCustomMDXComponent:function(){return ra},getLogoUrl:function(){return eo},isActive:function(){return er},isExternalHref:function(){return ei},isMobileDevice:function(){return ea},scrollToTarget:function(){return J},setup:function(){return et},useEditLink:function(){return Q},useLocaleSiteData:function(){return Z},usePathUtils:function(){return en},usePrevNextPage:function(){return K},useSidebarData:function(){return X}});var r,i,o,a=n("20469"),l=n("33888"),s=n("37599"),c=n("28003"),u=n("93160"),d=n("73706"),p=n("9880"),h=n("85464");n("57520");var f=n("57814"),m=n("78585"),g=n("19730"),b=n("80061"),x=n("60421"),v=n("23169"),y=n("97150"),w=n("1765"),j=n("42256"),P=n("76819"),O=n("74007"),k=n("88273"),I=n("31952"),S=n("53816"),_=n("11167"),E=n("84404"),C=n("61932"),z=n("75208"),N=n("72858"),A=n("73846"),T=n("4249"),D=n("14917"),L=n("57077"),M=n("54466"),R=n("81130"),B=n("64227"),F=n("68448"),H=n("73513"),W=n("43184"),q=n("33204"),U=n("97575"),$=n("29385"),G=n("53274");function V(){var e=(0,h.usePageData)().siteData,t=e.lang;if(!(t&&"undefined"!=typeof window&&location.pathname.includes("/".concat(t,"/"))))return(0,p.jsxs)("div",{className:"m-auto mt-50 p-16 sm:p-8 sm:pt-24 sm:pb-40 text-center flex-center flex-col",children:[(0,p.jsx)("p",{className:"text-6xl font-semibold",children:"404"}),(0,p.jsx)("h1",{className:"leading-5 pt-3 text-xl font-bold",children:"PAGE NOT FOUND"}),(0,p.jsx)("div",{style:{height:"1px"},className:"mt-6 mx-auto mb-4.5 w-16 bg-gray-light-1"}),(0,p.jsx)("div",{className:"pt-5",children:(0,p.jsx)("a",{className:"py-2 px-4 rounded-2xl inline-block border-solid border-brand text-brand font-medium hover:border-brand-dark hover:text-brand-dark transition-colors duration-300",href:e.base,"aria-label":"go to home",children:"Take me home"})})]});var n=location.pathname.replace("/".concat(t,"/"),"/");return window.location.replace(n),(0,p.jsx)(p.Fragment,{})}function Z(){var e,t,n,r,i,o=(0,h.usePageData)(),a=o.page.lang,l=null!==(r=null==o?void 0:null===(n=o.siteData)||void 0===n?void 0:n.themeConfig)&&void 0!==r?r:{},s=null!==(i=o.siteData.lang)&&void 0!==i?i:"",c=null==l?void 0:l.locales;if(!c||0===c.length)return{nav:l.nav,sidebar:l.sidebar,prevPageText:l.prevPageText,nextPageText:l.nextPageText};return e=function(e){for(var t=1;t span'));o&&(r&&r.classList.remove("aside-active"),(r=o).classList.add("aside-active"))}},a=(0,y.default)(function(){if(document.documentElement.scrollTop+window.innerHeight>=document.documentElement.scrollHeight)o(n,n.length-1);else for(var e=0;e=a&&i2&&void 0!==arguments[2]&&arguments[2],r=null;try{r=e.classList.contains("header-anchor")?e:document.getElementById(decodeURIComponent(t.slice(1)))}catch(e){console.warn(e)}r&&J(r,n)},window.addEventListener("click",function(t){var n=t.target.closest("a");if(n){var r=n.origin,i=n.hash,o=n.target,a=n.pathname,l=n.search,s=window.location;i&&"_blank"!==o&&r===s.origin&&(a===s.pathname&&l===s.search&&i&&n.classList.contains("header-anchor")?(t.preventDefault(),history.pushState(null,"",i),e(n,i,!0),window.dispatchEvent(new Event("hashchange"))):window.addEventListener("RspressReloadContent",function(){location.hash.length>1&&J(document.getElementById(location.hash.slice(1)),!1)}))}},{capture:!0}),window.addEventListener("hashchange",function(e){e.preventDefault()})}}function en(){var e=(0,h.useLang)(),t=(0,h.useVersion)(),n=(0,h.usePageData)(),r=n.siteData.lang,i=n.siteData.multiVersion.default;return{normalizeLinkHref:function(n){var o=n;if(!r&&!i||(0,w.isExternalUrl)(o)||o.startsWith("#"))return o;var a=(o=(0,h.removeBase)(o)).split("/").filter(Boolean),l="",s="",c="";return i&&(t!==i?(l=t,a[0]===t&&a.shift()):a[0]===i&&a.shift()),r&&(e!==r?(s=e,a[0]===e&&a.shift()):a[0]===r&&a.shift()),c=a.join("/"),(0,h.normalizeHrefInRuntime)((0,h.withBase)([l,s,c].filter(Boolean).join("/")))}}}function er(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return!!t&&(n?(0,h.isEqualPath)(e,t):(0,h.isEqualPath)(e,t)||e.startsWith(t))}function ei(e){return/^https?:\/\//.test(e)}function eo(e,t){return"string"==typeof e?e:"dark"===t?e.dark:e.light}function ea(){return window.innerWidth<768}function el(e){var t,n=e.headers,r=n.length>0,i=(0,f.useRef)(null),o=(null===(t=n[0])||void 0===t?void 0:t.depth)||2;return(0,f.useEffect)(function(){i.current&&(i.current.style.opacity="0"),setTimeout(function(){e=ee()},100);var e,t=decodeURIComponent(window.location.hash);if(t){var n=document.getElementById(t.slice(1));n&&J(n,!1)}else window.scrollTo(0,0);return function(){e&&e()}},[n]),(0,p.jsx)("div",{className:"flex flex-col",children:(0,p.jsx)("div",{className:r?"0?[{name:e_,items:n.map(e)}]:[]))},[o]);return(0,p.jsxs)("div",{className:"overview-index mx-auto px-8",children:[(0,p.jsx)("div",{className:"flex items-center justify-between",children:(0,p.jsx)("h1",{children:"Overview"})}),a.map(function(e){return(0,p.jsxs)("div",{className:"mb-16",children:[e.name===e_&&1===a.length?(0,p.jsx)("h2",{style:{paddingTop:0}}):(0,p.jsx)("h2",{children:e.name}),(0,p.jsx)("div",{className:eS.overviewGroups,children:e.items.map(function(e){var t;return(0,p.jsxs)("div",{className:eS.overviewGroup,children:[(0,p.jsx)("div",{className:"flex",children:(0,p.jsx)("h3",{style:{marginBottom:8},children:(0,p.jsx)(eh,{href:(0,h.normalizeHrefInRuntime)(e.link),children:e.text})})}),(0,p.jsx)("ul",{className:"list-none",children:null===(t=e.headers)||void 0===t?void 0:t.map(function(t){return(0,p.jsx)("li",{className:"".concat(eS.overviewGroupLi," ").concat(eS["level".concat(t.depth)]," first:mt-2"),children:(0,p.jsx)(eh,{href:"".concat((0,h.normalizeHrefInRuntime)(e.link),"#").concat(t.id),children:t.text})},t.id)})})]},e.link)})})]},e.name)})]})}var eC=(0,f.createContext)({}),ez={asideContainer:"aside-container_feeda",docLayout:"docLayout_feeda",content:"content_feeda"};function eN(e){for(var t=1;t0,T=(null==S?void 0:S.outlineTitle)||(null==I?void 0:I.outlineTitle)||"ON THIS PAGE",D=null!==(r=null==w?void 0:w.overview)&&void 0!==r&&r,L=null===(i=null==w?void 0:w.footer)||void 0===i||i,M=function(){var e,t,n="undefined"==typeof window||window.top===window.self;return(null!==(t=null!==(e=null==w?void 0:w.outline)&&void 0!==e?e:null==I?void 0:I.outline)&&void 0!==t?t:n)&&k.length>0},R=(0,c._)((0,f.useState)(M()),2),B=R[0],F=R[1];return(0,f.useEffect)(function(){F(M())},[b,m]),(0,p.jsxs)("div",{className:"".concat(ez.docLayout," pt-0"),style:eN({},N?{marginTop:0}:{}),children:[a,A?(0,p.jsx)(eI,{pathname:E,langRoutePrefix:z,sidebarData:C}):null,(0,p.jsxs)("div",{className:"".concat(ez.content," rspress-doc-container flex flex-shrink-0"),children:[(0,p.jsx)("div",{className:"w-full",children:D?(0,p.jsx)(eE,{}):(0,p.jsxs)("div",{children:[(0,p.jsx)("div",{className:"rspress-doc",children:(0,p.jsx)(eC.Provider,{value:{tabData:P,setTabData:O},children:(0,p.jsx)(v.MDXProvider,{components:(0,g.getCustomMDXComponent)(),children:(0,p.jsx)(h.Content,{})})})}),(0,p.jsxs)("div",{className:"rspress-doc-footer",children:[o,L&&(0,p.jsx)(em,{})]})]})}),B?(0,p.jsx)("div",{className:ez.asideContainer,style:eN({maxHeight:"calc(100vh - (var(--rp-nav-height) + 32px))",overflow:"scroll"},N?{marginTop:0,paddingTop:"32px"}:{}),children:(0,p.jsxs)("div",{children:[s,(0,p.jsx)(el,{headers:k,outlineTitle:T}),u]})}):null]}),l]})}function eT(e){for(var t=1;t3,r=[],i=[];t.forEach(function(e,t){t<3?r.push(e):i.push(e)});var o=(0,c._)((0,f.useState)(!1),2),a=o[0],l=o[1];return(0,p.jsxs)("div",{className:"social-links ".concat(e5.menuItem," flex-center relative"),onMouseLeave:function(){return l(!1)},children:[(0,p.jsx)(e9,{links:r,moreIconVisible:n,mouseEnter:function(){return l(!0)}}),a?(0,p.jsx)(te,{links:i}):null]})},tn={navScreen:"navScreen_8624f",active:"active_8624f",container:"container_8624f",navMenu:"navMenu_8624f",navMenuItem:"navMenuItem_8624f",navAppearance:"navAppearance_8624f"};function tr(e){for(var t=1;t1,m=i.nav||[],g=!1!==o.themeConfig.darkMode,b=(null==o?void 0:null===(t=o.themeConfig)||void 0===t?void 0:t.socialLinks)||[],x=b.length>0,v=u.map(function(e){return e.lang||"zh"})||[],y=o.base,w=o.logo,j=d?{text:(0,p.jsx)(e3,{style:{width:"18px",height:"18px"}}),items:u.map(function(e){return{text:null==e?void 0:e.label,link:"/".concat(e.lang)}}),activeValue:null===(n=u.find(function(e){return e.lang===i.lang}))||void 0===n?void 0:n.label}:null;return(0,f.useEffect)(function(){return s.current&&r&&(0,O.disableBodyScroll)(s.current,{reserveScrollBarGap:!0}),function(){(0,O.clearAllBodyScrollLocks)()}},[r]),(0,p.jsx)("div",{className:"".concat(tn.navScreen," ").concat(r?tn.active:""),ref:s,id:"navScreen",children:(0,p.jsxs)("div",{className:tn.container,children:[(0,p.jsx)(function(e){var t=e.menuItems;return(0,p.jsx)("div",{className:tn.navMenu,children:t.map(function(e,t){var n,r;return(0,p.jsx)("div",{className:"".concat(tn.navMenuItem," w-full"),children:"link"in e?(0,p.jsx)(eX,tr({pathname:a,base:y,langs:v},e),t):(0,p.jsx)("div",{className:"mx-3 last:mr-0",children:(0,p.jsx)(eZ,(n=tr({},e),r=(r={items:"items"in e?e.items:e},r),Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(r)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(r)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(r,e))}),n))},t)},t)})})},{menuItems:m}),(0,p.jsxs)("div",{className:"flex-center flex-col gap-2",children:[g&&(0,p.jsx)(function(){return(0,p.jsx)("div",{className:"mt-2 ".concat(tn.navAppearance," flex justify-center"),children:(0,p.jsx)(h.NoSSR,{children:(0,p.jsx)(e2,{onClick:function(){l(eo(w,"dark"===c?"light":"dark"))}})})})},{}),d&&(0,p.jsx)(ti,{translationMenuData:j}),x&&(0,p.jsx)(tt,{socialLinks:b})]})]})})}var ta=function(e){var t,n;return(0,p.jsxs)("svg",(t=function(e){for(var t=1;t=768&&n()},o=(i=(0,c._)((0,f.useState)(!1),2))[0],a=i[1],{isScreenOpen:o,openScreen:t,closeScreen:n,toggleScreen:function(){o?n():t()}}),m=h.isScreenOpen,g=h.toggleScreen;return(0,p.jsxs)(f.Fragment,{children:[(0,p.jsx)(to,{isScreenOpen:m,localeData:l,siteData:s,pathname:u,setLogo:d}),(0,p.jsx)("button",{onClick:g,className:"".concat(m?tl.active:""," ").concat(tl.navHamburger," text-gray-500"),children:(0,p.jsx)(ta,{fill:"currentColor"})})]})}function tc(e){var t=e.item;return(0,p.jsxs)("div",{className:"rounded-2xl my-1 flex",style:{padding:"0.4rem 1.5rem 0.4rem 0.75rem"},children:[t.tag&&(0,p.jsx)(eb,{tag:t.tag}),(0,p.jsx)("span",{className:"text-brand",children:t.text})]},t.link)}function tu(e){var t=e.item;return(0,p.jsx)("div",{className:"font-medium my-1",children:(0,p.jsx)(eh,{href:t.link,children:(0,p.jsx)("div",{className:"rounded-2xl hover:bg-mute",style:{padding:"0.4rem 1.5rem 0.4rem 0.75rem"},children:(0,p.jsxs)("div",{className:"flex",children:[t.tag&&(0,p.jsx)(eb,{tag:t.tag}),(0,p.jsx)("span",{children:t.text})]})})})},t.link)}function td(e){var t,n,r=e.activeValue,i=e.isTranslation,o=e.items,a=e.base,l=void 0===a?"":a,s=e.link,u=e.pathname,d=void 0===u?"":u,h=(0,c._)((0,f.useState)(!1),2),m=h[0],g=h[1],b=function(e){var t=new RegExp(e.activeMatch||e.link).test((0,w.withoutBase)(d,l));return r===e.text||!r&&t?(0,p.jsx)(tc,{item:e},e.link):(0,p.jsx)(tu,{item:e},e.link)};return(0,p.jsxs)("div",{className:"relative flex-center h-14",onMouseLeave:function(){return g(!1)},children:[(0,p.jsx)("button",{onMouseEnter:function(){return g(!0)},className:"nav-menu-group-button flex-center items-center font-medium text-sm text-text-1 hover:text-text-2 transition-colors duration-200",children:(void 0===s?"":s)?(0,p.jsx)(eX,(t=function(e){for(var t=1;t1,E=u.themeConfig.socialLinks||[],C=E.length>0,z=u.lang||"",N=u.multiVersion.default||"",A=d.lang,T=S.map(function(e){return e.lang||""})||[],D=(0,c._)((0,f.useState)(eo(m,y)),2),L=D[0],M=D[1],R=_?{items:S.map(function(e){return{text:null==e?void 0:e.label,link:(0,w.replaceLang)(v,{current:A,target:e.lang,default:z},{current:P,default:N},b)}}),activeValue:null===(t=S.find(function(e){return A===e.lang}))||void 0===t?void 0:t.label}:null;(0,f.useEffect)(function(){M(eo(m,y))},[y]),(0,f.useEffect)(function(){I(ea())},[]);var B=function(e){var t=e.menuItems;return(0,p.jsx)("div",{className:"rspress-nav-menu menu h-14",children:t.map(function(e){return"items"in e||Array.isArray(e)?(0,p.jsx)("div",{className:"mx-3 last:mr-0",children:(0,p.jsx)(td,th(tp({},e),{base:b,pathname:v,langs:T,items:"items"in e?e.items:e}))},e.text):(0,p.jsx)(eX,tp({pathname:v,langs:T,base:b},e),e.link)})})},F=j.nav||[],H=function(e){return null!==(r=e.position)&&void 0!==r?r:"right"},W=F.filter(function(e){return"left"===H(e)}),q=F.filter(function(e){return"right"===H(e)}),U=(null==u?void 0:null===(n=u.themeConfig)||void 0===n?void 0:n.search)!==!1,$=null!==(i=j.title)&&void 0!==i?i:u.title,G=!1!==u.themeConfig.darkMode;return(0,p.jsxs)("header",{className:"top-0 left-0 md:fixed w-full",style:{zIndex:"var(--rp-z-index-nav)",background:"var(--rp-c-bg)"},children:[l,(0,p.jsx)("div",{className:"".concat(eY.navContainer," rspress-nav px-6"),children:(0,p.jsxs)("div",{className:"".concat(eY.container," flex justify-between items-center h-full"),children:[o,(0,p.jsx)(tf,{title:$,langRoutePrefix:j.langRoutePrefix||"/",logo:L}),a,(0,p.jsxs)("div",{className:"".concat(eY.content," flex flex-1 justify-end items-center"),children:[W.length>0?(0,p.jsx)("div",{className:eY.leftNav,children:(0,p.jsx)(B,{menuItems:W})}):null,(0,p.jsxs)("div",{className:eY.rightNav,children:[U&&(0,p.jsx)("div",{className:"flex sm:flex-1 items-center sm:pl-4 sm:pr-2",children:(0,p.jsx)(g.Search,{})}),(0,p.jsx)(B,{menuItems:q}),(0,p.jsxs)("div",{className:"flex-center flex-row",children:[_&&(0,p.jsx)(tm,{translationMenuData:R}),G&&(0,p.jsx)("div",{className:"mx-2",children:(0,p.jsx)(e2,{})}),C&&(0,p.jsx)(tt,{socialLinks:E})]})]}),(0,p.jsxs)("div",{className:eY.mobileNavMenu,children:[k&&(0,p.jsx)(g.Search,{}),(0,p.jsx)(ts,{localeData:j,siteData:u,pathname:v,setLogo:M})]})]})]})})]})}var tb=function(e){var t,n;return(0,p.jsx)("svg",(t=function(e){for(var t=1;t=0)&&(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0))Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}}return i}(e,["children"]);return(0,p.jsx)("div",tw(ty({},n),{className:"rounded px-2",children:t}))}var tk=function(e){var t,n;return(0,p.jsx)("svg",(t=function(e){for(var t=1;t255?3:1}function tz(e,t){for(var n=0,r=0,i=0;i=t);i++)r+=tC(e.charAt(i)),n++;return n}function tN(e){for(var t=0,n=0;n1&&void 0!==arguments[1]?arguments[1]:7,n=this;return t2(function(){var r,i,o,a;return(0,d._)(this,function(l){switch(l.label){case 0:return[4,null===(r=t5(n,nn))||void 0===r?void 0:r.search({keyword:e,limit:t})];case 1:return i=l.sent(),o=t_(e),a=(null==i?void 0:i.find(function(e){return t8(n,ns,nm).call(n,e.index)}))||{index:tS,hits:[]},[2,{current:t8(n,nr,nu).call(n,o,a),others:((null==i?void 0:i.filter(function(e){return!t8(n,ns,nm).call(n,e.index)}))||[]).map(function(e){return{index:e.index,items:t8(n,nr,nu).call(n,o,e)}})}]}})})()}}]),e}();function nu(e,t){var n=this,r=[];return null==t||t.hits.forEach(function(t){t8(n,ni,nd).call(n,t,e,r),!t8(n,no,np).call(n,t,e,r)&&t8(n,na,nh).call(n,t,e,r)}),r}function nd(e,t,n){var r=e.title,i=void 0===r?"":r,o=t_(i);return!!o.includes(t)&&(n.push({type:"title",title:i,header:i,link:"".concat(e.domain).concat((0,h.normalizeHrefInRuntime)(e.routePath)),query:t,highlightInfoList:[{start:o.indexOf(t),length:tN(t)}],group:t5(this,ne).extractGroupName(e.routePath)}),!0)}function np(e,t,n){var r=e.toc,i=void 0===r?[]:r,o=e.domain,a=void 0===o?"":o,l=e.title,s=void 0===l?"":l,u=!0,d=!1,p=void 0;try{for(var f,m=i.entries()[Symbol.iterator]();!(u=(f=m.next()).done);u=!0){var g=(0,c._)(f.value,2),b=g[0],x=g[1];if(t_(x.text).includes(t)){var v=(function(e,t){for(var n=e[t],r=t,i=[n];n&&n.depth>2;){for(var o=!1,a=r-1;a>=0;a--){var l=e[a];if(l.depth>1&&l.depth===n.depth-1){n=l,r=a,i.unshift(n),o=!0;break}}if(!o)break}return i})(i,b).map(function(e){return e.text}).join(" > "),y=t_(v).indexOf(t),w="".concat(s," > ");return n.push({type:"header",title:e.title,header:"".concat(w).concat(v),highlightInfoList:[{start:y+w.length,length:tN(t)}],link:"".concat(a).concat((0,h.normalizeHrefInRuntime)(e.routePath),"#").concat(x.id),query:t,group:t5(this,ne).extractGroupName(e.routePath)}),!0}}}catch(e){d=!0,p=e}finally{try{!u&&null!=m.return&&m.return()}finally{if(d)throw p}}return!1}function nh(e,t,n){var r=e.content,i=e.toc,o=e.domain;if(r.length){var a=t_(r),l=a.indexOf(t),s=i.map(function(e){return e.charIndex}),c=function(e){return i[s.findIndex(function(t,n){if(!(n=e)return!0;return!1})]};if(-1===l){var u,d,p=null===(u=e._matchesPosition)||void 0===u?void 0:u.content;if(!(null==p?void 0:p.length))return;var f=e._matchesPosition.content[0].start,m=c(f),g=tz(r,f),b=tz(r,f+100),x=r.slice(g,b),v=e._matchesPosition.content.filter(function(e){return e.start>=f&&e.start+e.length<=f+100}).map(function(e){return{start:tz(r,e.start)-g+3,length:e.length}});n.push({type:"content",title:e.title,header:null!==(d=null==m?void 0:m.text)&&void 0!==d?d:e.title,link:"".concat(o).concat((0,h.normalizeHrefInRuntime)(e.routePath)).concat(m?"#".concat(m.id):""),query:t,highlightInfoList:v,group:t5(this,ne).extractGroupName(e.routePath),statement:"...".concat(x,"...")});return}for(;-1!==l;){var y,w=c(l),j=r.slice(0,l).lastIndexOf("\n");j=-1===j?0:j;var P=r.indexOf("\n\n",l+t.length),O=r.slice(j,P);O.length>100&&(O=t8(this,nl,nf).call(this,O,t));var k=t_(O).indexOf(t),I=[{start:k,length:tN(t)}];n.push({type:"content",title:e.title,header:null!==(y=null==w?void 0:w.text)&&void 0!==y?y:e.title,statement:O,highlightInfoList:I,link:"".concat(o).concat((0,h.normalizeHrefInRuntime)(e.routePath)).concat(w?"#".concat(w.id):""),query:t,group:t5(this,ne).extractGroupName(e.routePath)}),l=a.indexOf(t,l+O.length-k)}}}function nf(e,t){var n=t_(e).indexOf(t_(t)),r=Math.floor((100-t.length)/2),i=e.slice(0,n);i.length>r&&(i="...".concat(e.slice(n-r+3,n)));var o=e.slice(n+t.length);return o.length>r&&(o="".concat(e.slice(n+t.length,n+r-3),"...")),i+t+o}function nm(e){return e===t5(this,nt)||e===tS}var ng=function(e){var t,n;return(0,p.jsx)("svg",(t=function(e){for(var t=1;tt+n);a++){;i>t&&(r+=e.charAt(a))}return r}(c.slice(u),0,d));n.push(g),n.push((0,p.jsx)("span",{className:tx.mark,children:b},f)),r=f+b.length}}catch(e){o=!0,a=e}finally{try{!i&&null!=s.return&&s.return()}finally{if(o)throw a}}return r=0){var t=T[j];j1)||void 0===arguments[1]||arguments[1];if(0===e.length&&!v)return(0,p.jsx)("div",{className:"mt-4 flex-center",children:(0,p.jsx)("div",{className:"p-2 font-bold text-md",style:{color:"#2c3e50"},children:"No results found"})});var r=(t=e,(0,S.default)(t,"group"));return(0,p.jsx)("ul",{className:tx.suggestList,children:Object.keys(r).map(function(e){var t=r[e]||[];return(0,p.jsxs)("li",{children:[n&&(0,p.jsx)("h2",{className:tx.groupTitle,children:e}),(0,p.jsx)("ul",{className:"pb-2",children:t.map(function(e){var t=++R;return(0,p.jsx)(nx,{suggestion:e,isCurrent:t===j,setCurrentSuggestionIndex:function(){P(t)},closeSearch:function(){return i(!1)},inCurrentDocIndex:t0,r=e.others.map(function(e){if(!t||"remote"!==t.mode)return e;return(t.searchIndexes||[]).map(function(e){return"string"==typeof e?{value:e,label:e}:e}).find(function(t){return t.value===e.index}).label});return(0,p.jsxs)("div",{children:[B(e.current),n&&(0,p.jsx)("h2",{className:tx.groupTitle,children:nO[z]}),(0,p.jsx)("div",{style:{marginTop:"-12px"},children:(0,p.jsx)(tP,{values:r,tabContainerClassName:tx.tabClassName,children:e.others.map(function(e){return(0,p.jsx)(tO,{children:B(e.items,!1)},e.index)})})})]})}(m,A)}):null,v&&(0,p.jsx)("div",{className:"flex-center",children:(0,p.jsx)("div",{className:"p-2 text-sm",children:(0,p.jsx)(tk,{})})})]})}),document.getElementById("search-container"))})}function nI(){var e=(0,c._)((0,f.useState)(!1),2),t=e[0],n=e[1];return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)("div",{className:tx.navSearchButton,onClick:function(){return n(!0)},children:(0,p.jsxs)("button",{children:[(0,p.jsx)(tb,{width:"18",hight:"18"}),(0,p.jsx)("p",{className:tx.searchWord,children:"Search Docs"}),(0,p.jsxs)("div",{children:[(0,p.jsx)("span",{children:"\u2318"}),(0,p.jsx)("span",{children:"K"})]})]})}),(0,p.jsx)("div",{className:tx.mobileNavSearchButton,onClick:function(){return n(!0)},children:(0,p.jsx)(tb,{})}),(0,p.jsx)(nk,{focused:t,setFocused:n})]})}function nS(){var e=((0,h.usePageData)().siteData.themeConfig.footer||{}).message;return(0,p.jsx)("footer",{className:"absolute bottom-0 mt-12 py-8 px-6 sm:p-8 w-full border-t border-solid border-divider-light",children:(0,p.jsx)("div",{className:"m-auto w-full text-center",children:e&&(0,p.jsx)("div",{className:"font-meduim text-sm text-text-2",children:e})})})}var n_=function(e){return(0,p.jsx)("li",{className:"py-1",children:(0,p.jsx)("a",{href:"#".concat(e.id),className:"toc-link transition-all duration-300 hover:text-text-1 text-text-2 block underline underline-offset-2",style:{marginLeft:12*e.depth},onClick:function(t){t.preventDefault(),window.location.hash=e.id;var n=document.getElementById(e.id);n&&J(n,!1)},children:(0,p.jsx)("span",{className:"toc-link-text block",children:e.text})})},e.id)};function nE(){var e=(0,h.usePageData)().page;return(0,p.jsx)("ul",{children:e.toc.map(function(e){return(0,p.jsx)(n_,function(e){for(var t=1;t0,lineProps:function(e){var t=u.includes(e);return{className:t?"line highlighted":"",style:{backgroundColor:t?"var(--rp-code-line-highlight-color)":"",display:"block",padding:"0 1.25rem"}}},children:t}),(0,p.jsx)("button",{className:"copy",onClick:function(){var e=G(t),n=r.current;if(e&&n){n.classList.add("copied"),clearTimeout(nA.get(n));var i=setTimeout(function(){n.classList.remove("copied"),n.blur(),nA.delete(n)},2e3);nA.set(n,i)}},ref:r})]})}function nD(e){var t,n;return(0,p.jsxs)("svg",(t=function(e){for(var t=1;t-1},v.prototype.set=function(e,t){var n=this.__data__,r=b(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this};var y="object"==typeof global&&global&&global.Object===Object&&global,w="object"==typeof self&&self&&self.Object===Object&&self,j=y||w||Function("return this")(),P=j.Symbol,O=Object.prototype,k=O.hasOwnProperty,I=O.toString,S=P?P.toStringTag:void 0,_=function(e){var t=k.call(e,S),n=e[S];try{e[S]=void 0;var r=!0}catch(e){}var i=I.call(e);return r&&(t?e[S]=n:delete e[S]),i},E=Object.prototype.toString,C=P?P.toStringTag:void 0,z=function(e){var t;if(null==e)return void 0===e?"[object Undefined]":"[object Null]";return C&&C in Object(e)?_(e):(t=e,E.call(t))},N=function(e){var t=void 0===e?"undefined":(0,m._)(e);return null!=e&&("object"==t||"function"==t)},A=function(e){if(!N(e))return!1;var t=z(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t},T=j["__core-js_shared__"];var D=(r=/[^.]+$/.exec(T&&T.keys&&T.keys.IE_PROTO||""))?"Symbol(src)_1."+r:"",L=Function.prototype.toString,M=function(e){if(null!=e){try{return L.call(e)}catch(e){}try{return e+""}catch(e){}}return""},R=/^\[object .+?Constructor\]$/,B=Object.prototype,F=Function.prototype.toString,H=B.hasOwnProperty,W=RegExp("^"+F.call(H).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),q=function(e){var t;return!!N(e)&&(t=e,!D||!(D in t))&&(A(e)?W:R).test(M(e))},U=function(e,t){var n,r,i=(n=e,r=t,null==n?void 0:n[r]);return q(i)?i:void 0},$=U(j,"Map"),G=U(Object,"create"),V=Object.prototype.hasOwnProperty,Z=Object.prototype.hasOwnProperty;function Y(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t-1&&e%1==0&&e<=9007199254740991},eI=function(e){return null!=e&&ek(e.length)&&!A(e)},eS="object"==typeof exports&&exports&&!exports.nodeType&&exports,e_=eS&&"object"==typeof module&&module&&!module.nodeType&&module,eE=e_&&e_.exports===eS?j.Buffer:void 0,eC=eE?eE.isBuffer:void 0,ez=eC||function(){return!1},eN=Object.prototype,eA=Function.prototype.toString,eT=eN.hasOwnProperty,eD=eA.call(Object),eL=function(e){if(!ex(e)||"[object Object]"!=z(e))return!1;var t=em(e);if(null===t)return!0;var n=eT.call(t,"constructor")&&t.constructor;return"function"==typeof n&&(0,h._)(n,n)&&eA.call(n)==eD},eM={};eM["[object Float32Array]"]=eM["[object Float64Array]"]=eM["[object Int8Array]"]=eM["[object Int16Array]"]=eM["[object Int32Array]"]=eM["[object Uint8Array]"]=eM["[object Uint8ClampedArray]"]=eM["[object Uint16Array]"]=eM["[object Uint32Array]"]=!0,eM["[object Arguments]"]=eM["[object Array]"]=eM["[object ArrayBuffer]"]=eM["[object Boolean]"]=eM["[object DataView]"]=eM["[object Date]"]=eM["[object Error]"]=eM["[object Function]"]=eM["[object Map]"]=eM["[object Number]"]=eM["[object Object]"]=eM["[object RegExp]"]=eM["[object Set]"]=eM["[object String]"]=eM["[object WeakMap]"]=!1;var eR="object"==typeof exports&&exports&&!exports.nodeType&&exports,eB=eR&&"object"==typeof module&&module&&!module.nodeType&&module,eF=eB&&eB.exports===eR&&y.process,eH=function(){try{var e=eB&&eB.require&&eB.require("util").types;if(e)return e;return eF&&eF.binding&&eF.binding("util")}catch(e){}}(),eW=eH&&eH.isTypedArray;var eq=eW?(s=eW,function(e){return s(e)}):function(e){return ex(e)&&ek(e.length)&&!!eM[z(e)]},eU=function(e,t){if("constructor"!==t||"function"!=typeof e[t]){if("__proto__"!=t)return e[t]}},e$=Object.prototype.hasOwnProperty,eG=function(e,t,n){var r=e[t];(!(e$.call(e,t)&&g(r,n))||void 0===n&&!(t in e))&&et(e,t,n)},eV=function(e,t,n,r){var i=!n;n||(n={});for(var o=-1,a=t.length;++o-1&&e%1==0&&e0){if(++u>=800)return arguments[0]}else u=0;return c.apply(void 0,arguments)}),tt=function(e,t){var n,r,i;return te((n=e,r=t,i=e5,r=e7(void 0===r?n.length-1:r,0),function(){for(var e=arguments,t=-1,o=e7(e.length-r,0),a=Array(o);++t1?t[r-1]:void 0,o=r>2?t[2]:void 0;for(i=p.length>3&&"function"==typeof i?(r--,i):void 0,o&&tn(t[0],t[1],o)&&(i=r<3?void 0:i,r=1),e=Object(e);++n0&&".."!==i[i.length-1]?i.pop():n&&i.push(".."):i.push(u)}}catch(e){a=!0,l=e}finally{try{!o&&null!=c.return&&c.return()}finally{if(a)throw l}}var d=i.join("/");return n&&(d="/".concat(d)),d}(e))).charAt(t.length-1)?t.slice(0,-1):t}function tp(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("mailto:")||e.startsWith("tel:")}function th(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",i=tx(e,r);!i&&(i="/index.html");var o="",a="",l="",s=i.split("/").filter(Boolean);return n.current&&n.current!==n.default&&(o=s.shift()||""),t.target!==t.default?(a=t.target,t.current!==t.default&&s.shift()):s.shift(),l=s.join("/")||"",(o||a)&&!l&&(l="index.html"),tb(tu([o,a,l].filter(Boolean).join("/")),r)}var tf=function(e){var t=(0,f._)(e.split("#"),2),n=t[0],r=t[1];return{url:n,hash:void 0===r?"":r}};function tm(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!e)return"/";if(tp(e))return e;var n=tf(decodeURIComponent(e)),r=n.url,i=n.hash;return e.startsWith("mailto:")||e.startsWith("tel:")?e:(!t&&!r.endsWith(".html")&&(r.endsWith("/")?r+="index.html":r+=".html"),tu(i?"".concat(r,"#").concat(i):r))}function tg(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return tu(e).replace(td(t),"")}function tb(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=tu(e),r=td(t);return n.startsWith(r)?n:"".concat(r).concat(n)}function tx(e,t){return tu(e).replace(td(t),"")}},88273:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return r}});var r={title:"Modern.js Module",description:"",icon:"https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/logo-1x-0104.png",themeConfig:{footer:{message:"Copyright \xa9 2023 ByteDance."},socialLinks:[{icon:"github",mode:"link",content:"https://github.com/web-infra-dev/modern.js/tree/main/packages/solutions/module-tools"}],locales:[{lang:"zh",label:"\u7B80\u4F53\u4E2D\u6587",nav:[{text:"\u6307\u5357",link:"/guide/intro/welcome",activeMatch:"^/guide/"},{text:"API",link:"/api/",activeMatch:"^/api/"},{text:"\u63D2\u4EF6",link:"/plugins/guide/getting-started",activeMatch:"^/plugins/"},{text:"v2.35.1",items:[{text:"\u66F4\u65B0\u65E5\u5FD7",link:"https://github.com/web-infra-dev/modern.js/tree/main/packages/solutions/module-tools/CHANGELOG.md"},{text:"\u8D21\u732E\u6307\u5357",link:"https://modernjs.dev/en/community/contributing-guide.html"}]}],title:"Modern.js Module",outlineTitle:"\u76EE\u5F55",prevPageText:"\u4E0A\u4E00\u9875",nextPageText:"\u4E0B\u4E00\u9875",description:"\u6A21\u5757\u5DE5\u7A0B\u89E3\u51B3\u65B9\u6848",sidebar:{"/api/":[{text:"\u6982\u89C8",link:"/module-tools/api/"},{text:"\u914D\u7F6E\u9879",collapsed:!1,collapsible:!0,items:[{text:"buildConfig",link:"/module-tools/api/config/build-config"},{text:"buildPreset",link:"/module-tools/api/config/build-preset"},{text:"dev",link:"/module-tools/api/config/dev"},{text:"plugins",link:"/module-tools/api/config/plugins"},{text:"testing",link:"/module-tools/api/config/testing"}]},{text:"Plugin API",collapsed:!1,collapsible:!0,items:[{text:"Plugin Hooks",link:"/module-tools/api/plugin-api/plugin-hooks"}]}],"/guide/":[{text:"\u4ECB\u7ECD",collapsed:!1,collapsible:!0,items:[{text:"\u6B22\u8FCE\u4F7F\u7528",link:"/module-tools/guide/intro/welcome"},{text:"\u4E3A\u4EC0\u4E48\u9700\u8981 Modern.js Module",link:"/module-tools/guide/intro/why-module-engineering-solution"},{text:"\u5FEB\u901F\u5F00\u59CB",link:"/module-tools/guide/intro/getting-started"}]},{text:"\u57FA\u7840\u4F7F\u7528",collapsed:!1,collapsible:!0,items:[{text:"\u5F00\u59CB\u4E4B\u524D",link:"/module-tools/guide/basic/before-getting-started"},{text:"CLI \u547D\u4EE4",link:"/module-tools/guide/basic/command-preview"},{text:"\u4FEE\u6539\u8F93\u51FA\u4EA7\u7269",link:"/module-tools/guide/basic/modify-output-product"},{text:"\u4F7F\u7528\u5FAE\u751F\u6210\u5668",link:"/module-tools/guide/basic/use-micro-generator"},{text:"\u4F7F\u7528 Storybook",link:"/module-tools/guide/basic/using-storybook"},{text:"\u6D4B\u8BD5\u9879\u76EE",link:"/module-tools/guide/basic/test-your-project"},{text:"\u7248\u672C\u7BA1\u7406\u4E0E\u53D1\u5E03",link:"/module-tools/guide/basic/publish-your-project"}]},{text:"\u8FDB\u9636\u6307\u5357",collapsed:!1,collapsible:!0,items:[{text:"\u6DF1\u5165\u7406\u89E3\u6784\u5EFA",link:"/module-tools/guide/advance/in-depth-about-build"},{text:"\u6DF1\u5165\u7406\u89E3 dev \u547D\u4EE4",link:"/module-tools/guide/advance/in-depth-about-dev-command"},{text:"\u4F7F\u7528 Copy \u5DE5\u5177",link:"/module-tools/guide/advance/copy"},{text:"\u5904\u7406\u4E09\u65B9\u4F9D\u8D56",link:"/module-tools/guide/advance/external-dependency"},{text:"\u6784\u5EFA umd \u4EA7\u7269",link:"/module-tools/guide/advance/build-umd"},{text:"\u5904\u7406\u9759\u6001\u8D44\u6E90",link:"/module-tools/guide/advance/asset"}]},{text:"\u6700\u4F73\u5B9E\u8DF5",collapsed:!1,collapsible:!0,items:[{text:"\u5F00\u53D1\u7EC4\u4EF6",link:"/module-tools/guide/best-practices/components"},{text:"\u4F7F\u7528 Tailwind CSS",link:"/module-tools/guide/best-practices/use-tailwindcss"}]},{text:"\u5E38\u89C1\u95EE\u9898",link:"/module-tools/guide/faq/",collapsed:!1,collapsible:!0,items:[{text:"\u6784\u5EFA\u76F8\u5173\u95EE\u9898",link:"/module-tools/guide/faq/build"},{text:"Storybook \u76F8\u5173\u95EE\u9898",link:"/module-tools/guide/faq/storybook"},{text:"\u6D4B\u8BD5\u76F8\u5173\u95EE\u9898",link:"/module-tools/guide/faq/test"}]}],"/plugins/":[{text:"\u6307\u5357",collapsed:!1,collapsible:!0,items:[{text:"\u5FEB\u901F\u5F00\u59CB",link:"/module-tools/plugins/guide/getting-started"},{text:"\u63D2\u4EF6\u5BF9\u8C61",link:"/module-tools/plugins/guide/plugin-object"},{text:"Setup \u51FD\u6570",link:"/module-tools/plugins/guide/setup-function"}]},{text:"\u63D2\u4EF6\u5217\u8868",collapsed:!1,collapsible:!0,items:[{text:"\u603B\u89C8",link:"/module-tools/plugins/official-list/overview"},{text:"Babel \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-babel"},{text:"Banner \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-banner"},{text:"Import \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-import"},{text:"Node Polyfill \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-node-polyfill"},{text:"Polyfill \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-polyfill"}]}]}},{lang:"en",label:"English",nav:[{text:"Guide",link:"/en/guide/intro/welcome",activeMatch:"^/guide/"},{text:"API",link:"/en/api/",activeMatch:"^/api/"},{text:"Plugins",link:"/en/plugins/guide/getting-started",activeMatch:"^/plugins/"},{text:"v2.35.1",items:[{text:"Changelog",link:"https://github.com/web-infra-dev/modern.js/tree/main/packages/solutions/module-tools/CHANGELOG.md"},{text:"Contributing",link:"https://modernjs.dev/en/community/contributing-guide.html"}]}],title:"Modern.js Module",description:"Module Engineering Solutions",sidebar:{"/en/api/":[{text:"Overview",link:"/module-tools/en/api/"},{text:"Config",collapsed:!1,collapsible:!0,items:[{text:"buildConfig",link:"/module-tools/en/api/config/build-config"},{text:"buildPreset",link:"/module-tools/en/api/config/build-preset"},{text:"dev",link:"/module-tools/en/api/config/dev"},{text:"plugins",link:"/module-tools/en/api/config/plugins"},{text:"testing",link:"/module-tools/en/api/config/testing"}]},{text:"Plugin API",collapsed:!1,collapsible:!0,items:[{text:"Plugin Hooks",link:"/module-tools/en/api/plugin-api/plugin-hooks"}]}],"/en/guide/":[{text:"Introduction",collapsed:!1,collapsible:!0,items:[{text:"Welcome to Modern.js Module",link:"/module-tools/en/guide/intro/welcome"},{text:"Why you need Modern.js Module",link:"/module-tools/en/guide/intro/why-module-engineering-solution"},{text:"Quick Start",link:"/module-tools/en/guide/intro/getting-started"}]},{text:"Basic Guide",collapsed:!1,collapsible:!0,items:[{text:"Before you start",link:"/module-tools/en/guide/basic/before-getting-started"},{text:"CLI Commands",link:"/module-tools/en/guide/basic/command-preview"},{text:"Modify the output product",link:"/module-tools/en/guide/basic/modify-output-product"},{text:"Using the Microgenerator",link:"/module-tools/en/guide/basic/use-micro-generator"},{text:"Using Storybook",link:"/module-tools/en/guide/basic/using-storybook"},{text:"Testing Projects",link:"/module-tools/en/guide/basic/test-your-project"},{text:"Versioning and Publishing",link:"/module-tools/en/guide/basic/publish-your-project"}]},{text:"Advanced Guide",collapsed:!1,collapsible:!0,items:[{text:"In-depth understanding of build",link:"/module-tools/en/guide/advance/in-depth-about-build"},{text:"In-depth understanding of the dev command",link:"/module-tools/en/guide/advance/in-depth-about-dev-command"},{text:"Use the Copy Tools",link:"/module-tools/en/guide/advance/copy"},{text:"Handle third-party dependencies",link:"/module-tools/en/guide/advance/external-dependency"},{text:"Build umd artifacts",link:"/module-tools/en/guide/advance/build-umd"},{text:"Handle static assets",link:"/module-tools/en/guide/advance/asset"}]},{text:"Best practices",collapsed:!1,collapsible:!0,items:[{text:"Developing Components",link:"/module-tools/en/guide/best-practices/components"},{text:"Using Tailwind CSS",link:"/module-tools/en/guide/best-practices/use-tailwindcss"}]},{text:"FAQ",link:"/module-tools/en/guide/faq/",collapsed:!1,collapsible:!0,items:[{text:"Build FAQ",link:"/module-tools/en/guide/faq/build"},{text:"Storybook FAQ",link:"/module-tools/en/guide/faq/storybook"},{text:"Test FAQ",link:"/module-tools/en/guide/faq/test"}]}],"/en/plugins/":[{text:"Guide",collapsed:!1,collapsible:!0,items:[{text:"Quick Start",link:"/module-tools/en/plugins/guide/getting-started"},{text:"Plugin Object",link:"/module-tools/en/plugins/guide/plugin-object"},{text:"Setup function",link:"/module-tools/en/plugins/guide/setup-function"}]},{text:"Plugins List",collapsed:!1,collapsible:!0,items:[{text:"Overview",link:"/module-tools/en/plugins/official-list/overview"},{text:"Babel Plugin",link:"/module-tools/en/plugins/official-list/plugin-babel"},{text:"Banner Plugin",link:"/module-tools/en/plugins/official-list/plugin-banner"},{text:"Import Plugin",link:"/module-tools/en/plugins/official-list/plugin-import"},{text:"Node Polyfill Plugin",link:"/module-tools/en/plugins/official-list/plugin-node-polyfill"},{text:"Polyfill Plugin",link:"/module-tools/en/plugins/official-list/plugin-polyfill"}]}]}}],editLink:{docRepoBaseUrl:"https://github.com/web-infra-dev/modern.js/tree/main/packages/document/module-doc/docs",text:"Edit this page on GitHub"}},base:"/module-tools/",lang:"zh",locales:[{lang:"zh",label:"\u7B80\u4F53\u4E2D\u6587",nav:[{text:"\u6307\u5357",link:"/guide/intro/welcome",activeMatch:"^/guide/"},{text:"API",link:"/api/",activeMatch:"^/api/"},{text:"\u63D2\u4EF6",link:"/plugins/guide/getting-started",activeMatch:"^/plugins/"},{text:"v2.35.1",items:[{text:"\u66F4\u65B0\u65E5\u5FD7",link:"https://github.com/web-infra-dev/modern.js/tree/main/packages/solutions/module-tools/CHANGELOG.md"},{text:"\u8D21\u732E\u6307\u5357",link:"https://modernjs.dev/en/community/contributing-guide.html"}]}],title:"Modern.js Module",outlineTitle:"\u76EE\u5F55",prevPageText:"\u4E0A\u4E00\u9875",nextPageText:"\u4E0B\u4E00\u9875",description:"\u6A21\u5757\u5DE5\u7A0B\u89E3\u51B3\u65B9\u6848",sidebar:{"/api/":[{text:"\u6982\u89C8",link:"/module-tools/api/"},{text:"\u914D\u7F6E\u9879",collapsed:!1,collapsible:!0,items:[{text:"buildConfig",link:"/module-tools/api/config/build-config"},{text:"buildPreset",link:"/module-tools/api/config/build-preset"},{text:"dev",link:"/module-tools/api/config/dev"},{text:"plugins",link:"/module-tools/api/config/plugins"},{text:"testing",link:"/module-tools/api/config/testing"}]},{text:"Plugin API",collapsed:!1,collapsible:!0,items:[{text:"Plugin Hooks",link:"/module-tools/api/plugin-api/plugin-hooks"}]}],"/guide/":[{text:"\u4ECB\u7ECD",collapsed:!1,collapsible:!0,items:[{text:"\u6B22\u8FCE\u4F7F\u7528",link:"/module-tools/guide/intro/welcome"},{text:"\u4E3A\u4EC0\u4E48\u9700\u8981 Modern.js Module",link:"/module-tools/guide/intro/why-module-engineering-solution"},{text:"\u5FEB\u901F\u5F00\u59CB",link:"/module-tools/guide/intro/getting-started"}]},{text:"\u57FA\u7840\u4F7F\u7528",collapsed:!1,collapsible:!0,items:[{text:"\u5F00\u59CB\u4E4B\u524D",link:"/module-tools/guide/basic/before-getting-started"},{text:"CLI \u547D\u4EE4",link:"/module-tools/guide/basic/command-preview"},{text:"\u4FEE\u6539\u8F93\u51FA\u4EA7\u7269",link:"/module-tools/guide/basic/modify-output-product"},{text:"\u4F7F\u7528\u5FAE\u751F\u6210\u5668",link:"/module-tools/guide/basic/use-micro-generator"},{text:"\u4F7F\u7528 Storybook",link:"/module-tools/guide/basic/using-storybook"},{text:"\u6D4B\u8BD5\u9879\u76EE",link:"/module-tools/guide/basic/test-your-project"},{text:"\u7248\u672C\u7BA1\u7406\u4E0E\u53D1\u5E03",link:"/module-tools/guide/basic/publish-your-project"}]},{text:"\u8FDB\u9636\u6307\u5357",collapsed:!1,collapsible:!0,items:[{text:"\u6DF1\u5165\u7406\u89E3\u6784\u5EFA",link:"/module-tools/guide/advance/in-depth-about-build"},{text:"\u6DF1\u5165\u7406\u89E3 dev \u547D\u4EE4",link:"/module-tools/guide/advance/in-depth-about-dev-command"},{text:"\u4F7F\u7528 Copy \u5DE5\u5177",link:"/module-tools/guide/advance/copy"},{text:"\u5904\u7406\u4E09\u65B9\u4F9D\u8D56",link:"/module-tools/guide/advance/external-dependency"},{text:"\u6784\u5EFA umd \u4EA7\u7269",link:"/module-tools/guide/advance/build-umd"},{text:"\u5904\u7406\u9759\u6001\u8D44\u6E90",link:"/module-tools/guide/advance/asset"}]},{text:"\u6700\u4F73\u5B9E\u8DF5",collapsed:!1,collapsible:!0,items:[{text:"\u5F00\u53D1\u7EC4\u4EF6",link:"/module-tools/guide/best-practices/components"},{text:"\u4F7F\u7528 Tailwind CSS",link:"/module-tools/guide/best-practices/use-tailwindcss"}]},{text:"\u5E38\u89C1\u95EE\u9898",link:"/module-tools/guide/faq/",collapsed:!1,collapsible:!0,items:[{text:"\u6784\u5EFA\u76F8\u5173\u95EE\u9898",link:"/module-tools/guide/faq/build"},{text:"Storybook \u76F8\u5173\u95EE\u9898",link:"/module-tools/guide/faq/storybook"},{text:"\u6D4B\u8BD5\u76F8\u5173\u95EE\u9898",link:"/module-tools/guide/faq/test"}]}],"/plugins/":[{text:"\u6307\u5357",collapsed:!1,collapsible:!0,items:[{text:"\u5FEB\u901F\u5F00\u59CB",link:"/module-tools/plugins/guide/getting-started"},{text:"\u63D2\u4EF6\u5BF9\u8C61",link:"/module-tools/plugins/guide/plugin-object"},{text:"Setup \u51FD\u6570",link:"/module-tools/plugins/guide/setup-function"}]},{text:"\u63D2\u4EF6\u5217\u8868",collapsed:!1,collapsible:!0,items:[{text:"\u603B\u89C8",link:"/module-tools/plugins/official-list/overview"},{text:"Babel \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-babel"},{text:"Banner \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-banner"},{text:"Import \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-import"},{text:"Node Polyfill \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-node-polyfill"},{text:"Polyfill \u63D2\u4EF6",link:"/module-tools/plugins/official-list/plugin-polyfill"}]}]}},{lang:"en",label:"English",nav:[{text:"Guide",link:"/en/guide/intro/welcome",activeMatch:"^/guide/"},{text:"API",link:"/en/api/",activeMatch:"^/api/"},{text:"Plugins",link:"/en/plugins/guide/getting-started",activeMatch:"^/plugins/"},{text:"v2.35.1",items:[{text:"Changelog",link:"https://github.com/web-infra-dev/modern.js/tree/main/packages/solutions/module-tools/CHANGELOG.md"},{text:"Contributing",link:"https://modernjs.dev/en/community/contributing-guide.html"}]}],title:"Modern.js Module",description:"Module Engineering Solutions",sidebar:{"/en/api/":[{text:"Overview",link:"/module-tools/en/api/"},{text:"Config",collapsed:!1,collapsible:!0,items:[{text:"buildConfig",link:"/module-tools/en/api/config/build-config"},{text:"buildPreset",link:"/module-tools/en/api/config/build-preset"},{text:"dev",link:"/module-tools/en/api/config/dev"},{text:"plugins",link:"/module-tools/en/api/config/plugins"},{text:"testing",link:"/module-tools/en/api/config/testing"}]},{text:"Plugin API",collapsed:!1,collapsible:!0,items:[{text:"Plugin Hooks",link:"/module-tools/en/api/plugin-api/plugin-hooks"}]}],"/en/guide/":[{text:"Introduction",collapsed:!1,collapsible:!0,items:[{text:"Welcome to Modern.js Module",link:"/module-tools/en/guide/intro/welcome"},{text:"Why you need Modern.js Module",link:"/module-tools/en/guide/intro/why-module-engineering-solution"},{text:"Quick Start",link:"/module-tools/en/guide/intro/getting-started"}]},{text:"Basic Guide",collapsed:!1,collapsible:!0,items:[{text:"Before you start",link:"/module-tools/en/guide/basic/before-getting-started"},{text:"CLI Commands",link:"/module-tools/en/guide/basic/command-preview"},{text:"Modify the output product",link:"/module-tools/en/guide/basic/modify-output-product"},{text:"Using the Microgenerator",link:"/module-tools/en/guide/basic/use-micro-generator"},{text:"Using Storybook",link:"/module-tools/en/guide/basic/using-storybook"},{text:"Testing Projects",link:"/module-tools/en/guide/basic/test-your-project"},{text:"Versioning and Publishing",link:"/module-tools/en/guide/basic/publish-your-project"}]},{text:"Advanced Guide",collapsed:!1,collapsible:!0,items:[{text:"In-depth understanding of build",link:"/module-tools/en/guide/advance/in-depth-about-build"},{text:"In-depth understanding of the dev command",link:"/module-tools/en/guide/advance/in-depth-about-dev-command"},{text:"Use the Copy Tools",link:"/module-tools/en/guide/advance/copy"},{text:"Handle third-party dependencies",link:"/module-tools/en/guide/advance/external-dependency"},{text:"Build umd artifacts",link:"/module-tools/en/guide/advance/build-umd"},{text:"Handle static assets",link:"/module-tools/en/guide/advance/asset"}]},{text:"Best practices",collapsed:!1,collapsible:!0,items:[{text:"Developing Components",link:"/module-tools/en/guide/best-practices/components"},{text:"Using Tailwind CSS",link:"/module-tools/en/guide/best-practices/use-tailwindcss"}]},{text:"FAQ",link:"/module-tools/en/guide/faq/",collapsed:!1,collapsible:!0,items:[{text:"Build FAQ",link:"/module-tools/en/guide/faq/build"},{text:"Storybook FAQ",link:"/module-tools/en/guide/faq/storybook"},{text:"Test FAQ",link:"/module-tools/en/guide/faq/test"}]}],"/en/plugins/":[{text:"Guide",collapsed:!1,collapsible:!0,items:[{text:"Quick Start",link:"/module-tools/en/plugins/guide/getting-started"},{text:"Plugin Object",link:"/module-tools/en/plugins/guide/plugin-object"},{text:"Setup function",link:"/module-tools/en/plugins/guide/setup-function"}]},{text:"Plugins List",collapsed:!1,collapsible:!0,items:[{text:"Overview",link:"/module-tools/en/plugins/official-list/overview"},{text:"Babel Plugin",link:"/module-tools/en/plugins/official-list/plugin-babel"},{text:"Banner Plugin",link:"/module-tools/en/plugins/official-list/plugin-banner"},{text:"Import Plugin",link:"/module-tools/en/plugins/official-list/plugin-import"},{text:"Node Polyfill Plugin",link:"/module-tools/en/plugins/official-list/plugin-node-polyfill"},{text:"Polyfill Plugin",link:"/module-tools/en/plugins/official-list/plugin-polyfill"}]}]}}],logo:"",multiVersion:{default:"",versions:[]},search:{mode:"local"},pages:[{title:"buildConfig",routePath:"/module-tools/en/api/config/build-config",lang:"en",toc:[{text:"alias",id:"alias",depth:2,charIndex:378},{text:"asset",id:"asset",depth:2,charIndex:1394},{text:"asset.path",id:"assetpath",depth:2,charIndex:1453},{text:"asset.limit",id:"assetlimit",depth:2,charIndex:1557},{text:"asset.publicPath",id:"assetpublicpath",depth:2,charIndex:2123},{text:"asset.svgr",id:"assetsvgr",depth:2,charIndex:2406},{text:"asset.svgr.include",id:"assetsvgrinclude",depth:2,charIndex:3027},{text:"asset.svgr.exclude",id:"assetsvgrexclude",depth:2,charIndex:3145},{text:"autoExternal",id:"autoexternal",depth:2,charIndex:3262},{text:"autoExternal.dependencies",id:"autoexternaldependencies",depth:2,charIndex:3992},{text:"autoExternal.peerDependencies",id:"autoexternalpeerdependencies",depth:2,charIndex:4128},{text:"banner",id:"banner",depth:2,charIndex:4259},{text:"buildType",id:"buildtype",depth:2,charIndex:4876},{text:"copy",id:"copy",depth:2,charIndex:5036},{text:"copy.patterns",id:"copypatterns",depth:2,charIndex:5301},{text:"copy.options",id:"copyoptions",depth:2,charIndex:5474},{text:"define",id:"define",depth:2,charIndex:5771},{text:"dts",id:"dts",depth:2,charIndex:7136},{text:"dts.abortOnError",id:"dtsabortonerror",depth:2,charIndex:7318},{text:"dts.distPath",id:"dtsdistpath",depth:2,charIndex:7903},{text:"dts.only",id:"dtsonly",depth:2,charIndex:8166},{text:"dts.tsconfigPath",id:"dtstsconfigpath",depth:2,charIndex:8414},{text:"dts.respectExternal",id:"dtsrespectexternal",depth:2,charIndex:8662},{text:"esbuildOptions",id:"esbuildoptions",depth:2,charIndex:9198},{text:"externalHelpers",id:"externalhelpers",depth:2,charIndex:10723},{text:"externals",id:"externals",depth:2,charIndex:11689},{text:"footer",id:"footer",depth:2,charIndex:12025},{text:"format",id:"format",depth:2,charIndex:12121},{text:"format: esm",id:"format-esm",depth:3,charIndex:12308},{text:"format: cjs",id:"format-cjs",depth:3,charIndex:12523},{text:"format: iife",id:"format-iife",depth:3,charIndex:12794},{text:"format: umd",id:"format-umd",depth:3,charIndex:13164},{text:"hooks",id:"hooks",depth:2,charIndex:13542},{text:"input",id:"input",depth:2,charIndex:14500},{text:"jsx",id:"jsx",depth:2,charIndex:16089},{text:"metafile",id:"metafile",depth:2,charIndex:16702},{text:"minify",id:"minify",depth:2,charIndex:17232},{text:"outDir",id:"outdir",depth:2,charIndex:17493},{text:"platform",id:"platform",depth:2,charIndex:17669},{text:"redirect",id:"redirect",depth:2,charIndex:17947},{text:"resolve",id:"resolve",depth:2,charIndex:18639},{text:"resolve.mainFields",id:"resolvemainfields",depth:3,charIndex:18684},{text:"resolve.jsExtentions",id:"resolvejsextentions",depth:3,charIndex:19307},{text:"sideEffects",id:"sideeffects",depth:2,charIndex:19885},{text:"sourceDir",id:"sourcedir",depth:2,charIndex:21098},{text:"sourceMap",id:"sourcemap",depth:2,charIndex:21331},{text:"sourceType",id:"sourcetype",depth:2,charIndex:21442},{text:"splitting",id:"splitting",depth:2,charIndex:21669},{text:"style",id:"style",depth:2,charIndex:21752},{text:"style.less",id:"styleless",depth:2,charIndex:21800},{text:"style.less.lessOptions",id:"stylelesslessoptions",depth:2,charIndex:21842},{text:"style.less.additionalData",id:"stylelessadditionaldata",depth:2,charIndex:21967},{text:"style.less.implementation",id:"stylelessimplementation",depth:2,charIndex:22222},{text:"style.sass",id:"stylesass",depth:2,charIndex:22827},{text:"style.sass.sassOptions",id:"stylesasssassoptions",depth:2,charIndex:22870},{text:"style.sass.additionalData",id:"stylesassadditionaldata",depth:2,charIndex:22976},{text:"style.sass.implementation",id:"stylesassimplementation",depth:2,charIndex:23291},{text:"style.postcss",id:"stylepostcss",depth:2,charIndex:23891},{text:"style.inject",id:"styleinject",depth:2,charIndex:24893},{text:"style.autoModules",id:"styleautomodules",depth:2,charIndex:26353},{text:"style.modules",id:"stylemodules",depth:2,charIndex:26700},{text:"style.tailwindcss",id:"styletailwindcss",depth:2,charIndex:27160},{text:"Enabling Tailwind CSS",id:"enabling-tailwind-css",depth:3,charIndex:27413},{text:"Type",id:"type",depth:3,charIndex:27622},{text:"Notes",id:"notes",depth:3,charIndex:27927},{text:"target",id:"target",depth:2,charIndex:28510},{text:"transformImport",id:"transformimport",depth:2,charIndex:29101},{text:"transformLodash",id:"transformlodash",depth:2,charIndex:29655},{text:"tsconfig",id:"tsconfig",depth:2,charIndex:30260},{text:"umdGlobals",id:"umdglobals",depth:2,charIndex:30457},{text:"umdModuleName",id:"umdmodulename",depth:2,charIndex:30888}],frontmatter:{sidebar_position:1},version:"",_relativePath:"en/api/config/build-config.mdx"},{title:"buildPreset",routePath:"/module-tools/en/api/config/build-preset",lang:"en",toc:[{text:"npm-library",id:"npm-library",depth:3,charIndex:118},{text:"npm-library-with-umd",id:"npm-library-with-umd",depth:3,charIndex:827},{text:"npm-component",id:"npm-component",depth:3,charIndex:1685},{text:"npm-component-with-umd",id:"npm-component-with-umd",depth:3,charIndex:2617},{text:"npm-library-{es5...esnext}",id:"npm-library-es5esnext",depth:3,charIndex:3476},{text:"string / function",id:"string--function",depth:2,charIndex:3911}],frontmatter:{sidebar_position:2},version:"",_relativePath:"en/api/config/build-preset.mdx"},{title:"dev",routePath:"/module-tools/en/api/config/dev",lang:"en",toc:[{text:"storybook",id:"storybook",depth:2,charIndex:182},{text:"storybook.webpack",id:"storybookwebpack",depth:3,charIndex:440},{text:"Configure Manager App",id:"configure-manager-app",depth:4,charIndex:821},{text:"storybook.webpackChain",id:"storybookwebpackchain",depth:3,charIndex:1194}],frontmatter:{sidebar_position:3},version:"",_relativePath:"en/api/config/dev.md"},{title:"plugins",routePath:"/module-tools/en/api/config/plugins",lang:"en",toc:[{text:"Plugin Execution Order",id:"plugin-execution-order",depth:2,charIndex:140},{text:"Developing Plugins",id:"developing-plugins",depth:2,charIndex:584},{text:"Example",id:"example",depth:2,charIndex:680},{text:"Using Plugins from npm",id:"using-plugins-from-npm",depth:3,charIndex:691},{text:"Using Local Plugins",id:"using-local-plugins",depth:4,charIndex:898},{text:"Plugin Configuration",id:"plugin-configuration",depth:3,charIndex:1082}],frontmatter:{sidebar_position:4},version:"",_relativePath:"en/api/config/plugins.md"},{title:"testing",routePath:"/module-tools/en/api/config/testing",lang:"en",toc:[{text:"jest",id:"jest",depth:2,charIndex:133},{text:"transformer",id:"transformer",depth:2,charIndex:736}],frontmatter:{sidebar_position:5},version:"",_relativePath:"en/api/config/testing.md"},{title:"Overview",routePath:"/module-tools/en/api/",lang:"en",toc:[],frontmatter:{overview:!0,sidebar_label:"Overview",sidebar_position:1},version:"",_relativePath:"en/api/index.md"},{title:"Plugin Hooks",routePath:"/module-tools/en/api/plugin-api/plugin-hooks",lang:"en",toc:[{text:"build hooks",id:"build-hooks",depth:2,charIndex:424},{text:"beforeBuild",id:"beforebuild",depth:3,charIndex:586},{text:"beforeBuildTask",id:"beforebuildtask",depth:3,charIndex:1223},{text:"afterBuildTask",id:"afterbuildtask",depth:3,charIndex:1699},{text:"afterBuild",id:"afterbuild",depth:3,charIndex:2103},{text:"buildPlatform hooks",id:"buildplatform-hooks",depth:2,charIndex:2558},{text:"registerBuildPlatform",id:"registerbuildplatform",depth:3,charIndex:3057},{text:"beforeBuildPlatform",id:"beforebuildplatform",depth:3,charIndex:3779},{text:"buildPlatform",id:"buildplatform",depth:3,charIndex:4503},{text:"afterBuildPlatform",id:"afterbuildplatform",depth:3,charIndex:4998},{text:"Dev Hooks",id:"dev-hooks",depth:2,charIndex:5702},{text:"registerDev.",id:"registerdev",depth:3,charIndex:6177},{text:"beforeDev",id:"beforedev",depth:3,charIndex:7287},{text:"(before|after)DevMenu",id:"beforeafterdevmenu",depth:3,charIndex:7889},{text:"beforeDevTask",id:"beforedevtask",depth:3,charIndex:9070},{text:"afterDev",id:"afterdev",depth:3,charIndex:9640}],frontmatter:{},version:"",_relativePath:"en/api/plugin-api/plugin-hooks.md"},{title:"",routePath:"/module-tools/en/components/faq-build-exception",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/components/faq-build-exception.mdx"},{title:"",routePath:"/module-tools/en/components/faq-build-other",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/components/faq-build-other.mdx"},{title:"",routePath:"/module-tools/en/components/faq-build-product",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/components/faq-build-product.mdx"},{title:"",routePath:"/module-tools/en/components/faq-storybook",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/components/faq-storybook.mdx"},{title:"",routePath:"/module-tools/en/components/faq-test",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/components/faq-test.mdx"},{title:"",routePath:"/module-tools/en/components/register-esbuild-plugin",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/components/register-esbuild-plugin.mdx"},{title:"Handle static assets",routePath:"/module-tools/en/guide/advance/asset",lang:"en",toc:[{text:"Default behavior",id:"default-behavior",depth:2,charIndex:139},{text:"Example",id:"example",depth:2,charIndex:571}],frontmatter:{sidebar_position:6},version:"",_relativePath:"en/guide/advance/asset.mdx"},{title:"Build umd artifacts",routePath:"/module-tools/en/guide/advance/build-umd",lang:"en",toc:[{text:"Third-party dependency handling for umd artifacts",id:"third-party-dependency-handling-for-umd-artifacts",depth:2,charIndex:487},{text:"Example",id:"example",depth:3,charIndex:791},{text:"Global variable names of third-party dependencies",id:"global-variable-names-of-third-party-dependencies",depth:3,charIndex:2178},{text:"Changing the name of a global variable in a project",id:"changing-the-name-of-a-global-variable-in-a-project",depth:2,charIndex:3607}],frontmatter:{sidebar_position:5},version:"",_relativePath:"en/guide/advance/build-umd.mdx"},{title:"Use the Copy Tools",routePath:"/module-tools/en/guide/advance/copy",lang:"en",toc:[{text:"Understanding the Copy API",id:"understanding-the-copy-api",depth:2,charIndex:171},{text:"API Description",id:"api-description",depth:2,charIndex:335},{text:"Examples of Different Scenarios",id:"examples-of-different-scenarios",depth:2,charIndex:2449},{text:"Copying Files",id:"copying-files",depth:3,charIndex:2484},{text:"Copying Files to a Directory",id:"copying-files-to-a-directory",depth:3,charIndex:2834},{text:"Copying from Directory to Directory",id:"copying-from-directory-to-directory",depth:3,charIndex:3192},{text:"Copying from Directory to File",id:"copying-from-directory-to-file",depth:3,charIndex:3613},{text:"Using Glob",id:"using-glob",depth:3,charIndex:4042}],frontmatter:{sidebar_position:3},version:"",_relativePath:"en/guide/advance/copy.md"},{title:"Handle third-party dependencies",routePath:"/module-tools/en/guide/advance/external-dependency",lang:"en",toc:[{text:"Default handling of third-party dependencies",id:"default-handling-of-third-party-dependencies",depth:2,charIndex:861},{text:"Example",id:"example",depth:3,charIndex:1423},{text:"Exclude specified third-party dependencies",id:"exclude-specified-third-party-dependencies",depth:2,charIndex:1840}],frontmatter:{sidebar_position:4},version:"",_relativePath:"en/guide/advance/external-dependency.mdx"},{title:"In-depth understanding of build",routePath:"/module-tools/en/guide/advance/in-depth-about-build",lang:"en",toc:[{text:"bundle / bundleless",id:"bundle--bundleless",depth:2,charIndex:497},{text:"input / sourceDir",id:"input--sourcedir",depth:2,charIndex:1630},{text:"use swc",id:"use-swc",depth:2,charIndex:2902},{text:"Using Hooks to Intervene in the Build Process",id:"using-hooks-to-intervene-in-the-build-process",depth:2,charIndex:3852},{text:"Hook type",id:"hook-type",depth:3,charIndex:4232},{text:"AsyncSeriesBailHook",id:"asyncseriesbailhook",depth:4,charIndex:4244},{text:"AsyncSeriesWaterFallHooks",id:"asyncserieswaterfallhooks",depth:4,charIndex:4383},{text:"Hook API",id:"hook-api",depth:3,charIndex:4480},{text:"load",id:"load",depth:4,charIndex:4491},{text:"transform",id:"transform",depth:4,charIndex:5185},{text:"renderChunk",id:"renderchunk",depth:4,charIndex:5696},{text:"dts",id:"dts",depth:2,charIndex:6675},{text:"Turn off type generation",id:"turn-off-type-generation",depth:3,charIndex:6758},{text:"Build type files",id:"build-type-files",depth:3,charIndex:7035},{text:"Alias Conversion",id:"alias-conversion",depth:3,charIndex:7729},{text:"Some examples of the use of dts",id:"some-examples-of-the-use-of-dts",depth:3,charIndex:8305},{text:"Build process",id:"build-process",depth:2,charIndex:9002},{text:"Build errors",id:"build-errors",depth:2,charIndex:9295},{text:"Debug mode",id:"debug-mode",depth:2,charIndex:10045}],frontmatter:{sidebar_position:1},version:"",_relativePath:"en/guide/advance/in-depth-about-build.md"},{title:"In-depth understanding of the dev command",routePath:"/module-tools/en/guide/advance/in-depth-about-dev-command",lang:"en",toc:[{text:"The overall flow of the command run",id:"the-overall-flow-of-the-command-run",depth:2,charIndex:92},{text:"Extending the dev command",id:"extending-the-dev-command",depth:2,charIndex:805}],frontmatter:{sidebar_position:2},version:"",_relativePath:"en/guide/advance/in-depth-about-dev-command.md"},{title:"Before you start",routePath:"/module-tools/en/guide/basic/before-getting-started",lang:"en",toc:[{text:"Environment preparation",id:"environment-preparation",depth:2,charIndex:3},{text:"Getting Started with npm",id:"getting-started-with-npm",depth:2,charIndex:425},{text:"npm package type project",id:"npm-package-type-project",depth:2,charIndex:907},{text:"Using third-party npm packages",id:"using-third-party-npm-packages",depth:2,charIndex:2127},{text:"Other npm bits and pieces to know",id:"other-npm-bits-and-pieces-to-know",depth:2,charIndex:3994},{text:"Program entry for npm packages",id:"program-entry-for-npm-packages",depth:3,charIndex:4031},{text:"scripts",id:"scripts",depth:3,charIndex:4916},{text:"npm install",id:"npm-install",depth:4,charIndex:5729},{text:"npm publish",id:"npm-publish",depth:4,charIndex:6090},{text:"peerDependencies",id:"peerdependencies",depth:3,charIndex:6360},{text:"npm package manager",id:"npm-package-manager",depth:2,charIndex:7062},{text:"Modern.js Module configuration file",id:"modernjs-module-configuration-file",depth:2,charIndex:7347}],frontmatter:{sidebar_position:1},version:"",_relativePath:"en/guide/basic/before-getting-started.md"},{title:"CLI Commands",routePath:"/module-tools/en/guide/basic/command-preview",lang:"en",toc:[{text:"modern build",id:"modern-build",depth:2,charIndex:73},{text:"modern new",id:"modern-new",depth:2,charIndex:2087},{text:"modern dev",id:"modern-dev",depth:2,charIndex:2866},{text:"modern test",id:"modern-test",depth:2,charIndex:3439},{text:"modern lint",id:"modern-lint",depth:2,charIndex:3747},{text:"modern change",id:"modern-change",depth:2,charIndex:4183},{text:"modern pre",id:"modern-pre",depth:2,charIndex:4511},{text:"modern bump",id:"modern-bump",depth:2,charIndex:4742},{text:"modern release",id:"modern-release",depth:2,charIndex:5261},{text:"modern gen-release-note",id:"modern-gen-release-note",depth:2,charIndex:5741},{text:"modern upgrade",id:"modern-upgrade",depth:2,charIndex:6237}],frontmatter:{sidebar_position:2},version:"",_relativePath:"en/guide/basic/command-preview.md"},{title:"Modify the output product",routePath:"/module-tools/en/guide/basic/modify-output-product",lang:"en",toc:[{text:"Default output products",id:"default-output-products",depth:2,charIndex:3},{text:"buildPreset",id:"buildpreset",depth:2,charIndex:1002},{text:"buildConfig",id:"buildconfig",depth:2,charIndex:1823},{text:"Combining Configuration and Presets",id:"combining-configuration-and-presets",depth:2,charIndex:4571}],frontmatter:{sidebar_position:3},version:"",_relativePath:"en/guide/basic/modify-output-product.md"},{title:"Versioning and Publishing",routePath:"/module-tools/en/guide/basic/publish-your-project",lang:"en",toc:[{text:"Tracking changes",id:"tracking-changes",depth:2,charIndex:406},{text:"Version update",id:"version-update",depth:2,charIndex:1748},{text:"Publish",id:"publish",depth:2,charIndex:2227},{text:"Pre-releases",id:"pre-releases",depth:2,charIndex:2941}],frontmatter:{sidebar_position:7},version:"",_relativePath:"en/guide/basic/publish-your-project.md"},{title:"Testing Projects",routePath:"/module-tools/en/guide/basic/test-your-project",lang:"en",toc:[{text:"Prerequisites and conventions",id:"prerequisites-and-conventions",depth:2,charIndex:52},{text:"Run the tests",id:"run-the-tests",depth:2,charIndex:745},{text:"Usage Configuration",id:"usage-configuration",depth:2,charIndex:1015},{text:"Test example",id:"test-example",depth:2,charIndex:1160},{text:"Common modules",id:"common-modules",depth:3,charIndex:1176},{text:"Components",id:"components",depth:3,charIndex:1781}],frontmatter:{sidebar_position:6},version:"",_relativePath:"en/guide/basic/test-your-project.mdx"},{title:"Using the Microgenerator",routePath:"/module-tools/en/guide/basic/use-micro-generator",lang:"en",toc:[{text:"Test",id:"test",depth:2,charIndex:431},{text:"Storybook",id:"storybook",depth:2,charIndex:908},{text:"Tailwind CSS Support",id:"tailwind-css-support",depth:2,charIndex:1544},{text:"Modern.js Runtime API",id:"modernjs-runtime-api",depth:2,charIndex:1829}],frontmatter:{sidebar_position:4},version:"",_relativePath:"en/guide/basic/use-micro-generator.md"},{title:"Using Storybook",routePath:"/module-tools/en/guide/basic/using-storybook",lang:"en",toc:[{text:"Debugging code",id:"debugging-code",depth:2,charIndex:682},{text:"Referencing component products",id:"referencing-component-products",depth:3,charIndex:1322},{text:"Referencing component source code",id:"referencing-component-source-code",depth:3,charIndex:3382},{text:"Configure Storybook",id:"configure-storybook",depth:2,charIndex:4225},{text:"Building Storybook Products",id:"building-storybook-products",depth:2,charIndex:5155},{text:"Use Tailwind CSS with Storybook",id:"use-tailwind-css-with-storybook",depth:2,charIndex:5542}],frontmatter:{sidebar_position:5},version:"",_relativePath:"en/guide/basic/using-storybook.mdx"},{title:"Developing Components",routePath:"/module-tools/en/guide/best-practices/components",lang:"en",toc:[{text:"Initialize the project",id:"initialize-the-project",depth:2,charIndex:93},{text:"Debugging code with Storybook",id:"debugging-code-with-storybook",depth:2,charIndex:881},{text:"Developing Styles",id:"developing-styles",depth:2,charIndex:980},{text:"CSS/PostCSS",id:"csspostcss",depth:3,charIndex:1186},{text:"Less",id:"less",depth:3,charIndex:1831},{text:"Sass/Scss",id:"sassscss",depth:3,charIndex:2144},{text:"Tailwind CSS",id:"tailwind-css",depth:3,charIndex:2486},{text:"CSS Modules",id:"css-modules",depth:3,charIndex:2560},{text:"Configuring build products",id:"configuring-build-products",depth:2,charIndex:2999},{text:"Testing components",id:"testing-components",depth:2,charIndex:3933},{text:"Releasing components",id:"releasing-components",depth:2,charIndex:4036}],frontmatter:{sidebar_position:1},version:"",_relativePath:"en/guide/best-practices/components.mdx"},{title:"Using Tailwind CSS",routePath:"/module-tools/en/guide/best-practices/use-tailwindcss",lang:"en",toc:[{text:"Enabling Tailwind CSS",id:"enabling-tailwind-css",depth:2,charIndex:252},{text:"Configuring Tailwind CSS",id:"configuring-tailwind-css",depth:2,charIndex:1573},{text:"Tailwind CSS Autocomplete",id:"tailwind-css-autocomplete",depth:3,charIndex:2541},{text:"Build Modes",id:"build-modes",depth:2,charIndex:3112},{text:"Bundle Mode",id:"bundle-mode",depth:3,charIndex:3380},{text:"Bundleless Mode",id:"bundleless-mode",depth:3,charIndex:4149},{text:"Class Name Prefix",id:"class-name-prefix",depth:2,charIndex:4450},{text:"Usage Guide",id:"usage-guide",depth:2,charIndex:5064},{text:"HTML Class Names",id:"html-class-names",depth:3,charIndex:5126},{text:"@apply",id:"apply",depth:3,charIndex:5562},{text:"Sass",id:"sass",depth:4,charIndex:5866},{text:"Less",id:"less",depth:4,charIndex:6157},{text:"About designSystem config",id:"about-designsystem-config",depth:2,charIndex:6796}],frontmatter:{sidebar_position:2},version:"",_relativePath:"en/guide/best-practices/use-tailwindcss.mdx"},{title:"Build FAQ",routePath:"/module-tools/en/guide/faq/build",lang:"en",toc:[{text:"Product FAQ",id:"product-faq",depth:2,charIndex:3},{text:"Initialization of Class Fields",id:"initialization-of-class-fields",depth:3,charIndex:18},{text:"babel-plugin-lodash treats the introduced lodash as undefined",id:"babel-plugin-lodash-treats-the-introduced-lodash-as-undefined",depth:3,charIndex:2081},{text:"Exceptions FAQ",id:"exceptions-faq",depth:2,charIndex:2772},{text:'Dynamic require of \\"react\\" is not supported',id:"dynamic-require-of-react-is-not-supported",depth:3,charIndex:-1},{text:"Problem Description",id:"problem-description",depth:4,charIndex:2836},{text:"Solution",id:"solution",depth:4,charIndex:3139},{text:"Reference Links",id:"reference-links",depth:4,charIndex:3735},{text:"During compilation, an error was reported in the less file of a component library:\\'Operation on an invalid type\\'",id:"during-compilation-an-error-was-reported-in-the-less-file-of-a-component-libraryoperation-on-an-invalid-type",depth:3,charIndex:-1},{text:"Bundle DTS failed",id:"bundle-dts-failed",depth:3,charIndex:5274},{text:'Error reported for defineConfig function type: If there is no reference to \\"...\\" then the inferred type of \\"default\\" cannot be named',id:"error-reported-for-defineconfig-function-type-if-there-is-no-reference-to--then-the-inferred-type-of-default-cannot-be-named",depth:3,charIndex:-1},{text:"Other FAQ",id:"other-faq",depth:2,charIndex:6300},{text:"Add additional compilation feature",id:"add-additional-compilation-feature",depth:3,charIndex:6313},{text:"Support for generating TypeScript declaration files for CSS Modules",id:"support-for-generating-typescript-declaration-files-for-css-modules",depth:3,charIndex:7224}],frontmatter:{},version:"",_relativePath:"en/guide/faq/build.mdx"},{title:"FAQ",routePath:"/module-tools/en/guide/faq/",lang:"en",toc:[],frontmatter:{},version:"",_relativePath:"en/guide/faq/index.md"},{title:"Storybook FAQ",routePath:"/module-tools/en/guide/faq/storybook",lang:"en",toc:[{text:"Storybook v7 Support",id:"storybook-v7-support",depth:2,charIndex:3},{text:"Using Storybook Addon or other configurations does not work",id:"using-storybook-addon-or-other-configurations-does-not-work",depth:2,charIndex:186},{text:"Cannot find module \\'react-dom/package.json",id:"cannot-find-module-react-dompackagejson",depth:2,charIndex:-1},{text:"Unable to locate the specific error message",id:"unable-to-locate-the-specific-error-message",depth:2,charIndex:880},{text:"Can`t find any stories is your Storybook",id:"cant-find-any-stories-is-your-storybook",depth:2,charIndex:1653},{text:"Storybook Adds Proxy Functionality",id:"storybook-adds-proxy-functionality",depth:2,charIndex:1953},{text:"Modify the directory where the Story file exists",id:"modify-the-directory-where-the-story-file-exists",depth:2,charIndex:2800}],frontmatter:{},version:"",_relativePath:"en/guide/faq/storybook.mdx"},{title:"Test FAQ",routePath:"/module-tools/en/guide/faq/test",lang:"en",toc:[{text:"Execute test command with an error TypeError: Cannot read property \\'testEnvironmentOptions\\' of undefined",id:"execute-test-command-with-an-error-typeerror-cannot-read-property-testenvironmentoptions-of-undefined",depth:3,charIndex:-1}],frontmatter:{},version:"",_relativePath:"en/guide/faq/test.mdx"},{title:"Quick Start",routePath:"/module-tools/en/guide/intro/getting-started",lang:"en",toc:[{text:"3 minute demo",id:"3-minute-demo",depth:2,charIndex:3},{text:"Create new project",id:"create-new-project",depth:3,charIndex:210},{text:"Add to an existing project",id:"add-to-an-existing-project",depth:3,charIndex:1097},{text:"Core npm Package",id:"core-npm-package",depth:3,charIndex:1934},{text:"View official example",id:"view-official-example",depth:3,charIndex:2693},{text:"Let\\'s get started",id:"lets-get-started",depth:2,charIndex:-1}],frontmatter:{sidebar_position:3},version:"",_relativePath:"en/guide/intro/getting-started.mdx"},{title:"Welcome to Modern.js Module",routePath:"/module-tools/en/guide/intro/welcome",lang:"en",toc:[],frontmatter:{sidebar_position:1},version:"",_relativePath:"en/guide/intro/welcome.md"},{title:"Why you need Modern.js Module",routePath:"/module-tools/en/guide/intro/why-module-engineering-solution",lang:"en",toc:[],frontmatter:{sidebar_position:2},version:"",_relativePath:"en/guide/intro/why-module-engineering-solution.md"},{title:"index",routePath:"/module-tools/en/",lang:"en",toc:[],frontmatter:{pageType:"home",hero:{name:"Modern.js Module",text:"Module engineering solutions",tagline:"simple, powerful, high-performance modern npm package development solution",actions:[{theme:"brand",text:"Welcome",link:"/en/guide/intro/welcome"},{theme:"alt",text:"Quick Start",link:"/en/guide/intro/getting-started"}]},features:[{title:"esbuild: The High Performance JS Bundler",details:"Built on esbuild, the build is extremely fast and gives you the ultimate development experience.",icon:"\uD83D\uDE80"},{title:"Two build modes",details:"Both bundle and bundleless build modes are supported.",icon:"\u2728"},{title:"Out of the box",details:"Develop your npm packages without too much configuration, with built-in presets covering a wide range of scenarios.",icon:"\uD83D\uDEE0\uFE0F"},{title:"Extensible: Provides a powerful plugin mechanism",details:"With its plugin extension mechanism, you can easily extend the capabilities of Modern.js Module.",icon:"\uD83C\uDFA8"},{title:"Storybook: The community popular UI development tool",details:"Integrated with Storybook, you can use it to debug UI.",icon:"\uD83D\uDCE6"},{title:"Jest: Delightful Testing Framework",details:"Jest integration makes it easier to test code\u3002",icon:"\uD83D\uDCD0"}]},version:"",_relativePath:"en/index.md"},{title:"Quick Start",routePath:"/module-tools/en/plugins/guide/getting-started",lang:"en",toc:[],frontmatter:{sidebar_position:1},version:"",_relativePath:"en/plugins/guide/getting-started.mdx"},{title:"Plugin Object",routePath:"/module-tools/en/plugins/guide/plugin-object",lang:"en",toc:[{text:"Plugin type definitions",id:"plugin-type-definitions",depth:2,charIndex:805},{text:"Plugin configuration options",id:"plugin-configuration-options",depth:2,charIndex:1163}],frontmatter:{sidebar_position:2},version:"",_relativePath:"en/plugins/guide/plugin-object.mdx"},{title:"Setup function",routePath:"/module-tools/en/plugins/guide/setup-function",lang:"en",toc:[{text:"Plugin API objects",id:"plugin-api-objects",depth:2,charIndex:173},{text:"api.useAppContext",id:"apiuseappcontext",depth:3,charIndex:783},{text:"api.useResolvedConfigContext",id:"apiuseresolvedconfigcontext",depth:3,charIndex:1343},{text:"api.useHookRunners",id:"apiusehookrunners",depth:3,charIndex:1811},{text:"Asynchronous setup",id:"asynchronous-setup",depth:2,charIndex:2132},{text:"Life cycle hooks",id:"life-cycle-hooks",depth:2,charIndex:2694}],frontmatter:{sidebar_position:3},version:"",_relativePath:"en/plugins/guide/setup-function.mdx"},{title:"Overview",routePath:"/module-tools/en/plugins/official-list/overview",lang:"en",toc:[{text:"Official Plugin",id:"official-plugin",depth:2,charIndex:3}],frontmatter:{},version:"",_relativePath:"en/plugins/official-list/overview.md"},{title:"Babel Plugin",routePath:"/module-tools/en/plugins/official-list/plugin-babel",lang:"en",toc:[{text:"Quick start",id:"quick-start",depth:2,charIndex:110},{text:"Install",id:"install",depth:3,charIndex:125},{text:"Register",id:"register",depth:3,charIndex:136},{text:"Config",id:"config",depth:2,charIndex:708}],frontmatter:{},version:"",_relativePath:"en/plugins/official-list/plugin-babel.mdx"},{title:"Banner Plugin",routePath:"/module-tools/en/plugins/official-list/plugin-banner",lang:"en",toc:[{text:"Quick Start",id:"quick-start",depth:2,charIndex:89},{text:"Install",id:"install",depth:3,charIndex:104},{text:"Register",id:"register",depth:3,charIndex:115},{text:"Example",id:"example",depth:2,charIndex:456},{text:"Add copyright information at the top of a JS file",id:"add-copyright-information-at-the-top-of-a-js-file",depth:3,charIndex:467},{text:"Configuration",id:"configuration",depth:2,charIndex:967},{text:"banner",id:"banner",depth:3,charIndex:1126},{text:"footer",id:"footer",depth:3,charIndex:1266}],frontmatter:{},version:"",_relativePath:"en/plugins/official-list/plugin-banner.mdx"},{title:"Import Plugin",routePath:"/module-tools/en/plugins/official-list/plugin-import",lang:"en",toc:[{text:"Quick Start",id:"quick-start",depth:2,charIndex:231},{text:"Install",id:"install",depth:3,charIndex:246},{text:"Register",id:"register",depth:3,charIndex:257},{text:"Configurations",id:"configurations",depth:2,charIndex:627},{text:"pluginImport",id:"pluginimport",depth:3,charIndex:708},{text:"Notes",id:"notes",depth:2,charIndex:1127}],frontmatter:{},version:"",_relativePath:"en/plugins/official-list/plugin-import.mdx"},{title:"Node Polyfill Plugin",routePath:"/module-tools/en/plugins/official-list/plugin-node-polyfill",lang:"en",toc:[{text:"Quick Start",id:"quick-start",depth:2,charIndex:460},{text:"Install",id:"install",depth:3,charIndex:475},{text:"Register",id:"register",depth:3,charIndex:486},{text:"Configurations",id:"configurations",depth:2,charIndex:662},{text:"exclude",id:"exclude",depth:3,charIndex:768},{text:"overrides",id:"overrides",depth:3,charIndex:965},{text:"Node Polyfills",id:"node-polyfills",depth:2,charIndex:1211},{text:"Globals",id:"globals",depth:3,charIndex:1229},{text:"Modules",id:"modules",depth:3,charIndex:1420},{text:"Fallbacks",id:"fallbacks",depth:3,charIndex:1921}],frontmatter:{},version:"",_relativePath:"en/plugins/official-list/plugin-node-polyfill.mdx"},{title:"Polyfill Plugin",routePath:"/module-tools/en/plugins/official-list/plugin-polyfill",lang:"en",toc:[{text:"Quick start",id:"quick-start",depth:2,charIndex:497},{text:"Install",id:"install",depth:3,charIndex:512},{text:"Register",id:"register",depth:3,charIndex:523},{text:"Config",id:"config",depth:2,charIndex:1108},{text:"targets",id:"targets",depth:3,charIndex:1178}],frontmatter:{},version:"",_relativePath:"en/plugins/official-list/plugin-polyfill.mdx"},{title:"buildConfig",routePath:"/module-tools/api/config/build-config",lang:"zh",toc:[{text:"alias",id:"alias",depth:2,charIndex:141},{text:"asset",id:"asset",depth:2,charIndex:862},{text:"asset.path",id:"assetpath",depth:2,charIndex:885},{text:"asset.limit",id:"assetlimit",depth:2,charIndex:956},{text:"asset.publicPath",id:"assetpublicpath",depth:2,charIndex:1276},{text:"asset.svgr",id:"assetsvgr",depth:2,charIndex:1493},{text:"asset.svgr.include",id:"assetsvgrinclude",depth:2,charIndex:1889},{text:"asset.svgr.exclude",id:"assetsvgrexclude",depth:2,charIndex:1988},{text:"autoExternal",id:"autoexternal",depth:2,charIndex:2089},{text:"autoExternal.dependencies",id:"autoexternaldependencies",depth:2,charIndex:2588},{text:"autoExternal.peerDependencies",id:"autoexternalpeerdependencies",depth:2,charIndex:2676},{text:"banner",id:"banner",depth:2,charIndex:2772},{text:"buildType",id:"buildtype",depth:2,charIndex:3278},{text:"copy",id:"copy",depth:2,charIndex:3381},{text:"copy.patterns",id:"copypatterns",depth:2,charIndex:3549},{text:"copy.options",id:"copyoptions",depth:2,charIndex:3716},{text:"define",id:"define",depth:2,charIndex:3949},{text:"dts",id:"dts",depth:2,charIndex:4761},{text:"dts.abortOnError",id:"dtsabortonerror",depth:2,charIndex:4882},{text:"dts.distPath",id:"dtsdistpath",depth:2,charIndex:5216},{text:"dts.only",id:"dtsonly",depth:2,charIndex:5416},{text:"dts.respectExternal",id:"dtsrespectexternal",depth:2,charIndex:5588},{text:"dts.tsconfigPath",id:"dtstsconfigpath",depth:2,charIndex:5911},{text:"esbuildOptions",id:"esbuildoptions",depth:2,charIndex:6102},{text:"externalHelpers",id:"externalhelpers",depth:2,charIndex:6954},{text:"externals",id:"externals",depth:2,charIndex:7553},{text:"footer",id:"footer",depth:2,charIndex:7807},{text:"format",id:"format",depth:2,charIndex:7845},{text:"format: esm",id:"format-esm",depth:3,charIndex:7970},{text:"format: cjs",id:"format-cjs",depth:3,charIndex:8124},{text:"format: iife",id:"format-iife",depth:3,charIndex:8297},{text:"format: umd",id:"format-umd",depth:3,charIndex:8474},{text:"hooks",id:"hooks",depth:2,charIndex:8702},{text:"input",id:"input",depth:2,charIndex:9321},{text:"jsx",id:"jsx",depth:2,charIndex:10360},{text:"metafile",id:"metafile",depth:2,charIndex:10761},{text:"minify",id:"minify",depth:2,charIndex:11100},{text:"outDir",id:"outdir",depth:2,charIndex:11352},{text:"platform",id:"platform",depth:2,charIndex:11488},{text:"redirect",id:"redirect",depth:2,charIndex:11679},{text:"resolve",id:"resolve",depth:2,charIndex:12046},{text:"resolve.mainFields",id:"resolvemainfields",depth:3,charIndex:12068},{text:"resolve.jsExtentions",id:"resolvejsextentions",depth:3,charIndex:12513},{text:"sideEffects",id:"sideeffects",depth:2,charIndex:12883},{text:"sourceDir",id:"sourcedir",depth:2,charIndex:13689},{text:"sourceMap",id:"sourcemap",depth:2,charIndex:13785},{text:"sourceType",id:"sourcetype",depth:2,charIndex:13872},{text:"splitting",id:"splitting",depth:2,charIndex:14030},{text:"style",id:"style",depth:2,charIndex:14084},{text:"style.less",id:"styleless",depth:2,charIndex:14105},{text:"style.less.lessOptions",id:"stylelesslessoptions",depth:2,charIndex:14131},{text:"style.less.additionalData",id:"stylelessadditionaldata",depth:2,charIndex:14222},{text:"style.less.implementation",id:"stylelessimplementation",depth:2,charIndex:14454},{text:"sass",id:"sass",depth:2,charIndex:14917},{text:"style.sass.sassOptions",id:"stylesasssassoptions",depth:2,charIndex:14937},{text:"style.sass.additionalData",id:"stylesassadditionaldata",depth:2,charIndex:15007},{text:"style.sass.implementation",id:"stylesassimplementation",depth:2,charIndex:15299},{text:"style.postcss",id:"stylepostcss",depth:2,charIndex:15763},{text:"style.inject",id:"styleinject",depth:2,charIndex:16502},{text:"style.autoModules",id:"styleautomodules",depth:2,charIndex:17446},{text:"style.modules",id:"stylemodules",depth:2,charIndex:17680},{text:"style.tailwindcss",id:"styletailwindcss",depth:2,charIndex:18033},{text:"\u542F\u7528 Tailwind CSS",id:"\u542F\u7528-tailwind-css",depth:3,charIndex:18254},{text:"\u7C7B\u578B",id:"\u7C7B\u578B",depth:3,charIndex:18374},{text:"\u6CE8\u610F\u4E8B\u9879",id:"\u6CE8\u610F\u4E8B\u9879",depth:3,charIndex:18505},{text:"target",id:"target",depth:2,charIndex:18795},{text:"transformImport",id:"transformimport",depth:2,charIndex:19188},{text:"transformLodash",id:"transformlodash",depth:2,charIndex:19578},{text:"tsconfig",id:"tsconfig",depth:2,charIndex:19924},{text:"umdGlobals",id:"umdglobals",depth:2,charIndex:20104},{text:"umdModuleName",id:"umdmodulename",depth:2,charIndex:20398}],frontmatter:{sidebar_position:1},version:"",_relativePath:"zh/api/config/build-config.mdx"},{title:"buildPreset",routePath:"/module-tools/api/config/build-preset",lang:"zh",toc:[{text:"npm-library",id:"npm-library",depth:2,charIndex:76},{text:"npm-library-with-umd",id:"npm-library-with-umd",depth:2,charIndex:655},{text:"npm-component",id:"npm-component",depth:2,charIndex:1376},{text:"npm-component-with-umd",id:"npm-component-with-umd",depth:2,charIndex:2027},{text:"npm-library-{es5...esnext}",id:"npm-library-es5esnext",depth:2,charIndex:2784},{text:"string / function",id:"string--function",depth:2,charIndex:3082}],frontmatter:{sidebar_position:2},version:"",_relativePath:"zh/api/config/build-preset.mdx"},{title:"dev",routePath:"/module-tools/api/config/dev",lang:"zh",toc:[{text:"storybook",id:"storybook",depth:2,charIndex:132},{text:"storybook.webpack",id:"storybookwebpack",depth:3,charIndex:295},{text:"\u914D\u7F6E Manager App",id:"\u914D\u7F6E-manager-app",depth:4,charIndex:605},{text:"storybook.webpackChain",id:"storybookwebpackchain",depth:3,charIndex:901}],frontmatter:{sidebar_position:3},version:"",_relativePath:"zh/api/config/dev.md"},{title:"plugins",routePath:"/module-tools/api/config/plugins",lang:"zh",toc:[{text:"\u63D2\u4EF6\u6267\u884C\u987A\u5E8F",id:"\u63D2\u4EF6\u6267\u884C\u987A\u5E8F",depth:2,charIndex:79},{text:"\u5F00\u53D1\u63D2\u4EF6",id:"\u5F00\u53D1\u63D2\u4EF6",depth:2,charIndex:221},{text:"\u793A\u4F8B",id:"\u793A\u4F8B",depth:2,charIndex:253},{text:"\u4F7F\u7528 npm \u4E0A\u7684\u63D2\u4EF6",id:"\u4F7F\u7528-npm-\u4E0A\u7684\u63D2\u4EF6",depth:3,charIndex:259},{text:"\u4F7F\u7528\u672C\u5730\u63D2\u4EF6",id:"\u4F7F\u7528\u672C\u5730\u63D2\u4EF6",depth:4,charIndex:377},{text:"\u63D2\u4EF6\u914D\u7F6E\u9879",id:"\u63D2\u4EF6\u914D\u7F6E\u9879",depth:3,charIndex:486}],frontmatter:{sidebar_position:4},version:"",_relativePath:"zh/api/config/plugins.md"},{title:"testing",routePath:"/module-tools/api/config/testing",lang:"zh",toc:[{text:"jest",id:"jest",depth:2,charIndex:55},{text:"transformer",id:"transformer",depth:2,charIndex:457}],frontmatter:{sidebar_position:5},version:"",_relativePath:"zh/api/config/testing.md"},{title:"\u6982\u89C8",routePath:"/module-tools/api/",lang:"zh",toc:[],frontmatter:{overview:!0,sidebar_label:"\u6982\u89C8",sidebar_position:1},version:"",_relativePath:"zh/api/index.md"},{title:"Plugin Hooks",routePath:"/module-tools/api/plugin-api/plugin-hooks",lang:"zh",toc:[{text:"\u6784\u5EFA\u94A9\u5B50",id:"\u6784\u5EFA\u94A9\u5B50",depth:2,charIndex:172},{text:"beforeBuild",id:"beforebuild",depth:3,charIndex:281},{text:"beforeBuildTask",id:"beforebuildtask",depth:3,charIndex:831},{text:"afterBuildTask",id:"afterbuildtask",depth:3,charIndex:1163},{text:"afterBuild",id:"afterbuild",depth:3,charIndex:1513},{text:"buildPlatform \u94A9\u5B50",id:"buildplatform-\u94A9\u5B50",depth:2,charIndex:1905},{text:"registerBuildPlatform",id:"registerbuildplatform",depth:3,charIndex:2244},{text:"beforeBuildPlatform",id:"beforebuildplatform",depth:3,charIndex:2851},{text:"buildPlatform",id:"buildplatform",depth:3,charIndex:3432},{text:"afterBuildPlatform",id:"afterbuildplatform",depth:3,charIndex:3807},{text:"\u8C03\u8BD5\u94A9\u5B50",id:"\u8C03\u8BD5\u94A9\u5B50",depth:2,charIndex:4385},{text:"registerDev",id:"registerdev",depth:3,charIndex:4614},{text:"beforeDev",id:"beforedev",depth:3,charIndex:5460},{text:"(before|after)DevMenu",id:"beforeafterdevmenu",depth:3,charIndex:5972},{text:"beforeDevTask",id:"beforedevtask",depth:3,charIndex:7008},{text:"afterDev",id:"afterdev",depth:3,charIndex:7517}],frontmatter:{},version:"",_relativePath:"zh/api/plugin-api/plugin-hooks.md"},{title:"",routePath:"/module-tools/components/faq-build-exception",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/components/faq-build-exception.mdx"},{title:"",routePath:"/module-tools/components/faq-build-other",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/components/faq-build-other.mdx"},{title:"",routePath:"/module-tools/components/faq-build-product",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/components/faq-build-product.mdx"},{title:"",routePath:"/module-tools/components/faq-storybook",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/components/faq-storybook.mdx"},{title:"",routePath:"/module-tools/components/faq-test",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/components/faq-test.mdx"},{title:"",routePath:"/module-tools/components/register-esbuild-plugin",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/components/register-esbuild-plugin.mdx"},{title:"\u5904\u7406\u9759\u6001\u8D44\u6E90",routePath:"/module-tools/guide/advance/asset",lang:"zh",toc:[{text:"\u9ED8\u8BA4\u884C\u4E3A",id:"\u9ED8\u8BA4\u884C\u4E3A",depth:2,charIndex:74},{text:"\u793A\u4F8B",id:"\u793A\u4F8B",depth:2,charIndex:355}],frontmatter:{sidebar_position:7},version:"",_relativePath:"zh/guide/advance/asset.mdx"},{title:"\u6784\u5EFA umd \u4EA7\u7269",routePath:"/module-tools/guide/advance/build-umd",lang:"zh",toc:[{text:"umd \u4EA7\u7269\u7684\u7B2C\u4E09\u65B9\u4F9D\u8D56\u5904\u7406",id:"umd-\u4EA7\u7269\u7684\u7B2C\u4E09\u65B9\u4F9D\u8D56\u5904\u7406",depth:2,charIndex:256},{text:"\u793A\u4F8B",id:"\u793A\u4F8B",depth:3,charIndex:377},{text:"\u4E09\u65B9\u4F9D\u8D56\u7684\u5168\u5C40\u53D8\u91CF\u540D\u79F0",id:"\u4E09\u65B9\u4F9D\u8D56\u7684\u5168\u5C40\u53D8\u91CF\u540D\u79F0",depth:3,charIndex:1563},{text:"\u66F4\u6539\u9879\u76EE\u7684\u5168\u5C40\u53D8\u91CF\u540D\u79F0",id:"\u66F4\u6539\u9879\u76EE\u7684\u5168\u5C40\u53D8\u91CF\u540D\u79F0",depth:2,charIndex:2612}],frontmatter:{sidebar_position:5},version:"",_relativePath:"zh/guide/advance/build-umd.mdx"},{title:"\u4F7F\u7528 Copy \u5DE5\u5177",routePath:"/module-tools/guide/advance/copy",lang:"zh",toc:[{text:"\u4E86\u89E3 Copy API",id:"\u4E86\u89E3-copy-api",depth:2,charIndex:72},{text:"API \u8BE6\u89E3",id:"api-\u8BE6\u89E3",depth:2,charIndex:165},{text:"\u4E0D\u540C\u573A\u666F\u4F7F\u7528\u793A\u4F8B",id:"\u4E0D\u540C\u573A\u666F\u4F7F\u7528\u793A\u4F8B",depth:2,charIndex:1492},{text:"\u5C06\u6587\u4EF6\u590D\u5236\u6587\u4EF6",id:"\u5C06\u6587\u4EF6\u590D\u5236\u6587\u4EF6",depth:3,charIndex:1504},{text:"\u5C06\u6587\u4EF6\u590D\u5236\u5230\u76EE\u5F55",id:"\u5C06\u6587\u4EF6\u590D\u5236\u5230\u76EE\u5F55",depth:3,charIndex:1848},{text:"\u4ECE\u76EE\u5F55\u590D\u5236\u5230\u76EE\u5F55",id:"\u4ECE\u76EE\u5F55\u590D\u5236\u5230\u76EE\u5F55",depth:3,charIndex:2186},{text:"\u4ECE\u76EE\u5F55\u5230\u6587\u4EF6",id:"\u4ECE\u76EE\u5F55\u5230\u6587\u4EF6",depth:3,charIndex:2580},{text:"\u4F7F\u7528 Glob",id:"\u4F7F\u7528-glob",depth:3,charIndex:2985}],frontmatter:{sidebar_position:3},version:"",_relativePath:"zh/guide/advance/copy.md"},{title:"\u5904\u7406\u4E09\u65B9\u4F9D\u8D56",routePath:"/module-tools/guide/advance/external-dependency",lang:"zh",toc:[{text:"\u7B2C\u4E09\u65B9\u4F9D\u8D56\u7684\u9ED8\u8BA4\u5904\u7406",id:"\u7B2C\u4E09\u65B9\u4F9D\u8D56\u7684\u9ED8\u8BA4\u5904\u7406",depth:2,charIndex:314},{text:"\u793A\u4F8B",id:"\u793A\u4F8B",depth:3,charIndex:571},{text:"\u6392\u9664\u6307\u5B9A\u7B2C\u4E09\u65B9\u4F9D\u8D56",id:"\u6392\u9664\u6307\u5B9A\u7B2C\u4E09\u65B9\u4F9D\u8D56",depth:2,charIndex:849}],frontmatter:{sidebar_position:4},version:"",_relativePath:"zh/guide/advance/external-dependency.mdx"},{title:"\u6DF1\u5165\u7406\u89E3\u6784\u5EFA",routePath:"/module-tools/guide/advance/in-depth-about-build",lang:"zh",toc:[{text:"bundle / bundleless",id:"bundle--bundleless",depth:2,charIndex:195},{text:"input / sourceDir",id:"input--sourcedir",depth:2,charIndex:715},{text:"\u4F7F\u7528 swc",id:"\u4F7F\u7528-swc",depth:2,charIndex:1372},{text:"\u4F7F\u7528 Hook \u4ECB\u5165\u6784\u5EFA\u6D41\u7A0B",id:"\u4F7F\u7528-hook-\u4ECB\u5165\u6784\u5EFA\u6D41\u7A0B",depth:2,charIndex:1851},{text:"Hook \u7C7B\u578B",id:"hook-\u7C7B\u578B",depth:3,charIndex:2025},{text:"AsyncSeriesBailHook",id:"asyncseriesbailhook",depth:4,charIndex:2035},{text:"AsyncSeriesWaterFallHooks",id:"asyncserieswaterfallhooks",depth:4,charIndex:2137},{text:"Hook API",id:"hook-api",depth:3,charIndex:2206},{text:"load",id:"load",depth:4,charIndex:2217},{text:"transform",id:"transform",depth:4,charIndex:2824},{text:"renderChunk",id:"renderchunk",depth:4,charIndex:3246},{text:"\u7C7B\u578B\u6587\u4EF6\u751F\u6210",id:"\u7C7B\u578B\u6587\u4EF6\u751F\u6210",depth:2,charIndex:4134},{text:"\u5173\u95ED\u7C7B\u578B\u751F\u6210",id:"\u5173\u95ED\u7C7B\u578B\u751F\u6210",depth:3,charIndex:4176},{text:"\u6253\u5305\u7C7B\u578B\u6587\u4EF6",id:"\u6253\u5305\u7C7B\u578B\u6587\u4EF6",depth:3,charIndex:4327},{text:"\u522B\u540D\u8F6C\u6362",id:"\u522B\u540D\u8F6C\u6362",depth:3,charIndex:4624},{text:"\u4E00\u4E9B\u793A\u4F8B",id:"\u4E00\u4E9B\u793A\u4F8B",depth:3,charIndex:4909},{text:"\u6784\u5EFA\u8FC7\u7A0B",id:"\u6784\u5EFA\u8FC7\u7A0B",depth:2,charIndex:5480},{text:"\u6784\u5EFA\u62A5\u9519",id:"\u6784\u5EFA\u62A5\u9519",depth:2,charIndex:5654},{text:"\u8C03\u8BD5\u6A21\u5F0F",id:"\u8C03\u8BD5\u6A21\u5F0F",depth:2,charIndex:6052}],frontmatter:{sidebar_position:1},version:"",_relativePath:"zh/guide/advance/in-depth-about-build.md"},{title:"\u6DF1\u5165\u7406\u89E3 dev \u547D\u4EE4",routePath:"/module-tools/guide/advance/in-depth-about-dev-command",lang:"zh",toc:[{text:"\u547D\u4EE4\u8FD0\u884C\u7684\u6574\u4F53\u6D41\u7A0B",id:"\u547D\u4EE4\u8FD0\u884C\u7684\u6574\u4F53\u6D41\u7A0B",depth:2,charIndex:42},{text:"\u6269\u5C55 dev \u547D\u4EE4",id:"\u6269\u5C55-dev-\u547D\u4EE4",depth:2,charIndex:339}],frontmatter:{sidebar_position:2},version:"",_relativePath:"zh/guide/advance/in-depth-about-dev-command.md"},{title:"\u5F00\u59CB\u4E4B\u524D",routePath:"/module-tools/guide/basic/before-getting-started",lang:"zh",toc:[{text:"\u73AF\u5883\u51C6\u5907",id:"\u73AF\u5883\u51C6\u5907",depth:2,charIndex:3},{text:"\u521D\u8BC6 npm",id:"\u521D\u8BC6-npm",depth:2,charIndex:189},{text:"npm \u5305\u7C7B\u578B\u9879\u76EE",id:"npm-\u5305\u7C7B\u578B\u9879\u76EE",depth:2,charIndex:392},{text:"\u4F7F\u7528\u7B2C\u4E09\u65B9 npm \u5305",id:"\u4F7F\u7528\u7B2C\u4E09\u65B9-npm-\u5305",depth:2,charIndex:1023},{text:"\u8FD8\u9700\u8981\u4E86\u89E3\u7684 npm \u96F6\u788E\u77E5\u8BC6",id:"\u8FD8\u9700\u8981\u4E86\u89E3\u7684-npm-\u96F6\u788E\u77E5\u8BC6",depth:2,charIndex:1990},{text:"npm \u5305\u7684\u7A0B\u5E8F\u5165\u53E3",id:"npm-\u5305\u7684\u7A0B\u5E8F\u5165\u53E3",depth:3,charIndex:2009},{text:'\\"scripts\\"',id:"scripts",depth:3,charIndex:-1},{text:"npm install",id:"npm-install",depth:4,charIndex:2878},{text:"npm publish",id:"npm-publish",depth:4,charIndex:3142},{text:"peerDependencies",id:"peerdependencies",depth:3,charIndex:3302},{text:"npm \u5305\u7BA1\u7406\u5668",id:"npm-\u5305\u7BA1\u7406\u5668",depth:2,charIndex:3616},{text:"Modern.js Module \u914D\u7F6E\u6587\u4EF6",id:"modernjs-module-\u914D\u7F6E\u6587\u4EF6",depth:2,charIndex:3744}],frontmatter:{sidebar_position:1},version:"",_relativePath:"zh/guide/basic/before-getting-started.md"},{title:"CLI \u547D\u4EE4",routePath:"/module-tools/guide/basic/command-preview",lang:"zh",toc:[{text:"modern build",id:"modern-build",depth:2,charIndex:39},{text:"modern new",id:"modern-new",depth:2,charIndex:1090},{text:"modern dev",id:"modern-dev",depth:2,charIndex:1549},{text:"modern test",id:"modern-test",depth:2,charIndex:1925},{text:"modern lint",id:"modern-lint",depth:2,charIndex:2129},{text:"modern change",id:"modern-change",depth:2,charIndex:2422},{text:"modern pre",id:"modern-pre",depth:2,charIndex:2662},{text:"modern bump",id:"modern-bump",depth:2,charIndex:2808},{text:"modern release",id:"modern-release",depth:2,charIndex:3151},{text:"modern gen-release-note",id:"modern-gen-release-note",depth:2,charIndex:3502},{text:"modern upgrade",id:"modern-upgrade",depth:2,charIndex:3832}],frontmatter:{sidebar_position:2},version:"",_relativePath:"zh/guide/basic/command-preview.md"},{title:"\u4FEE\u6539\u8F93\u51FA\u4EA7\u7269",routePath:"/module-tools/guide/basic/modify-output-product",lang:"zh",toc:[{text:"\u9ED8\u8BA4\u8F93\u51FA\u4EA7\u7269",id:"\u9ED8\u8BA4\u8F93\u51FA\u4EA7\u7269",depth:2,charIndex:3},{text:"\u6784\u5EFA\u9884\u8BBE",id:"\u6784\u5EFA\u9884\u8BBE",depth:2,charIndex:486},{text:"\u6784\u5EFA\u914D\u7F6E",id:"\u6784\u5EFA\u914D\u7F6E",depth:2,charIndex:804},{text:"\u7ED3\u5408\u914D\u7F6E\u4E0E\u9884\u8BBE",id:"\u7ED3\u5408\u914D\u7F6E\u4E0E\u9884\u8BBE",depth:2,charIndex:2092}],frontmatter:{sidebar_position:3},version:"",_relativePath:"zh/guide/basic/modify-output-product.md"},{title:"\u7248\u672C\u7BA1\u7406\u4E0E\u53D1\u5E03",routePath:"/module-tools/guide/basic/publish-your-project",lang:"zh",toc:[{text:"\u8DDF\u8E2A\u53D8\u66F4",id:"\u8DDF\u8E2A\u53D8\u66F4",depth:2,charIndex:156},{text:"\u7248\u672C\u66F4\u65B0",id:"\u7248\u672C\u66F4\u65B0",depth:2,charIndex:1050},{text:"\u53D1\u5E03",id:"\u53D1\u5E03",depth:2,charIndex:1313},{text:"\u9884\u53D1\u5E03",id:"\u9884\u53D1\u5E03",depth:2,charIndex:1651}],frontmatter:{sidebar_position:7},version:"",_relativePath:"zh/guide/basic/publish-your-project.md"},{title:"\u6D4B\u8BD5\u9879\u76EE",routePath:"/module-tools/guide/basic/test-your-project",lang:"zh",toc:[{text:"\u5148\u51B3\u6761\u4EF6\u548C\u7EA6\u5B9A",id:"\u5148\u51B3\u6761\u4EF6\u548C\u7EA6\u5B9A",depth:2,charIndex:21},{text:"\u8FD0\u884C\u6D4B\u8BD5",id:"\u8FD0\u884C\u6D4B\u8BD5",depth:2,charIndex:417},{text:"\u4F7F\u7528\u914D\u7F6E",id:"\u4F7F\u7528\u914D\u7F6E",depth:2,charIndex:551},{text:"\u6D4B\u8BD5\u793A\u4F8B",id:"\u6D4B\u8BD5\u793A\u4F8B",depth:2,charIndex:633},{text:"\u666E\u901A\u6A21\u5757",id:"\u666E\u901A\u6A21\u5757",depth:3,charIndex:641},{text:"\u7EC4\u4EF6",id:"\u7EC4\u4EF6",depth:3,charIndex:1057}],frontmatter:{sidebar_position:6},version:"",_relativePath:"zh/guide/basic/test-your-project.mdx"},{title:"\u4F7F\u7528\u5FAE\u751F\u6210\u5668",routePath:"/module-tools/guide/basic/use-micro-generator",lang:"zh",toc:[{text:"Test \u6D4B\u8BD5",id:"test-\u6D4B\u8BD5",depth:2,charIndex:166},{text:"Storybook \u8C03\u8BD5",id:"storybook-\u8C03\u8BD5",depth:2,charIndex:407},{text:"Tailwind CSS \u652F\u6301",id:"tailwind-css-\u652F\u6301",depth:2,charIndex:751},{text:"Modern.js Runtime API \u652F\u6301",id:"modernjs-runtime-api-\u652F\u6301",depth:2,charIndex:899}],frontmatter:{sidebar_position:4},version:"",_relativePath:"zh/guide/basic/use-micro-generator.md"},{title:"\u4F7F\u7528 Storybook",routePath:"/module-tools/guide/basic/using-storybook",lang:"zh",toc:[{text:"\u8C03\u8BD5\u4EE3\u7801",id:"\u8C03\u8BD5\u4EE3\u7801",depth:2,charIndex:292},{text:"\u5F15\u7528\u7EC4\u4EF6\u4EA7\u7269",id:"\u5F15\u7528\u7EC4\u4EF6\u4EA7\u7269",depth:3,charIndex:491},{text:"\u5F15\u7528\u7EC4\u4EF6\u6E90\u7801",id:"\u5F15\u7528\u7EC4\u4EF6\u6E90\u7801",depth:3,charIndex:1862},{text:"\u914D\u7F6E Storybook",id:"\u914D\u7F6E-storybook",depth:2,charIndex:2277},{text:"\u6784\u5EFA Storybook \u4EA7\u7269",id:"\u6784\u5EFA-storybook-\u4EA7\u7269",depth:2,charIndex:2686},{text:"\u7ED3\u5408 Tailwind CSS \u4F7F\u7528",id:"\u7ED3\u5408-tailwind-css-\u4F7F\u7528",depth:2,charIndex:2901}],frontmatter:{sidebar_position:5},version:"",_relativePath:"zh/guide/basic/using-storybook.mdx"},{title:"\u5F00\u53D1\u7EC4\u4EF6",routePath:"/module-tools/guide/best-practices/components",lang:"zh",toc:[{text:"\u521D\u59CB\u5316\u9879\u76EE",id:"\u521D\u59CB\u5316\u9879\u76EE",depth:2,charIndex:40},{text:"\u4F7F\u7528 Storybook \u8C03\u8BD5\u4EE3\u7801",id:"\u4F7F\u7528-storybook-\u8C03\u8BD5\u4EE3\u7801",depth:2,charIndex:513},{text:"\u5F00\u53D1\u6837\u5F0F",id:"\u5F00\u53D1\u6837\u5F0F",depth:2,charIndex:574},{text:"CSS/PostCSS",id:"csspostcss",depth:3,charIndex:682},{text:"Less",id:"less",depth:3,charIndex:1192},{text:"Sass/Scss",id:"sassscss",depth:3,charIndex:1445},{text:"Tailwind CSS",id:"tailwind-css",depth:3,charIndex:1728},{text:"CSS Modules",id:"css-modules",depth:3,charIndex:1776},{text:"\u914D\u7F6E\u6784\u5EFA\u4EA7\u7269",id:"\u914D\u7F6E\u6784\u5EFA\u4EA7\u7269",depth:2,charIndex:2090},{text:"\u6D4B\u8BD5\u7EC4\u4EF6",id:"\u6D4B\u8BD5\u7EC4\u4EF6",depth:2,charIndex:2571},{text:"\u53D1\u5E03\u7EC4\u4EF6",id:"\u53D1\u5E03\u7EC4\u4EF6",depth:2,charIndex:2605}],frontmatter:{sidebar_position:1},version:"",_relativePath:"zh/guide/best-practices/components.mdx"},{title:"\u4F7F\u7528 Tailwind CSS",routePath:"/module-tools/guide/best-practices/use-tailwindcss",lang:"zh",toc:[{text:"\u542F\u7528 Tailwind CSS",id:"\u542F\u7528-tailwind-css",depth:2,charIndex:127},{text:"\u914D\u7F6E Tailwind CSS",id:"\u914D\u7F6E-tailwind-css",depth:2,charIndex:962},{text:"Tailwind CSS \u81EA\u52A8\u8865\u5168",id:"tailwind-css-\u81EA\u52A8\u8865\u5168",depth:2,charIndex:1608},{text:"\u6784\u5EFA\u6A21\u5F0F",id:"\u6784\u5EFA\u6A21\u5F0F",depth:2,charIndex:1921},{text:"Bundle \u6A21\u5F0F",id:"bundle-\u6A21\u5F0F",depth:3,charIndex:2038},{text:"Bundleless \u6A21\u5F0F",id:"bundleless-\u6A21\u5F0F",depth:3,charIndex:2627},{text:"\u7C7B\u540D\u524D\u7F00",id:"\u7C7B\u540D\u524D\u7F00",depth:2,charIndex:2837},{text:"\u7528\u6CD5\u4ECB\u7ECD",id:"\u7528\u6CD5\u4ECB\u7ECD",depth:2,charIndex:3222},{text:"HTML \u7C7B\u540D",id:"html-\u7C7B\u540D",depth:3,charIndex:3257},{text:"@apply",id:"apply",depth:3,charIndex:3568},{text:"Sass",id:"sass",depth:4,charIndex:3756},{text:"Less",id:"less",depth:4,charIndex:3953},{text:"\u5173\u4E8E designSystem \u914D\u7F6E",id:"\u5173\u4E8E-designsystem-\u914D\u7F6E",depth:2,charIndex:4467}],frontmatter:{sidebar_position:2},version:"",_relativePath:"zh/guide/best-practices/use-tailwindcss.mdx"},{title:"\u6784\u5EFA\u76F8\u5173\u95EE\u9898",routePath:"/module-tools/guide/faq/build",lang:"zh",toc:[{text:"\u4EA7\u7269\u95EE\u9898",id:"\u4EA7\u7269\u95EE\u9898",depth:2,charIndex:3},{text:"Class Fields \u7684\u521D\u59CB\u5316\u5904\u7406",id:"class-fields-\u7684\u521D\u59CB\u5316\u5904\u7406",depth:3,charIndex:11},{text:"babel-plugin-lodash \u5C06\u5F15\u5165\u7684 lodash \u5904\u7406\u6210 undefined",id:"babel-plugin-lodash-\u5C06\u5F15\u5165\u7684-lodash-\u5904\u7406\u6210-undefined",depth:3,charIndex:1315},{text:"\u5F02\u5E38\u7C7B\u95EE\u9898",id:"\u5F02\u5E38\u7C7B\u95EE\u9898",depth:2,charIndex:1722},{text:'Dynamic require of \\"react\\" is not supported',id:"dynamic-require-of-react-is-not-supported",depth:3,charIndex:-1},{text:"\u95EE\u9898\u63CF\u8FF0",id:"\u95EE\u9898\u63CF\u8FF0",depth:4,charIndex:1777},{text:"\u89E3\u51B3\u529E\u6CD5",id:"\u89E3\u51B3\u529E\u6CD5",depth:4,charIndex:1952},{text:"\u53C2\u8003\u94FE\u63A5",id:"\u53C2\u8003\u94FE\u63A5",depth:4,charIndex:2246},{text:"\u7F16\u8BD1\u8FC7\u7A0B\u4E2D\uFF0C\u56E0\u4E3A\u67D0\u4E2A\u7EC4\u4EF6\u5E93\u7684 less \u6587\u4EF6\u62A5\u9519\uFF1A\\'Operation on an invalid type\\'",id:"\u7F16\u8BD1\u8FC7\u7A0B\u4E2D\u56E0\u4E3A\u67D0\u4E2A\u7EC4\u4EF6\u5E93\u7684-less-\u6587\u4EF6\u62A5\u9519operation-on-an-invalid-type",depth:3,charIndex:-1},{text:"Bundle DTS failed",id:"bundle-dts-failed",depth:3,charIndex:3439},{text:'defineConfig \u51FD\u6570\u7C7B\u578B\u62A5\u9519\uFF1A\u5982\u679C\u6CA1\u6709\u5F15\u7528 \\"...\\"\uFF0C\u5219\u65E0\u6CD5\u547D\u540D \\"default\\" \u7684\u63A8\u65AD\u7C7B\u578B',id:"defineconfig-\u51FD\u6570\u7C7B\u578B\u62A5\u9519\u5982\u679C\u6CA1\u6709\u5F15\u7528-\u5219\u65E0\u6CD5\u547D\u540D-default-\u7684\u63A8\u65AD\u7C7B\u578B",depth:3,charIndex:-1},{text:"\u5176\u4ED6",id:"\u5176\u4ED6",depth:2,charIndex:3873},{text:"\u589E\u52A0\u989D\u5916\u7684\u7F16\u8BD1\u80FD\u529B",id:"\u589E\u52A0\u989D\u5916\u7684\u7F16\u8BD1\u80FD\u529B",depth:3,charIndex:3879},{text:"\u652F\u6301\u751F\u6210 CSS Modules \u7684 TypeScript \u58F0\u660E\u6587\u4EF6",id:"\u652F\u6301\u751F\u6210-css-modules-\u7684-typescript-\u58F0\u660E\u6587\u4EF6",depth:3,charIndex:4370}],frontmatter:{},version:"",_relativePath:"zh/guide/faq/build.mdx"},{title:"\u5E38\u89C1\u95EE\u9898",routePath:"/module-tools/guide/faq/",lang:"zh",toc:[],frontmatter:{},version:"",_relativePath:"zh/guide/faq/index.md"},{title:"Storybook \u76F8\u5173\u95EE\u9898",routePath:"/module-tools/guide/faq/storybook",lang:"zh",toc:[{text:"\u652F\u6301 Storybook v7",id:"\u652F\u6301-storybook-v7",depth:2,charIndex:3},{text:"\u4F7F\u7528 Storybook Addon \u6216\u8005\u5176\u4ED6\u914D\u7F6E\u4E0D\u751F\u6548",id:"\u4F7F\u7528-storybook-addon-\u6216\u8005\u5176\u4ED6\u914D\u7F6E\u4E0D\u751F\u6548",depth:2,charIndex:102},{text:"Cannot find module \\'react-dom/package.json",id:"cannot-find-module-react-dompackagejson",depth:2,charIndex:-1},{text:"\u62A5\u9519\u540E\uFF0C\u770B\u4E0D\u5230\u5177\u4F53\u62A5\u9519\u4FE1\u606F",id:"\u62A5\u9519\u540E\u770B\u4E0D\u5230\u5177\u4F53\u62A5\u9519\u4FE1\u606F",depth:2,charIndex:534},{text:"Couldn\\'t find any stories is your Storybook",id:"couldnt-find-any-stories-is-your-storybook",depth:2,charIndex:-1},{text:"Storybook \u6DFB\u52A0 Proxy \u529F\u80FD",id:"storybook-\u6DFB\u52A0-proxy-\u529F\u80FD",depth:2,charIndex:1411},{text:"\u4FEE\u6539\u5B58\u5728 Story \u6587\u4EF6\u7684\u76EE\u5F55",id:"\u4FEE\u6539\u5B58\u5728-story-\u6587\u4EF6\u7684\u76EE\u5F55",depth:2,charIndex:2095}],frontmatter:{},version:"",_relativePath:"zh/guide/faq/storybook.mdx"},{title:"\u6D4B\u8BD5\u76F8\u5173\u95EE\u9898",routePath:"/module-tools/guide/faq/test",lang:"zh",toc:[{text:"\u6267\u884C test \u547D\u4EE4\u62A5\u9519 TypeError: Cannot read property \\'testEnvironmentOptions\\' of undefined",id:"\u6267\u884C-test-\u547D\u4EE4\u62A5\u9519-typeerror-cannot-read-property-testenvironmentoptions-of-undefined",depth:2,charIndex:-1}],frontmatter:{},version:"",_relativePath:"zh/guide/faq/test.mdx"},{title:"\u5FEB\u901F\u5F00\u59CB",routePath:"/module-tools/guide/intro/getting-started",lang:"zh",toc:[{text:"\u4E09\u5206\u949F\u5FEB\u901F\u4E0A\u624B",id:"\u4E09\u5206\u949F\u5FEB\u901F\u4E0A\u624B",depth:2,charIndex:3},{text:"\u521B\u5EFA\u65B0\u9879\u76EE",id:"\u521B\u5EFA\u65B0\u9879\u76EE",depth:3,charIndex:111},{text:"\u63A5\u5165\u5DF2\u6709\u9879\u76EE",id:"\u63A5\u5165\u5DF2\u6709\u9879\u76EE",depth:3,charIndex:516},{text:"\u6838\u5FC3 npm \u5305",id:"\u6838\u5FC3-npm-\u5305",depth:3,charIndex:1013},{text:"\u67E5\u770B\u5B98\u65B9\u793A\u4F8B",id:"\u67E5\u770B\u5B98\u65B9\u793A\u4F8B",depth:3,charIndex:1411},{text:"\u8BA9\u6211\u4EEC\u5F00\u59CB\u5427",id:"\u8BA9\u6211\u4EEC\u5F00\u59CB\u5427",depth:2,charIndex:1669}],frontmatter:{sidebar_position:3},version:"",_relativePath:"zh/guide/intro/getting-started.mdx"},{title:"\u6B22\u8FCE\u4F7F\u7528",routePath:"/module-tools/guide/intro/welcome",lang:"zh",toc:[],frontmatter:{sidebar_position:1},version:"",_relativePath:"zh/guide/intro/welcome.md"},{title:"\u4E3A\u4EC0\u4E48\u9700\u8981 Modern.js Module",routePath:"/module-tools/guide/intro/why-module-engineering-solution",lang:"zh",toc:[],frontmatter:{sidebar_position:2},version:"",_relativePath:"zh/guide/intro/why-module-engineering-solution.md"},{title:"index",routePath:"/module-tools/",lang:"zh",toc:[],frontmatter:{pageType:"home",hero:{name:"Modern.js Module",text:"\u6A21\u5757\u5DE5\u7A0B\u89E3\u51B3\u65B9\u6848",tagline:"\u7B80\u5355\u3001\u5F3A\u5927\u3001\u9AD8\u6027\u80FD\u7684\u73B0\u4EE3\u5316 npm \u5305\u5F00\u53D1\u65B9\u6848",actions:[{theme:"brand",text:"\u6B22\u8FCE\u4F7F\u7528",link:"/guide/intro/welcome"},{theme:"alt",text:"\u5FEB\u901F\u4E0A\u624B",link:"/guide/intro/getting-started"}]},features:[{title:"esbuild: \u9AD8\u6027\u80FD\u7684 JS Bundler",details:"\u57FA\u4E8E esbuild \u6784\u5EFA\uFF0C\u6784\u5EFA\u901F\u5EA6\u6781\u5FEB\uFF0C\u5E26\u7ED9\u4F60\u6781\u81F4\u7684\u5F00\u53D1\u4F53\u9A8C\u3002",icon:"\uD83D\uDE80"},{title:"\u53CC\u6784\u5EFA\u6A21\u5F0F",details:"\u652F\u6301 Bundle \u548C Bundleless \u4E24\u79CD\u6784\u5EFA\u6A21\u5F0F\u3002",icon:"\u2728"},{title:"\u5F00\u7BB1\u5373\u7528",details:"\u65E0\u9700\u8FC7\u591A\u914D\u7F6E\u5373\u53EF\u5F00\u53D1\u4F60\u7684 npm \u5305\uFF0C\u5185\u7F6E\u9884\u8BBE\u8986\u76D6\u591A\u79CD\u573A\u666F\u3002",icon:"\uD83D\uDEE0\uFE0F"},{title:"\u6269\u5C55\u6027\u5F3A: \u63D0\u4F9B\u5F3A\u5927\u7684\u63D2\u4EF6\u673A\u5236",details:"\u901A\u8FC7\u5176\u63D2\u4EF6\u6269\u5C55\u673A\u5236\uFF0C\u4F60\u53EF\u4EE5\u8F7B\u677E\u7684\u6269\u5C55 Modern.js Module \u7684\u5404\u9879\u80FD\u529B\u3002",icon:"\uD83C\uDFA8"},{title:"Storybook: \u793E\u533A\u6D41\u884C\u7684 UI \u5F00\u53D1\u5DE5\u5177",details:"\u96C6\u6210\u4E86 Storybook\uFF0C\u4F60\u53EF\u4EE5\u4F7F\u7528\u5B83\u8C03\u8BD5 UI\u3002",icon:"\uD83D\uDCE6"},{title:"Jest: \u4EE4\u4EBA\u6109\u5FEB\u7684\u6D4B\u8BD5\u6846\u67B6",details:"\u96C6\u6210\u4E86 Jest\uFF0C\u4F7F\u5F97\u4EE3\u7801\u6D4B\u8BD5\u66F4\u52A0\u5BB9\u6613\u3002",icon:"\uD83D\uDCD0"}]},version:"",_relativePath:"zh/index.md"},{title:"\u5FEB\u901F\u5F00\u59CB",routePath:"/module-tools/plugins/guide/getting-started",lang:"zh",toc:[],frontmatter:{sidebar_position:1},version:"",_relativePath:"zh/plugins/guide/getting-started.mdx"},{title:"\u63D2\u4EF6\u5BF9\u8C61",routePath:"/module-tools/plugins/guide/plugin-object",lang:"zh",toc:[{text:"\u63D2\u4EF6\u7C7B\u578B\u5B9A\u4E49",id:"\u63D2\u4EF6\u7C7B\u578B\u5B9A\u4E49",depth:2,charIndex:480},{text:"\u63D2\u4EF6\u914D\u7F6E\u9879",id:"\u63D2\u4EF6\u914D\u7F6E\u9879",depth:2,charIndex:745}],frontmatter:{sidebar_position:2},version:"",_relativePath:"zh/plugins/guide/plugin-object.mdx"},{title:"Setup \u51FD\u6570",routePath:"/module-tools/plugins/guide/setup-function",lang:"zh",toc:[{text:"\u63D2\u4EF6 API \u5BF9\u8C61",id:"\u63D2\u4EF6-api-\u5BF9\u8C61",depth:2,charIndex:77},{text:"api.useAppContext",id:"apiuseappcontext",depth:3,charIndex:441},{text:"api.useResolvedConfigContext",id:"apiuseresolvedconfigcontext",depth:3,charIndex:823},{text:"api.useHookRunners",id:"apiusehookrunners",depth:3,charIndex:1198},{text:"\u5F02\u6B65 setup",id:"\u5F02\u6B65-setup",depth:2,charIndex:1461},{text:"\u751F\u547D\u5468\u671F\u94A9\u5B50",id:"\u751F\u547D\u5468\u671F\u94A9\u5B50",depth:2,charIndex:1731}],frontmatter:{sidebar_position:3},version:"",_relativePath:"zh/plugins/guide/setup-function.mdx"},{title:"\u603B\u89C8",routePath:"/module-tools/plugins/official-list/overview",lang:"zh",toc:[{text:"\u5B98\u65B9\u63D2\u4EF6",id:"\u5B98\u65B9\u63D2\u4EF6",depth:2,charIndex:3}],frontmatter:{},version:"",_relativePath:"zh/plugins/official-list/overview.md"},{title:"Babel \u63D2\u4EF6",routePath:"/module-tools/plugins/official-list/plugin-babel",lang:"zh",toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2,charIndex:50},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3,charIndex:58},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3,charIndex:64},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2,charIndex:508}],frontmatter:{},version:"",_relativePath:"zh/plugins/official-list/plugin-babel.mdx"},{title:"Banner \u63D2\u4EF6",routePath:"/module-tools/plugins/official-list/plugin-banner",lang:"zh",toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2,charIndex:133},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3,charIndex:141},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3,charIndex:147},{text:"\u793A\u4F8B",id:"\u793A\u4F8B",depth:2,charIndex:426},{text:"\u5728 JS \u6587\u4EF6\u9876\u90E8\u589E\u52A0\u7248\u6743\u4FE1\u606F",id:"\u5728-js-\u6587\u4EF6\u9876\u90E8\u589E\u52A0\u7248\u6743\u4FE1\u606F",depth:3,charIndex:432},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2,charIndex:898},{text:"banner",id:"banner",depth:3,charIndex:1045},{text:"footer",id:"footer",depth:3,charIndex:1124}],frontmatter:{},version:"",_relativePath:"zh/plugins/official-list/plugin-banner.mdx"},{title:"Import \u63D2\u4EF6",routePath:"/module-tools/plugins/official-list/plugin-import",lang:"zh",toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2,charIndex:145},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3,charIndex:153},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3,charIndex:159},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2,charIndex:459},{text:"pluginImport",id:"pluginimport",depth:3,charIndex:526},{text:"\u6CE8\u610F\u4E8B\u9879",id:"\u6CE8\u610F\u4E8B\u9879",depth:2,charIndex:878}],frontmatter:{},version:"",_relativePath:"zh/plugins/official-list/plugin-import.mdx"},{title:"Node Polyfill \u63D2\u4EF6",routePath:"/module-tools/plugins/official-list/plugin-node-polyfill",lang:"zh",toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2,charIndex:213},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3,charIndex:221},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3,charIndex:227},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2,charIndex:367},{text:"exclude",id:"exclude",depth:3,charIndex:459},{text:"overrides",id:"overrides",depth:3,charIndex:636},{text:"Node Polyfills",id:"node-polyfills",depth:2,charIndex:866},{text:"Globals",id:"globals",depth:3,charIndex:884},{text:"Modules",id:"modules",depth:3,charIndex:1007},{text:"Fallbacks",id:"fallbacks",depth:3,charIndex:1445}],frontmatter:{},version:"",_relativePath:"zh/plugins/official-list/plugin-node-polyfill.mdx"},{title:"Polyfill \u63D2\u4EF6",routePath:"/module-tools/plugins/official-list/plugin-polyfill",lang:"zh",toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2,charIndex:197},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3,charIndex:205},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3,charIndex:211},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2,charIndex:652},{text:"targets",id:"targets",depth:3,charIndex:717}],frontmatter:{},version:"",_relativePath:"zh/plugins/official-list/plugin-polyfill.mdx"}],markdown:{showLineNumbers:!1}}},66428:function(e,t,n){e.exports={AElig:"\xc6",AMP:"&",Aacute:"\xc1",Acirc:"\xc2",Agrave:"\xc0",Aring:"\xc5",Atilde:"\xc3",Auml:"\xc4",COPY:"\xa9",Ccedil:"\xc7",ETH:"\xd0",Eacute:"\xc9",Ecirc:"\xca",Egrave:"\xc8",Euml:"\xcb",GT:">",Iacute:"\xcd",Icirc:"\xce",Igrave:"\xcc",Iuml:"\xcf",LT:"<",Ntilde:"\xd1",Oacute:"\xd3",Ocirc:"\xd4",Ograve:"\xd2",Oslash:"\xd8",Otilde:"\xd5",Ouml:"\xd6",QUOT:'"',REG:"\xae",THORN:"\xde",Uacute:"\xda",Ucirc:"\xdb",Ugrave:"\xd9",Uuml:"\xdc",Yacute:"\xdd",aacute:"\xe1",acirc:"\xe2",acute:"\xb4",aelig:"\xe6",agrave:"\xe0",amp:"&",aring:"\xe5",atilde:"\xe3",auml:"\xe4",brvbar:"\xa6",ccedil:"\xe7",cedil:"\xb8",cent:"\xa2",copy:"\xa9",curren:"\xa4",deg:"\xb0",divide:"\xf7",eacute:"\xe9",ecirc:"\xea",egrave:"\xe8",eth:"\xf0",euml:"\xeb",frac12:"\xbd",frac14:"\xbc",frac34:"\xbe",gt:">",iacute:"\xed",icirc:"\xee",iexcl:"\xa1",igrave:"\xec",iquest:"\xbf",iuml:"\xef",laquo:"\xab",lt:"<",macr:"\xaf",micro:"\xb5",middot:"\xb7",nbsp:"\xa0",not:"\xac",ntilde:"\xf1",oacute:"\xf3",ocirc:"\xf4",ograve:"\xf2",ordf:"\xaa",ordm:"\xba",oslash:"\xf8",otilde:"\xf5",ouml:"\xf6",para:"\xb6",plusmn:"\xb1",pound:"\xa3",quot:'"',raquo:"\xbb",reg:"\xae",sect:"\xa7",shy:"\xad",sup1:"\xb9",sup2:"\xb2",sup3:"\xb3",szlig:"\xdf",thorn:"\xfe",times:"\xd7",uacute:"\xfa",ucirc:"\xfb",ugrave:"\xf9",uml:"\xa8",uuml:"\xfc",yacute:"\xfd",yen:"\xa5",yuml:"\xff"}},20165:function(e,t,n){e.exports={0:"\uFFFD",128:"\u20AC",130:"\u201A",131:"\u0192",132:"\u201E",133:"\u2026",134:"\u2020",135:"\u2021",136:"\u02C6",137:"\u2030",138:"\u0160",139:"\u2039",140:"\u0152",142:"\u017D",145:"\u2018",146:"\u2019",147:"\u201C",148:"\u201D",149:"\u2022",150:"\u2013",151:"\u2014",152:"\u02DC",153:"\u2122",154:"\u0161",155:"\u203A",156:"\u0153",158:"\u017E",159:"\u0178"}},15467:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return a}});var r=n("99462"),i=n("41989"),o=n("57814");function a(e){var t=(0,r.useLocation)().pathname,n=e.selector,a=void 0===n?".rspress-doc img":n,l=e.options,s=void 0===l?{}:l;return(0,o.useEffect)(function(){var e=document.querySelectorAll(a);(0,i.default)(e,s)},[t]),null}n("49857")},88916:function(e,t,n){"use strict";n.r(t);var r=n("85464");n.es(r,t)},56885:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return r.default}});var r=n("48589");n.es(r,t)},99462:function(e,t,n){"use strict";n.r(t);var r=n("88916");n.es(r,t)},53868:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return r.default}});var r=n("56885");n.es(r,t)},84404:function(e,t,n){"use strict";n.r(t),n.d(t,{onSearch:function(){return r}});var r=function(){}}}]); \ No newline at end of file diff --git a/modern-js/module-tools/static/js/7396.b2bc4a2b.js.LICENSE.txt b/modern-js/module-tools/static/js/7396.630e7410.js.LICENSE.txt similarity index 100% rename from modern-js/module-tools/static/js/7396.b2bc4a2b.js.LICENSE.txt rename to modern-js/module-tools/static/js/7396.630e7410.js.LICENSE.txt diff --git a/modern-js/module-tools/static/js/async/1687.1318b297.js b/modern-js/module-tools/static/js/async/1687.1318b297.js deleted file mode 100644 index 878ac414be..0000000000 --- a/modern-js/module-tools/static/js/async/1687.1318b297.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_modern_js_module_tools_docs=self.webpackChunk_modern_js_module_tools_docs||[]).push([["1687"],{63097:function(e,n,l){"use strict";l.r(n),l.d(n,{default:function(){return c}});var s=l("15169"),r=l("43932"),i=l("9880"),d=l("23169"),o=l("19730");function a(e){var n=Object.assign({h1:"h1",a:"a",div:"div",p:"p",code:"code",h2:"h2",h3:"h3",pre:"pre",ul:"ul",li:"li",strong:"strong"},(0,d.useMDXComponents)(),e.components);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.h1,{id:"polyfill-\u63D2\u4EF6",children:["Polyfill \u63D2\u4EF6",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#polyfill-\u63D2\u4EF6",children:"#"})]}),"\n",(0,i.jsxs)(n.div,{className:"rspress-directive tip",children:[(0,i.jsx)(n.div,{className:"rspress-directive-title",children:"TIP"}),(0,i.jsxs)(n.div,{className:"rspress-directive-content",children:[(0,i.jsx)(n.p,{children:"\u901A\u5E38\u60C5\u51B5\u4E0B\uFF0C\u6211\u4EEC\u4E0D\u9700\u8981\u4E3A npm \u5305\u6CE8\u5165 polyfill\uFF0C\u8FD9\u4E00\u6B65\u5E94\u8BE5\u5728 Web \u5E94\u7528\u7684\u6846\u67B6\u4FA7\u5B8C\u6210\uFF0C\u4F46\u662F\u5728\u67D0\u4E9B\u573A\u666F\uFF0C\u4E3A\u4E86\u8BA9\u6211\u4EEC\u7684\u5E93\u80FD\u591F\u76F4\u63A5\u8FD0\u884C\u5728\u4F4E\u7248\u672C\u6D4F\u89C8\u5668\u91CC\uFF0C\u6211\u4EEC\u9700\u8981\u6CE8\u5165 polyfill\u3002"}),"\n",(0,i.jsxs)(n.p,{children:["\u8BF7\u6CE8\u610F\uFF0C\u6B64\u63D2\u4EF6\u5E76\u4E0D\u4F1A\u8F6C\u5316\u4F60\u7684\u4EE3\u7801\u8BED\u6CD5\uFF0C\u53EA\u4F1A\u4E3A\u4F60\u7684\u4EE3\u7801\u4E2D\u4F7F\u7528\u5230\u7684\u4E0D\u652F\u6301\u7684\u529F\u80FD\u6CE8\u5165 polyfill\uFF0C\u628A\u5B83\u4EEC\u4F5C\u4E3A\u666E\u901A\u51FD\u6570\u5BFC\u5165\u800C\u4E0D\u662F\u6C61\u67D3\u5168\u5C40\u3002\u4F60\u9700\u8981\u5B89\u88C5 ",(0,i.jsx)(n.code,{children:"core-js-pure"})," \u4F9D\u8D56"]}),"\n"]})]}),"\n",(0,i.jsxs)(n.h2,{id:"\u5FEB\u901F\u5F00\u59CB",children:["\u5FEB\u901F\u5F00\u59CB",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u5FEB\u901F\u5F00\u59CB",children:"#"})]}),"\n",(0,i.jsxs)(n.h3,{id:"\u5B89\u88C5",children:["\u5B89\u88C5",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u5B89\u88C5",children:"#"})]}),"\n","\n",(0,i.jsx)(o.PackageManagerTabs,{command:"add @modern-js/plugin-module-polyfill -D"}),"\n",(0,i.jsxs)(n.h3,{id:"\u6CE8\u518C\u63D2\u4EF6",children:["\u6CE8\u518C\u63D2\u4EF6",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u6CE8\u518C\u63D2\u4EF6",children:"#"})]}),"\n",(0,i.jsx)(n.p,{children:"\u5728 Modern.js Module \u4E2D\uFF0C\u4F60\u53EF\u4EE5\u6309\u7167\u5982\u4E0B\u65B9\u5F0F\u6CE8\u518C\u63D2\u4EF6\uFF1A"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginPolyfill } from '@modern-js/plugin-module-polyfill';\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginPolyfill()],\n});\n"})}),"\n",(0,i.jsxs)(n.h2,{id:"\u914D\u7F6E",children:["\u914D\u7F6E",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u914D\u7F6E",children:"#"})]}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.strong,{children:"\u7C7B\u578B\uFF1A"})}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"type options = {\n targets?: Record | string;\n};\n"})}),"\n",(0,i.jsxs)(n.h3,{id:"targets",children:["targets",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#targets",children:"#"})]}),"\n",(0,i.jsxs)(n.p,{children:["\u53C2\u8003 ",(0,i.jsx)(n.a,{href:"https://babeljs.io/docs/options#targets",target:"_blank",rel:"noopener noreferrer",children:"Babel target"}),"."]}),"\n",(0,i.jsx)(n.p,{children:"\u4E0B\u9762\u662F\u4E00\u4E2A\u4F8B\u5B50\uFF1A"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginPolyfill } from '@modern-js/plugin-module-polyfill';\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginPolyfill({\n targets: '> 0.25%, not dead',\n }),\n ],\n});\n"})})]})}function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},(0,d.useMDXComponents)(),e.components).wrapper;return n?(0,i.jsx)(n,(0,r._)((0,s._)({},e),{children:(0,i.jsx)(a,(0,s._)({},e))})):a(e)}var c=t;t.__RSPRESS_PAGE_META={},t.__RSPRESS_PAGE_META["zh%2Fplugins%2Fofficial-list%2Fplugin-polyfill.mdx"]={toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2},{text:"targets",id:"targets",depth:3}],title:"Polyfill \u63D2\u4EF6"}}}]); \ No newline at end of file diff --git a/modern-js/module-tools/static/js/async/1687.457de97b.js b/modern-js/module-tools/static/js/async/1687.457de97b.js new file mode 100644 index 0000000000..7493a21864 --- /dev/null +++ b/modern-js/module-tools/static/js/async/1687.457de97b.js @@ -0,0 +1 @@ +(self.webpackChunk_modern_js_module_tools_docs=self.webpackChunk_modern_js_module_tools_docs||[]).push([["1687"],{63097:function(e,n,l){"use strict";l.r(n),l.d(n,{default:function(){return c}});var s=l("15169"),o=l("43932"),i=l("9880"),r=l("23169"),d=l("19730");function t(e){var n=Object.assign({h1:"h1",a:"a",div:"div",p:"p",code:"code",h2:"h2",h3:"h3",pre:"pre",ul:"ul",li:"li",strong:"strong"},(0,r.useMDXComponents)(),e.components);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.h1,{id:"polyfill-\u63D2\u4EF6",children:["Polyfill \u63D2\u4EF6",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#polyfill-\u63D2\u4EF6",children:"#"})]}),"\n",(0,i.jsxs)(n.div,{className:"rspress-directive tip",children:[(0,i.jsx)(n.div,{className:"rspress-directive-title",children:"TIP"}),(0,i.jsxs)(n.div,{className:"rspress-directive-content",children:[(0,i.jsx)(n.p,{children:"\u901A\u5E38\u60C5\u51B5\u4E0B\uFF0C\u6211\u4EEC\u4E0D\u9700\u8981\u4E3A npm \u5305\u6CE8\u5165 polyfill\uFF0C\u8FD9\u4E00\u6B65\u5E94\u8BE5\u5728 Web \u5E94\u7528\u7684\u6846\u67B6\u4FA7\u5B8C\u6210\uFF0C\u4F46\u662F\u5728\u67D0\u4E9B\u573A\u666F\uFF0C\u4E3A\u4E86\u8BA9\u6211\u4EEC\u7684\u5E93\u80FD\u591F\u76F4\u63A5\u8FD0\u884C\u5728\u4F4E\u7248\u672C\u6D4F\u89C8\u5668\u91CC\uFF0C\u6211\u4EEC\u9700\u8981\u6CE8\u5165 polyfill\u3002"}),"\n",(0,i.jsxs)(n.p,{children:["\u8BF7\u6CE8\u610F\uFF0C\u6B64\u63D2\u4EF6\u5E76\u4E0D\u4F1A\u8F6C\u5316\u4F60\u7684\u4EE3\u7801\u8BED\u6CD5\uFF0C\u53EA\u4F1A\u4E3A\u4F60\u7684\u4EE3\u7801\u4E2D\u4F7F\u7528\u5230\u7684\u4E0D\u652F\u6301\u7684\u529F\u80FD\u6CE8\u5165 polyfill\uFF0C\u628A\u5B83\u4EEC\u4F5C\u4E3A\u666E\u901A\u51FD\u6570\u5BFC\u5165\u800C\u4E0D\u662F\u6C61\u67D3\u5168\u5C40\u3002\u4F60\u9700\u8981\u5B89\u88C5 ",(0,i.jsx)(n.code,{children:"core-js-pure"})," \u4F9D\u8D56"]}),"\n"]})]}),"\n",(0,i.jsxs)(n.h2,{id:"\u5FEB\u901F\u5F00\u59CB",children:["\u5FEB\u901F\u5F00\u59CB",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u5FEB\u901F\u5F00\u59CB",children:"#"})]}),"\n",(0,i.jsxs)(n.h3,{id:"\u5B89\u88C5",children:["\u5B89\u88C5",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u5B89\u88C5",children:"#"})]}),"\n","\n",(0,i.jsx)(d.PackageManagerTabs,{command:"add @modern-js/plugin-module-polyfill -D"}),"\n",(0,i.jsxs)(n.h3,{id:"\u6CE8\u518C\u63D2\u4EF6",children:["\u6CE8\u518C\u63D2\u4EF6",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u6CE8\u518C\u63D2\u4EF6",children:"#"})]}),"\n",(0,i.jsx)(n.p,{children:"\u5728 Modern.js Module \u4E2D\uFF0C\u4F60\u53EF\u4EE5\u6309\u7167\u5982\u4E0B\u65B9\u5F0F\u6CE8\u518C\u63D2\u4EF6\uFF1A"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginPolyfill } from '@modern-js/plugin-module-polyfill';\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginPolyfill()],\n});\n"})}),"\n",(0,i.jsx)(n.p,{children:"\u4F60\u4E5F\u53EF\u4EE5\u901A\u8FC7 hooks \u914D\u7F6E\u6CE8\u518C\uFF0C\u4F8B\u5982\u4F60\u540C\u65F6\u5177\u6709\u591A\u4EFD\u6784\u5EFA\u914D\u7F6E\uFF0C\u5E76\u53EA\u9700\u8981\u5728 bundle \u6784\u5EFA\u65F6\u6CE8\u5165 polyfill\uFF1A"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { getPolyfillHook } from '@modern-js/plugin-module-polyfill';\n\nconst polyfillHook = getPolyfillHook();\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildConfig: [\n {\n buildType: 'bundle',\n hooks: [polyfillHook],\n },\n {\n buildType: 'bundleless',\n },\n ],\n});\n"})}),"\n",(0,i.jsxs)(n.h2,{id:"\u914D\u7F6E",children:["\u914D\u7F6E",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u914D\u7F6E",children:"#"})]}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.strong,{children:"\u7C7B\u578B\uFF1A"})}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"type options = {\n targets?: Record | string;\n};\n"})}),"\n",(0,i.jsxs)(n.h3,{id:"targets",children:["targets",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#targets",children:"#"})]}),"\n",(0,i.jsxs)(n.p,{children:["\u53C2\u8003 ",(0,i.jsx)(n.a,{href:"https://babeljs.io/docs/options#targets",target:"_blank",rel:"noopener noreferrer",children:"Babel target"}),"."]}),"\n",(0,i.jsx)(n.p,{children:"\u4E0B\u9762\u662F\u4E00\u4E2A\u4F8B\u5B50\uFF1A"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginPolyfill } from '@modern-js/plugin-module-polyfill';\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginPolyfill({\n targets: '> 0.25%, not dead',\n }),\n ],\n});\n"})})]})}function a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},(0,r.useMDXComponents)(),e.components).wrapper;return n?(0,i.jsx)(n,(0,o._)((0,s._)({},e),{children:(0,i.jsx)(t,(0,s._)({},e))})):t(e)}var c=a;a.__RSPRESS_PAGE_META={},a.__RSPRESS_PAGE_META["zh%2Fplugins%2Fofficial-list%2Fplugin-polyfill.mdx"]={toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2},{text:"targets",id:"targets",depth:3}],title:"Polyfill \u63D2\u4EF6"}}}]); \ No newline at end of file diff --git a/modern-js/module-tools/static/js/async/179.0af876da.js b/modern-js/module-tools/static/js/async/179.0af876da.js new file mode 100644 index 0000000000..69c979b823 --- /dev/null +++ b/modern-js/module-tools/static/js/async/179.0af876da.js @@ -0,0 +1 @@ +(self.webpackChunk_modern_js_module_tools_docs=self.webpackChunk_modern_js_module_tools_docs||[]).push([["179"],{16863:function(e,n,s){"use strict";s.r(n),s.d(n,{default:function(){return c}});var o=s("15169"),l=s("43932"),i=s("9880"),r=s("23169"),a=s("19730");function d(e){var n=Object.assign({h1:"h1",a:"a",div:"div",p:"p",h2:"h2",h3:"h3",pre:"pre",code:"code"},(0,r.useMDXComponents)(),e.components);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.h1,{id:"babel-plugin",children:["Babel Plugin",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#babel-plugin",children:"#"})]}),"\n",(0,i.jsxs)(n.div,{className:"rspress-directive tip",children:[(0,i.jsx)(n.div,{className:"rspress-directive-title",children:"TIP"}),(0,i.jsx)(n.div,{className:"rspress-directive-content",children:(0,i.jsx)(n.p,{children:"Normally, we don't need to use Babel to transform our code, this plugin is only used as a downgrade."})})]}),"\n",(0,i.jsxs)(n.h2,{id:"quick-start",children:["Quick start",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#quick-start",children:"#"})]}),"\n",(0,i.jsxs)(n.h3,{id:"install",children:["Install",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#install",children:"#"})]}),"\n","\n",(0,i.jsx)(a.PackageManagerTabs,{command:"add @modern-js/plugin-module-babel -D"}),"\n",(0,i.jsxs)(n.h3,{id:"register",children:["Register",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#register",children:"#"})]}),"\n",(0,i.jsx)(n.p,{children:"You can install the plugin with the following command:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginBabel } from '@modern-js/plugin-module-babel';\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginBabel()],\n});\n"})}),"\n",(0,i.jsx)(n.p,{children:"You can also configure the registration via hooks, for example,\nif you need to bundle two files A and B at the same time and only need to use babel when bundle A:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { getBabelHook } from '@modern-js/plugin-module-babel';\n\nconst babelHook = getBabelHook({\n // babel options\n});\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildConfig: [\n {\n hooks: [babelHook],\n input: ['src/a.ts'],\n },\n {\n input: ['src/b.ts'],\n },\n ],\n});\n"})}),"\n",(0,i.jsxs)(n.h2,{id:"config",children:["Config",(0,i.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#config",children:"#"})]}),"\n",(0,i.jsxs)(n.p,{children:["See ",(0,i.jsx)(n.a,{href:"https://babeljs.io/docs/options",target:"_blank",rel:"noopener noreferrer",children:"babel options"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:["Here is an example with ",(0,i.jsx)(n.code,{children:"@babel/preset-env"})," configured"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginBabel } from '@modern-js/plugin-module-babel';\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBabel({\n presets: [['@babel/preset-env']],\n }),\n ],\n});\n"})})]})}function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},(0,r.useMDXComponents)(),e.components).wrapper;return n?(0,i.jsx)(n,(0,l._)((0,o._)({},e),{children:(0,i.jsx)(d,(0,o._)({},e))})):d(e)}var c=t;t.__RSPRESS_PAGE_META={},t.__RSPRESS_PAGE_META["en%2Fplugins%2Fofficial-list%2Fplugin-babel.mdx"]={toc:[{text:"Quick start",id:"quick-start",depth:2},{text:"Install",id:"install",depth:3},{text:"Register",id:"register",depth:3},{text:"Config",id:"config",depth:2}],title:"Babel Plugin"}}}]); \ No newline at end of file diff --git a/modern-js/module-tools/static/js/async/179.8c12038a.js b/modern-js/module-tools/static/js/async/179.8c12038a.js deleted file mode 100644 index 2455cfa695..0000000000 --- a/modern-js/module-tools/static/js/async/179.8c12038a.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_modern_js_module_tools_docs=self.webpackChunk_modern_js_module_tools_docs||[]).push([["179"],{16863:function(e,n,s){"use strict";s.r(n),s.d(n,{default:function(){return c}});var i=s("15169"),r=s("43932"),l=s("9880"),a=s("23169"),d=s("19730");function o(e){var n=Object.assign({h1:"h1",a:"a",div:"div",p:"p",h2:"h2",h3:"h3",pre:"pre",code:"code"},(0,a.useMDXComponents)(),e.components);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(n.h1,{id:"babel-plugin",children:["Babel Plugin",(0,l.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#babel-plugin",children:"#"})]}),"\n",(0,l.jsxs)(n.div,{className:"rspress-directive tip",children:[(0,l.jsx)(n.div,{className:"rspress-directive-title",children:"TIP"}),(0,l.jsx)(n.div,{className:"rspress-directive-content",children:(0,l.jsx)(n.p,{children:"Normally, we don't need to use Babel to transform our code, this plugin is only used as a downgrade."})})]}),"\n",(0,l.jsxs)(n.h2,{id:"quick-start",children:["Quick start",(0,l.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#quick-start",children:"#"})]}),"\n",(0,l.jsxs)(n.h3,{id:"install",children:["Install",(0,l.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#install",children:"#"})]}),"\n","\n",(0,l.jsx)(d.PackageManagerTabs,{command:"add @modern-js/plugin-module-babel -D"}),"\n",(0,l.jsxs)(n.h3,{id:"register",children:["Register",(0,l.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#register",children:"#"})]}),"\n",(0,l.jsx)(n.p,{children:"You can install the plugin with the following command:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginBabel } from '@modern-js/plugin-module-babel';\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginBabel()],\n});\n"})}),"\n",(0,l.jsxs)(n.h2,{id:"config",children:["Config",(0,l.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#config",children:"#"})]}),"\n",(0,l.jsxs)(n.p,{children:["See ",(0,l.jsx)(n.a,{href:"https://babeljs.io/docs/options",target:"_blank",rel:"noopener noreferrer",children:"babel options"}),"."]}),"\n",(0,l.jsxs)(n.p,{children:["Here is an example with ",(0,l.jsx)(n.code,{children:"@babel/preset-env"})," configured"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginBabel } from '@modern-js/plugin-module-babel';\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBabel({\n presets: [['@babel/preset-env']],\n }),\n ],\n});\n"})})]})}function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},(0,a.useMDXComponents)(),e.components).wrapper;return n?(0,l.jsx)(n,(0,r._)((0,i._)({},e),{children:(0,l.jsx)(o,(0,i._)({},e))})):o(e)}var c=t;t.__RSPRESS_PAGE_META={},t.__RSPRESS_PAGE_META["en%2Fplugins%2Fofficial-list%2Fplugin-babel.mdx"]={toc:[{text:"Quick start",id:"quick-start",depth:2},{text:"Install",id:"install",depth:3},{text:"Register",id:"register",depth:3},{text:"Config",id:"config",depth:2}],title:"Babel Plugin"}}}]); \ No newline at end of file diff --git a/modern-js/module-tools/static/js/async/41.150764c4.js b/modern-js/module-tools/static/js/async/41.150764c4.js deleted file mode 100644 index 694730ae61..0000000000 --- a/modern-js/module-tools/static/js/async/41.150764c4.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_modern_js_module_tools_docs=self.webpackChunk_modern_js_module_tools_docs||[]).push([["41"],{31461:function(e,n,s){"use strict";s.r(n),s.d(n,{default:function(){return c}});var l=s("15169"),i=s("43932"),r=s("9880"),o=s("23169"),t=s("19730");function d(e){var n=Object.assign({h1:"h1",a:"a",div:"div",p:"p",code:"code",h2:"h2",h3:"h3",pre:"pre",ul:"ul",li:"li",strong:"strong"},(0,o.useMDXComponents)(),e.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.h1,{id:"polyfill-plugin",children:["Polyfill Plugin",(0,r.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#polyfill-plugin",children:"#"})]}),"\n",(0,r.jsxs)(n.div,{className:"rspress-directive tip",children:[(0,r.jsx)(n.div,{className:"rspress-directive-title",children:"TIP"}),(0,r.jsxs)(n.div,{className:"rspress-directive-content",children:[(0,r.jsx)(n.p,{children:"Normally, we don't need to inject polyfill for npm packages, this step should be done on the web application framework side, but in some scenarios we need to inject polyfill in order to make our library run directly in low version browsers."}),"\n",(0,r.jsxs)(n.p,{children:["Note that this plugin does not transform your code syntax, it only injects polyfill for unsupported functions used in your code, importing them as normal functions instead of polluting the global. You need to install the ",(0,r.jsx)(n.code,{children:"core-js-pure"})," dependency."]}),"\n"]})]}),"\n",(0,r.jsxs)(n.h2,{id:"quick-start",children:["Quick start",(0,r.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#quick-start",children:"#"})]}),"\n",(0,r.jsxs)(n.h3,{id:"install",children:["Install",(0,r.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#install",children:"#"})]}),"\n","\n",(0,r.jsx)(t.PackageManagerTabs,{command:"add @modern-js/plugin-module-polyfill -D"}),"\n",(0,r.jsxs)(n.h3,{id:"register",children:["Register",(0,r.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#register",children:"#"})]}),"\n",(0,r.jsx)(n.p,{children:"In Modern.js Module, you can register plugins in the following way:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginPolyfill } from '@modern-js/plugin-module-polyfill';\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginPolyfill()],\n});\n"})}),"\n",(0,r.jsxs)(n.h2,{id:"config",children:["Config",(0,r.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#config",children:"#"})]}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.strong,{children:"Type"})}),"\n"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-ts",children:"type options = {\n targets?: Record | string;\n};\n"})}),"\n",(0,r.jsxs)(n.h3,{id:"targets",children:["targets",(0,r.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#targets",children:"#"})]}),"\n",(0,r.jsxs)(n.p,{children:["See ",(0,r.jsx)(n.a,{href:"https://babeljs.io/docs/options#targets",target:"_blank",rel:"noopener noreferrer",children:"Babel target"}),"."]}),"\n",(0,r.jsx)(n.p,{children:"This is a example."}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginPolyfill } from '@modern-js/plugin-module-polyfill';\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginPolyfill({\n targets: '> 0.25%, not dead',\n }),\n ],\n});\n"})})]})}function a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},(0,o.useMDXComponents)(),e.components).wrapper;return n?(0,r.jsx)(n,(0,i._)((0,l._)({},e),{children:(0,r.jsx)(d,(0,l._)({},e))})):d(e)}var c=a;a.__RSPRESS_PAGE_META={},a.__RSPRESS_PAGE_META["en%2Fplugins%2Fofficial-list%2Fplugin-polyfill.mdx"]={toc:[{text:"Quick start",id:"quick-start",depth:2},{text:"Install",id:"install",depth:3},{text:"Register",id:"register",depth:3},{text:"Config",id:"config",depth:2},{text:"targets",id:"targets",depth:3}],title:"Polyfill Plugin"}}}]); \ No newline at end of file diff --git a/modern-js/module-tools/static/js/async/41.86df2528.js b/modern-js/module-tools/static/js/async/41.86df2528.js new file mode 100644 index 0000000000..5ae87f3ae3 --- /dev/null +++ b/modern-js/module-tools/static/js/async/41.86df2528.js @@ -0,0 +1 @@ +(self.webpackChunk_modern_js_module_tools_docs=self.webpackChunk_modern_js_module_tools_docs||[]).push([["41"],{31461:function(e,n,l){"use strict";l.r(n),l.d(n,{default:function(){return c}});var i=l("15169"),o=l("43932"),s=l("9880"),r=l("23169"),t=l("19730");function d(e){var n=Object.assign({h1:"h1",a:"a",div:"div",p:"p",code:"code",h2:"h2",h3:"h3",pre:"pre",ul:"ul",li:"li",strong:"strong"},(0,r.useMDXComponents)(),e.components);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.h1,{id:"polyfill-plugin",children:["Polyfill Plugin",(0,s.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#polyfill-plugin",children:"#"})]}),"\n",(0,s.jsxs)(n.div,{className:"rspress-directive tip",children:[(0,s.jsx)(n.div,{className:"rspress-directive-title",children:"TIP"}),(0,s.jsxs)(n.div,{className:"rspress-directive-content",children:[(0,s.jsx)(n.p,{children:"Normally, we don't need to inject polyfill for npm packages, this step should be done on the web application framework side, but in some scenarios we need to inject polyfill in order to make our library run directly in low version browsers."}),"\n",(0,s.jsxs)(n.p,{children:["Note that this plugin does not transform your code syntax, it only injects polyfill for unsupported functions used in your code, importing them as normal functions instead of polluting the global. You need to install the ",(0,s.jsx)(n.code,{children:"core-js-pure"})," dependency."]}),"\n"]})]}),"\n",(0,s.jsxs)(n.h2,{id:"quick-start",children:["Quick start",(0,s.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#quick-start",children:"#"})]}),"\n",(0,s.jsxs)(n.h3,{id:"install",children:["Install",(0,s.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#install",children:"#"})]}),"\n","\n",(0,s.jsx)(t.PackageManagerTabs,{command:"add @modern-js/plugin-module-polyfill -D"}),"\n",(0,s.jsxs)(n.h3,{id:"register",children:["Register",(0,s.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#register",children:"#"})]}),"\n",(0,s.jsx)(n.p,{children:"In Modern.js Module, you can register plugins in the following way:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginPolyfill } from '@modern-js/plugin-module-polyfill';\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginPolyfill()],\n});\n"})}),"\n",(0,s.jsx)(n.p,{children:"You can also configure registration via hooks, for example,\nif you have multiple build configurations at the same time and only need to inject the polyfill when bundle:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { getPolyfillHook } from '@modern-js/plugin-module-polyfill';\n\nconst polyfillHook = getPolyfillHook();\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildConfig: [\n {\n buildType: 'bundle',\n hooks: [polyfillHook],\n },\n {\n buildType: 'bundleless',\n },\n ],\n});\n"})}),"\n",(0,s.jsxs)(n.h2,{id:"config",children:["Config",(0,s.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#config",children:"#"})]}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.strong,{children:"Type"})}),"\n"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"type options = {\n targets?: Record | string;\n};\n"})}),"\n",(0,s.jsxs)(n.h3,{id:"targets",children:["targets",(0,s.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#targets",children:"#"})]}),"\n",(0,s.jsxs)(n.p,{children:["See ",(0,s.jsx)(n.a,{href:"https://babeljs.io/docs/options#targets",target:"_blank",rel:"noopener noreferrer",children:"Babel target"}),"."]}),"\n",(0,s.jsx)(n.p,{children:"This is a example."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginPolyfill } from '@modern-js/plugin-module-polyfill';\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginPolyfill({\n targets: '> 0.25%, not dead',\n }),\n ],\n});\n"})})]})}function a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},(0,r.useMDXComponents)(),e.components).wrapper;return n?(0,s.jsx)(n,(0,o._)((0,i._)({},e),{children:(0,s.jsx)(d,(0,i._)({},e))})):d(e)}var c=a;a.__RSPRESS_PAGE_META={},a.__RSPRESS_PAGE_META["en%2Fplugins%2Fofficial-list%2Fplugin-polyfill.mdx"]={toc:[{text:"Quick start",id:"quick-start",depth:2},{text:"Install",id:"install",depth:3},{text:"Register",id:"register",depth:3},{text:"Config",id:"config",depth:2},{text:"targets",id:"targets",depth:3}],title:"Polyfill Plugin"}}}]); \ No newline at end of file diff --git a/modern-js/module-tools/static/js/async/8349.20ef3d57.js b/modern-js/module-tools/static/js/async/8349.20ef3d57.js new file mode 100644 index 0000000000..c872a58c7a --- /dev/null +++ b/modern-js/module-tools/static/js/async/8349.20ef3d57.js @@ -0,0 +1 @@ +(self.webpackChunk_modern_js_module_tools_docs=self.webpackChunk_modern_js_module_tools_docs||[]).push([["8349"],{37136:function(e,n,s){"use strict";s.r(n),s.d(n,{default:function(){return c}});var o=s("15169"),l=s("43932"),r=s("9880"),d=s("23169"),i=s("19730");function a(e){var n=Object.assign({h1:"h1",a:"a",div:"div",p:"p",h2:"h2",h3:"h3",pre:"pre",code:"code"},(0,d.useMDXComponents)(),e.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.h1,{id:"babel-\u63D2\u4EF6",children:["Babel \u63D2\u4EF6",(0,r.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#babel-\u63D2\u4EF6",children:"#"})]}),"\n",(0,r.jsxs)(n.div,{className:"rspress-directive tip",children:[(0,r.jsx)(n.div,{className:"rspress-directive-title",children:"TIP"}),(0,r.jsx)(n.div,{className:"rspress-directive-content",children:(0,r.jsx)(n.p,{children:"\u901A\u5E38\u60C5\u51B5\u4E0B\uFF0C\u6211\u4EEC\u65E0\u9700\u4F7F\u7528 Babel \u8F6C\u6362\u6211\u4EEC\u7684\u4EE3\u7801\uFF0C\u6B64\u63D2\u4EF6\u4EC5\u4F5C\u4E3A\u4E00\u79CD\u964D\u7EA7\u65B9\u5F0F\u3002"})})]}),"\n",(0,r.jsxs)(n.h2,{id:"\u5FEB\u901F\u5F00\u59CB",children:["\u5FEB\u901F\u5F00\u59CB",(0,r.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u5FEB\u901F\u5F00\u59CB",children:"#"})]}),"\n",(0,r.jsxs)(n.h3,{id:"\u5B89\u88C5",children:["\u5B89\u88C5",(0,r.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u5B89\u88C5",children:"#"})]}),"\n","\n",(0,r.jsx)(i.PackageManagerTabs,{command:"add @modern-js/plugin-module-babel -D"}),"\n",(0,r.jsxs)(n.h3,{id:"\u6CE8\u518C\u63D2\u4EF6",children:["\u6CE8\u518C\u63D2\u4EF6",(0,r.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u6CE8\u518C\u63D2\u4EF6",children:"#"})]}),"\n",(0,r.jsx)(n.p,{children:"\u5728 Modern.js Module \u4E2D\uFF0C\u4F60\u53EF\u4EE5\u6309\u7167\u5982\u4E0B\u65B9\u5F0F\u6CE8\u518C\u63D2\u4EF6\uFF1A"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginBabel } from '@modern-js/plugin-module-babel';\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginBabel()],\n});\n"})}),"\n",(0,r.jsx)(n.p,{children:"\u4F60\u4E5F\u53EF\u4EE5\u901A\u8FC7 hooks \u914D\u7F6E\u6CE8\u518C\uFF0C\u4F8B\u5982\u4F60\u540C\u65F6\u9700\u8981\u6253\u5305 A\uFF0CB \u4E24\u4E2A\u6587\u4EF6\uFF0C\u5E76\u53EA\u9700\u8981\u5728\u6253\u5305 A \u65F6\u4F7F\u7528 babel\uFF1A"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { getBabelHook } from '@modern-js/plugin-module-babel';\n\nconst babelHook = getBabelHook({\n // babel options\n});\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildConfig: [\n {\n hooks: [babelHook],\n input: ['src/a.ts'],\n },\n {\n input: ['src/b.ts'],\n },\n ],\n});\n"})}),"\n",(0,r.jsxs)(n.h2,{id:"\u914D\u7F6E",children:["\u914D\u7F6E",(0,r.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u914D\u7F6E",children:"#"})]}),"\n",(0,r.jsxs)(n.p,{children:["See ",(0,r.jsx)(n.a,{href:"https://babeljs.io/docs/options",target:"_blank",rel:"noopener noreferrer",children:"Babel options"})]}),"\n",(0,r.jsxs)(n.p,{children:["\u4E0B\u9762\u662F\u4E00\u4E2A\u914D\u7F6E\u4E86",(0,r.jsx)(n.code,{children:"@babel/preset-env"}),"\u7684\u4F8B\u5B50\uFF1A"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginBabel } from '@modern-js/plugin-module-babel';\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBabel({\n presets: [['@babel/preset-env']],\n }),\n ],\n});\n"})})]})}function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},(0,d.useMDXComponents)(),e.components).wrapper;return n?(0,r.jsx)(n,(0,l._)((0,o._)({},e),{children:(0,r.jsx)(a,(0,o._)({},e))})):a(e)}var c=t;t.__RSPRESS_PAGE_META={},t.__RSPRESS_PAGE_META["zh%2Fplugins%2Fofficial-list%2Fplugin-babel.mdx"]={toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2}],title:"Babel \u63D2\u4EF6"}}}]); \ No newline at end of file diff --git a/modern-js/module-tools/static/js/async/8349.507f6af8.js b/modern-js/module-tools/static/js/async/8349.507f6af8.js deleted file mode 100644 index f34976d4f9..0000000000 --- a/modern-js/module-tools/static/js/async/8349.507f6af8.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_modern_js_module_tools_docs=self.webpackChunk_modern_js_module_tools_docs||[]).push([["8349"],{37136:function(e,n,s){"use strict";s.r(n),s.d(n,{default:function(){return c}});var r=s("15169"),d=s("43932"),l=s("9880"),i=s("23169"),a=s("19730");function o(e){var n=Object.assign({h1:"h1",a:"a",div:"div",p:"p",h2:"h2",h3:"h3",pre:"pre",code:"code"},(0,i.useMDXComponents)(),e.components);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(n.h1,{id:"babel-\u63D2\u4EF6",children:["Babel \u63D2\u4EF6",(0,l.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#babel-\u63D2\u4EF6",children:"#"})]}),"\n",(0,l.jsxs)(n.div,{className:"rspress-directive tip",children:[(0,l.jsx)(n.div,{className:"rspress-directive-title",children:"TIP"}),(0,l.jsx)(n.div,{className:"rspress-directive-content",children:(0,l.jsx)(n.p,{children:"\u901A\u5E38\u60C5\u51B5\u4E0B\uFF0C\u6211\u4EEC\u65E0\u9700\u4F7F\u7528 Babel \u8F6C\u6362\u6211\u4EEC\u7684\u4EE3\u7801\uFF0C\u6B64\u63D2\u4EF6\u4EC5\u4F5C\u4E3A\u4E00\u79CD\u964D\u7EA7\u65B9\u5F0F\u3002"})})]}),"\n",(0,l.jsxs)(n.h2,{id:"\u5FEB\u901F\u5F00\u59CB",children:["\u5FEB\u901F\u5F00\u59CB",(0,l.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u5FEB\u901F\u5F00\u59CB",children:"#"})]}),"\n",(0,l.jsxs)(n.h3,{id:"\u5B89\u88C5",children:["\u5B89\u88C5",(0,l.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u5B89\u88C5",children:"#"})]}),"\n","\n",(0,l.jsx)(a.PackageManagerTabs,{command:"add @modern-js/plugin-module-babel -D"}),"\n",(0,l.jsxs)(n.h3,{id:"\u6CE8\u518C\u63D2\u4EF6",children:["\u6CE8\u518C\u63D2\u4EF6",(0,l.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u6CE8\u518C\u63D2\u4EF6",children:"#"})]}),"\n",(0,l.jsx)(n.p,{children:"\u5728 Modern.js Module \u4E2D\uFF0C\u4F60\u53EF\u4EE5\u6309\u7167\u5982\u4E0B\u65B9\u5F0F\u6CE8\u518C\u63D2\u4EF6\uFF1A"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginBabel } from '@modern-js/plugin-module-babel';\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginBabel()],\n});\n"})}),"\n",(0,l.jsxs)(n.h2,{id:"\u914D\u7F6E",children:["\u914D\u7F6E",(0,l.jsx)(n.a,{className:"header-anchor","aria-hidden":"true",href:"#\u914D\u7F6E",children:"#"})]}),"\n",(0,l.jsxs)(n.p,{children:["See ",(0,l.jsx)(n.a,{href:"https://babeljs.io/docs/options",target:"_blank",rel:"noopener noreferrer",children:"Babel options"})]}),"\n",(0,l.jsxs)(n.p,{children:["\u4E0B\u9762\u662F\u4E00\u4E2A\u914D\u7F6E\u4E86",(0,l.jsx)(n.code,{children:"@babel/preset-env"}),"\u7684\u4F8B\u5B50\uFF1A"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-ts",children:"import { moduleTools, defineConfig } from '@modern-js/module-tools';\nimport { modulePluginBabel } from '@modern-js/plugin-module-babel';\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBabel({\n presets: [['@babel/preset-env']],\n }),\n ],\n});\n"})})]})}function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},(0,i.useMDXComponents)(),e.components).wrapper;return n?(0,l.jsx)(n,(0,d._)((0,r._)({},e),{children:(0,l.jsx)(o,(0,r._)({},e))})):o(e)}var c=t;t.__RSPRESS_PAGE_META={},t.__RSPRESS_PAGE_META["zh%2Fplugins%2Fofficial-list%2Fplugin-babel.mdx"]={toc:[{text:"\u5FEB\u901F\u5F00\u59CB",id:"\u5FEB\u901F\u5F00\u59CB",depth:2},{text:"\u5B89\u88C5",id:"\u5B89\u88C5",depth:3},{text:"\u6CE8\u518C\u63D2\u4EF6",id:"\u6CE8\u518C\u63D2\u4EF6",depth:3},{text:"\u914D\u7F6E",id:"\u914D\u7F6E",depth:2}],title:"Babel \u63D2\u4EF6"}}}]); \ No newline at end of file diff --git a/modern-js/module-tools/static/search_index.en.6e9af6b8.json b/modern-js/module-tools/static/search_index.en.20664666.json similarity index 94% rename from modern-js/module-tools/static/search_index.en.6e9af6b8.json rename to modern-js/module-tools/static/search_index.en.20664666.json index 091c3d5a53..ee727d6937 100644 --- a/modern-js/module-tools/static/search_index.en.6e9af6b8.json +++ b/modern-js/module-tools/static/search_index.en.20664666.json @@ -1 +1 @@ -[{"id":0,"title":"buildConfig","routePath":"/module-tools/en/api/config/build-config","lang":"en","toc":[{"text":"alias","id":"alias","depth":2,"charIndex":378},{"text":"asset","id":"asset","depth":2,"charIndex":1394},{"text":"asset.path","id":"assetpath","depth":2,"charIndex":1453},{"text":"asset.limit","id":"assetlimit","depth":2,"charIndex":1557},{"text":"asset.publicPath","id":"assetpublicpath","depth":2,"charIndex":2123},{"text":"asset.svgr","id":"assetsvgr","depth":2,"charIndex":2406},{"text":"asset.svgr.include","id":"assetsvgrinclude","depth":2,"charIndex":3027},{"text":"asset.svgr.exclude","id":"assetsvgrexclude","depth":2,"charIndex":3145},{"text":"autoExternal","id":"autoexternal","depth":2,"charIndex":3262},{"text":"autoExternal.dependencies","id":"autoexternaldependencies","depth":2,"charIndex":3992},{"text":"autoExternal.peerDependencies","id":"autoexternalpeerdependencies","depth":2,"charIndex":4128},{"text":"banner","id":"banner","depth":2,"charIndex":4259},{"text":"buildType","id":"buildtype","depth":2,"charIndex":4876},{"text":"copy","id":"copy","depth":2,"charIndex":5036},{"text":"copy.patterns","id":"copypatterns","depth":2,"charIndex":5301},{"text":"copy.options","id":"copyoptions","depth":2,"charIndex":5474},{"text":"define","id":"define","depth":2,"charIndex":5771},{"text":"dts","id":"dts","depth":2,"charIndex":7136},{"text":"dts.abortOnError","id":"dtsabortonerror","depth":2,"charIndex":7318},{"text":"dts.distPath","id":"dtsdistpath","depth":2,"charIndex":7903},{"text":"dts.only","id":"dtsonly","depth":2,"charIndex":8166},{"text":"dts.tsconfigPath","id":"dtstsconfigpath","depth":2,"charIndex":8414},{"text":"dts.respectExternal","id":"dtsrespectexternal","depth":2,"charIndex":8662},{"text":"esbuildOptions","id":"esbuildoptions","depth":2,"charIndex":9198},{"text":"externalHelpers","id":"externalhelpers","depth":2,"charIndex":10723},{"text":"externals","id":"externals","depth":2,"charIndex":11689},{"text":"footer","id":"footer","depth":2,"charIndex":12025},{"text":"format","id":"format","depth":2,"charIndex":12121},{"text":"format: esm","id":"format-esm","depth":3,"charIndex":12308},{"text":"format: cjs","id":"format-cjs","depth":3,"charIndex":12523},{"text":"format: iife","id":"format-iife","depth":3,"charIndex":12794},{"text":"format: umd","id":"format-umd","depth":3,"charIndex":13164},{"text":"hooks","id":"hooks","depth":2,"charIndex":13542},{"text":"input","id":"input","depth":2,"charIndex":14500},{"text":"jsx","id":"jsx","depth":2,"charIndex":16089},{"text":"metafile","id":"metafile","depth":2,"charIndex":16702},{"text":"minify","id":"minify","depth":2,"charIndex":17232},{"text":"outDir","id":"outdir","depth":2,"charIndex":17493},{"text":"platform","id":"platform","depth":2,"charIndex":17669},{"text":"redirect","id":"redirect","depth":2,"charIndex":17947},{"text":"resolve","id":"resolve","depth":2,"charIndex":18639},{"text":"resolve.mainFields","id":"resolvemainfields","depth":3,"charIndex":18684},{"text":"resolve.jsExtentions","id":"resolvejsextentions","depth":3,"charIndex":19307},{"text":"sideEffects","id":"sideeffects","depth":2,"charIndex":19885},{"text":"sourceDir","id":"sourcedir","depth":2,"charIndex":21098},{"text":"sourceMap","id":"sourcemap","depth":2,"charIndex":21331},{"text":"sourceType","id":"sourcetype","depth":2,"charIndex":21442},{"text":"splitting","id":"splitting","depth":2,"charIndex":21669},{"text":"style","id":"style","depth":2,"charIndex":21752},{"text":"style.less","id":"styleless","depth":2,"charIndex":21800},{"text":"style.less.lessOptions","id":"stylelesslessoptions","depth":2,"charIndex":21842},{"text":"style.less.additionalData","id":"stylelessadditionaldata","depth":2,"charIndex":21967},{"text":"style.less.implementation","id":"stylelessimplementation","depth":2,"charIndex":22222},{"text":"style.sass","id":"stylesass","depth":2,"charIndex":22827},{"text":"style.sass.sassOptions","id":"stylesasssassoptions","depth":2,"charIndex":22870},{"text":"style.sass.additionalData","id":"stylesassadditionaldata","depth":2,"charIndex":22976},{"text":"style.sass.implementation","id":"stylesassimplementation","depth":2,"charIndex":23291},{"text":"style.postcss","id":"stylepostcss","depth":2,"charIndex":23891},{"text":"style.inject","id":"styleinject","depth":2,"charIndex":24893},{"text":"style.autoModules","id":"styleautomodules","depth":2,"charIndex":26353},{"text":"style.modules","id":"stylemodules","depth":2,"charIndex":26700},{"text":"style.tailwindcss","id":"styletailwindcss","depth":2,"charIndex":27160},{"text":"Enabling Tailwind CSS","id":"enabling-tailwind-css","depth":3,"charIndex":27413},{"text":"Type","id":"type","depth":3,"charIndex":27622},{"text":"Notes","id":"notes","depth":3,"charIndex":27927},{"text":"target","id":"target","depth":2,"charIndex":28510},{"text":"transformImport","id":"transformimport","depth":2,"charIndex":29101},{"text":"transformLodash","id":"transformlodash","depth":2,"charIndex":29655},{"text":"tsconfig","id":"tsconfig","depth":2,"charIndex":30260},{"text":"umdGlobals","id":"umdglobals","depth":2,"charIndex":30457},{"text":"umdModuleName","id":"umdmodulename","depth":2,"charIndex":30888}],"domain":"","content":"#\n\nbuildConfig is a configuration option that describes how to compile and generate\nbuild artifacts. It contains all the configurations related to the build\nprocess.\n\n * Type: object | object[]\n\nTIP\n\nBefore start using buildConfig, please read the following documentation to\nunderstand its purpose:\n\n * Modifying Output Artifacts\n * In-Depth Understanding of the Build Process\n\n\nalias#\n\n * Type: Record | Function\n * Default: {'@': 'src',}\n\nTIP\n\nFor TypeScript projects, you only need to configure compilerOptions.paths in\ntsconfig.json, Modern.js Module will automatically recognize the alias in\ntsconfig.json, so there is no need to configure the alias field additionally.\n\nexport default {\n buildConfig: {\n alias: {\n '@common': '. /src/common',\n },\n },\n};\n\n\nAfter the above configuration is done, if @common/Foo.tsx is referenced in the\ncode, it will map to the /src/common/Foo.tsx path.\n\nWhen the value of alias is defined as a function, you can accept the pre-defined\nalias object and modify it.\n\nexport default {\n buildConfig: {\n alias: alias => {\n alias['@common'] = '. /src/common';\n },\n },\n};\n\n\nIt is also possible to return a new object as the final result in the function,\nwhich will override the pre-defined alias object.\n\nexport default {\n buildConfig: {\n alias: alias => {\n return {\n '@common': '. /src/common',\n };\n },\n },\n};\n\n\n\nasset#\n\nContains configuration related to static assets.\n\n\nasset.path#\n\nStatic resource output path, will be based on outDir\n\n * Type: string\n * Default: assets\n\n\nasset.limit#\n\nUsed to set the threshold for static assets to be automatically inlined as\nbase64.\n\nBy default, Modern.js Module will inline assets such as images, fonts and media\nsmaller than 10KB during bundling. They are Base64 encoded and inlined in the\nbundles, eliminating the need for separate HTTP requests.\n\nYou can adjust this threshold by modifying the limit config.\n\n * Type: number\n * Default: 10 * 1024\n\nFor example, set limit to 0 to avoid assets inlining:\n\nexport default defineConfig({\n buildConfig: {\n asset: {\n limit: 0,\n },\n },\n});\n\n\n\nasset.publicPath#\n\nThe CDN prefix given to unlinked assets when bundling.\n\n * Type: string\n * Default: undefined\n\nexport default {\n buildConfig: {\n asset: {\n publicPath: 'https://xxx/',\n },\n },\n};\n\n\nAt this point, all static assets will be prefixed with https://xxx/.\n\n\nasset.svgr#\n\nPackaged to handle svg as a React component, options reference svgr, plus\nsupport for two configuration options include and exclude to match the svg file\nto be handled\n\n * Type: boolean | object\n * Default: false\n\nWhen svgr feature is enabled, you can use svg as a component using the default\nexport.\n\n// true\n\n\nexport default () => ;\n\n\nWARNING\n\nThe following usage is not currently supported:\n\n\n\n\nWhen enabled, the type of svg used can be modified by adding a type definition\nto the modern-app-env.d.ts file:\n\ndeclare module '*.svg' {\n const src: React.FunctionComponent>;\n export default src;\n}\n\n/// \n\n\n\nasset.svgr.include#\n\nSet the matching svg file\n\n * Type: string | RegExp | (string | RegExp)[]\n * Default: /\\.svg$/\n\n\nasset.svgr.exclude#\n\nSet unmatched svg files\n\n * Type: string | RegExp | (string | RegExp)[]\n * Default: undefined\n\n\nautoExternal#\n\nAutomatically externalize project dependencies and peerDependencies and not\npackage them into the final bundle\n\n * Type: boolean | object\n * Default: true\n\nWhen we want to turn off the default handling behavior for third-party\ndependencies, we can do so by:\n\nexport default defineConfig({\n buildConfig: {\n autoExternal: false,\n },\n});\n\n\nThis way the dependencies under \"dependencies\" and \"peerDependencies\" will be\nbundled. If you want to turn off the processing of only one of these\ndependencies, you can use the buildConfig.autoExternal in the form of an object.\n\nexport default defineConfig({\n buildConfig: {\n autoExternal: {\n dependencies: false,\n peerDependencies: false,\n },\n },\n});\n\n\n\nautoExternal.dependencies#\n\nWhether or not the dep dependencies of the external project are needed\n\n * Type: boolean\n * Default: true\n\n\nautoExternal.peerDependencies#\n\nWhether to require peerDep dependencies for external projects\n\n * Type: boolean\n * Default: true\n\n\nbanner#\n\nProvides the ability to inject content into the top and bottom of each JS , CSS\nand DTS file.\n\ninterface BannerAndFooter {\n js?: string;\n css?: string;\n dts?: string;\n}\n\n\n * Type: BannerAndFooter\n * Default: {}\n * Version: v2.36.0\n\nLet's say you want to add copyright information to JS and CSS files.\n\n\n\nconst copyRight = `/*\n © Copyright 2020 xxx.com or one of its affiliates.\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n*/`;\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildConfig: {\n banner: {\n js: copyRight,\n css: copyRight,\n },\n },\n});\n\n\n\nbuildType#\n\nThe build type, bundle will package your code, bundleless will only do the code\nconversion\n\n * Type: 'bundle' | 'bundleless'\n * Default: 'bundle'\n\n\ncopy#\n\nCopies the specified file or directory into the build output directory\n\n * Type: object[]\n * Default: []\n\nexport default {\n buildConfig: {\n copy: [{ from: '. /src/assets', to: '' }],\n },\n};\n\n\nReference for array settings: copy-webpack-plugin patterns\n\n\ncopy.patterns#\n\n * Type: CopyPattern[]\n * Default: []\n\ninterface CopyPattern {\n from: string;\n to?: string;\n context?: string;\n globOptions?: globby.GlobbyOptions;\n}\n\n\n\ncopy.options#\n\n * Type:\n\ntype Options = {\n concurrency?: number;\n enableCopySync?: boolean;\n};\n\n\n * Default: { concurrency: 100, enableCopySync: false }\n\n * concurrency: Specifies how many copy tasks to execute in parallel.\n\n * enableCopySync: Uses fs.copySync by default, instead of fs.copy.\n\n\ndefine#\n\nDefine global variables that will be injected into the code\n\n * Type: Record\n * Default: {}\n\nSince the define function is implemented by global text replacement, you need to\nensure that the global variable values are strings. A safer approach is to\nconvert the value of each global variable to a string, using JSON.stringify, as\nfollows.\n\nexport default {\n buildConfig: {\n define: {\n VERSION: JSON.stringify('1.0'),\n },\n },\n};\n\n\nIf the project is a TypeScript project, then you may need to add the following\nto the .d.ts file in the project source directory.\n\n> If the .d.ts file does not exist, then you can create it manually.\n\ndeclare const YOUR_ADD_GLOBAL_VAR;\n\n\nYou can also replace environment variable:\n\n\nexport default defineConfig({\n buildConfig: {\n define: {\n 'process.env.VERSION': JSON.stringify(process.env.VERSION || '0.0.0'),\n },\n },\n});\n\n\nWith the above configuration, we can put the following code.\n\n// pre-compiler code\nconsole.log(process.env.VERSION);\n\n\nWhen executing VERSION=1.0.0 modern build, the conversion is:\n\n// compiled code\nconsole.log('1.0.0');\n\n\nTIP\n\nTo prevent excessive global replacement substitution, it is recommended that the\nfollowing two principles be followed when using\n\n * Use upper case for global constants\n * Customize the prefix and suffix of global constants to ensure uniqueness\n\n\ndts#\n\nThe dts file generates the relevant configuration, by default it generates.\n\n * Type: false | object\n * Default:\n\n{\n abortOnError: true,\n distPath: './',\n only: false,\n}\n\n\n\ndts.abortOnError#\n\nWhether to allow the build to succeed if a type error occurs.\n\n * Type: boolean\n * Default: true\n\nBy default, type errors will cause the build to fail. When abortOnError is set\nto false, the build will still succeed even if there are type issues in the\ncode:\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n abortOnError: false,\n },\n },\n});\n\n\nWARNING\n\nWhen this configuration is disabled, there is no guarantee that the type files\nwill be generated correctly. In buildType: 'bundle', which is the bundle mode,\ntype files will not be generated.\n\n\ndts.distPath#\n\nThe output path of the dts file, based on outDir\n\n * Type: string\n * Default: ./\n\nFor example, output to the types directory under the outDir:\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n distPath: './types',\n },\n },\n});\n\n\n\ndts.only#\n\nWhether to generate only type files during the build process without generating\nJavaScript output files.\n\n * Type: boolean\n * Default: false\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n only: true,\n },\n },\n});\n\n\n\ndts.tsconfigPath#\n\ndeprecated,use tsconfig instead.\n\nSpecifies the path to the tsconfig file used to generate the type file.\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n tsconfigPath: './other-tsconfig.json',\n },\n },\n});\n\n\n\ndts.respectExternal#\n\nWhen set to false, the type of third-party packages will be excluded from the\nbundle, when set to true, it will determine whether third-party types need to be\nbundled based on externals.\n\nWhen bundle d.ts, export is not analyzed, so any third-party package type you\nuse may break your build, which is obviously uncontrollable. So we can avoid it\nwith this configuration.\n\n * Type: boolean\n * Default: true\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n respectExternal: false,\n },\n },\n});\n\n\n\nesbuildOptions#\n\nUsed to modify the esbuild configuration.\n\n * Type: Function\n * Build Type: Only supported for buildType: 'bundle'\n * Default: c => c\n\nFor example, if we need to modify the file extension of the generated files:\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.outExtension = { '.js': '.mjs' };\n return options;\n },\n },\n});\n\n\nFor example, register an esbuild plugin:\n\n\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.plugins = [myEsbuildPlugin, ...options.plugins];\n return options;\n },\n },\n});\n\n\nWhen adding an esbuild plugin, please note that you need to add the plugin at\nthe beginning of the plugins array. This is because the Modern.js Module is also\nintegrated into the entire build process through an esbuild plugin. Therefore,\ncustom plugins need to be registered with higher priority.\n\nTIP\n\nWe have done many extensions based on the original esbuild build. Therefore,\nwhen using this configuration, pay attention to the following:\n\n 1. Prefer to use the configuration that Modern.js Module provides. For example,\n esbuild does not support target: 'es5', but we support this scenario\n internally using SWC. Setting target: 'es5' through esbuildOptions will\n result in an error.\n 2. Currently, we use enhanced-resolve internally to replace esbuild's resolve\n algorithm, so modifying esbuild resolve-related configurations is invalid.\n We plan to switch back in the future.\n\n\nexternalHelpers#\n\nBy default, the output JS code may depend on helper functions to support the\ntarget environment or output format, and these helper functions will be inlined\nin the file that requires it.\n\nWith this configuration, the code will be converted using SWC, it will inline\nhelper functions to import them from the external module @swc/helpers.\n\n * Type: boolean\n * Default: false\n\nBelow is a comparison of the output file changes before and after using this\nconfiguration.\n\nBefore enable:\n\n// helper function\nfunction asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {\n // ...\n}\n// helper function\nfunction _async_to_generator(fn) {\n return function () {\n // use asyncGeneratorStep\n // ...\n };\n}\n\n// your code\nexport var yourCode = function () {\n // use _async_to_generator\n};\n\n\nAfter enabled:\n\n// helper functions imported from @swc/helpers\n\n\n// your code\nexport var yourCode = function () {\n // use _async_to_generator\n};\n\n\n\nexternals#\n\nConfigure external dependencies that will not be bundled into the final bundle.\n\n * Type:\n\ntype External = (string | RegExp)[];\n\n\n * Default: []\n * Build Type: Only supported for buildType: 'bundle'\n * Example:\n\nexport default defineConfig({\n buildConfig: {\n // do not bundle React\n externals: ['react'],\n },\n});\n\n\n\nfooter#\n\nSame as the banner configuration for adding a comment at the end of the output\nfile.\n\n\nformat#\n\nUsed to set the output format of JavaScript files. The options iife and umd only\ntake effect when buildType is bundle.\n\n * Type: 'esm' | 'cjs' | 'iife' | 'umd'\n * Default: cjs\n\n\nformat: esm#\n\nesm stands for \"ECMAScript module\" and requires the runtime environment to\nsupport import and export syntax.\n\n * Example:\n\nexport default defineConfig({\n buildConfig: {\n format: 'esm',\n },\n});\n\n\n\nformat: cjs#\n\ncjs stands for \"CommonJS\" and requires the runtime environment to support\nexports, require, and module syntax. This format is commonly used in Node.js\nenvironments.\n\n * Example:\n\nexport default defineConfig({\n buildConfig: {\n format: 'cjs',\n },\n});\n\n\n\nformat: iife#\n\niife stands for \"immediately-invoked function expression\" and wraps the code in\na function expression to ensure that any variables in the code do not\naccidentally conflict with variables in the global scope. This format is\ncommonly used in browser environments.\n\n * Example:\n\nexport default defineConfig({\n buildConfig: {\n format: 'iife',\n },\n});\n\n\n\nformat: umd#\n\numd stands for \"Universal Module Definition\" and is used to run modules in\ndifferent environments such as browsers and Node.js. Modules in UMD format can\nbe used in various environments, either as global variables or loaded as modules\nusing module loaders like RequireJS.\n\n * Example:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n },\n});\n\n\n\nhooks#\n\nBuild lifecycle hooks that allow custom logic to be injected at specific stages\nof the build process.\n\n * Types:\n\ntype HookList = {\n name: string;\n apply: (compiler: ICompiler) => void.\n}\n\n\n\n * Default: [].\n\nWe can get the compiler instance in the apply method, modify its properties, and\nexecute custom logic at different stages. For more information on Hooks, see\n[Using Hooks to Intervene in the Build Process](see [Using Hooks to Intervene in\nthe Build Process]). For more information on Hooks, see\nUsing-hooks-to-intervene-in-the-build-process.\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundle',\n hooks: [\n {\n name: 'renderChunk',\n apply: compiler => {\n // any logic for compiler\n compiler.hooks.renderChunk.tapPromise(\n { name: 'renderChunk' },\n async chunk => {\n return chunk;\n },\n );\n },\n },\n ],\n },\n});\n\n\n\ninput#\n\nSpecify the entry file for the build, in the form of an array that can specify\nthe directory\n\n * Type:\n\ntype Input =\n | string[];\n | {\n [name: string]: string;\n }\n\n\n * Default: ['src/index.ts'] in bundle mode, ['src'] in bundleless mode\n\nArray usage:\n\nIn bundle mode, the following configurations will be built using src/index.ts\nand src/index2.ts as entry points. The bundle mode does not support configuring\ninput as a directory.\n\nexport default {\n buildConfig: {\n buildType: 'bundle',\n input: ['src/index.ts', 'src/index2.ts'],\n },\n};\n\n\nIn bundleless mode, the following configuration compiles both files in the src/a\ndirectory and src/index.ts file.\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundleless',\n input: ['src/a', 'src/index.ts'],\n },\n});\n\n\nIn bundleless mode, Array usage also supports the usage of ! to filter partial\nfiles:\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundleless',\n input: ['src', '!src/*.spec.ts'],\n },\n});\n\n\nThe above configuration will build the files in the src directory, and will also\nfilter files with the spec.ts suffix.This is useful in cases where the test\nfiles are in the same root directory as the source files.\n\nObject usage:\n\nWhen you need to modify the output file name in bundle mode, you can use an\nobject configuration.\n\nThe key of the object is the file name of the output, and the value is the file\npath of the source code.\n\nexport default defineConfig({\n buildConfig: {\n format: 'esm',\n input: {\n 'index.esm': './src/index.ts',\n },\n },\n});\n\n\n\njsx#\n\nSpecify the compilation method for JSX, which by default supports React 17 and\nhigher versions and automatically injects JSX runtime code.\n\n * Type: automatic | transform\n * Default: automatic\n\nIf you need to support React 16, you can set jsx to transform:\n\nexport default defineConfig({\n buildConfig: {\n jsx: 'transform',\n },\n});\n\n\nTIP\n\nIf you don't need to convert JSX, you can set jsx to preserve, but don't use swc\nto do the code conversion. For more information about JSX Transform, you can\nrefer to the following links:\n\n * React Blog - Introducing the New JSX Transform.\n * esbuild - JSX. :::\n\n\nmetafile#\n\nThis option is used for build analysis. When enabled, esbuild will generate\nmetadata about the build in JSON format.\n\n * Type: boolean\n * Default: false\n * Build Type: Only supported for buildType: 'bundle'\n\nTo enable metafile generation:\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundle',\n metafile: true,\n },\n});\n\n\nAfter executing the build, a metafile-[xxx].json file will be generated in the\noutput directory. You can use tools like esbuild analyze and bundle-buddy for\nvisual analysis.\n\n\nminify#\n\nUse esbuild or terser to compress code, also pass terserOptions\n\n * Type: 'terser' | 'esbuild' | false | object\n * Default: false\n\nexport default {\n buildConfig: {\n minify: {\n compress: {\n drop_console: true,\n },\n },\n },\n};\n\n\n\noutDir#\n\nSpecifies the output directory of the build.\n\n * Type: string\n * Default: ./dist\n\nexport default defineConfig({\n buildConfig: {\n outDir: './dist/esm',\n },\n});\n\n\n\nplatform#\n\nGenerates code for the node environment by default, you can also specify browser\nwhich will generate code for the browser environment\n\n * Type: 'browser' | 'node'\n * Default: 'node'\n\nexport default defineConfig({\n buildConfig: {\n platform: 'browser',\n },\n});\n\n\n\nredirect#\n\nIn buildType: 'bundleless' build mode, the reference path is redirected to\nensure that it points to the correct product, e.g:\n\n * import '. /index.less' will be rewritten to import '. /index.css'\n * would be rewritten as to `` (depending on the situation)\n\nIn some scenarios, you may not need these functions, then you can turn it off\nwith this configuration, and its reference path will not be changed after\nturning it off.\n\nexport default {\n buildConfig: {\n redirect: {\n alias: false, // Turn off modifying alias paths\n style: false, // Turn off modifying the path to the style file\n asset: false, // Turn off modifying the path to the asset\n },\n },\n};\n\n\n\nresolve#\n\nCustom module resolution options\n\n\nresolve.mainFields#\n\nA list of fields in package.json to try when parsing the package entry point.\n\n * Type: string[]\n * Default: depends on platform\n * node: ['module', 'main']\n * browser: ['module', 'browser', 'main']\n * Version: v2.36.0\n\nFor example, we want to load the js:source field first:\n\nexport default defineConfig({\n buildConfig: {\n resolve: {\n mainFields: ['js:source', 'module', 'main'],\n },\n },\n});\n\n\n:::warning resolve.mainFields has a lower priority than the exports field in\npackage.json, and if an entry point is successfully resolved from exports,\nresolve.mainFields will be ignored.\n\n\nresolve.jsExtentions#\n\nSupport for implicit file extensions\n\n * Type: string[]\n * Default: ['.jsx', '.tsx', '.js', '.ts', '.json']\n * Version: v2.36.0\n\nDo not use implicit file extensions for css files, currently Module only\nsupports ['.less', '.css', '.sass', '.scss'] suffixes.\n\nNode's parsing algorithm does not consider .mjs and cjs as implicit file\nextensions, so they are not included here by default, but can be included by\nchanging this configuration:\n\nexport default defineConfig({\n buildConfig: {\n resolve: {\n jsExtentions: ['.mts', 'ts'],\n },\n },\n});\n\n\n\nsideEffects#\n\nModule sideEffects\n\n * Type: RegExg[] | (filePath: string, isExternal: boolean) => boolean | boolean\n * Default: undefined\n\nNormally, we configure the module's side effects via the sideEffects field in\npackage.json, but in some cases, The package.json of a third-party package is\nunreliable.Such as when we reference a third-party package style file\n\nimport 'other-package/dist/index.css';\n\n\nBut the package.json of this third-party package does not have the style file\nconfigured in the sideEffects\n\n{\n \"sideEffects\": [\"dist/index.js\"]\n}\n\n\nAt the same time you set style.inject to true and you will see a warning message\nlike this in the console\n\n[LIBUILD:ESBUILD_WARN] Ignoring this import because \"other-package/dist/index.css\" was marked as having no side effects\n\n\nAt this point, you can use this configuration option to manually configure the\nmodule's \"sideEffects\" to support regular and functional forms.\n\nexport default defineConfig({\n buildConfig: {\n sideEffects: [/\\.css$/],\n // or\n // sideEffects: (filePath, isExternal) => /\\.css$/.test(filePath),\n },\n});\n\n\nTIP\n\nAfter adding this configuration, the sideEffects field in package.json will no\nlonger be read when packaging\n\n\nsourceDir#\n\nSpecify the source directory of the build, default is src, which is used to\ngenerate the corresponding output directory based on the source directory\nstructure when building bundleless.\n\n * Type: string\n * Default: src\n\n\nsourceMap#\n\nWhether to generate sourceMap or not\n\n * Type: boolean | 'inline' | 'external'\n * Default: false\n\n\nsourceType#\n\nSets the format of the source code. By default, the source code will be treated\nas EsModule. When the source code is using CommonJS, you need to set commonjs.\n\n * Type: 'commonjs' | 'module'\n * Default: 'module'\n\n\nsplitting#\n\nWhether to enable code splitting\n\n * Type: boolean\n * Default: false\n\n\nstyle#\n\nConfigure style-related configuration\n\n\nstyle.less#\n\nless-related configuration\n\n\nstyle.less.lessOptions#\n\nRefer to less for detailed configuration\n\n * Type: object\n * Default: { javascriptEnabled: true }\n\n\nstyle.less.additionalData#\n\nAdd Less code to the beginning of the entry file.\n\n * Type: string\n * Default: undefined\n\nexport default {\n buildConfig: {\n style: {\n less: {\n additionalData: `@base-color: #c6538c;`,\n },\n },\n },\n};\n\n\n\nstyle.less.implementation#\n\nConfigure the implementation library used by Less, if not specified, the\nbuilt-in version used is 4.1.3.\n\n * Type: string | object\n * Default: undefined\n\nSpecify the implementation library for Less when the object type is specified.\n\nexport default {\n buildConfig: {\n style: {\n less: {\n implementation: require('less'),\n },\n },\n },\n};\n\n\nFor the string type, specify the path to the implementation library for Less\n\nexport default {\n buildConfig: {\n style: {\n less: {\n implementation: require.resolve('less'),\n },\n },\n },\n};\n\n\n\nstyle.sass#\n\nsass-related configuration.\n\n\nstyle.sass.sassOptions#\n\nRefer to node-sass for detailed configuration.\n\n * Type: object\n * Default: {}\n\n\nstyle.sass.additionalData#\n\nAdd Sass code to the beginning of the entry file.\n\n * Type: string | Function\n * Default: undefined\n\nexport default {\n buildConfig: {\n style: {\n sass: {\n additionalData: `$base-color: #c6538c;\n $border-dark: rgba($base-color, 0.88);`,\n },\n },\n },\n};\n\n\n\nstyle.sass.implementation#\n\nConfigure the implementation library used by Sass, the built-in version used is\n1.5.4 if not specified.\n\n * Type: string | object\n * Default: undefined\n\nSpecify the implementation library for Sass when the object type is specified.\n\nexport default {\n buildConfig: {\n style: {\n sass: {\n implementation: require('sass'),\n },\n },\n },\n};\n\n\nFor the string type, specify the path to the Sass implementation library\n\nexport default {\n buildConfig: {\n style: {\n sass: {\n implementation: require.resolve('sass'),\n },\n },\n },\n};\n\n\n\nstyle.postcss#\n\nUsed to configure options for PostCSS. The provided values will be merged with\nthe default configuration using Object.assign. Note that Object.assign performs\na shallow copy, so it will completely override the built-in plugins array.\n\nFor detailed configuration, please refer to PostCSS.\n\n * Type:\n\ntype PostcssOptions = {\n processOptions?: ProcessOptions;\n plugins?: AcceptedPlugin[];\n};\n\n\n * Default:\n\nconst defaultConfig = {\n plugins: [\n // The following plugins are enabled by default\n require('postcss-flexbugs-fixes'),\n require('postcss-media-minmax'),\n require('postcss-nesting'),\n // The following plugins are only enabled when the target is `es5`\n require('postcss-custom-properties'),\n require('postcss-initial'),\n require('postcss-page-break'),\n require('postcss-font-variant'),\n ],\n};\n\n\n * Example:\n\nexport default defineConfig({\n buildConfig: {\n style: {\n postcss: {\n plugins: [yourPostCSSPlugin],\n },\n },\n },\n});\n\n\n\nstyle.inject#\n\nConfigure whether to insert CSS styles into JavaScript code in bundle mode.\n\n * Type: boolean\n * Default: false\n\nSet inject to true to enable this feature:\n\nexport default defineConfig({\n buildConfig: {\n inject: true,\n },\n});\n\n\nOnce enabled, you will see the CSS code referenced in the source code included\nin the bundled JavaScript output.\n\nFor example, if you write import './index.scss' in the source code, you will see\nthe following code in the output:\n\n// node_modules/style-inject/dist/style-inject.es.js\nfunction styleInject(css, ref) {\n // ...\n}\nvar style_inject_es_default = styleInject;\n\n// src/index.scss\nvar css_248z = '.body {\\n color: black;\\n}';\nstyle_inject_es_default(css_248z);\n\n\nTIP\n\nAfter enabling inject, you need to pay attention to the following points:\n\n * @import in CSS files will not be processed. If your CSS file contains\n @import, you need to manually import the CSS file in the JS file (less and\n scss files are not required because they have preprocessing).\n * Consider the impact of sideEffects. By default, our builder assumes that CSS\n has side effects. If the sideEffects field is set in your project or\n third-party package's package.json and does not include this CSS file, you\n will receive a warning:\n\n[LIBUILD:ESBUILD_WARN] Ignoring this import because \"src/index.scss\" was marked as having no side effects by plugin \"libuild:adapter\"\n\n\nYou can resolve this by configuring sideEffects.\n\n\nstyle.autoModules#\n\nEnable CSS Modules automatically based on the filename.\n\n * Type: boolean | RegExp\n * Default: true\n\ntrue : Enables CSS Modules for style files ending with .module.css .module.less\n.module.scss .module.sass filenames\n\nfalse : Disable CSS Modules.\n\nRegExp : Enables CSS Modules for all files that match the regular condition.\n\n\nstyle.modules#\n\nCSS Modules configuration\n\n * Type: object\n * Default: {}\n\nA common configuration is localsConvention, which changes the class name\ngeneration rules for css modules\n\nexport default {\n buildConfig: {\n style: {\n modules: {\n localsConvention: 'camelCaseOnly',\n },\n },\n },\n};\n\n\nFor the following styles\n\n.box-title {\n color: red;\n}\n\n\nYou can use styles.boxTitle to access\n\nFor detailed configuration see postcss-modules\n\n\nstyle.tailwindcss#\n\nUsed to modify the configuration of Tailwind CSS.\n\n * Type: object | Function\n * Default:\n\nconst tailwind = {\n content: [\n './src/**/*.{js,jsx,ts,tsx}',\n './config/html/**/*.{html,ejs,hbs}',\n './storybook/**/*',\n ],\n};\n\n\n\nEnabling Tailwind CSS#\n\nBefore using style.tailwindcss, you need to enable the Tailwind CSS plugin for\nModern.js Module.\n\nPlease refer to the section Using Tailwind CSS for instructions on how to enable\nit.\n\n\nType#\n\nWhen the value is of type object, it is merged with the default configuration\nvia Object.assign.\n\nWhen the value is of type Function, the object returned by the function is\nmerged with the default configuration via Object.assign.\n\nThe rest of the usage is the same as Tailwind CSS: Quick Portal.\n\n\nNotes#\n\nPlease note that:\n\n * If you are using both the tailwind.config.{ts,js} file and tools.tailwindcss\n option, the configuration defined in tools.tailwindcss will take precedence\n and override the content defined in tailwind.config.{ts,js}.\n * If you are using the designSystem configuration option simultaneously, the\n theme configuration of Tailwind CSS will be overridden by the value of\n designSystem.\n\nThe usage of other configurations follows the same approach as the official\nusage of Tailwind CSS. Please refer to tailwindcss - Configuration for more\ndetails.\n\n\ntarget#\n\ntarget is used to set the target environment for the generated JavaScript code.\nIt enables Modern.js Module to transform JavaScript syntax that is not\nrecognized by the target environment into older versions of JavaScript syntax\nthat are compatible with these environments.\n\n * Type:\n\ntype Target =\n | 'es5'\n | 'es6'\n | 'es2015'\n | 'es2016'\n | 'es2017'\n | 'es2018'\n | 'es2019'\n | 'es2020'\n | 'es2021'\n | 'es2022'\n | 'esnext';\n\n\n * Default: 'es6'\n\nFor example, compile the code to es5 syntax:\n\nexport default defineConfig({\n buildConfig: {\n target: 'es5',\n },\n});\n\n\n\ntransformImport#\n\nUsing SWC provides the same ability and configuration as babel-plugin-import.\nWith this configuration, the code will be converted using SWC.\n\n * Type: object[]\n * Default: []\n\nThe elements of the array are configuration objects for babel-plugin-import,\nwhich can be referred to options。\n\nExample:\n\nexport default defineConfig({\n buildConfig: {\n transformImport: [\n // babel-plugin-import`s options config\n {\n libraryName: 'foo',\n style: true,\n },\n ],\n },\n});\n\n\nReference the Import Plugin - Notes\n\n\ntransformLodash#\n\nSpecifies whether to modularize the import of lodash and remove unused lodash\nmodules to reduce the code size of lodash.\n\nThis optimization is implemented using babel-plugin-lodash and swc-plugin-lodash\nunder the hood.\n\nWith this configuration, the code will be converted using SWC.\n\n * Type: boolean\n * Default: false\n\nWhen you enable this, Modern.js Module will automatically redirects the code\nreferences of lodash to sub-paths.\n\nFor example:\n\n\n\n\nconst addOne = add(1);\n_.map([1, 2, 3], addOne);\n\n\nThe transformed code will be:\n\n\n\n\nconst addOne = _add(1);\n_map([1, 2, 3], addOne);\n\n\n\ntsconfig#\n\nPath to the tsconfig file\n\n * Type: string\n * Default: tsconfig.json\n * Version: v2.36.0\n\nexport default defineConfig({\n buildConfig: {\n tsconfig: 'tsconfig.build.json',\n },\n});\n\n\n\numdGlobals#\n\nSpecify global variables for external import of umd artifacts\n\n * Type: Record\n * Default: {}\n\nexport default {\n buildConfig: {\n umdGlobals: {\n react: 'React',\n 'react-dom': 'ReactDOM',\n },\n },\n};\n\n\nAt this point, react and react-dom will be seen as global variables imported\nexternally and will not be packed into the umd product, but will be accessible\nby way of global.React and global.ReactDOM\n\n\numdModuleName#\n\nSpecifies the module name of the umd product\n\n * Type: string | Function\n * Default: name => name\n\nexport default {\n buildConfig: {\n format: 'umd',\n umdModuleName: 'myLib',\n },\n};\n\n\nAt this point the umd artifact will go to mount on global.myLib\n\n:::tip\n\n * The module name of the umd artifact must not conflict with the global\n variable name.\n * Module names will be converted to camelCase, e.g. my-lib will be converted to\n myLib, refer to toIdentifier. :::\n\nAlso the function form can take one parameter, which is the output path of the\ncurrent package file\n\nexport default {\n buildConfig: {\n format: 'umd',\n umdModuleName: path => {\n if (path.includes('index')) {\n return 'myLib';\n } else {\n return 'myLib2';\n }\n },\n },\n};\n","frontmatter":{"sidebar_position":1},"version":""},{"id":1,"title":"buildPreset","routePath":"/module-tools/en/api/config/build-preset","lang":"en","toc":[{"text":"npm-library","id":"npm-library","depth":3,"charIndex":118},{"text":"npm-library-with-umd","id":"npm-library-with-umd","depth":3,"charIndex":827},{"text":"npm-component","id":"npm-component","depth":3,"charIndex":1685},{"text":"npm-component-with-umd","id":"npm-component-with-umd","depth":3,"charIndex":2617},{"text":"npm-library-{es5...esnext}","id":"npm-library-es5esnext","depth":3,"charIndex":3476},{"text":"string / function","id":"string--function","depth":2,"charIndex":3911}],"domain":"","content":"#\n\nA build preset string or preset function. Provides out-of-the-box build\nconfiguration\n\n * Type: string | Function\n\n\nnpm-library#\n\nLibrary generic schema used under class NPM package manager, contains esm and\ncjs Bundle products, and includes a type file.\n\nINFO\n\nAbout the class NPM Package Manager\n\n * npm\n * yarn\n * pnpm\n\n{\n \"main\": \". /dist/lib/index.js\",\n \"module\": \". /dist/es/index.js\",\n \"types\": \". /dist/types/index.d.ts\"\n}\n\n\nThe build configuration corresponding to the preset string.\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/es',\n },\n {\n buildType: 'bundle',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-library-with-umd#\n\nUsed under class NPM package manager, and Library supports a similar pattern to\nunpkg. Additional umd artifacts are provided on top of the pre-defined\nnpm-library.\n\n{\n \"main\": \". /dist/lib/index.js\",\n \"module\": \". /dist/es/index.js\",\n \"types\": \". /dist/types/index.d.ts\",\n \"unpkg\": \". /dist/umd/index.js\",\n};\n\n\nThe build configuration corresponding to the preset string.\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/es',\n },\n {\n format: 'umd',\n target: 'es6',\n platform: 'browser',\n buildType: 'bundle',\n outDir: './dist/umd',\n },\n {\n buildType: 'bundle',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-component#\n\nA generic pattern for components (libraries) used under the class NPM package\nmanager. Contains both esm and cjs Bundleless artifacts (for easy Tree shaking\noptimization), as well as including a copy of the type file.\n\nFor style files included in the source code, the artifacts provide the compiled\nfiles of the style and the source file of the style.\n\n{\n \"main\": \". /dist/lib/index.js\", // bundleless type\n \"module\": \". /dist/es/index.js\", // bundleless type\n \"types\": \". /dist/types/index.d.ts\",\n};\n\n\nThe pre-defined strings correspond to the build configuration.\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/es',\n },\n {\n buildType: 'bundleless',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-component-with-umd#\n\nComponent (library) used under class NPM package manager, with support for class\nunpkg schema. Additional umd artifacts are provided on top of the pre-defined\nnpm-component.\n\n{\n \"main\": \". /dist/lib/index.js\", // bundleless type\n \"module\": \". /dist/es/index.js\", // bundleless type\n \"types\": \". /dist/types/index.d.ts\",\n \"unpkg\": \". /dist/umd/index.js\",\n};\n\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/es',\n },\n {\n format: 'umd',\n target: 'es6',\n platform: 'browser',\n buildType: 'bundle',\n outDir: './dist/umd',\n },\n {\n buildType: 'bundleless',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-library-{es5...esnext}#\n\nWhen you want to use a buildPreset preset that supports other ECMAScript\nversions, you can directly add the supported versions to the 'npm-library',\n'npm-library-with-umd', 'npm-component', 'npm-component-with-umd' presets.\n\nFor example, if you want the 'npm-library' preset to support 'es2017', you can\nconfigure it as follows.\n\n\n\nexport default defineConfig({\n buildPreset: 'npm-library-es2017',\n});\n\n\n\nstring / function#\n\nThe buildPreset not only supports basic string forms, but also function forms,\nwhich can obtain the default values we provide through the preset or extend\nPreset parameter and then modify them.\n\nHere are two examples using preset and extend Preset:\n\n\n\nexport default defineConfig({\n buildPreset({ preset }) {\n const { NPM_LIBRARY } = preset;\n return NPM_LIBRARY.map(config => {\n config.define = {\n VERSION: '1.0.1',\n };\n return config;\n });\n },\n});\n\n\nIn the extend Preset, lodash.merge is used for configuration merge.\n\n\n\nexport default defineConfig({\n buildPreset({ extendPreset }) {\n return extendPreset('npm-library', {\n define: {\n VERSION: '1.0.1',\n },\n });\n },\n});\n","frontmatter":{"sidebar_position":2},"version":""},{"id":2,"title":"dev","routePath":"/module-tools/en/api/config/dev","lang":"en","toc":[{"text":"storybook","id":"storybook","depth":2,"charIndex":182},{"text":"storybook.webpack","id":"storybookwebpack","depth":3,"charIndex":440},{"text":"Configure Manager App","id":"configure-manager-app","depth":4,"charIndex":821},{"text":"storybook.webpackChain","id":"storybookwebpackchain","depth":3,"charIndex":1194}],"domain":"","content":"#\n\nThis section describes all configuration of Modern.js Module related to\ndebugging tools.\n\nexport default {\n dev: {\n storybook: {\n /* Storybook Config */\n },\n },\n};\n\n\n\nstorybook#\n\nRequirements:\n\n * Turn on Storybook debugging or install the @modern-js/plugin-storybook\n plugin.\n * Register the @modern-js/plugin-storybook plugin。\n\n> For more information on how to enable Storybook debugging, please refer\n> to:\"Storybook\"\n\n\nstorybook.webpack#\n\n * Type: object | Function | undefined\n * Default: undefined\n\nexport default {\n dev: {\n storybook: {\n webpack(config) {\n return config;\n },\n },\n },\n};\n\n\nYou can modify the webpack configuration of the Storybook Preview-iframe via\ndev.storybook.webpack. The usage can be found in the tools.webpack configuration\nof Modern.js Builder.\n\n\n\nConfigure Manager App#\n\nFor the webpack configuration of the Storybook Manager app section, you can\nconfigure it by adding the ./config/storybook/main.js file to configure it.\n\n// ./config/storybook/main.js\n\nmodule.exports = {\n // it controls the Storybook manager app\n managerWebpack: async (config, options) => {\n // update config here\n return config;\n },\n};\n\n\n\nstorybook.webpackChain#\n\n * Type: Function | undefined\n * Default: undefined\n\nexport default {\n dev: {\n storybook: {\n webpackChain(chain) {\n return chain;\n },\n },\n },\n};\n\n\nYou can modify the webpack configuration of the Storybook Preview-iframe via\ndev.storybook.webpackChain. You can refer to Modern.js Builder's\ntools.webpackChain configuration for how to use it.","frontmatter":{"sidebar_position":3},"version":""},{"id":3,"title":"plugins","routePath":"/module-tools/en/api/config/plugins","lang":"en","toc":[{"text":"Plugin Execution Order","id":"plugin-execution-order","depth":2,"charIndex":140},{"text":"Developing Plugins","id":"developing-plugins","depth":2,"charIndex":584},{"text":"Example","id":"example","depth":2,"charIndex":680},{"text":"Using Plugins from npm","id":"using-plugins-from-npm","depth":3,"charIndex":691},{"text":"Using Local Plugins","id":"using-local-plugins","depth":4,"charIndex":898},{"text":"Plugin Configuration","id":"plugin-configuration","depth":3,"charIndex":1082}],"domain":"","content":"#\n\nThis chapter describes the configuration of the registered Modern.js Module\nplugin.\n\n * Type: ModuleToolsPlugin[]\n * Default: undefined\n\n\nPlugin Execution Order#\n\nBy default, custom plugins are executed in the order specified in the plugins\narray. The execution of built-in plugins provided by Modern.js Module happens\nbefore the execution of custom plugins.\n\nWhen plugins use fields that control the execution order, such as pre and post,\nthe execution order is adjusted based on the declared fields. For more\ninformation, please refer to the Relationship Between Plugins guide.\n\n\nDeveloping Plugins#\n\nTo learn how to write plugins, please refer to the Plugin Writing Guide.\n\n\nExample#\n\n\nUsing Plugins from npm#\n\nTo use plugins from npm, you need to install them using a package manager and\nimport them in your configuration file.\n\n\n\nexport default defineConfig({\n plugins: [myPlugin()],\n});\n\n\nUsing Local Plugins#\n\nTo use plugins from a local code repository, you can directly import them using\na relative path.\n\n\n\nexport default defineConfig({\n plugins: [myPlugin()],\n});\n\n\n\nPlugin Configuration#\n\nIf a plugin provides custom configuration options, you can pass the\nconfiguration through the plugin function's parameters.\n\n\n\nexport default defineConfig({\n plugins: [\n myPlugin({\n foo: 1,\n bar: 2,\n }),\n ],\n});\n","frontmatter":{"sidebar_position":4},"version":""},{"id":4,"title":"testing","routePath":"/module-tools/en/api/config/testing","lang":"en","toc":[{"text":"jest","id":"jest","depth":2,"charIndex":133},{"text":"transformer","id":"transformer","depth":2,"charIndex":736}],"domain":"","content":"#\n\nThis chapter describes the test-related configuration\n\nTIP\n\nYou need to enable the unit testing feature with pnpm run new first.\n\n\njest#\n\n * Type: object | Function\n * Default: {}\n\nThe configuration corresponding to Jest, when of type object, can be configured\nwith all the underlying configurations supported by Jest .\n\n\n\nexport default defineConfig({\n testing: {\n jest: {\n testTimeout: 10000,\n },\n },\n});\n\n\nWhen the value is of type Function, the default configuration is passed as the\nfirst parameter and a new Jest configuration object needs to be returned.\n\n\n\nexport default defineConfig({\n testing: {\n jest: options => {\n return {\n ... . options,\n testTimeout: 10000\n }\n }\n }\n});\n\n\n\ntransformer#\n\n * Type: 'babel-jest' | 'ts-jest'\n * Default: 'babel-jest'\n\nConfigure the compilation tool for the source code when executing tests:\nbabel-jest or ts-jest. The default is babel-jest.\n\nINFO\n\nbabel-jest can also compile TS files without type errors, so use ts-jest if you\nneed to check the TS type when running tests.","frontmatter":{"sidebar_position":5},"version":""},{"id":5,"title":"Overview","routePath":"/module-tools/en/api/","lang":"en","toc":[],"domain":"","content":"#","frontmatter":{"overview":true,"sidebar_label":"Overview","sidebar_position":1},"version":""},{"id":6,"title":"Plugin Hooks","routePath":"/module-tools/en/api/plugin-api/plugin-hooks","lang":"en","toc":[{"text":"build hooks","id":"build-hooks","depth":2,"charIndex":424},{"text":"beforeBuild","id":"beforebuild","depth":3,"charIndex":586},{"text":"beforeBuildTask","id":"beforebuildtask","depth":3,"charIndex":1223},{"text":"afterBuildTask","id":"afterbuildtask","depth":3,"charIndex":1699},{"text":"afterBuild","id":"afterbuild","depth":3,"charIndex":2103},{"text":"buildPlatform hooks","id":"buildplatform-hooks","depth":2,"charIndex":2558},{"text":"registerBuildPlatform","id":"registerbuildplatform","depth":3,"charIndex":3057},{"text":"beforeBuildPlatform","id":"beforebuildplatform","depth":3,"charIndex":3779},{"text":"buildPlatform","id":"buildplatform","depth":3,"charIndex":4503},{"text":"afterBuildPlatform","id":"afterbuildplatform","depth":3,"charIndex":4998},{"text":"Dev Hooks","id":"dev-hooks","depth":2,"charIndex":5702},{"text":"registerDev.","id":"registerdev","depth":3,"charIndex":6177},{"text":"beforeDev","id":"beforedev","depth":3,"charIndex":7287},{"text":"(before|after)DevMenu","id":"beforeafterdevmenu","depth":3,"charIndex":7889},{"text":"beforeDevTask","id":"beforedevtask","depth":3,"charIndex":9070},{"text":"afterDev","id":"afterdev","depth":3,"charIndex":9640}],"domain":"","content":"#\n\nThis chapter describes the lifecycle hooks supported by module-tools.\n\nCurrently there are two main types of lifecycle hooks.\n\n * Build hooks: triggered only when the build command is executed to build the\n source code product.\n * buildPlatform hook: triggered only when the build --platform command is\n executed to generate other build products.\n * dev hooks: hooks that are triggered when running the dev command.\n\n\nbuild hooks#\n\nThe following Hooks are triggered in order when the build command is executed.\n\n * beforeBuild\n * beforeBuildTask\n * afterBuildTask\n * afterBuild\n\n\nbeforeBuild#\n\nTriggered before the execution of the overall build process.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuild(options: Options): Return {\n return options.config;\n }\n }\n },\n});\n\n\nParameters and return value types.\n\ntype Options = { options: { config: BuildConfig; cliOptions: BuildCommandOptions } }\n\nexport interface BuildCommandOptions {\n config: string;\n clear?: boolean;\n dts?: boolean;\n platform?: boolean | string[];\n tsconfig: string;\n watch?: boolean;\n}\n\ntype Return = BuildConfig;\n\n\n> BuildConfig type reference API configuration\n\n\nbeforeBuildTask#\n\nBased on the build configuration, Modern.js Module will split the overall build\ninto multiple sub-build tasks. The Hook will be triggered before each build\nsubtask.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuildTask(config: BaseBuildConfig): BaseBuildConfig {\n return config;\n }\n }\n },\n});\n\n\nParameters and return value types.\n\nBaseBuildConfig type reference API configuration\n\n\nafterBuildTask#\n\nTriggered after the end of each build subtask.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuildTask(options: BuildTaskResult): void {\n // ...\n }\n }\n },\n});\n\n\nParameters and return value types.\n\nexport interface BuildTaskResult {\n status: 'success' | 'fail';\n message?: string;\n config: BaseBuildConfig;\n}\n\n\n\nafterBuild#\n\nTriggered after the end of the overall build process.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuild(options: BuildResult): void {\n // ...\n }\n }\n },\n});\n\n\nParameters and return value types.\n\nexport interface BuildResult {\n status: 'success' | 'fail';\n message?: string;\n config: BuildConfig;\n commandOptions: BuildCommandOptions;\n totalDuration: number;\n}\n\n\n\nbuildPlatform hooks#\n\nmodule-tools also provides the build --platform command to perform specific\nbuild tasks.\n\nFor example, after installing the Storybook plugin, you can run build --platform\nor build --platform storybook to perform Storybook build tasks. This is because\nthe Storybook plugin is based on the buildPlatform Hooks.\n\nHooks are triggered in the following order after executing build --platform.\n\n * registerBuildPlatform\n * beforeBuildPlatform\n * buildPlatform\n * afterBuildPlatform\n\n\nregisterBuildPlatform#\n\nGets information about the tasks that need to be run when executing the build\n--platform command.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n registerBuildPlatform(): RegisterBuildPlatformResult {\n // ...\n return {\n platform: 'stroybook',\n build() {\n // run storybook logic\n },\n }, };\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface RegisterBuildPlatformResult {\n platform: string | string[];\n build: (\n currentPlatform: string, // the currently running platform build task\n context: { isTsProject: boolean },\n ) => void | Promise;\n}\n\n\n\nbeforeBuildPlatform#\n\nTriggers all registered build tasks when the build --platform command is\nexecuted. beforeBuildPlatform will be triggered before the execution of the\noverall build task.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuildPlatform(platforms: RegisterBuildPlatformResult[]): void {\n console.info(`have ${platforms.length} platform tasks`);\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface RegisterBuildPlatformResult {\n platform: string | string[];\n build: (\n currentPlatform: string, // the currently running platform build task\n context: { isTsProject: boolean },\n ) => void | Promise;\n}\n\n\n\nbuildPlatform#\n\nWhen the build --platform command is executed, all registered build tasks will\nbe triggered. buildPlatform will be triggered before each build task is\nexecuted.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n buildPlatform({ platform }: Options): void {\n console.info(`current task is ${platform}`);\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface Options {\n platform: string;\n}\n\n\n\nafterBuildPlatform#\n\nWhen the build --platform command is executed, all registered build tasks will\nbe triggered. afterBuildPlatform will be triggered after the overall platform\nbuild task is finished.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuildPlatform(result: BuildPlatformResult): void {\n if (result.status === 'success') {\n console.info(`all platform build task success`);\n } else {\n console.error(result.message);\n }\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface BuildPlatformResult {\n status: 'success' | 'fail';\n message: string | Error | null;\n}\n\n\n\nDev Hooks#\n\nThe following Hooks are triggered in order when the dev command is executed.\n\n * registerDev: triggered when getting dev function information.\n * beforeDev: Triggered before starting the dev process as a whole.\n * beforeDevMenu: triggered before the dev list/menu appears.\n * afterDevMenu: triggered after dev list/menu option is selected.\n * beforeDevTask: Triggered before executing the dev task.\n * afterDev: Triggered at the end of the overall dev process.\n\n\nregisterDev.#\n\nRegister dev tool related data. Mainly contains.\n\n * the name of the dev tool\n * The name of the item displayed in the menu list and the corresponding value.\n * The definition of the dev subcommand.\n * Whether to execute the source code build before running the dev task\n * The function to execute the dev task.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n registerDev() {\n return {\n // Dev tool name\n name: 'storybook',\n // Menu content\n menuItem: {\n name: 'Storybook',\n value: 'storybook',\n },\n // Defined dev subcommands\n subCommands: ['storybook', 'story'],\n async action() {\n // dev logic\n },\n };\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\nbeforeDev#\n\nTriggered before the dev task is executed after all dev tool metadata has been\ncollected.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDev(metas: DevToolData[]) {\n console.info(`have ${metas.length} dev tools`);\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\n(before|after)DevMenu#\n\nbeforeDevMenu is triggered before the dev list/menu appears. Receives inquirer\nquestion as argument. Default value is.\n\nconst question = [\n {\n name: 'choiceDevTool',\n message: 'Select dev tool',\n type: 'list',\n // Registered dev messages\n choices,\n },\n];\n\n\nafterDevMenu Triggered after selecting dev list/menu options.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDevMenu(questions) {\n questions[0].message += '!' ;\n return questions; // required\n },\n afterDevMenu(options: Options) {\n console.info(`choise ${options.result.choiceDevTool} dev tools`);\n }\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport type { QuestionCollection } from 'inquirer';\n\nexport interface Options {\n result: PromptResult;\n devTools: DevToolData[];\n}\n\nexport type PromptResult = { choiceDevTool: string }\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\nbeforeDevTask#\n\nTriggered before the dev task is executed.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDevTask(currentDevData: DevToolData) {\n console.info(`${currentDevData.name} running`);\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\nafterDev#\n\nTriggered when the dev task process is interrupted.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterDev() {\n console.info(`exit!`);\n },\n };\n },\n});\n","frontmatter":{},"version":""},{"id":7,"title":"","routePath":"/module-tools/en/components/faq-build-exception","lang":"en","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":8,"title":"","routePath":"/module-tools/en/components/faq-build-other","lang":"en","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":9,"title":"","routePath":"/module-tools/en/components/faq-build-product","lang":"en","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":10,"title":"","routePath":"/module-tools/en/components/faq-storybook","lang":"en","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":11,"title":"","routePath":"/module-tools/en/components/faq-test","lang":"en","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":12,"title":"","routePath":"/module-tools/en/components/register-esbuild-plugin","lang":"en","toc":[],"domain":"","content":"\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.plugins = [myEsbuildPlugin, ...options.plugins];\n return options;\n },\n },\n});\n\n\nWhen adding an esbuild plugin, please note that you need to add the plugin at\nthe beginning of the plugins array. This is because the Modern.js Module is also\nintegrated into the entire build process through an esbuild plugin. Therefore,\ncustom plugins need to be registered with higher priority.","frontmatter":{},"version":""},{"id":13,"title":"Handle static assets","routePath":"/module-tools/en/guide/advance/asset","lang":"en","toc":[{"text":"Default behavior","id":"default-behavior","depth":2,"charIndex":139},{"text":"Example","id":"example","depth":2,"charIndex":571}],"domain":"","content":"#\n\nModern.js Module will handle static assets used in the code. If configuration is\nrequired, then the buildConfig.asset API can be used.\n\n\nDefault behavior#\n\nBy default, Modern.js Module handles the following static assets:\n\n * '.svg'、'.png'、'.jpg'、'.jpeg'、'.gif'、'.webp'\n * '.ttf'、'.otf'、'.woff'、'.woff2'、'.eot'\n * '.mp3'、'.mp4'、'.webm'、'.ogg'、'.wav'、'.flac'、'.aac'、'.mov'\n\nFor the handling of static files, Modern.js Module currently supports the\nfollowing functions.\n\n * Set the static asset path to . /assets.\n * Files less than 10kb will be inlined into the code.\n\n\nExample#\n\nLet us look at the following example:\n\n * Project source code:\n\n\n//...\n\n\n * If the size of bg.png is less than 10 kb, then the output directory structure\n and file content are.\n\n./dist\n└── asset.js\n\n\nvar bg_default = 'data:image/png;base64,';\nconsole.info(bg_default);\n\n\n * If the size of bg.png is larger than 10 kb, then the output directory\n structure and file content are.\n\n./dist\n├── asset.js\n└── assets\n └── bg.13e2aba2.png\n\n\n\nconsole.info(img);\n\n\nWhen wanting to modify the default behavior, the following API can be used:\n\n * asset.path: modify the output path of the static assets.\n * asset.limit: modify the threshold value for inline assets.","frontmatter":{"sidebar_position":6},"version":""},{"id":14,"title":"Build umd artifacts","routePath":"/module-tools/en/guide/advance/build-umd","lang":"en","toc":[{"text":"Third-party dependency handling for umd artifacts","id":"third-party-dependency-handling-for-umd-artifacts","depth":2,"charIndex":487},{"text":"Example","id":"example","depth":3,"charIndex":791},{"text":"Global variable names of third-party dependencies","id":"global-variable-names-of-third-party-dependencies","depth":3,"charIndex":2178},{"text":"Changing the name of a global variable in a project","id":"changing-the-name-of-a-global-variable-in-a-project","depth":2,"charIndex":3607}],"domain":"","content":"#\n\nThe full name of umd is Universal Module Definition, and JS files in this format\ncan run in multiple runtime environments: the\n\n * Browser environment: module loading based on AMD specification\n * Node.js environment: module loading based on CommonJS\n * Other cases: mount the module on a global object.\n\nWe can therefore specify the build artifacts of the project as an umd artifact\nin the following way:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n },\n});\n\n\n\nThird-party dependency handling for umd artifacts#\n\nIn the \"How to handle third-party dependencies\" chapter, we know that we can\ncontrol whether or not the project packages third-party dependencies via the\nautoExternals and externals APIs. So when building umd artifacts, we can also\nuse it like this:\n\n\nExample#\n\n * If the project depends on react:\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n * modern.config.ts:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n autoExternal: false,\n externals: ['react'],\n },\n});\n\n\n * When a react dependency is used in the source code:\n\n\nconsole.info(React);\n\n\n * The react code is not bundled into the artifact at this point:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports, require('react'));\n else if (typeof define === 'function' && define.amd)\n define(['exports', 'react'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.index = {}), global.react);\n})(this, function (exports, _react) {\n 'use strict';\n Object.defineProperty(exports, '__esModule', {\n value: true,\n });\n _react = /*#__PURE__*/ _interopRequireDefault(_react);\n function _interopRequireDefault(obj) {\n return obj && obj.__esModule\n ? obj\n : {\n default: obj,\n };\n }\n console.info(_react.default);\n});\n\n\nWe know from the above example that when using the autoExternal and externals\nAPIs.\n\n * In a Node.js environment, you can get the react dependency with\n require('react').\n * In a browser environment, you can get the react dependency via global.react.\n\n\nGlobal variable names of third-party dependencies#\n\nHowever, in the browser environment, when getting third-party dependencies,\nglobal variable names are not necessarily identical to the dependency names, so\nyou have to use the buildConfig.umdGlobals API.\n\nAgain using the previous example, when the react dependency exists in the\nbrowser environment as a windows.React or global.React global variable, then:\n\n * modern.config.ts config file:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdGlobals: {\n react: 'React',\n },\n },\n});\n\n\nWhen a react dependency is used in the source code:\n\n\nconsole.info(React);\n\n\nAt this point we will see the output code like this:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory();\n else if (typeof define === 'function' && define.amd) define([], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory();\n})(this, function () {\n // ...\n // libuild:globals:react\n var require_react = __commonJS({\n 'libuild:globals:react'(exports, module1) {\n module1.exports = Function('return this')()['React'];\n },\n });\n // src/index.ts\n var import_react = __toESM(require_react());\n console.info(import_react.default);\n});\n\n\nThe project can then run in the browser and use the React variables that exist\non the global object.\n\n\nChanging the name of a global variable in a project#\n\nWhen we package the following code into an umd artifact and run it in the\nbrowser, we can use the module via window.index.\n\nexport default () => {\n console.info('hello world');\n};\n\n\n** By default, the name of the source file is used as the name of the module's\nglobal variable in the browser. **For the above example, the artifact would read\nas follows:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports);\n else if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.index = {}));\n})(this, function (exports) {\n //...\n});\n\n\nIf you need to modify it, you need to use the buildConfig.umdModuleName API.\n\nWhen this API is used:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdModuleName: 'myLib',\n },\n});\n\n\nThe build artifact at this point are:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports);\n else if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.myLib = {}));\n})(this, function (exports) {\n //...\n});\n","frontmatter":{"sidebar_position":5},"version":""},{"id":15,"title":"Use the Copy Tools","routePath":"/module-tools/en/guide/advance/copy","lang":"en","toc":[{"text":"Understanding the Copy API","id":"understanding-the-copy-api","depth":2,"charIndex":171},{"text":"API Description","id":"api-description","depth":2,"charIndex":335},{"text":"Examples of Different Scenarios","id":"examples-of-different-scenarios","depth":2,"charIndex":2449},{"text":"Copying Files","id":"copying-files","depth":3,"charIndex":2484},{"text":"Copying Files to a Directory","id":"copying-files-to-a-directory","depth":3,"charIndex":2834},{"text":"Copying from Directory to Directory","id":"copying-from-directory-to-directory","depth":3,"charIndex":3192},{"text":"Copying from Directory to File","id":"copying-from-directory-to-file","depth":3,"charIndex":3613},{"text":"Using Glob","id":"using-glob","depth":3,"charIndex":4042}],"domain":"","content":"#\n\nModern.js Module provides the Copy utility for copying already existing\nindividual files or entire directories into the output directory. Next we learn\nhow to use it.\n\n\nUnderstanding the Copy API#\n\nWe can use the Copy tool via the buildConfig.copy API, which contains the\nfollowing two main configurations.\n\n * patterns\n * options\n\n\nAPI Description#\n\ncopy.patterns is used to find files to be copied and configure the output path.\n\nThe patterns.from parameter is used to specify the file or directory to be\ncopied. It accepts either a Glob pattern string or a specific path. A Glob\npattern string refers to the fast-glob pattern syntax. Therefore, we can use it\nin two ways as follows:\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n { from: './index.html', to: '' },\n { from: './*.html', to: '' },\n ],\n },\n },\n});\n\n\nThe patterns.context parameter is generally used in conjunction with\npatterns.from. By default, its value is the same as buildConfig.sourceDir.\nTherefore, we can specify the file src/data.json to be copied in the following\nway:\n\n> By default, buildConfig.sourceDir is set to src.\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n { from: './data.json' to: ''},\n ],\n },\n },\n});\n\n\nWhen the specified file is not in the source code directory, you can modify the\ncontext configuration. For example, to specify the file temp/index.html in the\nproject directory to be copied:\n\n\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n {\n from: './index.html',\n context: path.join(__dirname, './temp')\n to: '',\n }\n ],\n },\n },\n});\n\n\nThe patterns.to parameter is used to specify the output path for the copied\nfiles. By default, its value corresponds to buildConfig.outDir. Therefore, we\ncan copy src/index.html to the dist directory as follows:\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [{ from: './index.html' }],\n },\n },\n});\n\n\nWhen we configure patterns.to:\n\n * If it is a relative path, the path will be calculated relative to\n buildConfig.outDir to determine the absolute path for copying the files.\n * If it is an absolute path, the value will be used directly.\n\nFinally, patterns.globOptions is used to configure the globby object for finding\nfiles to copy. Its configuration can be referenced from:\n\n * globby.options\n\n\nExamples of Different Scenarios#\n\n\nCopying Files#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy file to file\n */\n {\n from: './temp-1/a.png',\n context: __dirname,\n to: './temp-1/b.png',\n },\n ],\n },\n },\n ],\n});\n\n\n\nCopying Files to a Directory#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy file to dir\n */\n {\n from: './temp-2/a.png',\n context: __dirname,\n to: './temp-2',\n },\n ],\n },\n },\n ],\n});\n\n\n\nCopying from Directory to Directory#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy dir to dir\n */\n {\n from: './temp-3/',\n to: './temp-3',\n context: __dirname,\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n\n\n\nCopying from Directory to File#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy dir to file\n */\n {\n from: './temp-4/',\n context: __dirname,\n to: './temp-4/_index.html',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n\n\n\nUsing Glob#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy glob to dir\n */\n {\n from: './*.html',\n to: './temp-5',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n {\n copy: {\n patterns: [\n /**\n * copy glob to file\n */\n {\n from: './*.html',\n to: './temp-6/index.html',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n","frontmatter":{"sidebar_position":3},"version":""},{"id":16,"title":"Handle third-party dependencies","routePath":"/module-tools/en/guide/advance/external-dependency","lang":"en","toc":[{"text":"Default handling of third-party dependencies","id":"default-handling-of-third-party-dependencies","depth":2,"charIndex":861},{"text":"Example","id":"example","depth":3,"charIndex":1423},{"text":"Exclude specified third-party dependencies","id":"exclude-specified-third-party-dependencies","depth":2,"charIndex":1840}],"domain":"","content":"#\n\nGenerally, third-party dependencies required by a project can be installed via\nthe install command in the package manager. After the third-party dependencies\nare successfully installed, they will generally appear under dependencies and\ndevDependencies in the project package.json.\n\n{\n \"dependencies\": {},\n \"devDependencies\": {}\n}\n\n\nDependencies under \"dependencies\" are generally related to project code and\nbuilds, and if these third-party dependencies are declared under\n\"devDependencies\", then there will be missing dependencies in production\nenvironments.\n\nIn addition to \"dependencies\", \"peerDependencies\" can also declare dependencies\nthat are needed in the production environment, but it puts more emphasis on the\nexistence of these dependencies declared by \"peerDependencies\" in the project's\nruntime environment, similar to the plugin mechanism.\n\n\nDefault handling of third-party dependencies#\n\nBy default, third-party dependencies under \"dependencies\" and \"peerDependencies\"\nare not bundled by Modern.js Module.\n\nThis is because when the npm package is installed, its \"dependencies\" will also\nbe installed. By not packaging \"dependencies\", you can reduce the size of the\npackage product.\n\nIf you need to package some dependencies, it is recommended to move them from\n\"dependencies\" to \"devDependencies\", which is equivalent to prebundle the\ndependencies and reduces the size of the dependency installation.\n\n\nExample#\n\nIf the project has a dependency on react.\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n },\n // or\n \"peerDependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\nWhen a react dependency is used in the source code:\n\n\nconsole.info(React);\n\n\nThe react code is not bundled into the artifact:\n\n\nconsole.info(React);\n\n\nIf you want to modify the default processing, you can use the following API.\n\n * buildConfig.autoExternal\n\n\nExclude specified third-party dependencies#\n\nWe mentioned above the use of the buildConfig.autoExternal API, and\nbuildConfig.externals can control which third-party dependencies to handle the\nproject's dependencies in a more granular way.\n\nFor example, when we need to leave only certain dependencies unpacked, we can\nconfigure it as follows.\n\n> In this case, it is likely that some dependencies are not suitable for\n> packaging. If this is the case, then you can handle it as follows.\n\nepxort default defineConfig({\n buildConfig: {\n autoExternal: false,\n externals: ['pkg-1', /pkg-2/],\n }\n});\n","frontmatter":{"sidebar_position":4},"version":""},{"id":17,"title":"In-depth understanding of build","routePath":"/module-tools/en/guide/advance/in-depth-about-build","lang":"en","toc":[{"text":"bundle / bundleless","id":"bundle--bundleless","depth":2,"charIndex":497},{"text":"input / sourceDir","id":"input--sourcedir","depth":2,"charIndex":1630},{"text":"use swc","id":"use-swc","depth":2,"charIndex":2902},{"text":"Using Hooks to Intervene in the Build Process","id":"using-hooks-to-intervene-in-the-build-process","depth":2,"charIndex":3852},{"text":"Hook type","id":"hook-type","depth":3,"charIndex":4232},{"text":"AsyncSeriesBailHook","id":"asyncseriesbailhook","depth":4,"charIndex":4244},{"text":"AsyncSeriesWaterFallHooks","id":"asyncserieswaterfallhooks","depth":4,"charIndex":4383},{"text":"Hook API","id":"hook-api","depth":3,"charIndex":4480},{"text":"load","id":"load","depth":4,"charIndex":4491},{"text":"transform","id":"transform","depth":4,"charIndex":5185},{"text":"renderChunk","id":"renderchunk","depth":4,"charIndex":5696},{"text":"dts","id":"dts","depth":2,"charIndex":6675},{"text":"Turn off type generation","id":"turn-off-type-generation","depth":3,"charIndex":6758},{"text":"Build type files","id":"build-type-files","depth":3,"charIndex":7035},{"text":"Alias Conversion","id":"alias-conversion","depth":3,"charIndex":7729},{"text":"Some examples of the use of dts","id":"some-examples-of-the-use-of-dts","depth":3,"charIndex":8305},{"text":"Build process","id":"build-process","depth":2,"charIndex":9002},{"text":"Build errors","id":"build-errors","depth":2,"charIndex":9295},{"text":"Debug mode","id":"debug-mode","depth":2,"charIndex":10045}],"domain":"","content":"#\n\nIn the \"Basic Usage\" section, we already knew that you can modify the output\nfiles of a project through the buildConfig configuration. buildConfig not only\ndescribes some of the features of the product, but also provides some\nfunctionality for building the product.\n\nTIP\n\nIf you are not familiar with buildConfig, please read modify-output-product.\n\nIn this chapter we'll dive into the use of certain build configurations and\nunderstand what happens when the modern build command is executed.\n\n\nbundle / bundleless#\n\nSo first let's understand bundle and bundleless.\n\nA bundle is a package of build products, which may be a single file or multiple\nfiles based on a certain code splitting strategy.\n\nbundleless, on the other hand, means that each source file is compiled and built\nseparately, but not bundled together. Each output file can be found with its\ncorresponding source code file. The process of bundleless build can also be\nunderstood as the process of code conversion of source files only.\n\nThey have their own benefits.\n\n * bundle can reduce the size of build artifacts and also pre-package\n dependencies to reduce the size of installed dependencies. Packaging\n libraries in advance can speed up application project builds.\n * bundleless maintains the original file structure and is more conducive to\n debugging and tree shaking.\n\nWARNING\n\nbundleless is a single file compilation mode, so for type references and exports\nyou need to add the type field, e.g. import type { A } from '. /types\n\nIn buildConfig you can specify whether the current build task is bundle or\nbundleless by using buildConfig.buildType.\n\n\ninput / sourceDir#\n\nbuildConfig.input is used to specify the path to a file or directory from which\nto read the source code, the default value of which varies between bundle and\nbundleless builds:\n\n * When buildType: 'bundle', input defaults to src/index.(j|t)sx?.\n * When buildType: 'bundleless', input defaults to ['src'].\n\nFrom the default value, we know that building in bundle mode usually specifies\none or more files as the entry point for the build, while building in bundleless\nmode specifies a directory and uses all the files in that directory as the entry\npoint.\n\nsourceDir is used to specify the source directory, which is only related to the\nfollowing two elements:\n\n * Type file generation\n * outbase for specifying the build process\n\nSo we can get its best practices:\n\n * Only specify input during the bundle build.\n * In general, bundleless only needs to specify sourceDir (where input will be\n aligned with sourceDir). If we want to use the input in bundleless, we only\n need to specify sourceDir.\n\nIf you want to convert only some of the files in bundleless, e.g. only the files\nin the src/runtime directory, you need to configure input:\n\n\n\nexport default defineConfig({\n buildConfig: {\n input: ['src/runtime'],\n sourceDir: 'src',\n },\n});\n\n\n\nuse swc#\n\nIn some scenarios, esbuild is not enough to meet our needs, and we will use swc\nto do the code conversion.\n\nStarting from version 2.36.0, the Modern.js Module will use swc by default when\nit comes to the following functionality, but that doesn't mean we don't use\nesbuild any more, the rest of the functionality will still use esbuild.\n\n * transformImport\n * transformLodash\n * externalHelpers\n * format: umd\n * target: es5\n * emitDecoratorMetadata: true\n\nIn fact, we've been using swc for full code conversion since 2.16.0. However,\nswc also has some limitations, so we added sourceType to turn off swc when the\nsource is formatted as 'commonjs', which isn't really user-intuitive, and the\ncjs mode of the swc formatted outputs don't have annotate each export name,\nwhich can cause problems in node. So we deprecated this behaviour and went back\nto the original design - using swc as a supplement only in situations where it\nwas needed.\n\n\nUsing Hooks to Intervene in the Build Process#\n\nThe Modern.js Module provides a Hook mechanism that allows us to inject custom\nlogic at different stages of the build process. The Modern.js Module Hook is\nimplemented using tapable, which extends esbuild's plugin mechanism, and is\nrecommended to be used directly if esbuild plugins already meet your needs.\nHere's how to use it:\n\n\nHook type#\n\nAsyncSeriesBailHook#\n\nSerial hooks that stop the execution of other tapped functions if a tapped\nfunction returns a non-undefined result.\n\nAsyncSeriesWaterFallHooks#\n\nSerial hooks whose results are passed to the next tapped function.\n\n\nHook API#\n\nload#\n\n * AsyncSeriesBailHook\n * Triggered at esbuild onLoad callbacks to fetch module content based on the\n module path\n * Input parameters\n\ninterface LoadArgs {\n path: string;\n namespace: string;\n suffix: string;\n}\n\n\n * Return parameters\n\ntype LoadResult =\n | {\n contents: string; // module contents\n map?: SourceMap; // https://esbuild.github.io/api/#sourcemap\n loader?: Loader; // https://esbuild.github.io/api/#loader\n resolveDir?: string;\n }\n | undefined;\n\n\n * Example\n\ncompiler.hooks.load.tapPromise('load content from memfs', async args => {\n const contents = memfs.readFileSync(args.path);\n return {\n contents: contents,\n loader: 'js',\n };\n});\n\n\ntransform#\n\n * AsyncSeriesWaterFallHooks\n * Triggered at esbuild onLoad callbacks. Transforms the contents of the module\n fetched during the load phase\n * Input parameters (return parameters)\n\nexport type Source = {\n code: string;\n map?: SourceMap;\n path: string;\n loader?: string;\n};\n\n\n * Example\n\ncompiler.hooks.transform.tapPromise('6to5', async args => {\n const result = babelTransform(args.code, { presets: ['@babel/preset-env'] });\n return {\n code: result.code,\n map: result.map,\n };\n});\n\n\nrenderChunk#\n\n * AsyncSeriesWaterFallHooks\n * Triggered at esbuild onEnd callbacks. This is similar to the transform hook,\n but works on the products generated by esbuild.\n * Input parameters (return parameters)\n\nexport type AssetChunk = {\n type: 'asset';\n contents: string | Buffer;\n entryPoint?: string;\n /**\n * absolute file path\n */\n fileName: string;\n originalFileName?: string;\n};\n\nexport type JsChunk = {\n type: 'chunk';\n contents: string;\n entryPoint?: string;\n /**\n * absolute file path\n */\n fileName: string;\n map?: SourceMap;\n modules?: Record;\n originalFileName?: string;\n};\n\nexport type Chunk = AssetChunk | JsChunk;\n\n\n * Examples\n\ncompiler.hooks.renderChunk.tapPromise('minify', async chunk => {\n if (chunk.type === 'chunk') {\n const code = chunk.contents.toString();\n const result = await minify.call(compiler, code);\n return {\n ...chunk,\n contents: result.code,\n map: result.map,\n };\n }\n return chunk;\n});\n\n\n\ndts#\n\nThe buildConfig.dts configuration is mainly used for type file generation.\n\n\nTurn off type generation#\n\nType generation is turned on by default, if you need to turn it off, you can\nconfigure it as follows:\n\n\n\nexport default defineConfig({\n buildConfig: {\n dts: false,\n },\n});\n\n\nTIP\n\nThe build speed is generally improved by closing the type file.\n\n\nBuild type files#\n\nWith buildType: 'bundleless', type files are generated using the project's tsc\ncommand to complete production.\n\nThe Modern.js Module also supports bundling of type files, although care needs\nto be taken when using this feature.\n\n * Some third-party dependencies have incorrect syntax that can cause the\n bundling process to fail. So in this case, you need to exclude such\n third-party packages manually with buildConfig.externals.\n * It is not possible to handle the case where the type file of a third-party\n dependency points to a .ts file. For example, the package.json of a\n third-party dependency contains something like this: {\"types\": \".\n /src/index.ts\"}.\n\n\nAlias Conversion#\n\nDuring the bundleless build process, if an alias appears in the source code,\ne.g.\n\n\n\n\nNormally, the type files generated with tsc will also contain these aliases.\nHowever, Modern.js Module will convert the aliases in the type file generated by\ntsc to:\n\n * Alias conversion is possible for code of the form ``.\n * Aliasing is possible for code of the form export { utils } from\n '@common/utils'.\n\nHowever, there are some cases that cannot be handled at this time.Output types\nof the form Promise cannot be converted at this time. You can discuss it here\n\n\nSome examples of the use of dts#\n\nGeneral usage:\n\n\n\nexport default defineConfig({\n // The output path of the bundled type file at this point is `./dist/types`\n buildConfig: {\n buildType: 'bundle',\n dts: {\n tsconfigPath: './other-tsconfig.json',\n distPath: './types',\n },\n outDir: './dist',\n },\n});\n\n\nFor the use of dts.only:\n\n\n\nexport default defineConfig({\n // At this moment the type file is not bundled and the output path is `./dist/types`\n buildConfig: [\n {\n buildType: 'bundle',\n dts: false,\n outDir: './dist',\n },\n {\n buildType: 'bundleless',\n dts: {\n only: true,\n },\n outDir: './dist/types',\n },\n ],\n});\n\n\n\nBuild process#\n\nWhen the modern build command is executed, the\n\n * Clear the output directory according to buildConfig.outDir.\n * Compile js/ts source code to generate the JS build artifacts for\n bundle/bundleless.\n * Generate bundle/bundleless type files using tsc.\n * Handle Copy tasks.\n\n\nBuild errors#\n\nWhen a build error occurs, based on the information learned above, it is easy to\nunderstand what error appears in the terminal.\n\nErrors reported for js or ts builds:\n\nerror ModuleBuildError:\n\n╭───────────────────────╮\n│ bundle failed: │\n│ - format is \"cjs\" │\n│ - target is \"esnext\" │\n╰───────────────────────╯\n\nDetailed Information:\n\n\nErrors reported for the type file generation process:\n\nerror ModuleBuildError:\n\nbundle DTS failed:\n\n\nFor js/ts build errors, we can tell from the error message.\n\n * By 'bundle failed:' to determine if the error is reported for a bundle build\n or a bundleless build\n * What is the format of the build process\n * What is the target of the build process\n * The specific error message\n\n\nDebug mode#\n\nFrom 2.36.0, For troubleshooting purposes, the Modern.js Module provides a debug\nmode, which you can enable by adding the DEBUG=module environment variable when\nexecuting a build.\n\nDEBUG=module modern build\n\n\nIn debug mode, you'll see more detailed build logs output in Shell, which are\nmainly process logs:\n\nmodule run beforeBuildTask hooks +6ms\nmodule run beforeBuildTask hooks done +0ms\nmodule [DTS] Build Start +139ms\nmodule [CJS] Build Start +1ms\n\n\nIn addition, Module provides the ability to debug internal workflows. You can\nenable more detailed debugging logging by setting the DEBUG=module:* environment\nvariable.\n\nCurrently, only DEBUG=module:resolve is supported, which allows you to see a\ndetailed log of module resolution within the Module.\n\n module:resolve onResolve args: {\n path: './src/hooks/misc.ts',\n importer: '',\n namespace: 'file',\n resolveDir: '/Users/bytedance/modern.js/packages/solutions/module-tools',\n kind: 'entry-point',\n pluginData: undefined\n} +0ms\n module:resolve onResolve result: {\n path: '/Users/bytedance/modern.js/packages/solutions/module-tools/src/hooks/misc.ts',\n external: false,\n namespace: 'file',\n sideEffects: undefined,\n suffix: ''\n} +0ms\n","frontmatter":{"sidebar_position":1},"version":""},{"id":18,"title":"In-depth understanding of the dev command","routePath":"/module-tools/en/guide/advance/in-depth-about-dev-command","lang":"en","toc":[{"text":"The overall flow of the command run","id":"the-overall-flow-of-the-command-run","depth":2,"charIndex":92},{"text":"Extending the dev command","id":"extending-the-dev-command","depth":2,"charIndex":805}],"domain":"","content":"#\n\nThe dev command provided by the Modern.js Module is mainly used for debugging\nthe code.\n\n\nThe overall flow of the command run#\n\n 1. When the dev command is executed, Modern.js Module starts looking for\n debugging tools or tasks that can be executed. A debugging tool or task is a\n Modern.js Module debugging tool plugin like Storybook.\n 2. When a debugging tool is found, it is executed immediately.\n 3. When multiple debugging tools are found, the debugging tools list menu is\n displayed. A debug tool can be started by selecting the name option\n corresponding to it.\n 4. When no debug tool is found, the user is informed that no debug tool is\n available.\n\nIn addition to the dev command, you can also start a debugging tool or task\ndirectly by using the dev [debug tool name] option.\n\n\nExtending the dev command#\n\nIf you need to extend the dev command, or rather provide your own Modern.js\nModule debugging tool plugin, then you will need to know the following first.\n\n * Development of plugins\n * Debugging Tools Plugin API\n\nIn general, the code to implement a debugging tool that does nothing and the\nassociated configuration is as follows.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'do-nothing',\n setup() {\n return {\n registerDev() {\n return {\n // Debugging tool name\n name: 'do-nothing',\n // Menu display content\n menuItem: {\n name: 'DoNothing',\n value: 'do-nothing',\n },\n // The defined dev subcommand\n subCommands: ['donothing', 'dn'],\n async action() {\n // dev logic\n console.info('Run build --watch, and do nothing.');\n },\n };\n },\n };\n },\n});\n\n\nIf this debugging tool plugin is required, it needs to be added to the\nconfiguration file.\n\n\n\nexport default defineConfig({\n plugins: [\n //..\n doNothingPlugin()\n ],\n});\n\n\nAt this point we can execute it when we execute the dev or dev do-nothing\ncommand. After execution, it will first execute the source build task in\nlistening mode and print the log messages immediately afterwards.\n\nFor currently officially supported debugging tools and third-party supported\ndebugging tools, you can view them in plugins list.","frontmatter":{"sidebar_position":2},"version":""},{"id":19,"title":"Before you start","routePath":"/module-tools/en/guide/basic/before-getting-started","lang":"en","toc":[{"text":"Environment preparation","id":"environment-preparation","depth":2,"charIndex":3},{"text":"Getting Started with npm","id":"getting-started-with-npm","depth":2,"charIndex":425},{"text":"npm package type project","id":"npm-package-type-project","depth":2,"charIndex":907},{"text":"Using third-party npm packages","id":"using-third-party-npm-packages","depth":2,"charIndex":2127},{"text":"Other npm bits and pieces to know","id":"other-npm-bits-and-pieces-to-know","depth":2,"charIndex":3994},{"text":"Program entry for npm packages","id":"program-entry-for-npm-packages","depth":3,"charIndex":4031},{"text":"scripts","id":"scripts","depth":3,"charIndex":4916},{"text":"npm install","id":"npm-install","depth":4,"charIndex":5729},{"text":"npm publish","id":"npm-publish","depth":4,"charIndex":6090},{"text":"peerDependencies","id":"peerdependencies","depth":3,"charIndex":6360},{"text":"npm package manager","id":"npm-package-manager","depth":2,"charIndex":7062},{"text":"Modern.js Module configuration file","id":"modernjs-module-configuration-file","depth":2,"charIndex":7347}],"domain":"","content":"#\n\n\nEnvironment preparation#\n\nIn order to use the Modern.js Module, you first need NodeJS engine, we recommend\nthe latest LTS version, and make sure the Node version is >=14.18.0. because\nnon-stable NodeJS releases frequently have bugs. You might consider installing\nvia nvm-windows and nvm (Mac / Linux), so you can easily switch to different\nNodeJS versions that might be required for different projects that you work on.\n\n\nGetting Started with npm#\n\nOnce NodeJS is installed, not only can you access the node executable from the\ncommand line, but you can also execute the npm command.\n\nNpm is the standard package manager for NodeJS. It started out as a tool for\ndownloading and managing NodeJS package dependencies, but it has since evolved\ninto a tool for front-end JavaScript.\n\nIf you already know something about usage of npm and npm packages, then you can\ndirectly see npm package manager section.\n\n\nnpm package type project#\n\nSo what is an npm package type project? When we execute the npm init command in\nan empty project directory, it creates a JSON file with the file name\npackage.json under the current directory. During the creation process, we will\nneed to fill in information including but not limited to the name, version\nnumber, description, etc. of the npm package, which will be found in the\nresulting package.json file as follows\n\n{\n \"name\": \"npm-demo\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"index.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n },\n \"author\": \"\",\n \"license\": \"ISC\"\n}\n\n\nAt this point the project containing the initialized package.json file is an npm\npackage type project, and you can execute the npm publish command to publish the\nproject to the npm Registry.\n\nThe npm Registry is a npm package store where developers can not only publish\ntheir own npm packages to the npm Registry, but also use npm packages published\nby other developers through the npm Registry.\n\nA quality npm package will be used by more people because it not only saves a\nlot of code implementation work, but is also less likely to cause problems with\nthe project.\n\n\nUsing third-party npm packages#\n\nWhen adding a third-party npm package to an initial project, we can call this\nprocess \"installing dependencies for the project\" or \"adding dependencies to the\nproject\". Before adding dependencies, we need to know one thing in particular --\nthe types of packages npm depends on.\n\n * \"dependencies\": a type of package that your application will need in a\n production environment.\n * \"devDependencies\": another type of package that is only needed for local\n development and testing.\n \n > packages can be understood as third-party npm packages.\n\nYou can install the packages you need in a production environment by running npm\ninstall npm-package-name or npm add npm-package-name, or you can manually write\nthe packages you need to install and the corresponding semantic version in\n\"dependencies\" in the package.json file, and run the npm install command to.\n\n{\n \"name\": \"your-npm-project\",\n \"dependencies\": {\n \"npm-package-name\": \"0.1.0\"\n }\n}\n\n\nSimilarly, you can install only packages needed for local development and\ntesting by running npm install npm-package-name --save-dev or npm add\nnpm-package-name --save-dev, or you can manually write the packages to be\ninstalled and the corresponding semantic version in \"devDependencies\" in the\npackage.json file, and run the npm install command as follows\n\n{\n \"name\": \"your-npm-project\",\n \"devDependencies\": {\n \"npm-package-name\": \"0.1.0\"\n }\n}\n\n\nWhen installing or using third-party npm packages be sure to determine what they\nare for and whether they should be placed in \"dependencies\" or \"devDependencies\"\nby distinguishing between their types.\n\nTIP\n\nIn general, packages that need to be used in source code are dependencies\ndependencies. Unless you are exporting dependent code locally via packaging, in\nwhich case it can be treated as a devDependencies dependency.\n\n\nOther npm bits and pieces to know#\n\n\nProgram entry for npm packages#\n\nThere is a \"main\" attribute in package.json that corresponds to a module ID or,\nmore intuitively, a NodeJS file path, which is the main entry point for your\napplication.\n\nFor example, if your package is named foo and the user installs it, and then\nexecutes the require(\"foo\") code, then the file corresponding to the \"main\"\nfield of the npm package foo will be exported.\n\nIt is recommended to set the \"main\" field in your npm package. If \"main\" is not\nset, the default entry will be the index.js file in the root of the package.\n\nIn addition to the \"main\" attribute, the \"module\" attribute is usually set. It\nis similar to the \"main\" attribute in that it is mainly used in webpack\nscenarios. webpack reads the npm package entry (file) in most cases in the order\n\"module\" -> \"main \".\n\n> To learn more about how webpack does this, check out this link.\n\n\nscripts#\n\nThe \"scripts\" attribute of the package.json file supports a number of built-in\nscripts and npm-preset lifecycle events, as well as arbitrary scripts.\n\nThese can be executed by running npm run-script or simply npm run .\n\nName matching pre and post commands will also be run (e.g. premyscript,\nmyscript, postmyscript ).\n\n{\n \"scripts\": {\n \"premyscript\": \"\",\n \"myscript\": \"\",\n \"postmyscript\": \"\"\n }\n}\n\n\nWhen npm run myscripts is executed, the script corresponding to premyscripts\nwill be executed before it, and the script corresponding to postmyscripts will\nbe executed after it.\n\nScript commands from dependencies can be run with npm explore -- npm run .\n\nThere are also special lifecycle scripts that occur only under certain\ncircumstances. Here are a few that are usually necessary to know.\n\nnpm install#\n\nWhen you run npm install -g , the following scripts will run.\n\n * preinstall\n * install\n * postinstall\n * prepublish\n * preprepare\n * prepare\n * postprepare\n\nIf your package root has a binding.gyp file and you don't define an install or\npreinstall script, then npm will build with node-gyp rebuild as the default\ninstall command, using node-gyp.\n\nnpm publish#\n\nWhen publishing a project, executing this command will trigger the following\nscript.\n\n * prepublishOnly\n * prepack\n * prepare\n * postpack\n * publish\n * postpublish\n\nWhen running in -dry-run mode, the script corresponding to prepare will not be\nexecuted.\n\n\npeerDependencies#\n\nIn some cases, your npm project has a compatibility relationship with its host\ntool or library (e.g. a webpack plugin project and webpack), and your npm\nproject does not want to use the host as a necessary dependency, which usually\nmeans that your project is probably a plugin for that host tool or library. Your\nnpm project will have certain requirements for the version of the host package,\nas only the APIs required by the npm project will be exposed under a specific\nversion.\n\nFor more explanation of peerDependencies, you can learn about the different ways\nnpm, pnpm, and Yarn handle it at the following links.\n\n * npm's explanation of peerDependencies\n * pnpm vs npm vs Yarn\n\n\nnpm package manager#\n\nIn addition to the standard package manager like npm, the mainstream ones are\npnpm and Yarn, both of which are good alternatives to npm cli.\n\nIt is recommended to use pnpm to manage project dependencies, which can be\ninstalled as follows.\n\nnpm install -g pnpm\n\n\n\nModern.js Module configuration file#\n\nThe Modern.js Module configuration file - modern.config.(j|t)s - is provided in\nthe project directory of the module project created with @modern-js/create.\nHowever, the modern.config configuration file is not required to exist.\n\nBy default, the contents of the generated configuration file are as follows.\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n});\n\n\nWe recommend using the defineConfig function, but it is not mandatory to use it.\nSo you can also return an object directly in the config file: the\n\n\n\nexport default {\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n};\n","frontmatter":{"sidebar_position":1},"version":""},{"id":20,"title":"CLI Commands","routePath":"/module-tools/en/guide/basic/command-preview","lang":"en","toc":[{"text":"modern build","id":"modern-build","depth":2,"charIndex":73},{"text":"modern new","id":"modern-new","depth":2,"charIndex":2087},{"text":"modern dev","id":"modern-dev","depth":2,"charIndex":2866},{"text":"modern test","id":"modern-test","depth":2,"charIndex":3439},{"text":"modern lint","id":"modern-lint","depth":2,"charIndex":3747},{"text":"modern change","id":"modern-change","depth":2,"charIndex":4183},{"text":"modern pre","id":"modern-pre","depth":2,"charIndex":4511},{"text":"modern bump","id":"modern-bump","depth":2,"charIndex":4742},{"text":"modern release","id":"modern-release","depth":2,"charIndex":5261},{"text":"modern gen-release-note","id":"modern-gen-release-note","depth":2,"charIndex":5741},{"text":"modern upgrade","id":"modern-upgrade","depth":2,"charIndex":6237}],"domain":"","content":"#\n\nCLI Commands available for Modern.js Module projects are as follows:\n\n\nmodern build#\n\nUsage: modern build [options]\n\nBuild module command\n\nOptions:\n -w, --watch Build code in listening mode\n --tsconfig [tsconfig] Specify the path to the tsconfig.json file (default:\n \". /tsconfig.json\")\n --platform [platform] Build products for all or specified platforms\n --no-dts disables DTS type file generation and type checking\n --no-clear disables automatic clearing of output directories\n -h, --help Show information about the current command\n\n\nWhen you want to start a project build, you can execute the modern build\ncommand. When using this command, we can:\n\n * When wanting to start a build in watch mode, use the --watch option.\n * When you want to specify the path to the TypeScript configuration file read\n by the project build, use -build --tsconfig . /path/config.json option. This\n option overrides all buildConfig configurations in dts.tsconfigPath.\n * The -no-dts option can be used when the DTS type file generation and type\n checking behavior of the project needs to be turned off. Note: The generation\n of type files depends on the results of type checking. If type checking is\n turned off, then type files will not be generated either.\n * The --no-clear option can be used when the automatic clearing of the output\n directory needs to be turned off.\n\nIn addition to the above, Modern.js Module also support platform build mode,\nwhich can be used to perform build tasks for other tools. For example, it is\ncurrently officially supported to start a Storybook build task to generate\nStorybook artifacts by executing the modern build --platform or modern build\n--platform storybook commands after installing the @modern-js/plugin-storybook\nplugin.\n\nTIP\n\nWhen executing a Storybook build, if you need to read the build artifacts of the\nproject. Then don't forget to execute the modern build command to ensure the\nexistence of the project's build artifacts before executing the modern build\n--platform command to start the Storybook build.\n\n\nmodern new#\n\nUsage: modern new [options]\n\nExecute the generator in a modular project scenario\n\nOptions:\n -d, --debug Enable Debug mode, print debug log messages (default: false)\n -c, --config Generators run default configuration (JSON string)\n --dist-tag Generator uses a special version of npm Tag\n --registry customize npm Registry during generator runtime\n -h, --help display help for command\n\n\nThe modern new command is used to start the microgenerator functionality, which\nenables features for the project that are not provided by default.\n\nThe following features can currently be enabled.\n\n * Testing support\n * Storybook debugging\n * Tailwind CSS support\n * Modern.js Runtime API\n\nYou can learn more about these features in the Using the micro generator\nsection.\n\n\nmodern dev#\n\nUsage: modern dev [options]\n\nLocal development commands\n\nOptions:\n -h, --help display help for command\n\nCommands:\n[dev-tools-subCommand]\n\n\nThe Modern.js Module provides the ability to use debugging tools, which can be\nstarted with the modern dev command. Note, however, that no debugging-related\nplugins are provided by default, so executing modern dev will prompt: \"No dev\ntools found available \".\n\nThe officially supported debugging tool is Storybook, so you can run modern dev\nor modern dev storybook to execute it after you run modern new to enable it.\n\n\nmodern test#\n\nUsage: modern test [options]\n\nOptions:\n -h, --help display help for command\n\n\nYou need to execute modern new to turn on the test function before you can\nexecute the modern test command. The modern test command will automatically run\nthe src/tests/*.test.(js|ts|jsx|tsx) file as a test case.\n\n\nmodern lint#\n\nUsage: modern lint [options] [. .files]\n\nlint and fix source files\n\nOptions:\n --no-fix disable auto fix source file\n -h, --help display help for command\n\n\nRun ESLint to check the syntax of the code. Usually, we only need to check the\npart of the code that was changed in this commit with lint-staged during the\n-git commit phase.\n\n * The -no-fix argument turns off the ability to automatically fix lint error\n code.\n\n\nmodern change#\n\nUsage: modern change [options]\n\nCreate a changeset\n\nOptions:\n --empty Create an empty changeset (default: false)\n --open Open the created changeset in the editor (default: false)\n -h, --help display help for command\n\n\nThe modern change command is used to generate the required Markdown file for\nchangesets.\n\n\nmodern pre#\n\nUsage: modern pre [options] [tag]\n\nEntering and exiting pre-publishing mode\n\nOptions:\n -h, --help display help for command\n\n\nYou can use the modern pre command to pre-release a version before the official\nrelease.\n\n\nmodern bump#\n\nUsage: modern bump [options]\n\nUse changesets to automatically update releases and changelogs\n\nOptions:\n --canary Create a pre-release for testing (default: false)\n --preid Specify an identifier when versioning a pre-release (default: \"next\")\n --snapshot Create a special version for testing (default: false)\n -h, --help display help for command\n\n\nModify the version number in package.json according to the Markdown file of the\nchangelog generated by changesets, and generate the CHANGELOG.md file.\n\n\nmodern release#\n\nUsage: modern release [options]\n\nRelease npm packages\n\nOptions:\n --tag Release npm packages with a specific tag (default: \"\")\n --ignore-scripts release ignores the scripts command in package.json, only supported in pnpm monorepo\n (default: \"\")\n -h, --help display help for command\n\n\nThe -modern release command releases the module to the npm Registry.\n\n * The -tag argument specifies the specific dist tags to be used for the\n release.\n\n\nmodern gen-release-note#\n\nUsage: modern gen-release-note [options]\n\nGenerate Release Note based on current repository changeset information\n\nOptions:\n --repo The name of the repository to generate the Pull Request link, e.g.: web-infra-dev/modern.js\n --custom Custom Release Note generation function\n -h, --help display help for command\n\n\nAutomatically generate Release Note based on the changeset information of the\ncurrent repository.\n\nTIP\n\nneeds to be executed before the bump command.\n\n\nmodern upgrade#\n\nUsage: modern upgrade [options]\n\nUpgrade Modern.js to the latest version\n\nOptions:\n --registry customize npm registry (default: \"\")\n -d,--debug Enable Debug mode to print debug log messages (default: false)\n --cwd project path (default: \"\")\n -h, --help display help for command\n\n\nThe modern upgrade command is used to upgrade the project Modern.js related\ndependencies to the latest version.\n\nExecuting the command npx modern upgrade in the project root directory will\nupdate the Modern.js dependencies in package.json of the currently executing\nproject to the latest version by default.","frontmatter":{"sidebar_position":2},"version":""},{"id":21,"title":"Modify the output product","routePath":"/module-tools/en/guide/basic/modify-output-product","lang":"en","toc":[{"text":"Default output products","id":"default-output-products","depth":2,"charIndex":3},{"text":"buildPreset","id":"buildpreset","depth":2,"charIndex":1002},{"text":"buildConfig","id":"buildconfig","depth":2,"charIndex":1823},{"text":"Combining Configuration and Presets","id":"combining-configuration-and-presets","depth":2,"charIndex":4571}],"domain":"","content":"#\n\n\nDefault output products#\n\nWhen you use the modern build command in an initialized project, Modern.js\nModule will generate corresponding build artifacts based on the current\nconfiguration.\n\nThe default configuration is as follows:\n\n\n\nexport default defineConfig({\n // Register the CLI tool of Modern.js Module\n plugins: [moduleTools()],\n // Specify the build preset configuration\n buildPreset: 'npm-library',\n});\n\n\nThe default output files has the following characteristics.\n\n * will generate CommonJS and ESM.\n * The code syntax is supported up to ES6 , and more advanced syntax will be\n converted.\n * All code is bundled into one file, i.e. bundle processing is performed.\n * The output root directory is the dist directory under the project, and the\n type file output directory is dist/types.\n\nYou may have the following questions when you see this.\n\n 1. what is buildPreset?\n 2. what determines these characteristics of the product?\n\nThen the next step is to first explain buildPreset.\n\n\nbuildPreset#\n\nThe buildPreset represents a prepared set or sets of build-related\nconfigurations that can be used to eliminate the trouble and complexity of\nconfiguration by using the default values corresponding to the build Preset,\nresulting in the expected product.\n\nModern.js Module mainly comes with two built-in build presets, including:\n\n * npm-component: Used to build component libraries.\n * npm-library: Used to package projects of other library types, such as tool\n libraries.\n\nIt also provides some variations, such as npm-library-with-umd and\nnpm-library-es5, which, as their names suggest, correspond to library presets\nwith umd output and support for es5 syntax, respectively. For more detailed\nconfiguration, you can refer to its API.\n\nIn addition, we can also fully customize the build configuration:\n\n\nbuildConfig#\n\nbuildConfig is a configuration option that describes how to compile and generate\nbuild artifacts. What was mentioned at the beginning about \"features of build\nproducts\" are actually properties supported by buildConfig. The currently\nsupported properties cover the needs of most module type projects when building\nproducts. buildConfig not only contains some properties that artifacts have, but\nalso contains some features needed to build products. The following is a brief\nlist from a classification point of view.\n\nThe basic attributes of a build artifacts include:\n\n * Whether the artifact is bundled or not: the corresponding API is\n buildConfig.buildType.\n * Product support for syntax: the corresponding API is buildConfig.target.\n * Output format: the corresponding API is buildConfig.format.\n * How the output type file is handled: the corresponding API is\n buildConfig.dts.\n * How the sourceMap of the artifact is handled: the corresponding API is\n buildConfig.sourceMap.\n * The input (or source file) corresponding to the output: the corresponding API\n is buildConfig.input.\n * The directory of the output of the artifact: the corresponding API is\n buildConfig.outDir.\n * Build source directory: the corresponding API is buildConfig.sourceDir.\n\nCommon functions required for build artifacts include:\n\n * Alias: The corresponding API is buildConfig.alias.\n * Static resource handling: the corresponding API is buildConfig.asset.\n * Third-party dependency handling: The corresponding APIs are\n * buildConfig.autoExternal.\n * buildConfig.externals.\n * Copy: The corresponding API is buildConfig.copy.\n * Global variable substitution: the corresponding API is buildConfig.define.\n * Specify JSX compilation method, the corresponding API is\n [buildConfig.jsx](/api/config/ build-config#jsx).\n\nSome advanced properties or less frequently used functions:\n\n * Product code compression: The corresponding API is buildConfig.minify.\n * Code splitting: buildConfig.splitting\n * Specify whether the build artifacts is for the NodeJS environment or the\n browser environment: the corresponding API is buildConfig.platform.\n * umd product-related.\n * Specifies the global variables imported externally to the umd product: the\n corresponding API is buildConfig.umdGlobals.\n * Specify the module name of the umd product: the corresponding API is\n buildConfig.umdModuleName.\n\nIn addition to the above categories, frequently asked questions and best\npractices about these APIs can be found at the following links\n\n * About bundle and bundleless?\n * About input and sourceDir\n * About d.ts.\n * How to use define\n * How to handle third-party dependencies?\n * How to use copy?\n * How to use umd\n * How to use asset\n\n\nCombining Configuration and Presets#\n\nOnce we understand buildPreset and buildConfig, we can use them together.\n\nIn a real project, we can use buildPreset to quickly get a set of default build\nconfigurations. If you need to customise it, you can use buildConfig to override\nand extend it.\n\nThe extension logic is as follows.\n\n * When buildConfig is an array, new configuration items are added to the\n original preset.\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n buildConfig: [\n {\n format: 'iife',\n target: 'es2020',\n outDir: '. /dist/global'\n }\n ]\n});\n\n\nThis will generate an additional IIFE-formatted product that supports up to\nES2020 syntax on top of the original preset, in the dist/global directory under\nthe project.\n\n * When buildConfig is an object, the configuration items in the object are\n overwritten in the preset.\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n buildConfig: {\n sourceMap: true,\n },\n}).\n\n\nThis will cause a sourceMap file to be generated for each build task.","frontmatter":{"sidebar_position":3},"version":""},{"id":22,"title":"Versioning and Publishing","routePath":"/module-tools/en/guide/basic/publish-your-project","lang":"en","toc":[{"text":"Tracking changes","id":"tracking-changes","depth":2,"charIndex":406},{"text":"Version update","id":"version-update","depth":2,"charIndex":1748},{"text":"Publish","id":"publish","depth":2,"charIndex":2227},{"text":"Pre-releases","id":"pre-releases","depth":2,"charIndex":2941}],"domain":"","content":"#\n\nAn npm-type module project release process consists of two phases.\n\n * The first phase is during development, where the developer needs to provide a\n change file to record changes that need to be released.\n * The second phase is during release, where Modern.js Module can collect all\n the change files to update the version, update the release log, and release\n new packages to the npm Registry.\n\n\nTracking changes#\n\nChanges need to be logged when they happen to the project. Changes that occur in\na project are typically.\n\n * New features\n * Fixes to issues\n * Configuration file changes\n * ...\n\nOnce these changes have been made, the current changes need to be documented\nwith the following command.\n\n * modern change\n\nExecuting the modern change command asks the developer several questions and\ngenerates a change log based on the developer's answers. The changelog file\ncontains the type of change and its description, and is committed to the git\nrepository.\n\n$ npx modern change\n🦋 What kind of change is this for module-example? (current version is 0.1.0) - patch\n🦋 Please enter a summary for this change (this will be in the changelogs). Submit empty line to open external editor\n🦋 Summary - publish test\n🦋 === Releasing the following packages ===\n🦋 [Patch]\n🦋 module\n🦋 Is this your desired changeset? (Y/n) - true\n🦋 Changeset added! - you can now commit it\n🦋\n🦋 If you want to modify or expand on the changeset summary, you can find it here\n🦋 info /xxxxxx/module/.changeset/brave-dryers-agree.md\n\n\nWhen executed successfully, the resulting Markdown file containing the change\nlog is saved in the project's .changeset directory. The contents will look like\nthe following.\n\n---\n\"``module-example'': patch\n---\n\npublish test\n\n\n\nVersion update#\n\nWhen the project version needs to be updated, execute the following command.\n\n * modern bump\n\nExecuting modern bump will modify the version number in package.json based on\nthe contents of the Markdown file in the .changeset/ directory where the changes\nwere recorded, and generate the CHANGELOG.md file. These Markdown files are also\ndeleted when the version update is complete, so they are \"consumed \".\n\n# module\n\n## 0.1.1\n\n### Patch Changes\n\n- publish test\n\n\n\nPublish#\n\nTo publish a project, you can execute the following command.\n\n * modern publish\n\nThe modern release command publishes the project to the npm Registry.\n\nThe release is the latest version, which is also the official version. If you\nwant to change the dist-tag, you can specify it with the modern release --tag\ncommand. For example.\n\nmodern release --tag beta\n\n\nHowever, if you want to change the version number of the current project to a\npre-release as well, you need to use the modern pre command.\n\n> dist-tag can be understood as: tagging the current release. Generally\n> speaking, the dist-tag for the default release is latest, so you can consider\n> latest as the dist-tag for the official release.\n\n\nPre-releases#\n\nWhen a pre-release is needed before the official release, the following command\nis executed.\n\n * modern pre\n\nFirst modern pre enter to enter pre-release mode, can be the same as the tag\nspecified with the modern release --tag command when releasing the project.\n\n$ npx modern pre enter next\n🦋 success Entered pre mode with tag next\n🦋 info Run `changeset version` to version packages with prerelease versions\n✨ Done in 5.30s.\nDone in 5.30s.\n\n\nThen you can update the specific version number with the modern bump command,\nwhich doesn't actually \"consume\" the Markdown file that records the changes:\n\n$ npx modern bump\n🦋 warn ===============================IMPORTANT!===============================\n🦋 warn You are in prerelease mode\n🦋 warn If you meant to do a normal release you should revert these changes and run `changeset pre exit`\n🦋 warn You can then run `changeset version` again to do a normal release\n🦋 warn ----------------------------------------------------------------------\n🦋 All files have been updated. review them and commit at your leisure\n\n\nThen you can see that the updated version number in package.json will look like\nthis: 0.1.2-next.0.\n\nFinally, if you don't need to do a pre-release anymore, be sure to run the\nmodern pre exit command to exit the pre-release state and to release the\nofficial version when you run the modern bump command again.","frontmatter":{"sidebar_position":7},"version":""},{"id":23,"title":"Testing Projects","routePath":"/module-tools/en/guide/basic/test-your-project","lang":"en","toc":[{"text":"Prerequisites and conventions","id":"prerequisites-and-conventions","depth":2,"charIndex":52},{"text":"Run the tests","id":"run-the-tests","depth":2,"charIndex":745},{"text":"Usage Configuration","id":"usage-configuration","depth":2,"charIndex":1015},{"text":"Test example","id":"test-example","depth":2,"charIndex":1160},{"text":"Common modules","id":"common-modules","depth":3,"charIndex":1176},{"text":"Components","id":"components","depth":3,"charIndex":1781}],"domain":"","content":"#\n\nThis chapter will describe how to test modules.\n\n\nPrerequisites and conventions#\n\nTo use the testing features of the project, you need to make sure that the\nproject contains the dependency: \"@modern-js/plugin-testing\" , which can be done\nwith modern new.\n\nIn Modern.js Module, the following conventions are in place for test cases, or\nfiles for writing tests:\n\n * The tests directory in the project directory is the directory for test cases\n and test files, no support for changing the directory for running test cases.\n * Files with the suffix .test.[tj]sx? are automatically recognized as test\n files by default.\n * Other . [tj]sx? suffixes are recognized as normal files that can be used as\n test utils files or for other purposes.\n\n\nRun the tests#\n\nOnce the dependencies are prepared and we know where to write the test cases, we\ncan execute the tests with the following command:\n\nmodern test\n\n// Update snapshot\nmodern test --updateSnapshot\n\n\nAfter execution, you will see the results of the test:\n\n\n\n\nUsage Configuration#\n\nModern.js Module provides the following configurations for testing.\n\n * testing\n\nYou can add it in modern.config.(j|t)s.\n\n\nTest example#\n\n\nCommon modules#\n\nFor common modules, we can use the test function as follows:\n\n * First is the code of the module:\n\nexport default function () {\n return 'hello world';\n}\n\n\n * Then in the test file, we can import source code as the following way. Where\n @ points to the source directory, defined in tests/tsconfig.json in the\n initialization project.\n\n\n\ndescribe('default cases', () => {\n test('Have returns', () => {\n const drink = jest.fn(main);\n drink();\n expect(drink).toHaveReturned();\n });\n});\n\n\n * Finally we can execute modern test.\n\npnpm test\n## or\nyarn test\n## or\nnpm run test\n\n\n\nComponents#\n\nFor components, Modern.js's Runtime API provides functionality for testing UI\ncomponents, which is provided by @modern-js/runtime/testing.\n\nTIP\n\nIf you need to use the Runtime API, then you can turn it on via microgenerator.\n\n * First is the code of the component:\n\nexport const default () {\n return (\n \nThis is a UI Component\n );\n}\n\n\n * Then in the test file, we can import source code as the following way. Where\n @ points to the source directory, defined in tests/tsconfig.json in the\n initialization project.\n\n\n\n\n\ndescribe('default cases', () => {\n test('Rendered', () => {\n render();\n expect(screen.getByText('This is a UI Component')).toBeInTheDocument();\n });\n});\n\n\n * Finally we can execute modern test.\n\npnpm test\n## or\nyarn test\n## or\nnpm run test\n","frontmatter":{"sidebar_position":6},"version":""},{"id":24,"title":"Using the Microgenerator","routePath":"/module-tools/en/guide/basic/use-micro-generator","lang":"en","toc":[{"text":"Test","id":"test","depth":2,"charIndex":431},{"text":"Storybook","id":"storybook","depth":2,"charIndex":908},{"text":"Tailwind CSS Support","id":"tailwind-css-support","depth":2,"charIndex":1544},{"text":"Modern.js Runtime API","id":"modernjs-runtime-api","depth":2,"charIndex":1829}],"domain":"","content":"#\n\nModern.js Module provides the Microgenerator tool, which allows for the current\nproject to.\n\n * add new directories and files\n * Modify the contents of the package.json file\n * Execute commands\n\nThus with these capabilities, Microgenerator can enable additional feature\nfunctionality for the project.\n\nThe microgenerator can be started via modern new. The current Microgenerator\nfeatures supported by the Modern.js Module are:\n\n\nTest#\n\nWhen we want to test some modules, we can enable the test feature. When this\nfeature is enabled, a tests directory and related files will be created in the\nproject directory, and a new \"@modern-js/plugin-testing\" dependency will be\nadded to package.json.\n\nTIP\n\nAfter successfully enabling it, you will be prompted to manually add a code\nsimilar to the one below to the configuration.\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), testingPlugin()],\n});\n\n\n\nStorybook#\n\nThe Storybook feature can be enabled when we want to debug a component or a\ncommon module. When this feature is enabled, the stories directory and related\nfiles are created in the project directory, and a new\n\"@modern-js/plugin-storybook\" dependency is added to package.json.\n\nTIP\n\nAfter successfully enabling it, you will be prompted to manually add a code\nsimilar to the one below to the configuration.\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), storybookPlugin()],\n});\n\n\nFor more information on how to start Storybook and how to use it, check out the\nfollowing link.\n\n * modern dev\n * using Storybook\n\n\nTailwind CSS Support#\n\nTailwind CSS is a CSS framework and design system based on Utility Class, which\ncan quickly add common styles to components, and support flexible extension of\ntheme styles.\n\nIf you want to use Tailwind CSS for a project, you can refer to \"Using Tailwind\nCSS\".\n\n\nModern.js Runtime API#\n\nModern.js provides Runtime API capabilities that can only be used in the\nModern.js application project environment. If you need to develop a component\nfor use in a Modern.js application environment, then you can turn on this\nfeature and the microgenerator will add the \"@modern-js/runtime\" dependency.\n\nAlso, the Storybook debugging tool will determine if the project needs to use\nthe Runtime API by checking the project's dependencies and providing the same\nRuntime API runtime environment as the Modern.js application project.\n\nTIP\n\nAfter successfully enabling it, you will be prompted to manually add a code\nsimilar to the one below to the configuration.\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), runtime()],\n});\n","frontmatter":{"sidebar_position":4},"version":""},{"id":25,"title":"Using Storybook","routePath":"/module-tools/en/guide/basic/using-storybook","lang":"en","toc":[{"text":"Debugging code","id":"debugging-code","depth":2,"charIndex":682},{"text":"Referencing component products","id":"referencing-component-products","depth":3,"charIndex":1322},{"text":"Referencing component source code","id":"referencing-component-source-code","depth":3,"charIndex":3382},{"text":"Configure Storybook","id":"configure-storybook","depth":2,"charIndex":4225},{"text":"Building Storybook Products","id":"building-storybook-products","depth":2,"charIndex":5155},{"text":"Use Tailwind CSS with Storybook","id":"use-tailwind-css-with-storybook","depth":2,"charIndex":5542}],"domain":"","content":"#\n\nFirst of all, if you haven't read the following, take a few minutes to\nunderstand it first.\n\n * use micro-generator to enable Storybook debugging\n * modern dev\n\nStorybook is a tool dedicated to component debugging, providing around component\ndevelopment.\n\n * Develop UIs that are more durable\n * Test UIs with less effort and no flakes\n * Document UI for your team to reuse\n * Share how the UI actually works\n * Automate UI workflows\n\nSo Storybook is a complex and powerful tool.\n\nModern.js Module is integrated with Storybook, so you can pretty much follow the\nofficial Storybook documentation. However, there are still a few things to keep\nin mind, which are explained below.\n\n\nDebugging code#\n\nThe project code needs to be introduced during the debugging process and can\ncurrently be introduced in two ways:\n\n * Use of project products\n * Using the project source code\n\nWe recommend using the first \"referenced project product\" approach. Because it\nis closer to the real usage scenario, not only can we debug the component\nfunctionality, but also verify the correctness of the build product. However, we\ncan also refer to the source code when testing the project functionality and\nrefer to the project package name when verifying the project product.\n\nNext, we will talk about how to use each of these two methods.\n\n\nReferencing component products#\n\nIf the TypeScript project foo exists. Make sure the main and types of\npackage.json values are real paths.\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/types/index.d.ts\"\n}\n\n\nThe source code of the foo project:\n\nexport const content = 'hello world';\n\n\nMake sure that the paths configuration pointing to the project root is set in\nstories/tsconfig.json. The key of paths is the same as the project name.\n\n{\n \"extends\": \"../tsconfig.json\",\n \"include\": [\"./\"],\n \"compilerOptions\": {\n \"jsx\": \"preserve\",\n \"baseUrl\": \".\",\n \"paths\": {\n \"foo\": [\"../\"]\n }\n }\n}\n\n\nReferenced directly in Story code by the project name:\n\n\n\nconst Component = () => \nthis is a Story Component {content};\n\nexport const YourStory = () => ;\n\nexport default {\n title: 'Your Stories',\n};\n\n\nFinally, when executing the command, first start the source build in listening\nmode and then start Storybook debugging.\n\n## Source Code Build\nmodern build --watch\n\n\n## Storybook Debug\nmodern dev storybook\n\n\nIf, during development, you encounter a situation where the type definition is\nnot available in real time, at that point.\n\nFor pnpm projects, package.json can be modified as follows.\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./src/index.ts\",\n \"publishConfig\": {\n \"types\": \"./dist/index.d.ts\",\n }\n}\n\n\n> For the use of pnpm's publishConfig, you can read the following link.\n\nFor npm and Yarn projects, the values of types of package.json can only be\nchanged manually in development phase and release phase.\n\nSo why is it possible to reference the product directly?\n\n 1. execute modern build --watch command before executing modern dev storybook\n command to ensure the existence of project build products.\n 2. Add processing logic inside Storybook to ensure that the project's product\n paths can be parsed according to package.json, based on the\n compilerOptions.paths configuration in the tsconfig.json file or (in JS\n projects) directly with the project name as an alias.\n\n\nReferencing component source code#\n\nReferencing component source code can be done by means of relative paths to:\n\n\n\nconst Component = () => \nthis is a Story Component {content};\n\nexport const YourStory = () => ;\n\nexport default {\n title: 'Your Stories',\n};\n\n\nWhy is the source code approach not recommended\n\nNot only is it impossible to verify that the component product is correct using\nthe component source code, but also some of the configurations supported by\nModern.js Module for building the product cannot be fully translated into\nStorybook internal configuration. If some of the configurations cannot be\nconverted to each other, there will be unintended results during Storybook\ndebugging.\n\nModern.js Module is based on esbuild, while Storybook is based on Webpack, and\nesbuild's configuration is not fully compatible with Webpack.\n\n\nConfigure Storybook#\n\nStorybook is officially configured for projects through a folder called\n.storybook, which contains various configuration files. In Modern.js Module,\nStorybook configuration files can be added to the config/storybook directory of\nthe project.\n\nFor more information on how to use the various Storybook configuration files,\nsee the following links:\n\n * Configure Storybook\n\nBut there are some limitations to Storybooking in a module project:\n\n * It is currently not possible to change the location of the Story file, i.e.,\n you cannot change the stories configuration in the main.js file.\n * Currently you cannot modify Webpack and Babel related configuration, i.e. you\n cannot modify webpackFinal and babel configuration in the main.js file.\n\nIn the future we will consider whether these configurations can be allowed to be\nmodified, but for now we are limiting their use to reduce unpredictable issues.\n\n\nBuilding Storybook Products#\n\nIn addition to Storybook debugging of components or common modules, you can also\nperform Storybook build tasks with the following commands.\n\nmodern build --platform storybook\n\n\nFor the modern build --platform command you can see.\n\n * modern build\n\nAfter the build is complete, you can see the build artifacts files in the\ndist/storybook-static directory.\n\n\nUse Tailwind CSS with Storybook#\n\nIf you need to use Tailwind CSS in the stories directory, make sure that the\nTailwind CSS configuration for your current project includes the stories\ndirectory.\n\nTaking the tailwind.config.ts file as an example, you need to configure the\nfollowing content:\n\nexport default {\n content: [\n './src/**/*.{js,jsx,ts,tsx}',\n+ './stories/**/*.{js,jsx,ts,tsx}',\n ],\n};\n","frontmatter":{"sidebar_position":5},"version":""},{"id":26,"title":"Developing Components","routePath":"/module-tools/en/guide/best-practices/components","lang":"en","toc":[{"text":"Initialize the project","id":"initialize-the-project","depth":2,"charIndex":93},{"text":"Debugging code with Storybook","id":"debugging-code-with-storybook","depth":2,"charIndex":881},{"text":"Developing Styles","id":"developing-styles","depth":2,"charIndex":980},{"text":"CSS/PostCSS","id":"csspostcss","depth":3,"charIndex":1186},{"text":"Less","id":"less","depth":3,"charIndex":1831},{"text":"Sass/Scss","id":"sassscss","depth":3,"charIndex":2144},{"text":"Tailwind CSS","id":"tailwind-css","depth":3,"charIndex":2486},{"text":"CSS Modules","id":"css-modules","depth":3,"charIndex":2560},{"text":"Configuring build products","id":"configuring-build-products","depth":2,"charIndex":2999},{"text":"Testing components","id":"testing-components","depth":2,"charIndex":3933},{"text":"Releasing components","id":"releasing-components","depth":2,"charIndex":4036}],"domain":"","content":"#\n\nThis chapter will describe how to develop component projects using the Modern.js\nModule.\n\n\nInitialize the project#\n\n 1. It is recommended to use the @modern-js/create command to initialize an npm\n project.\n\nnpx @modern-js/create@latest components-project\n\n? Please select the type of project you want to create: Npm Module\n? Please fill in the project name: components-demo\n? Please select the programming language: TS\n? Please select the package manager: pnpm\n\n\n 2. The initialized directory structure:\n\n.\n├── README.md\n├── node_modules/\n├── dist/\n├── modern.config.ts\n├── package.json\n├── pnpm-lock.yaml\n├── src\n│ ├── index.ts\n│ └── modern-app-env.d.ts\n└── tsconfig.json\n\n\n 3. Finally, modify the file suffix and content of ./src/index.ts as follows,\n and the initialization of the component project is completed.\n\nexport default () => {\n return \nhello world;\n};\n\n\n\nDebugging code with Storybook#\n\nPlease refer to \"Using Storybook\" to debug code using Storybook.\n\n\nDeveloping Styles#\n\nNext we can add styles to the component.\n\nThe following capabilities are currently supported for developing styles.\n\n * CSS/PostCSS\n * Less\n * Scss/Sass\n * Tailwind CSS\n * CSS Modules\n\n\nCSS/PostCSS#\n\nModern.js Module supports PostCSS and has the following built-in PostCSS\nplugins.\n\n * flexbugs-fixes\n * custom-properties\n * initial\n * page-break\n * font-variant\n * media-minmax\n * nesting\n\nSo we can create .css files in our projects and use the syntax support and\ncapabilities provided by these plugins directly in our css files.\n\n * Source Code:\n\na,\nb {\n color: red;\n\n /* \"&\" comes first */\n & c,\n & d {\n color: white;\n }\n\n /* \"&\" comes later, requiring \"@nest\" */\n @nest e & {\n color: yellow;\n }\n}\n\n\n * CSS artifact:\n\na,\nb {\n color: red;\n}\na c,\nb c,\na d,\nb d {\n color: white;\n}\ne a,\ne b {\n color: yellow;\n}\n\n\n\nLess#\n\nModern.js Module supports development styles using Less.\n\n> The current built-in Less version is v4.1.3\n\n * Source Code:\n\n@bg: black;\n@bg-light: boolean(luma(@bg) > 50%);\n\ndiv {\n background: @bg;\n color: if(@bg-light, black, white);\n}\n\n\n * Less artifact:\n\ndiv {\n background: black;\n color: white;\n}\n\n\n\nSass/Scss#\n\nModern.js Module supports developing styles using Scss/Sass.\n\n> The current built-in Sass version is v1.54.4\n\n * Source code:\n\n$font-stack: Helvetica, sans-serif;\n$primary-color: #333;\n\nbody {\n font: 100% $font-stack;\n color: $primary-color;\n}\n\n\n * Less artifact:\n\nbody {\n font: 100% Helvetica, sans-serif;\n color: #333;\n}\n\n\n\nTailwind CSS#\n\nPlease refer to \"Using Tailwind CSS\" for detailed usage.\n\n\nCSS Modules#\n\nModern.js Module supports the development of styles using CSS Modules. By\ndefault, the following files are recognized as CSS Module files.\n\n * .module.css\n * .module.less\n * .module.scss\n * .module.sass\n\nIf you need to configure CSS Modules, you can check out the API at\n\n * style.autoModules\n * style.modules\n\nThe following is a code example.\n\n\n\nexport default () => {\n return \nhello world;\n};\n\n\n.btn {\n color: blue;\n}\n\n\n\nConfiguring build products#\n\nBased on most scenarios of component project usage, it is recommended to use the\nnpm-component build preset. This preset yields a output directory structure of\n\n.\n├── dist\n│ ├── es\n│ ├── lib\n│ └── types\n\n\n * . /dist/es: Contains bundleless artifacts in ES modules format that support\n the es6 syntax.\n * . /dist/lib: Contains bundleless artifacts in CommonJS format with support\n for es6 syntax.\n * . /dist/types: Contains the types file.\n\nThe buildPreset can be configured manually if there is a requirement to use\nsyntax support, and supports modifying the supported syntax by adding a suffix\nto npm-component.\n\nexport default defineConfig({\n buildPreset: 'npm-component-es2019',\n});\n\n\nIf you have special needs for the build artifacts directory structure, you can\nuse the buildConfig API, which can be used by the following documentation.\n\n * modify-output-product\n * in-depth-about-build\n\n\nTesting components#\n\nFor more information on how to test components, please refer to \"Test project\".\n\n\nReleasing components#\n\nIt is recommended to use the version release feature provided by Modern.js\nModule. You can refer to the \"Version Management and Release\" section for more\ninformation.","frontmatter":{"sidebar_position":1},"version":""},{"id":27,"title":"Using Tailwind CSS","routePath":"/module-tools/en/guide/best-practices/use-tailwindcss","lang":"en","toc":[{"text":"Enabling Tailwind CSS","id":"enabling-tailwind-css","depth":2,"charIndex":252},{"text":"Configuring Tailwind CSS","id":"configuring-tailwind-css","depth":2,"charIndex":1573},{"text":"Tailwind CSS Autocomplete","id":"tailwind-css-autocomplete","depth":3,"charIndex":2541},{"text":"Build Modes","id":"build-modes","depth":2,"charIndex":3112},{"text":"Bundle Mode","id":"bundle-mode","depth":3,"charIndex":3380},{"text":"Bundleless Mode","id":"bundleless-mode","depth":3,"charIndex":4149},{"text":"Class Name Prefix","id":"class-name-prefix","depth":2,"charIndex":4450},{"text":"Usage Guide","id":"usage-guide","depth":2,"charIndex":5064},{"text":"HTML Class Names","id":"html-class-names","depth":3,"charIndex":5126},{"text":"@apply","id":"apply","depth":3,"charIndex":5562},{"text":"Sass","id":"sass","depth":4,"charIndex":5866},{"text":"Less","id":"less","depth":4,"charIndex":6157},{"text":"About designSystem config","id":"about-designsystem-config","depth":2,"charIndex":6796}],"domain":"","content":"#\n\nTailwind CSS is a CSS framework and design system based on Utility Class, which\ncan quickly add common styles to components, and support flexible extension of\ntheme styles.\n\nModern.js Module supports developing component styles using Tailwind CSS.\n\n\nEnabling Tailwind CSS#\n\nTo use Tailwind CSS in Modern.js Module, you can follow the steps below:\n\n 1. Run pnpm run new in the root directory of your project and make the\n following selections:\n\n? Please select the operation you want: Enable features\n? Please select the feature name: Enable Tailwind CSS\n\n\nAfter successful initialization, you will see the following additions to the\npackage.json file:\n\n{\n \"dependencies\": {\n \"tailwindcss\": \"^3.0.0\"\n },\n \"devDependencies\": {\n \"@modern-js/plugin-tailwindcss\": \"^2.0.0\"\n }\n}\n\n\n 2. Register the Tailwind plugin in modern.config.ts:\n\n\n\nexport default defineConfig({\n plugins: [..., tailwindcssPlugin()],\n});\n\n\n 3. Create a index.css file and add the following code:\n\n/* base and components are optional, please add as appropriate */\n@tailwind base;\n@tailwind components;\n@tailwind utilities;\n\n\nINFO\n\nDepending on your needs, you can selectively import the CSS styles provided by\nTailwind CSS. Please refer to the @tailwind documentation for detailed usage of\nthe @tailwind directive.\n\n 4. Import the index.css file, for example, add the following code in the root\n component src/index.jsx:\n\nimport './index.css';\n\n\n 5. Now you can use the Utility Classes provided by Tailwind CSS in your\n components:\n\nconst Hello = () => (\n \n\n \n\nhello world\n \n);\n\n\n\nConfiguring Tailwind CSS#\n\nIn Modern.js Module, you have two ways to configure Tailwind CSS:\n\n 1. Using the tailwind.config.{ts,js} file, which follows the official usage of\n Tailwind CSS. Please refer to \"Tailwind CSS - Configuration\" for more\n details.\n\n\n\nexport default {\n content: ['./src/**/*.{js,jsx,ts,tsx}'],\n} as Config;\n\n\nTIP\n\nPlease upgrade Modern.js to version >= 2.33.0 to support automatic reading of\ntailwind.config.{ts,js} files.\n\n 2. Using the style.tailwindcss configuration option. This is the old way of\n configuring Tailwind CSS, and we recommend using the tailwind.config.{ts,js}\n file for configuration.\n\nexport default {\n tools: {\n tailwindcss: {\n content: ['./src/**/*.{js,jsx,ts,tsx}'],\n },\n },\n};\n\n\nIf you are using both the tailwind.config.{ts,js} file and style.tailwindcss\noption, the configuration defined in style.tailwindcss will take precedence and\noverride the content defined in tailwind.config.{ts,js}.\n\n\nTailwind CSS Autocomplete#\n\nTailwind CSS provides an official extension called Tailwind CSS IntelliSense for\nautocompletion of Tailwind CSS class names, CSS functions, and directives in VS\nCode.\n\nYou can follow the steps below to enable the autocomplete feature:\n\n 1. Install the Tailwind CSS IntelliSense extension in VS Code.\n 2. If the root directory of your project does not have a\n tailwind.config.{ts,js} file, you need to create one and write the Tailwind\n CSS configuration for your current project. Otherwise, the IDE plugin will\n not work correctly.\n\n\nBuild Modes#\n\nWhen using Tailwind CSS, please note that there are significant differences\nbetween the bundle and bundleless modes in terms of the build artifacts.\n\nTIP\n\nFor definitions of bundle and bundleless, please refer to the \"In-depth\nunderstanding of build\".\n\n\nBundle Mode#\n\nIn Bundle mode, a separate CSS file is generated, and the JS output does not\nautomatically reference the CSS output file.\n\n * Source code:\n\nimport './index.css';\n\nexport default () => {\n return \nhello world;\n};\n\n\n * Output code:\n\n// src/index.tsx\n\nvar src_default = () => {\n return /* @__PURE__ */ jsx('div', {\n className: 'bg-black',\n children: 'hello world',\n });\n};\nexport { src_default as default };\n\n\n.bg-black {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity));\n}\n/** some more... */\n\n\nIf you need to inject styles into the JS artifact, you can enable the\nstyle.inject option.\n\nIf you haven't enabled style.inject, you can also let users manually import the\nCSS file:\n\nimport 'your-package/dist/es/index.css';\n\n\n\nBundleless Mode#\n\nIn bundleless mode, the CSS file is automatically imported in the artifact code\nwithout the need for additional processing.\n\n * Output code:\n\n\nimport './index.css';\nexport default () =>\n /* @__PURE__ */ _jsx('div', {\n className: 'bg-black',\n children: 'hello world',\n });\n\n\n\nClass Name Prefix#\n\nYou can add a class name prefix using the prefix option provided by Tailwind\nCSS. This helps avoid potential class name conflicts, such as when different\nversions of Tailwind CSS are used in different parts of an application or\nmodule.\n\nFor example, you can add the foo- prefix using the prefix option in\ntailwind.config.js:\n\nmodule.exports = {\n prefix: 'foo-',\n};\n\n\n * Source Code:\n\nimport './index.css';\n\nexport default () => {\n return \nhello world;\n};\n\n\n * Output Code:\n\n.foo-bg-black {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity));\n}\n/** some more... */\n\n\n\nUsage Guide#\n\nHere are some usage examples of Tailwind CSS.\n\n\nHTML Class Names#\n\nTailwind CSS supports adding styles to HTML tags through class names. When using\nHTML class names, please note that the corresponding CSS styles of Tailwind CSS\nmust be imported in advance.\n\nimport './index.css';\n\nexport default () => {\n return \nhello world;\n};\n\n\nGenerated styles (after bundling):\n\n.bg-black {\n --tw-bg-opacity: 1;\n background-color: rgba(0, 0, 0, var(--tw-bg-opacity));\n}\n/** some more... */\n\n\n\n@apply#\n\nTailwind CSS provides the @apply directive, which allows us to inline the styles\nprovided by Tailwind CSS into our own styles.\n\n@apply can be used in CSS, Less, and Sass.\n\n.btn {\n @apply font-bold py-2 px-4 rounded;\n}\n\n\nHowever, there are some considerations when using it with Less and Sass:\n\nSass#\n\nWhen using Tailwind with Sass and there is an !important after @apply,\ninterpolation should be used to ensure Sass compiles correctly.\n\n * Won't work as expected:\n\n.alert {\n @apply bg-red-500 !important;\n}\n\n\n * Will work as expected:\n\n.alert {\n @apply bg-red-500 #{!important};\n}\n\n\nLess#\n\nWhen using Tailwind with Less, you cannot nest Tailwind's @screen directive.\n\n * Won't work as expected:\n\n.card {\n @apply rounded-none;\n\n @screen sm {\n @apply rounded-lg;\n }\n}\n\n\n * Instead, use regular media queries and the theme() function to reference your\n screen sizes or simply avoid nesting your @screen directive.\n\n// Use a regular media query and theme()\n.card {\n @apply rounded-none;\n\n @media (min-width: theme('screens.sm')) {\n @apply rounded-lg;\n }\n}\n\n\n// Use the @screen directive at the top-level\n.card {\n @apply rounded-none;\n\n @media (min-width: theme('screens.sm')) {\n @apply rounded-lg;\n }\n}\n\n\n\nAbout designSystem config#\n\ndesignSystem is a deprecated configuration option in Modern.js Module.\n\nStarting from Modern.js Module v2.33.0, you can use the theme configuration\noption of Tailwind CSS as a replacement for designSystem. It is no longer\nnecessary to split the theme configuration and set it on designSystem.\n\n * Previous usage:\n\nconst { theme, ...rest } = tailwindConfig;\n\nexport default {\n style: {\n tailwindcss: rest,\n },\n designSystem: theme,\n};\n\n\n * Current usage:\n\nexport default {\n style: {\n tailwindcss: tailwindConfig,\n },\n};\n","frontmatter":{"sidebar_position":2},"version":""},{"id":28,"title":"Build FAQ","routePath":"/module-tools/en/guide/faq/build","lang":"en","toc":[{"text":"Product FAQ","id":"product-faq","depth":2,"charIndex":3},{"text":"Initialization of Class Fields","id":"initialization-of-class-fields","depth":3,"charIndex":18},{"text":"babel-plugin-lodash treats the introduced lodash as undefined","id":"babel-plugin-lodash-treats-the-introduced-lodash-as-undefined","depth":3,"charIndex":2081},{"text":"Exceptions FAQ","id":"exceptions-faq","depth":2,"charIndex":2772},{"text":"Dynamic require of \\\"react\\\" is not supported","id":"dynamic-require-of-react-is-not-supported","depth":3,"charIndex":-1},{"text":"Problem Description","id":"problem-description","depth":4,"charIndex":2836},{"text":"Solution","id":"solution","depth":4,"charIndex":3139},{"text":"Reference Links","id":"reference-links","depth":4,"charIndex":3735},{"text":"During compilation, an error was reported in the less file of a component library:\\'Operation on an invalid type\\'","id":"during-compilation-an-error-was-reported-in-the-less-file-of-a-component-libraryoperation-on-an-invalid-type","depth":3,"charIndex":-1},{"text":"Bundle DTS failed","id":"bundle-dts-failed","depth":3,"charIndex":5274},{"text":"Error reported for defineConfig function type: If there is no reference to \\\"...\\\" then the inferred type of \\\"default\\\" cannot be named","id":"error-reported-for-defineconfig-function-type-if-there-is-no-reference-to--then-the-inferred-type-of-default-cannot-be-named","depth":3,"charIndex":-1},{"text":"Other FAQ","id":"other-faq","depth":2,"charIndex":6300},{"text":"Add additional compilation feature","id":"add-additional-compilation-feature","depth":3,"charIndex":6313},{"text":"Support for generating TypeScript declaration files for CSS Modules","id":"support-for-generating-typescript-declaration-files-for-css-modules","depth":3,"charIndex":7224}],"domain":"","content":"#\n\n\nProduct FAQ#\n\n\nInitialization of Class Fields#\n\nTypeSript provides the useDefineForClassFields configuration to control the\nconversion handling for public class fields.\n\nIf we have a piece of code:\n\nclass C {\n foo = 100;\n bar: string;\n}\n\n\nWhen useDefineForClassFields is false, then the compiled code will look like:\n\nclass C {\n constructor() {\n this.foo = 100;\n }\n}\n\n\nWhen useDefineForClassFields is true, then the compiled code will look like:\n\nclass C {\n constructor() {\n Object.defineProperty(this, 'foo', {\n enumerable: true,\n configurable: true,\n writable: true,\n value: 100,\n });\n Object.defineProperty(this, 'bar', {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0,\n });\n }\n}\n\n\nAlso the default value of this configuration will change depending on the target\nconfiguration of tsconfig.json: When target is ES2022 or higher, then\nuseDefineForClassFields is configured to true by default, otherwise it defaults\nto false.\n\nFor more information on this configuration of TypeScript, you can refer to the\nfollowing link:\n\n * The useDefineForClassFields Flag and The declare Property Modifier\n\nThe Modern.js Module will currently process according to the following logic:\n\n 1. The first decision to enable this feature inside Modern.js Module is based\n on the useDefineForClassFields configuration in tsconfig.json of the current\n project. Currently, only the contents of the tsconfig.json file under the\n current project path will be read, and the final tsconfig configuration\n based on the extends configuration is not supported at this time.\n 2. If the useDefineForClassFields configuration of tsconfig.json is not\n detected, the default value is determined based on the target configuration\n of tsconfig.json. If target is greater than ES2022 (including EsNext), then\n useDefineForClassFields defaults to true, otherwise it is false.\n 3. If the target of tsconfig.json is not detected, it is processed according to\n the value of useDefineForClassFields as true.\n\n\nbabel-plugin-lodash treats the introduced lodash as undefined#\n\nThis problem occurs when using something like the following:\n\n\n\nexport const libs = {\n _: Lodash,\n};\n\n\nCurrent related issues on the babel-plugin-lodash Github:\n\n * #235\n\nThe solution to this problem is to remove babel-plugin-lodash, since the plugin\nis not needed for on-demand referencing at this point and using it would have\nside effects.\n\nA similar situation occurs with babel-plugin-import. If there is code like the\nfollowing:\n\n\n\nexport const libs = {\n comps: Comps,\n};\n\n\nIn this case babel-plugin-import may also cause Comps to become undefined. So\nyou need to remove the corresponding babel-plugin-import as well.\n\n\nExceptions FAQ#\n\n\nDynamic require of \"react\" is not supported#\n\nProblem Description#\n\nWhen the product format in the product configuration of the build is ES modules.\n\nexport default defineConfig({\n buildConfig: {\n format: 'esm',\n },\n});\n\n\nIf you import a cjs product from a third-party npm package, the resulting\nproduct may not work properly under webpack.\n\n\n\nSolution#\n\n 1. First you need to find which third-party package is causing the problem. For\n example, if the error message points to the react package, then look for a\n third-party package that has code like require('react') in it. For example\n react-draggable, which only contains cjs products, then the problem is\n localized to the react-draggable package.\n 2. Then we need to exclude this package with the following configuration, i.e.\n not package problematic third-party packages.\n\nexport default defineConfig({\n buildConfig: {\n externals: ['react-draggable'],\n },\n});\n\n\nReference Links#\n\n * When using esbuild with external react I get Dynamic require of \"react\" is\n not supported\n\n\nDuring compilation, an error was reported in the less file of a component\nlibrary:'Operation on an invalid type'#\n\nThis is probably because the component library depends on Less version v3, while\nModern.js Module defaults to v4. v3 and v4 have a Break Change in the math\nconfiguration, check this link for details.\n\nTherefore, if a component library like this is used in the source code:\n\nbuildPreset is used in the build configuration, make the following changes:\n\nmodule.exports = {\n buildPreset({ extendPreset }) {\n return extendPreset('your-build-preset', {\n style: {\n less: {\n lessOptions: {\n math: 'always',\n },\n },\n },\n });\n },\n};\n\n\nOr, if a custom buildConfig is used, modify it as follows:\n\nmodule.exports = {\n buildConfig: {\n style: {\n less: {\n lessOptions: {\n math: 'always',\n },\n },\n },\n },\n};\n\n\nIf you are using a component like this in Storybook, you will need to modify the\ndebugging configuration of Storybook:\n\nmodule.exports = {\n dev: {\n storybook: {\n webpackChain(chain, { CHAIN_ID }) {\n chain.module\n .rule(CHAIN_ID.RULE.LESS)\n .use(CHAIN_ID.USE.LESS)\n .tap(options => {\n options.lessOptions = {\n ...options.lessOptions,\n math: 'always',\n };\n return options;\n });\n },\n },\n },\n};\n\n\n\nBundle DTS failed#\n\nNormally, the type file output with tsc is loose. Modern.js Module not only\nsupports outputting loose type file products, but also supports packing type\nfiles, which allows you to package these loose type files and third-party\ndependent type files into one file.\n\nHowever, there is a risk in packaging the type files of third-party\ndependencies, because there are cases where the type files of third-party\ndependencies cannot be packaged.\n\nSo when you encounter a Bundle DTS failed error message during the Modern.js\nModule build, you can observe that the error message comes from a third-party\ndependency. Try setting dts.respectExternal to false to disable the behavior of\npacking type files of third-party dependencies.\n\n\nError reported for defineConfig function type: If there is no reference to \"...\"\nthen the inferred type of \"default\" cannot be named#\n\nCheck if the include configuration exists in the project's tsconfig.json file,\nand if not, try adding the following:\n\n{\n \"include\": [\"src\"]\n}\n\n\n\nOther FAQ#\n\n\nAdd additional compilation feature#\n\nThe Modern.js Module is based on the esbuild implementation, so if you have\nspecial needs or want to add additional compilation capabilities, you can do so\nby implementing the esbuild plugin.\n\nThe Modern.js Module provides esbuildOptions configuration to allow modification\nof Modern.js's internal esbuild configuration, so that custom esbuild plugins\ncan be added via this configuration:\n\n\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.plugins = [myEsbuildPlugin, ...options.plugins];\n return options;\n },\n },\n});\n\n\nWhen adding an esbuild plugin, please note that you need to add the plugin at\nthe beginning of the plugins array. This is because the Modern.js Module is also\nintegrated into the entire build process through an esbuild plugin. Therefore,\ncustom plugins need to be registered with higher priority.\n\n\nSupport for generating TypeScript declaration files for CSS Modules#\n\n * First Solution: typed-css-modules\n * Second Solution: postcss-modules-dts\n\n\n\nexport default defineConfig(async () => {\n const { dts } = await import(\"@guanghechen/postcss-modules-dts\");\n return {\n buildConfig: {\n style: {\n modules: { ...dts },\n },\n },\n // custom config\n }\n});\n","frontmatter":{},"version":""},{"id":29,"title":"FAQ","routePath":"/module-tools/en/guide/faq/","lang":"en","toc":[],"domain":"","content":"#\n\nHere is a list of all frequently asked questions about Modern.js Module.\n\n * Build FAQ\n * Test FAQ\n * Storybook FAQ","frontmatter":{},"version":""},{"id":30,"title":"Storybook FAQ","routePath":"/module-tools/en/guide/faq/storybook","lang":"en","toc":[{"text":"Storybook v7 Support","id":"storybook-v7-support","depth":2,"charIndex":3},{"text":"Using Storybook Addon or other configurations does not work","id":"using-storybook-addon-or-other-configurations-does-not-work","depth":2,"charIndex":186},{"text":"Cannot find module \\'react-dom/package.json","id":"cannot-find-module-react-dompackagejson","depth":2,"charIndex":-1},{"text":"Unable to locate the specific error message","id":"unable-to-locate-the-specific-error-message","depth":2,"charIndex":880},{"text":"Can`t find any stories is your Storybook","id":"cant-find-any-stories-is-your-storybook","depth":2,"charIndex":1653},{"text":"Storybook Adds Proxy Functionality","id":"storybook-adds-proxy-functionality","depth":2,"charIndex":1953},{"text":"Modify the directory where the Story file exists","id":"modify-the-directory-where-the-story-file-exists","depth":2,"charIndex":2800}],"domain":"","content":"#\n\n\nStorybook v7 Support#\n\nStorybook v7 does not support it yet. Rspack builds are currently planned to be\nsupported in Storybook v7, so progress will be slower.\n\nRelated Issue: #3376.\n\n\nUsing Storybook Addon or other configurations does not work#\n\nModern.js Module is currently using Storybook version v6, if you are using Addon\nversion v7 you may not be able to get the addon to work.\n\nIn addition to the Addon, other configurations may also have differences. For\nexample, if you modify the preview.js configuration file, Storybook v6 is\nwritten differently than v7:\n\n * v6:Document\n * v7:Document\n\n\nCannot find module 'react-dom/package.json#\n\nWhen debug Storybook, the following problem occurs:\n\nERR! Error: Cannot find module 'react-dom/package.json'\n\n\nYou can install the react-dom dependency in the project.\n\n{\n \"devDependencies\": {\n \"react-dom\": \"^17\"\n }\n}\n\n\n\nUnable to locate the specific error message#\n\nSolutions:\n\n 1. Find @storybook/core-server/dist/cjs/dev-server.js\n 2. Find this code: var _await$Promise$all = await Promise.all([preview,\n manager,.\n 3. Modify it:\n\nvar _await$Promise$all = await Promise.all([\n preview.catch(e => console.info(e)),\n manager // TODO #13083 Restore this when compiling the preview is fast enough\n // .then((result) => {\n // if (!options.ci && !options.smokeTest) openInBrowser(address);\n // return result;\n // })\n .catch(previewBuilder.bail)]),\n _await$Promise$all2 = _slicedToArray(_await$Promise$all, 2),\n previewResult = _await$Promise$all2[0],\n managerResult = _await$Promise$all2[1]; // TODO #13083 Remove this when compiling the preview is fast enough\n\n\n\nCan`t find any stories is your Storybook#\n\n\n\nWhen you get a problem like this, you can first open the browser console and\nthere should be some error messages. You can use the error messages to deduce if\nthere is a problem in the code you are writing that is causing Storybook to not\nwork properly.\n\n\nStorybook Adds Proxy Functionality#\n\nStorybook does not provide a solution for this, but there is one in the\nStorybook Issue. In the Modern.js Module, you can:\n\n 1. Add the config/storybook/middleware.js file and initialize the following:\n\n/* eslint-disable filenames/match-exported */\nmodule.exports = function expressMiddleware(router) {\n // router is express router\n // \n // router = new Router();\n};\n\n\n 2. add http-proxy-middleware dependency\n 3. Add proxy routing-related configuration\n\n/* eslint-disable filenames/match-exported */\nconst { createProxyMiddleware } = require(\"http-proxy-middleware\");\n\nmodule.exports = function expressMiddleware (router) {\n router.use('/api', createProxyMiddleware({\n target: \"http://localhost:8000\",\n changeOrigin: true\n }))\n}\n\n\nLink:https://github.com/storybookjs/storybook/issues/11551\n\n\nModify the directory where the Story file exists#\n\nThe directory where Story files are stored cannot be modified at the moment,\nonly the *.stories.(t|j)s(x) and *.stories.md(x) files in the\nyour-project/stories directory are recognized as Story files.","frontmatter":{},"version":""},{"id":31,"title":"Test FAQ","routePath":"/module-tools/en/guide/faq/test","lang":"en","toc":[{"text":"Execute test command with an error TypeError: Cannot read property \\'testEnvironmentOptions\\' of undefined","id":"execute-test-command-with-an-error-typeerror-cannot-read-property-testenvironmentoptions-of-undefined","depth":3,"charIndex":-1}],"domain":"","content":"#\n\n\nExecute test command with an error TypeError: Cannot read property\n'testEnvironmentOptions' of undefined#\n\n\n\nYou can check whether other projects in Monorepo have jest-environment-jsdom\ndependencies and unify them with the overrides provided by Monorepo.","frontmatter":{},"version":""},{"id":32,"title":"Quick Start","routePath":"/module-tools/en/guide/intro/getting-started","lang":"en","toc":[{"text":"3 minute demo","id":"3-minute-demo","depth":2,"charIndex":3},{"text":"Create new project","id":"create-new-project","depth":3,"charIndex":210},{"text":"Add to an existing project","id":"add-to-an-existing-project","depth":3,"charIndex":1097},{"text":"Core npm Package","id":"core-npm-package","depth":3,"charIndex":1934},{"text":"View official example","id":"view-official-example","depth":3,"charIndex":2693},{"text":"Let\\'s get started","id":"lets-get-started","depth":2,"charIndex":-1}],"domain":"","content":"#\n\n\n3 minute demo#\n\nWant to experience Modern.js Module in action? The only prerequisite you need is\nNode.js LTS and make sure your Node version is >= 14.18.0.We recommend using the\nLTS version of Node.js 18.\n\n\nCreate new project#\n\nIf you want to create a complete Modern.js Module, you can execute the following\ncommand:\n\nnpx @modern-js/create your-project-dir-name\n\n\nINFO\n\nExecute npx @modern-js/create -h for more command line arguments\n\nNext, in the issue interaction, follow the options below.\n\n? Please select the type of project you want to create: Npm Module\n? Please fill in the project name: library\n? Please select the programming language: TS\n? Please select the package manager: pnpm\n\n\n> The project name is the value of the \"name\" field in package.json.\n\nThen the process of initializing the project will start. After the project\ndirectory and files are generated and the dependencies are installed, a complete\nmodule project is created.\n\nWe can start the project build directly with the pnpm build command, and start\nthe build in watching mode with the pnpm build --watch command.\n\n\nAdd to an existing project#\n\nFrom your shell, install the following dependencies in your project.\n\n * @modern-js/module-tools\n * \"typescript\" (omitted if not a TypeScript project)\n\n> If it's a TypeScript project, add the \"typescript\" dependency.\n\n> For projects that use pnpm or the Yarn package manager, just replace npm. pnpm\n> is recommended.\n\nNext, create the modern.config.(t|j)s file in the root of the project.\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n});\n\n\nFinally, add the command \"build\": \"modern build\" to the project's package.json\nfile.\n\n{\n \"scripts\": {\n \"build\": \"modern build\"\n }\n}\n\n\nIf your project has a src/index.(js|jsx) file or both src/index.(ts|tsx) and\ntsconfig.json files, then congratulations you can run the npm run build command\ndirectly to build your project with Modern.js Module.\n\n\nCore npm Package#\n\n@modern-js/module-tools is the core npm package of Modern.js Module, providing\nthe following capabilities:\n\n * It offers commonly used CLI commands such as modern dev, modern build, and\n more.\n * It integrates Modern.js Core, providing capabilities for configuration\n parsing, plugin loading, and more.\n * It integrates esbuild and SWC, providing build capabilities.\n * It integrates some commonly used plugins, such as plugin-lint,\n plugin-changeset, and others.\n\n@modern-js/module-tools is implemented based on the plugin system of Modern.js.\nEssentially, it is a plugin. Therefore, you need to register moduleTools in the\nplugins field of the configuration file:\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n});\n\n\n\nView official example#\n\nIf you want to see the complete project using the Modern.js Module, you can\nexecute the following command.\n\ngit clone https://github.com/web-infra-dev/module-tools-examples\ncd module-tools-example/base\n\n## Execute the build.\npnpm build\n\n## Execute the build in listening mode.\npnpm build --watch\n\n## Start Storybook\npnpm dev storybook\n\n## Test\npnpm test\n\n\n\nLet's get started#\n\nChoose your tutorial scenario...\n\n * I'm a beginner and need to learn basic usage of Modern.js Module.\n * I have learned the basic usage of Modern.js Module and can learn advanced\n usage of Modern.js Module.\n * I need to expand my project capabilities and need to learn how to develop\n plugins for Modern.js Module.","frontmatter":{"sidebar_position":3},"version":""},{"id":33,"title":"Welcome to Modern.js Module","routePath":"/module-tools/en/guide/intro/welcome","lang":"en","toc":[],"domain":"","content":"#\n\nModern.js Module is a modules engineering solution for Modern.js, as well as a\ncore dependency. It allows developers to build, debug, and publish module type\nproject more easily. A module type project can mostly be thought of as an npm\npackage type project, which may be a component, component library or tool\nlibrary project.\n\nIf you are planning to develop a project of the npm package type, then you came\nto the right place! Modern.js provides a professional Modern.js Module. It gives\nyou:\n\n * Simple project initialization: simply execute the npx @modern-js/create\n project-dir command, followed by a few interactive questions, to create a\n complete module type project. The created project also supports the choice of\n two package managers, pnpm and Yarn.\n * Code formatting: In Modern.js Module, you can execute modern lint to format\n the code. The initialized module project includes the ESLint ruleset for\n Modern.js for most scenarios.\n * Comprehensive build capabilities and faster builds: Modern.js Module provides\n high-performance build capabilities based on esbuild and SWC, and provides\n rich configurations for different build scenarios.\n * Storybook debugging tools: Modern.js Module provides Storybook debugging\n tools for debugging module projects. After installing the Storybook plugin\n for Modern.js Module, you can start it with the modern dev storybook command.\n You can use Storybook not only for debugging components, but also for other\n types of modules.\n * Testing capabilities with Jest: When you need to test a module, you can use\n the modern test command of Modern.js Module, which not only integrates with\n Jest, but also provides an API for configuring Jest.\n * Versioning based on Changesets: When you need to record changes to a project,\n you can use the modern change command to generate a Markdown file containing\n the changes; when you need to upgrade a project, you can use the modern bump\n command to analyze and upgrade the version through the Markdown file; when\n you need to release a project, you can use the modern release command to\n release the project; Modern.js Module implements these commands based on\n Changesets.\n * Extensible plugin mechanism: Want to integrate additional debugging tools for\n your project? Or maybe you want to do some extra processing during the build\n process, Modern.js Module provides a plugin mechanism and plugin hooks that\n cover both the dev command and the build command process. You can use them to\n extend the capabilities of your project.\n * Lots more! Modern.js Module will continue to optimize its build and debug\n features in the future. If there are important issues to be solved in module\n project building, or if a mainstream module project debugging tool or pattern\n emerges, then they will probably be supported by Modern.js Module.","frontmatter":{"sidebar_position":1},"version":""},{"id":34,"title":"Why you need Modern.js Module","routePath":"/module-tools/en/guide/intro/why-module-engineering-solution","lang":"en","toc":[],"domain":"","content":"#\n\nYou've probably all experienced it: when developing a component library or tool\nlibrary from scratch, we have to consider not only how to write the code logic\nof the project itself, but also how to build, debug, test, format the code, and\nother things that have nothing to do with the code logic.\n\nFor example, when we consider which builder is used to build the code for a\nmodule project, we might previously consider webpack or Rollup, but now we might\nalso consider esbuild or SWC.\n\nRegardless of which builder is chosen, this is going to be a costly learning\ncurve for developers who are not skilled in the use of these build tools. Even\nif you want to use them quickly, it will take a lot of time and effort.\n\nIn addition to the build, things like providing debugging tools for projects,\nsupporting testing capabilities, adding code format validation, etc. can take a\nlong time and effort for a novice to understand or master them and actually\nserve the current project.\n\nTo ensure the quality of the code and the integrity of the project, we often\nneed to do these things that are not related to the logical implementation of\nthe code. However, these things are likely to affect the overall project\ndevelopment progress, reduce the developer's development experience, and make\nthe developer feel that the development threshold of the module project is very\nhigh.\n\nIf you have to go through all this work every time you develop a module type\nproject, you will spend most of your development time in the beginning on these\nthings that are not related to code implementation. If we could provide a module\nengineering solution that would help developers to solve the project engineering\nissues and allow them to focus more on code implementation, it would greatly\nimprove the module type project development experience.\n\n\n\nModern.js, in order to make developing module type projects easier, provides a\nmodule engineering solution in order to solve the above mentioned problems and\nprovides the main features using Modern.js Module. Modern.js Module can be\nunderstood as a tool dedicated to the development of module type projects.","frontmatter":{"sidebar_position":2},"version":""},{"id":36,"title":"Quick Start","routePath":"/module-tools/en/plugins/guide/getting-started","lang":"en","toc":[],"domain":"","content":"#\n\nModern.js Module not only provides a rich set of features, but also supports\nextending the capabilities of the current project by way of plugins.\n\nWe can quickly see how to write a Modern.js Module plugin by using the following\nexample.\n\n 1. First we create . /plugins/example.ts file under the initialized project.\n\n. /project .\n├── plugins\n│ └── example.ts\n├── src/\n└── modern.config.ts\n\n\n 2. Next add the code for the plugin to the example.ts file.\n\n\n\nexport const ExamplePlugin = (): CliPlugin => {\n return {\n name: 'example',\n setup() {\n console.info('this is example plugin');\n return {\n // use hooks\n afterBuild() {\n console.info('build over');\n },\n };\n },\n };\n};\n\n\n 3. Then we register the plugin we just wrote via the plugins API.\n\n\nexport default defineConfig({\n plugins: [examplePlugin()],\n});\n\n\n 4. Finally, run modern build and you will see:\n\nThis is example plugin\nBuild succeed: 510.684ms\nbuild over\n\n\nWith the above example, we learned the following things.\n\n * The recommended plugin directory structure\n * The initialization code of the plugin\n * Plugin registration\n\nIn addition to the above, we also need to understand.\n\n * plugin objects, type definitions and recommended configuration options\n * setup functions, api object parameters, lifecycle hooks","frontmatter":{"sidebar_position":1},"version":""},{"id":37,"title":"Plugin Object","routePath":"/module-tools/en/plugins/guide/plugin-object","lang":"en","toc":[{"text":"Plugin type definitions","id":"plugin-type-definitions","depth":2,"charIndex":805},{"text":"Plugin configuration options","id":"plugin-configuration-options","depth":2,"charIndex":1163}],"domain":"","content":"#\n\nThe Modern.js Module plugin is an object, and the object contains the following\nproperties.\n\n * name: The name of the plugin, a unique identifier.\n * setup: plugin initialization function, which will be executed only once.\n setup function can return a Hooks object, and Modern.js Module will execute\n the function corresponding to the Hook defined on the Hooks object at a\n specific time.\n\nFor example, in the following plugin code example, the beforeBuild function is\ntriggered before the project starts the build task and the build start log is\nprinted.\n\n\n\nconst myPlugin: CliPlugin = {\n name: 'my-plugin',\n\n setup() {\n return {\n // this is hook\n beforeBuild: () => {\n console.info('build start');\n },\n };\n },\n};\n\n\n\nexport default {\n plugins: [myPlugin()],\n};\n\n\n\nPlugin type definitions#\n\nWhen using TypeScript, you can introduce the built-in CliPlugin and ModuleTools\ntypes to provide the correct type derivation for plugins: ``\n\n\n\nconst myPlugin: CliPlugin = {\n name: 'my-plugin',\n\n setup() {\n const foo = '1';\n\n return {\n // this is hook\n afterBuild: () => {\n //...\n },\n };\n },\n};\n\n\n\nPlugin configuration options#\n\nIt is recommended to write the plugin as a function, so that the plugin can\nreceive configuration options via function entry.\n\n\n\ntype MyPluginOptions = {\n foo: string;\n};\n\nconst myPlugin = (options: MyPluginOptions): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n console.log(options.foo);\n },\n});\n","frontmatter":{"sidebar_position":2},"version":""},{"id":38,"title":"Setup function","routePath":"/module-tools/en/plugins/guide/setup-function","lang":"en","toc":[{"text":"Plugin API objects","id":"plugin-api-objects","depth":2,"charIndex":173},{"text":"api.useAppContext","id":"apiuseappcontext","depth":3,"charIndex":783},{"text":"api.useResolvedConfigContext","id":"apiuseresolvedconfigcontext","depth":3,"charIndex":1343},{"text":"api.useHookRunners","id":"apiusehookrunners","depth":3,"charIndex":1811},{"text":"Asynchronous setup","id":"asynchronous-setup","depth":2,"charIndex":2132},{"text":"Life cycle hooks","id":"life-cycle-hooks","depth":2,"charIndex":2694}],"domain":"","content":"#\n\nIn the \"Plugin object\" section we know that the plugin object contains a setup\nfunction that not only contains an api object parameter, but also returns a\nHooks object.\n\n\nPlugin API objects#\n\nThe setup function of the plugin will provide an api object parameter, and you\ncan call some of the methods provided on this object to get information about\nthe configuration, project context, etc.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup(api) {\n // Get the original configuration of the application\n const config = api.useConfigContext();\n // Get the application runtime context\n const appContext = api.useAppContext();\n // Get the final configuration after resolving\n const resolvedConfig = api.useResolvedConfigContext();\n },\n});\n\n\n\napi.useAppContext#\n\nUsed to get project context information.\n\nconst useAppContext: () => IAppContext;\n\ninterface IAppContext {\n appDirectory: string;\n configFile: string | false;\n packageName: string;\n nodeModulesDirectory: string;\n internalDirectory: string;\n plugins: {\n cli?: any;\n server?: any;\n }[];\n}\n\n\nINFO\n\nThrough the actual type file, we can see that there are some additional fields.\nHowever, for Modern.js Module, the fields mentioned above are the only ones that\nare meaningful. The same applies to other methods of the api object.\n\n\napi.useResolvedConfigContext#\n\nUsed to get the final configuration after parsing.\n\nINFO\n\nIf you need to get the build-related final configuration, you need to use the\nbeforeBuild Hook.\n\nconst useResolvedConfigContext: () => NormalizedConfig;\n\ninterface NormalizedConfig {\n buildConfig: PartialBuildConfig;\n buildPreset: BuildPreset;\n dev: Dev;\n plugins: PluginConfig;\n runtime: RuntimeConfig;\n runtimeByEntries?: RuntimeByEntriesConfig;\n _raw: UserConfig;\n}\n\n\n\napi.useHookRunners#\n\nUsed to get the executors of Hooks and trigger the execution of a specific Hook.\n\n\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n async setup(api) {\n const hookRunners = api.useHookRunners();\n // trigger the afterBuild Hook\n await hookRunners.afterBuild();\n },\n});\n\n\n\nAsynchronous setup#\n\nThe setup of a CLI plugin can be an asynchronous function that performs\nasynchronous logic during the initialization process.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n async setup(api) {\n await doSomething();\n },\n});\n\n\nNote that the setup function of the next plugin is not executed until the async\nsetup function of the current plugin has finished. Therefore, you should avoid\nperforming time-consuming asynchronous operations in the setup function to avoid\nslowing down the startup performance of the CLI.\n\n\nLife cycle hooks#\n\nWe know that the setup function returns a Hooks object, which can also be\nunderstood as an object with Modern.js Module lifecycle hooks.\n\nCurrently there are two main types of hooks.\n\n * build hooks: triggered only when the build command is executed to build the\n source code product.\n * buildPlatform hook: triggered only when the build --platform command is\n executed to generate other build products.\n * debug hooks: hooks that are triggered when running the dev command.\n\nSee the API documentation for a full list of lifecycle hooks.","frontmatter":{"sidebar_position":3},"version":""},{"id":39,"title":"Overview","routePath":"/module-tools/en/plugins/official-list/overview","lang":"en","toc":[{"text":"Official Plugin","id":"official-plugin","depth":2,"charIndex":3}],"domain":"","content":"#\n\n\nOfficial Plugin#\n\n * @modern-js/plugin-module-import:Use SWC to provide the same ability as\n babel-plugin-import.\n * @modern-js/plugin-module-banner:Add custom content, such as copyright\n information, to the top and bottom of each JS and CSS file.\n * @modern-js/plugin-module-node-polyfill: Inject Polyfills of Node core modules\n in the browser side.\n * @modern-js/plugin-module-polyfill:Inject polyfill for unsupported features\n used in your code.\n * @modern-js/plugin-module-babel:Use Babel to transform your code.","frontmatter":{},"version":""},{"id":40,"title":"Babel Plugin","routePath":"/module-tools/en/plugins/official-list/plugin-babel","lang":"en","toc":[{"text":"Quick start","id":"quick-start","depth":2,"charIndex":110},{"text":"Install","id":"install","depth":3,"charIndex":125},{"text":"Register","id":"register","depth":3,"charIndex":136},{"text":"Config","id":"config","depth":2,"charIndex":292}],"domain":"","content":"#\n\nTIP\n\nNormally, we don't need to use Babel to transform our code, this plugin is only\nused as a downgrade.\n\n\nQuick start#\n\n\nInstall#\n\n\nRegister#\n\nYou can install the plugin with the following command:\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginBabel()],\n});\n\n\n\nConfig#\n\nSee babel options.\n\nHere is an example with @babel/preset-env configured\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBabel({\n presets: [['@babel/preset-env']],\n }),\n ],\n});\n","frontmatter":{},"version":""},{"id":41,"title":"Banner Plugin","routePath":"/module-tools/en/plugins/official-list/plugin-banner","lang":"en","toc":[{"text":"Quick Start","id":"quick-start","depth":2,"charIndex":89},{"text":"Install","id":"install","depth":3,"charIndex":104},{"text":"Register","id":"register","depth":3,"charIndex":115},{"text":"Example","id":"example","depth":2,"charIndex":456},{"text":"Add copyright information at the top of a JS file","id":"add-copyright-information-at-the-top-of-a-js-file","depth":3,"charIndex":467},{"text":"Configuration","id":"configuration","depth":2,"charIndex":967},{"text":"banner","id":"banner","depth":3,"charIndex":1126},{"text":"footer","id":"footer","depth":3,"charIndex":1266}],"domain":"","content":"#\n\nProvide the ability to inject content at the top and bottom of each JS and CSS\nfile.\n\n\nQuick Start#\n\n\nInstall#\n\n\nRegister#\n\nYou can install the plugin with the following command:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBanner({\n banner: {\n js: '//comment',\n css: '/*comment*/',\n },\n }),\n ],\n});\n\n\nTIP\n\nNote: CSS comments do not support the //comment syntax. Refer to \"CSS Comments\"\n\n\nExample#\n\n\nAdd copyright information at the top of a JS file#\n\n\n\n\nconst copyRight = `/*\n © Copyright 2020 xxx.com or one of its affiliates.\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n*/`;\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBanner({\n banner: {\n js: copyRight,\n },\n }),\n ],\n});\n\n\n\nConfiguration#\n\n * Type\n\ntype BannerOptions = {\n banner: {\n js?: string;\n css?: string;\n };\n footer?: {\n js?: string;\n css?: string;\n };\n};\n\n\n\nbanner#\n\nAdd content at the top.\n\n * banner.js: Add content at the top of a JS file.\n * banner.css: Add content at the top of a CSS file.\n\n\nfooter#\n\nAdd content at the bottom.\n\n * footer.js: Add content at the bottom of a JS file.\n * footer.css: Add content at the bottom of a CSS file.","frontmatter":{},"version":""},{"id":42,"title":"Import Plugin","routePath":"/module-tools/en/plugins/official-list/plugin-import","lang":"en","toc":[{"text":"Quick Start","id":"quick-start","depth":2,"charIndex":231},{"text":"Install","id":"install","depth":3,"charIndex":246},{"text":"Register","id":"register","depth":3,"charIndex":257},{"text":"Configurations","id":"configurations","depth":2,"charIndex":627},{"text":"pluginImport","id":"pluginimport","depth":3,"charIndex":708},{"text":"Notes","id":"notes","depth":2,"charIndex":1127}],"domain":"","content":"#\n\nUsing SWC provides the same ability and configuration as babel-plugin-import.\n\nTIP\n\nSince @modern-js/module-tools version >= v2.16.0, this plugin functionality is\nbuilt into Modern.js Module and is provided by transformImport.\n\n\nQuick Start#\n\n\nInstall#\n\n\nRegister#\n\nIn Modern.js Module, you can register plugins in the following way:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginImport({\n pluginImport: [\n {\n libraryName: 'antd',\n style: true,\n },\n ],\n }),\n ],\n});\n\n\nThis way we can use the ability of automatic import in Modern.js Module.\n\n\nConfigurations#\n\n * Type:\n\ntype Options = {\n pluginImport?: ImportItem[];\n};\n\n\n\npluginImport#\n\n * Type: object[]\n\nThe elements of the array are configuration objects for babel-plugin-import,\nwhich can be referred to options。\n\nExample:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginImport({\n pluginImport: [\n // babel-plugin-import`s options config\n {\n libraryName: 'foo',\n style: true,\n },\n ],\n }),\n ],\n});\n\n\n\nNotes#\n\nSWC (Speedy Web Compiler) is written in Rust, and this plugin is based on SWC\nand ported from babel-plugin-import. The configuration options remain\nconsistent.\n\nSome configurations can accept functions, such as customName, customStyleName,\netc. These JavaScript functions are called by Rust through Node-API, which can\ncause some performance degradation.\n\nSimple function logic can be replaced by template language. Therefore, for\nconfigurations such as customName, customStyleName, etc., instead of passing\nfunctions, you can also pass a string as a template to replace the function,\nimproving performance.\n\nWe will use the following code as example:\n\n\n\n\nAdd the following configuration on the right-hand side:\n\nmodulePluginImport({\n pluginImport: [\n {\n libraryName: 'foo',\n customName: 'foo/es/{{ member }}',\n },\n ],\n});\n\n\nThe {{ member }} in it will be replaced with the corresponding import member.\nAfter transformation:\n\n\n\n\nTemplate customName: 'foo/es/{{ member }}' is the same as customName: (member)\n=> `foo/es/${member}` , but template value has no performance overhead of\nNode-API.\n\nThe template used here is handlebars. There are some useful builtin tools, Take\nthe above import statement as an example:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginImport({\n pluginImport: [\n {\n libraryName: 'foo',\n customName: 'foo/es/{{ kebabCase member }}',\n },\n ],\n }),\n ],\n});\n\n\nTransformed to:\n\n\n\n\nIn addition to kebabCase, there are cameraCase, snakeCase, upperCase and\nlowerCase can be used as well.","frontmatter":{},"version":""},{"id":43,"title":"Node Polyfill Plugin","routePath":"/module-tools/en/plugins/official-list/plugin-node-polyfill","lang":"en","toc":[{"text":"Quick Start","id":"quick-start","depth":2,"charIndex":460},{"text":"Install","id":"install","depth":3,"charIndex":475},{"text":"Register","id":"register","depth":3,"charIndex":486},{"text":"Configurations","id":"configurations","depth":2,"charIndex":662},{"text":"exclude","id":"exclude","depth":3,"charIndex":768},{"text":"overrides","id":"overrides","depth":3,"charIndex":965},{"text":"Node Polyfills","id":"node-polyfills","depth":2,"charIndex":1211},{"text":"Globals","id":"globals","depth":3,"charIndex":1229},{"text":"Modules","id":"modules","depth":3,"charIndex":1420},{"text":"Fallbacks","id":"fallbacks","depth":3,"charIndex":1921}],"domain":"","content":"#\n\nAbout Node Polyfill\n\nNormally, we don't need to use Node libs on the browser side. However, it is\npossible to use some Node libs when the code will run on both the Node side and\nthe browser side, and Node Polyfill provides browser versions of polyfills for\nthese Node libs.\n\nBy using the Node Polyfill plugin, Node core libs polyfills are automatically\ninjected into the browser-side, allowing you to use these modules on the browser\nside with confidence.\n\n\nQuick Start#\n\n\nInstall#\n\n\nRegister#\n\nIn Modern.js Module, you can register plugins in the following way:\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginNodePolyfill()],\n});\n\n\n\nConfigurations#\n\n * Type:\n\ntype NodePolyfillOptions = {\n exclude?: string[];\n overrides?: Record;\n};\n\n\n\nexclude#\n\nExclude the Node Polyfill to be injected.\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginNodePolyfill({\n exclude: ['console'],\n }),\n ],\n});\n\n\n\noverrides#\n\nOverride the built-in Node Polyfill.\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginNodePolyfill({\n overrides: {\n fs: path.join(__dirname, './custom-fs.js'),\n },\n }),\n ],\n});\n\n\n\nNode Polyfills#\n\n\nGlobals#\n\n * Buffer\n * process\n * console\n\nWhen the above global variables are used directly in code, the corresponding\npolyfill will be injected.\n\nconst bufferData = Buffer.from('xxxx');\n\n\n\nModules#\n\n * assert\n * buffer\n * console\n * constants\n * crypto\n * domain\n * events\n * http\n * https\n * os\n * path\n * punycode\n * process\n * querystring\n * stream\n * _stream_duplex\n * _stream_passthrough\n * _stream_readable\n * _stream_transform\n * _stream_writable\n * string_decoder\n * sys\n * timers\n * tty\n * url\n * util\n * vm\n * zlib\n\nWhen the above module is referenced in code via import / require syntax, the\ncorresponding polyfill will be injected.\n\n\n\nconst bufferData = Buffer.from('xxxx');\n\n\n\nFallbacks#\n\n * child_process\n * cluster\n * dgram\n * dns\n * fs\n * module\n * net\n * readline\n * repl\n * tls\n\nCurrently there is no polyfill for the above modules on the browser side, so\nwhen you import the above modules, it will automatically fallback to an empty\nobject.\n\n\n\nconsole.log(fs); // -> {}\n","frontmatter":{},"version":""},{"id":44,"title":"Polyfill Plugin","routePath":"/module-tools/en/plugins/official-list/plugin-polyfill","lang":"en","toc":[{"text":"Quick start","id":"quick-start","depth":2,"charIndex":497},{"text":"Install","id":"install","depth":3,"charIndex":512},{"text":"Register","id":"register","depth":3,"charIndex":523},{"text":"Config","id":"config","depth":2,"charIndex":695},{"text":"targets","id":"targets","depth":3,"charIndex":765}],"domain":"","content":"#\n\nTIP\n\nNormally, we don't need to inject polyfill for npm packages, this step should be\ndone on the web application framework side, but in some scenarios we need to\ninject polyfill in order to make our library run directly in low version\nbrowsers.\n\nNote that this plugin does not transform your code syntax, it only injects\npolyfill for unsupported functions used in your code, importing them as normal\nfunctions instead of polluting the global. You need to install the core-js-pure\ndependency.\n\n\nQuick start#\n\n\nInstall#\n\n\nRegister#\n\nIn Modern.js Module, you can register plugins in the following way:\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginPolyfill()],\n});\n\n\n\nConfig#\n\n * Type\n\ntype options = {\n targets?: Record | string;\n};\n\n\n\ntargets#\n\nSee Babel target.\n\nThis is a example.\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginPolyfill({\n targets: '> 0.25%, not dead',\n }),\n ],\n});\n","frontmatter":{},"version":""}] \ No newline at end of file +[{"id":0,"title":"buildConfig","routePath":"/module-tools/en/api/config/build-config","lang":"en","toc":[{"text":"alias","id":"alias","depth":2,"charIndex":378},{"text":"asset","id":"asset","depth":2,"charIndex":1394},{"text":"asset.path","id":"assetpath","depth":2,"charIndex":1453},{"text":"asset.limit","id":"assetlimit","depth":2,"charIndex":1557},{"text":"asset.publicPath","id":"assetpublicpath","depth":2,"charIndex":2123},{"text":"asset.svgr","id":"assetsvgr","depth":2,"charIndex":2406},{"text":"asset.svgr.include","id":"assetsvgrinclude","depth":2,"charIndex":3027},{"text":"asset.svgr.exclude","id":"assetsvgrexclude","depth":2,"charIndex":3145},{"text":"autoExternal","id":"autoexternal","depth":2,"charIndex":3262},{"text":"autoExternal.dependencies","id":"autoexternaldependencies","depth":2,"charIndex":3992},{"text":"autoExternal.peerDependencies","id":"autoexternalpeerdependencies","depth":2,"charIndex":4128},{"text":"banner","id":"banner","depth":2,"charIndex":4259},{"text":"buildType","id":"buildtype","depth":2,"charIndex":4876},{"text":"copy","id":"copy","depth":2,"charIndex":5036},{"text":"copy.patterns","id":"copypatterns","depth":2,"charIndex":5301},{"text":"copy.options","id":"copyoptions","depth":2,"charIndex":5474},{"text":"define","id":"define","depth":2,"charIndex":5771},{"text":"dts","id":"dts","depth":2,"charIndex":7136},{"text":"dts.abortOnError","id":"dtsabortonerror","depth":2,"charIndex":7318},{"text":"dts.distPath","id":"dtsdistpath","depth":2,"charIndex":7903},{"text":"dts.only","id":"dtsonly","depth":2,"charIndex":8166},{"text":"dts.tsconfigPath","id":"dtstsconfigpath","depth":2,"charIndex":8414},{"text":"dts.respectExternal","id":"dtsrespectexternal","depth":2,"charIndex":8662},{"text":"esbuildOptions","id":"esbuildoptions","depth":2,"charIndex":9198},{"text":"externalHelpers","id":"externalhelpers","depth":2,"charIndex":10723},{"text":"externals","id":"externals","depth":2,"charIndex":11689},{"text":"footer","id":"footer","depth":2,"charIndex":12025},{"text":"format","id":"format","depth":2,"charIndex":12121},{"text":"format: esm","id":"format-esm","depth":3,"charIndex":12308},{"text":"format: cjs","id":"format-cjs","depth":3,"charIndex":12523},{"text":"format: iife","id":"format-iife","depth":3,"charIndex":12794},{"text":"format: umd","id":"format-umd","depth":3,"charIndex":13164},{"text":"hooks","id":"hooks","depth":2,"charIndex":13542},{"text":"input","id":"input","depth":2,"charIndex":14500},{"text":"jsx","id":"jsx","depth":2,"charIndex":16089},{"text":"metafile","id":"metafile","depth":2,"charIndex":16702},{"text":"minify","id":"minify","depth":2,"charIndex":17232},{"text":"outDir","id":"outdir","depth":2,"charIndex":17493},{"text":"platform","id":"platform","depth":2,"charIndex":17669},{"text":"redirect","id":"redirect","depth":2,"charIndex":17947},{"text":"resolve","id":"resolve","depth":2,"charIndex":18639},{"text":"resolve.mainFields","id":"resolvemainfields","depth":3,"charIndex":18684},{"text":"resolve.jsExtentions","id":"resolvejsextentions","depth":3,"charIndex":19307},{"text":"sideEffects","id":"sideeffects","depth":2,"charIndex":19885},{"text":"sourceDir","id":"sourcedir","depth":2,"charIndex":21098},{"text":"sourceMap","id":"sourcemap","depth":2,"charIndex":21331},{"text":"sourceType","id":"sourcetype","depth":2,"charIndex":21442},{"text":"splitting","id":"splitting","depth":2,"charIndex":21669},{"text":"style","id":"style","depth":2,"charIndex":21752},{"text":"style.less","id":"styleless","depth":2,"charIndex":21800},{"text":"style.less.lessOptions","id":"stylelesslessoptions","depth":2,"charIndex":21842},{"text":"style.less.additionalData","id":"stylelessadditionaldata","depth":2,"charIndex":21967},{"text":"style.less.implementation","id":"stylelessimplementation","depth":2,"charIndex":22222},{"text":"style.sass","id":"stylesass","depth":2,"charIndex":22827},{"text":"style.sass.sassOptions","id":"stylesasssassoptions","depth":2,"charIndex":22870},{"text":"style.sass.additionalData","id":"stylesassadditionaldata","depth":2,"charIndex":22976},{"text":"style.sass.implementation","id":"stylesassimplementation","depth":2,"charIndex":23291},{"text":"style.postcss","id":"stylepostcss","depth":2,"charIndex":23891},{"text":"style.inject","id":"styleinject","depth":2,"charIndex":24893},{"text":"style.autoModules","id":"styleautomodules","depth":2,"charIndex":26353},{"text":"style.modules","id":"stylemodules","depth":2,"charIndex":26700},{"text":"style.tailwindcss","id":"styletailwindcss","depth":2,"charIndex":27160},{"text":"Enabling Tailwind CSS","id":"enabling-tailwind-css","depth":3,"charIndex":27413},{"text":"Type","id":"type","depth":3,"charIndex":27622},{"text":"Notes","id":"notes","depth":3,"charIndex":27927},{"text":"target","id":"target","depth":2,"charIndex":28510},{"text":"transformImport","id":"transformimport","depth":2,"charIndex":29101},{"text":"transformLodash","id":"transformlodash","depth":2,"charIndex":29655},{"text":"tsconfig","id":"tsconfig","depth":2,"charIndex":30260},{"text":"umdGlobals","id":"umdglobals","depth":2,"charIndex":30457},{"text":"umdModuleName","id":"umdmodulename","depth":2,"charIndex":30888}],"domain":"","content":"#\n\nbuildConfig is a configuration option that describes how to compile and generate\nbuild artifacts. It contains all the configurations related to the build\nprocess.\n\n * Type: object | object[]\n\nTIP\n\nBefore start using buildConfig, please read the following documentation to\nunderstand its purpose:\n\n * Modifying Output Artifacts\n * In-Depth Understanding of the Build Process\n\n\nalias#\n\n * Type: Record | Function\n * Default: {'@': 'src',}\n\nTIP\n\nFor TypeScript projects, you only need to configure compilerOptions.paths in\ntsconfig.json, Modern.js Module will automatically recognize the alias in\ntsconfig.json, so there is no need to configure the alias field additionally.\n\nexport default {\n buildConfig: {\n alias: {\n '@common': '. /src/common',\n },\n },\n};\n\n\nAfter the above configuration is done, if @common/Foo.tsx is referenced in the\ncode, it will map to the /src/common/Foo.tsx path.\n\nWhen the value of alias is defined as a function, you can accept the pre-defined\nalias object and modify it.\n\nexport default {\n buildConfig: {\n alias: alias => {\n alias['@common'] = '. /src/common';\n },\n },\n};\n\n\nIt is also possible to return a new object as the final result in the function,\nwhich will override the pre-defined alias object.\n\nexport default {\n buildConfig: {\n alias: alias => {\n return {\n '@common': '. /src/common',\n };\n },\n },\n};\n\n\n\nasset#\n\nContains configuration related to static assets.\n\n\nasset.path#\n\nStatic resource output path, will be based on outDir\n\n * Type: string\n * Default: assets\n\n\nasset.limit#\n\nUsed to set the threshold for static assets to be automatically inlined as\nbase64.\n\nBy default, Modern.js Module will inline assets such as images, fonts and media\nsmaller than 10KB during bundling. They are Base64 encoded and inlined in the\nbundles, eliminating the need for separate HTTP requests.\n\nYou can adjust this threshold by modifying the limit config.\n\n * Type: number\n * Default: 10 * 1024\n\nFor example, set limit to 0 to avoid assets inlining:\n\nexport default defineConfig({\n buildConfig: {\n asset: {\n limit: 0,\n },\n },\n});\n\n\n\nasset.publicPath#\n\nThe CDN prefix given to unlinked assets when bundling.\n\n * Type: string\n * Default: undefined\n\nexport default {\n buildConfig: {\n asset: {\n publicPath: 'https://xxx/',\n },\n },\n};\n\n\nAt this point, all static assets will be prefixed with https://xxx/.\n\n\nasset.svgr#\n\nPackaged to handle svg as a React component, options reference svgr, plus\nsupport for two configuration options include and exclude to match the svg file\nto be handled\n\n * Type: boolean | object\n * Default: false\n\nWhen svgr feature is enabled, you can use svg as a component using the default\nexport.\n\n// true\n\n\nexport default () => ;\n\n\nWARNING\n\nThe following usage is not currently supported:\n\n\n\n\nWhen enabled, the type of svg used can be modified by adding a type definition\nto the modern-app-env.d.ts file:\n\ndeclare module '*.svg' {\n const src: React.FunctionComponent>;\n export default src;\n}\n\n/// \n\n\n\nasset.svgr.include#\n\nSet the matching svg file\n\n * Type: string | RegExp | (string | RegExp)[]\n * Default: /\\.svg$/\n\n\nasset.svgr.exclude#\n\nSet unmatched svg files\n\n * Type: string | RegExp | (string | RegExp)[]\n * Default: undefined\n\n\nautoExternal#\n\nAutomatically externalize project dependencies and peerDependencies and not\npackage them into the final bundle\n\n * Type: boolean | object\n * Default: true\n\nWhen we want to turn off the default handling behavior for third-party\ndependencies, we can do so by:\n\nexport default defineConfig({\n buildConfig: {\n autoExternal: false,\n },\n});\n\n\nThis way the dependencies under \"dependencies\" and \"peerDependencies\" will be\nbundled. If you want to turn off the processing of only one of these\ndependencies, you can use the buildConfig.autoExternal in the form of an object.\n\nexport default defineConfig({\n buildConfig: {\n autoExternal: {\n dependencies: false,\n peerDependencies: false,\n },\n },\n});\n\n\n\nautoExternal.dependencies#\n\nWhether or not the dep dependencies of the external project are needed\n\n * Type: boolean\n * Default: true\n\n\nautoExternal.peerDependencies#\n\nWhether to require peerDep dependencies for external projects\n\n * Type: boolean\n * Default: true\n\n\nbanner#\n\nProvides the ability to inject content into the top and bottom of each JS , CSS\nand DTS file.\n\ninterface BannerAndFooter {\n js?: string;\n css?: string;\n dts?: string;\n}\n\n\n * Type: BannerAndFooter\n * Default: {}\n * Version: v2.36.0\n\nLet's say you want to add copyright information to JS and CSS files.\n\n\n\nconst copyRight = `/*\n © Copyright 2020 xxx.com or one of its affiliates.\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n*/`;\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildConfig: {\n banner: {\n js: copyRight,\n css: copyRight,\n },\n },\n});\n\n\n\nbuildType#\n\nThe build type, bundle will package your code, bundleless will only do the code\nconversion\n\n * Type: 'bundle' | 'bundleless'\n * Default: 'bundle'\n\n\ncopy#\n\nCopies the specified file or directory into the build output directory\n\n * Type: object[]\n * Default: []\n\nexport default {\n buildConfig: {\n copy: [{ from: '. /src/assets', to: '' }],\n },\n};\n\n\nReference for array settings: copy-webpack-plugin patterns\n\n\ncopy.patterns#\n\n * Type: CopyPattern[]\n * Default: []\n\ninterface CopyPattern {\n from: string;\n to?: string;\n context?: string;\n globOptions?: globby.GlobbyOptions;\n}\n\n\n\ncopy.options#\n\n * Type:\n\ntype Options = {\n concurrency?: number;\n enableCopySync?: boolean;\n};\n\n\n * Default: { concurrency: 100, enableCopySync: false }\n\n * concurrency: Specifies how many copy tasks to execute in parallel.\n\n * enableCopySync: Uses fs.copySync by default, instead of fs.copy.\n\n\ndefine#\n\nDefine global variables that will be injected into the code\n\n * Type: Record\n * Default: {}\n\nSince the define function is implemented by global text replacement, you need to\nensure that the global variable values are strings. A safer approach is to\nconvert the value of each global variable to a string, using JSON.stringify, as\nfollows.\n\nexport default {\n buildConfig: {\n define: {\n VERSION: JSON.stringify('1.0'),\n },\n },\n};\n\n\nIf the project is a TypeScript project, then you may need to add the following\nto the .d.ts file in the project source directory.\n\n> If the .d.ts file does not exist, then you can create it manually.\n\ndeclare const YOUR_ADD_GLOBAL_VAR;\n\n\nYou can also replace environment variable:\n\n\nexport default defineConfig({\n buildConfig: {\n define: {\n 'process.env.VERSION': JSON.stringify(process.env.VERSION || '0.0.0'),\n },\n },\n});\n\n\nWith the above configuration, we can put the following code.\n\n// pre-compiler code\nconsole.log(process.env.VERSION);\n\n\nWhen executing VERSION=1.0.0 modern build, the conversion is:\n\n// compiled code\nconsole.log('1.0.0');\n\n\nTIP\n\nTo prevent excessive global replacement substitution, it is recommended that the\nfollowing two principles be followed when using\n\n * Use upper case for global constants\n * Customize the prefix and suffix of global constants to ensure uniqueness\n\n\ndts#\n\nThe dts file generates the relevant configuration, by default it generates.\n\n * Type: false | object\n * Default:\n\n{\n abortOnError: true,\n distPath: './',\n only: false,\n}\n\n\n\ndts.abortOnError#\n\nWhether to allow the build to succeed if a type error occurs.\n\n * Type: boolean\n * Default: true\n\nBy default, type errors will cause the build to fail. When abortOnError is set\nto false, the build will still succeed even if there are type issues in the\ncode:\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n abortOnError: false,\n },\n },\n});\n\n\nWARNING\n\nWhen this configuration is disabled, there is no guarantee that the type files\nwill be generated correctly. In buildType: 'bundle', which is the bundle mode,\ntype files will not be generated.\n\n\ndts.distPath#\n\nThe output path of the dts file, based on outDir\n\n * Type: string\n * Default: ./\n\nFor example, output to the types directory under the outDir:\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n distPath: './types',\n },\n },\n});\n\n\n\ndts.only#\n\nWhether to generate only type files during the build process without generating\nJavaScript output files.\n\n * Type: boolean\n * Default: false\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n only: true,\n },\n },\n});\n\n\n\ndts.tsconfigPath#\n\ndeprecated,use tsconfig instead.\n\nSpecifies the path to the tsconfig file used to generate the type file.\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n tsconfigPath: './other-tsconfig.json',\n },\n },\n});\n\n\n\ndts.respectExternal#\n\nWhen set to false, the type of third-party packages will be excluded from the\nbundle, when set to true, it will determine whether third-party types need to be\nbundled based on externals.\n\nWhen bundle d.ts, export is not analyzed, so any third-party package type you\nuse may break your build, which is obviously uncontrollable. So we can avoid it\nwith this configuration.\n\n * Type: boolean\n * Default: true\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n respectExternal: false,\n },\n },\n});\n\n\n\nesbuildOptions#\n\nUsed to modify the esbuild configuration.\n\n * Type: Function\n * Build Type: Only supported for buildType: 'bundle'\n * Default: c => c\n\nFor example, if we need to modify the file extension of the generated files:\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.outExtension = { '.js': '.mjs' };\n return options;\n },\n },\n});\n\n\nFor example, register an esbuild plugin:\n\n\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.plugins = [myEsbuildPlugin, ...options.plugins];\n return options;\n },\n },\n});\n\n\nWhen adding an esbuild plugin, please note that you need to add the plugin at\nthe beginning of the plugins array. This is because the Modern.js Module is also\nintegrated into the entire build process through an esbuild plugin. Therefore,\ncustom plugins need to be registered with higher priority.\n\nTIP\n\nWe have done many extensions based on the original esbuild build. Therefore,\nwhen using this configuration, pay attention to the following:\n\n 1. Prefer to use the configuration that Modern.js Module provides. For example,\n esbuild does not support target: 'es5', but we support this scenario\n internally using SWC. Setting target: 'es5' through esbuildOptions will\n result in an error.\n 2. Currently, we use enhanced-resolve internally to replace esbuild's resolve\n algorithm, so modifying esbuild resolve-related configurations is invalid.\n We plan to switch back in the future.\n\n\nexternalHelpers#\n\nBy default, the output JS code may depend on helper functions to support the\ntarget environment or output format, and these helper functions will be inlined\nin the file that requires it.\n\nWith this configuration, the code will be converted using SWC, it will inline\nhelper functions to import them from the external module @swc/helpers.\n\n * Type: boolean\n * Default: false\n\nBelow is a comparison of the output file changes before and after using this\nconfiguration.\n\nBefore enable:\n\n// helper function\nfunction asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {\n // ...\n}\n// helper function\nfunction _async_to_generator(fn) {\n return function () {\n // use asyncGeneratorStep\n // ...\n };\n}\n\n// your code\nexport var yourCode = function () {\n // use _async_to_generator\n};\n\n\nAfter enabled:\n\n// helper functions imported from @swc/helpers\n\n\n// your code\nexport var yourCode = function () {\n // use _async_to_generator\n};\n\n\n\nexternals#\n\nConfigure external dependencies that will not be bundled into the final bundle.\n\n * Type:\n\ntype External = (string | RegExp)[];\n\n\n * Default: []\n * Build Type: Only supported for buildType: 'bundle'\n * Example:\n\nexport default defineConfig({\n buildConfig: {\n // do not bundle React\n externals: ['react'],\n },\n});\n\n\n\nfooter#\n\nSame as the banner configuration for adding a comment at the end of the output\nfile.\n\n\nformat#\n\nUsed to set the output format of JavaScript files. The options iife and umd only\ntake effect when buildType is bundle.\n\n * Type: 'esm' | 'cjs' | 'iife' | 'umd'\n * Default: cjs\n\n\nformat: esm#\n\nesm stands for \"ECMAScript module\" and requires the runtime environment to\nsupport import and export syntax.\n\n * Example:\n\nexport default defineConfig({\n buildConfig: {\n format: 'esm',\n },\n});\n\n\n\nformat: cjs#\n\ncjs stands for \"CommonJS\" and requires the runtime environment to support\nexports, require, and module syntax. This format is commonly used in Node.js\nenvironments.\n\n * Example:\n\nexport default defineConfig({\n buildConfig: {\n format: 'cjs',\n },\n});\n\n\n\nformat: iife#\n\niife stands for \"immediately-invoked function expression\" and wraps the code in\na function expression to ensure that any variables in the code do not\naccidentally conflict with variables in the global scope. This format is\ncommonly used in browser environments.\n\n * Example:\n\nexport default defineConfig({\n buildConfig: {\n format: 'iife',\n },\n});\n\n\n\nformat: umd#\n\numd stands for \"Universal Module Definition\" and is used to run modules in\ndifferent environments such as browsers and Node.js. Modules in UMD format can\nbe used in various environments, either as global variables or loaded as modules\nusing module loaders like RequireJS.\n\n * Example:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n },\n});\n\n\n\nhooks#\n\nBuild lifecycle hooks that allow custom logic to be injected at specific stages\nof the build process.\n\n * Types:\n\ntype HookList = {\n name: string;\n apply: (compiler: ICompiler) => void.\n}\n\n\n\n * Default: [].\n\nWe can get the compiler instance in the apply method, modify its properties, and\nexecute custom logic at different stages. For more information on Hooks, see\n[Using Hooks to Intervene in the Build Process](see [Using Hooks to Intervene in\nthe Build Process]). For more information on Hooks, see\nUsing-hooks-to-intervene-in-the-build-process.\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundle',\n hooks: [\n {\n name: 'renderChunk',\n apply: compiler => {\n // any logic for compiler\n compiler.hooks.renderChunk.tapPromise(\n { name: 'renderChunk' },\n async chunk => {\n return chunk;\n },\n );\n },\n },\n ],\n },\n});\n\n\n\ninput#\n\nSpecify the entry file for the build, in the form of an array that can specify\nthe directory\n\n * Type:\n\ntype Input =\n | string[];\n | {\n [name: string]: string;\n }\n\n\n * Default: ['src/index.ts'] in bundle mode, ['src'] in bundleless mode\n\nArray usage:\n\nIn bundle mode, the following configurations will be built using src/index.ts\nand src/index2.ts as entry points. The bundle mode does not support configuring\ninput as a directory.\n\nexport default {\n buildConfig: {\n buildType: 'bundle',\n input: ['src/index.ts', 'src/index2.ts'],\n },\n};\n\n\nIn bundleless mode, the following configuration compiles both files in the src/a\ndirectory and src/index.ts file.\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundleless',\n input: ['src/a', 'src/index.ts'],\n },\n});\n\n\nIn bundleless mode, Array usage also supports the usage of ! to filter partial\nfiles:\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundleless',\n input: ['src', '!src/*.spec.ts'],\n },\n});\n\n\nThe above configuration will build the files in the src directory, and will also\nfilter files with the spec.ts suffix.This is useful in cases where the test\nfiles are in the same root directory as the source files.\n\nObject usage:\n\nWhen you need to modify the output file name in bundle mode, you can use an\nobject configuration.\n\nThe key of the object is the file name of the output, and the value is the file\npath of the source code.\n\nexport default defineConfig({\n buildConfig: {\n format: 'esm',\n input: {\n 'index.esm': './src/index.ts',\n },\n },\n});\n\n\n\njsx#\n\nSpecify the compilation method for JSX, which by default supports React 17 and\nhigher versions and automatically injects JSX runtime code.\n\n * Type: automatic | transform\n * Default: automatic\n\nIf you need to support React 16, you can set jsx to transform:\n\nexport default defineConfig({\n buildConfig: {\n jsx: 'transform',\n },\n});\n\n\nTIP\n\nIf you don't need to convert JSX, you can set jsx to preserve, but don't use swc\nto do the code conversion. For more information about JSX Transform, you can\nrefer to the following links:\n\n * React Blog - Introducing the New JSX Transform.\n * esbuild - JSX. :::\n\n\nmetafile#\n\nThis option is used for build analysis. When enabled, esbuild will generate\nmetadata about the build in JSON format.\n\n * Type: boolean\n * Default: false\n * Build Type: Only supported for buildType: 'bundle'\n\nTo enable metafile generation:\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundle',\n metafile: true,\n },\n});\n\n\nAfter executing the build, a metafile-[xxx].json file will be generated in the\noutput directory. You can use tools like esbuild analyze and bundle-buddy for\nvisual analysis.\n\n\nminify#\n\nUse esbuild or terser to compress code, also pass terserOptions\n\n * Type: 'terser' | 'esbuild' | false | object\n * Default: false\n\nexport default {\n buildConfig: {\n minify: {\n compress: {\n drop_console: true,\n },\n },\n },\n};\n\n\n\noutDir#\n\nSpecifies the output directory of the build.\n\n * Type: string\n * Default: ./dist\n\nexport default defineConfig({\n buildConfig: {\n outDir: './dist/esm',\n },\n});\n\n\n\nplatform#\n\nGenerates code for the node environment by default, you can also specify browser\nwhich will generate code for the browser environment\n\n * Type: 'browser' | 'node'\n * Default: 'node'\n\nexport default defineConfig({\n buildConfig: {\n platform: 'browser',\n },\n});\n\n\n\nredirect#\n\nIn buildType: 'bundleless' build mode, the reference path is redirected to\nensure that it points to the correct product, e.g:\n\n * import '. /index.less' will be rewritten to import '. /index.css'\n * would be rewritten as to `` (depending on the situation)\n\nIn some scenarios, you may not need these functions, then you can turn it off\nwith this configuration, and its reference path will not be changed after\nturning it off.\n\nexport default {\n buildConfig: {\n redirect: {\n alias: false, // Turn off modifying alias paths\n style: false, // Turn off modifying the path to the style file\n asset: false, // Turn off modifying the path to the asset\n },\n },\n};\n\n\n\nresolve#\n\nCustom module resolution options\n\n\nresolve.mainFields#\n\nA list of fields in package.json to try when parsing the package entry point.\n\n * Type: string[]\n * Default: depends on platform\n * node: ['module', 'main']\n * browser: ['module', 'browser', 'main']\n * Version: v2.36.0\n\nFor example, we want to load the js:source field first:\n\nexport default defineConfig({\n buildConfig: {\n resolve: {\n mainFields: ['js:source', 'module', 'main'],\n },\n },\n});\n\n\n:::warning resolve.mainFields has a lower priority than the exports field in\npackage.json, and if an entry point is successfully resolved from exports,\nresolve.mainFields will be ignored.\n\n\nresolve.jsExtentions#\n\nSupport for implicit file extensions\n\n * Type: string[]\n * Default: ['.jsx', '.tsx', '.js', '.ts', '.json']\n * Version: v2.36.0\n\nDo not use implicit file extensions for css files, currently Module only\nsupports ['.less', '.css', '.sass', '.scss'] suffixes.\n\nNode's parsing algorithm does not consider .mjs and cjs as implicit file\nextensions, so they are not included here by default, but can be included by\nchanging this configuration:\n\nexport default defineConfig({\n buildConfig: {\n resolve: {\n jsExtentions: ['.mts', 'ts'],\n },\n },\n});\n\n\n\nsideEffects#\n\nModule sideEffects\n\n * Type: RegExg[] | (filePath: string, isExternal: boolean) => boolean | boolean\n * Default: undefined\n\nNormally, we configure the module's side effects via the sideEffects field in\npackage.json, but in some cases, The package.json of a third-party package is\nunreliable.Such as when we reference a third-party package style file\n\nimport 'other-package/dist/index.css';\n\n\nBut the package.json of this third-party package does not have the style file\nconfigured in the sideEffects\n\n{\n \"sideEffects\": [\"dist/index.js\"]\n}\n\n\nAt the same time you set style.inject to true and you will see a warning message\nlike this in the console\n\n[LIBUILD:ESBUILD_WARN] Ignoring this import because \"other-package/dist/index.css\" was marked as having no side effects\n\n\nAt this point, you can use this configuration option to manually configure the\nmodule's \"sideEffects\" to support regular and functional forms.\n\nexport default defineConfig({\n buildConfig: {\n sideEffects: [/\\.css$/],\n // or\n // sideEffects: (filePath, isExternal) => /\\.css$/.test(filePath),\n },\n});\n\n\nTIP\n\nAfter adding this configuration, the sideEffects field in package.json will no\nlonger be read when packaging\n\n\nsourceDir#\n\nSpecify the source directory of the build, default is src, which is used to\ngenerate the corresponding output directory based on the source directory\nstructure when building bundleless.\n\n * Type: string\n * Default: src\n\n\nsourceMap#\n\nWhether to generate sourceMap or not\n\n * Type: boolean | 'inline' | 'external'\n * Default: false\n\n\nsourceType#\n\nSets the format of the source code. By default, the source code will be treated\nas EsModule. When the source code is using CommonJS, you need to set commonjs.\n\n * Type: 'commonjs' | 'module'\n * Default: 'module'\n\n\nsplitting#\n\nWhether to enable code splitting\n\n * Type: boolean\n * Default: false\n\n\nstyle#\n\nConfigure style-related configuration\n\n\nstyle.less#\n\nless-related configuration\n\n\nstyle.less.lessOptions#\n\nRefer to less for detailed configuration\n\n * Type: object\n * Default: { javascriptEnabled: true }\n\n\nstyle.less.additionalData#\n\nAdd Less code to the beginning of the entry file.\n\n * Type: string\n * Default: undefined\n\nexport default {\n buildConfig: {\n style: {\n less: {\n additionalData: `@base-color: #c6538c;`,\n },\n },\n },\n};\n\n\n\nstyle.less.implementation#\n\nConfigure the implementation library used by Less, if not specified, the\nbuilt-in version used is 4.1.3.\n\n * Type: string | object\n * Default: undefined\n\nSpecify the implementation library for Less when the object type is specified.\n\nexport default {\n buildConfig: {\n style: {\n less: {\n implementation: require('less'),\n },\n },\n },\n};\n\n\nFor the string type, specify the path to the implementation library for Less\n\nexport default {\n buildConfig: {\n style: {\n less: {\n implementation: require.resolve('less'),\n },\n },\n },\n};\n\n\n\nstyle.sass#\n\nsass-related configuration.\n\n\nstyle.sass.sassOptions#\n\nRefer to node-sass for detailed configuration.\n\n * Type: object\n * Default: {}\n\n\nstyle.sass.additionalData#\n\nAdd Sass code to the beginning of the entry file.\n\n * Type: string | Function\n * Default: undefined\n\nexport default {\n buildConfig: {\n style: {\n sass: {\n additionalData: `$base-color: #c6538c;\n $border-dark: rgba($base-color, 0.88);`,\n },\n },\n },\n};\n\n\n\nstyle.sass.implementation#\n\nConfigure the implementation library used by Sass, the built-in version used is\n1.5.4 if not specified.\n\n * Type: string | object\n * Default: undefined\n\nSpecify the implementation library for Sass when the object type is specified.\n\nexport default {\n buildConfig: {\n style: {\n sass: {\n implementation: require('sass'),\n },\n },\n },\n};\n\n\nFor the string type, specify the path to the Sass implementation library\n\nexport default {\n buildConfig: {\n style: {\n sass: {\n implementation: require.resolve('sass'),\n },\n },\n },\n};\n\n\n\nstyle.postcss#\n\nUsed to configure options for PostCSS. The provided values will be merged with\nthe default configuration using Object.assign. Note that Object.assign performs\na shallow copy, so it will completely override the built-in plugins array.\n\nFor detailed configuration, please refer to PostCSS.\n\n * Type:\n\ntype PostcssOptions = {\n processOptions?: ProcessOptions;\n plugins?: AcceptedPlugin[];\n};\n\n\n * Default:\n\nconst defaultConfig = {\n plugins: [\n // The following plugins are enabled by default\n require('postcss-flexbugs-fixes'),\n require('postcss-media-minmax'),\n require('postcss-nesting'),\n // The following plugins are only enabled when the target is `es5`\n require('postcss-custom-properties'),\n require('postcss-initial'),\n require('postcss-page-break'),\n require('postcss-font-variant'),\n ],\n};\n\n\n * Example:\n\nexport default defineConfig({\n buildConfig: {\n style: {\n postcss: {\n plugins: [yourPostCSSPlugin],\n },\n },\n },\n});\n\n\n\nstyle.inject#\n\nConfigure whether to insert CSS styles into JavaScript code in bundle mode.\n\n * Type: boolean\n * Default: false\n\nSet inject to true to enable this feature:\n\nexport default defineConfig({\n buildConfig: {\n inject: true,\n },\n});\n\n\nOnce enabled, you will see the CSS code referenced in the source code included\nin the bundled JavaScript output.\n\nFor example, if you write import './index.scss' in the source code, you will see\nthe following code in the output:\n\n// node_modules/style-inject/dist/style-inject.es.js\nfunction styleInject(css, ref) {\n // ...\n}\nvar style_inject_es_default = styleInject;\n\n// src/index.scss\nvar css_248z = '.body {\\n color: black;\\n}';\nstyle_inject_es_default(css_248z);\n\n\nTIP\n\nAfter enabling inject, you need to pay attention to the following points:\n\n * @import in CSS files will not be processed. If your CSS file contains\n @import, you need to manually import the CSS file in the JS file (less and\n scss files are not required because they have preprocessing).\n * Consider the impact of sideEffects. By default, our builder assumes that CSS\n has side effects. If the sideEffects field is set in your project or\n third-party package's package.json and does not include this CSS file, you\n will receive a warning:\n\n[LIBUILD:ESBUILD_WARN] Ignoring this import because \"src/index.scss\" was marked as having no side effects by plugin \"libuild:adapter\"\n\n\nYou can resolve this by configuring sideEffects.\n\n\nstyle.autoModules#\n\nEnable CSS Modules automatically based on the filename.\n\n * Type: boolean | RegExp\n * Default: true\n\ntrue : Enables CSS Modules for style files ending with .module.css .module.less\n.module.scss .module.sass filenames\n\nfalse : Disable CSS Modules.\n\nRegExp : Enables CSS Modules for all files that match the regular condition.\n\n\nstyle.modules#\n\nCSS Modules configuration\n\n * Type: object\n * Default: {}\n\nA common configuration is localsConvention, which changes the class name\ngeneration rules for css modules\n\nexport default {\n buildConfig: {\n style: {\n modules: {\n localsConvention: 'camelCaseOnly',\n },\n },\n },\n};\n\n\nFor the following styles\n\n.box-title {\n color: red;\n}\n\n\nYou can use styles.boxTitle to access\n\nFor detailed configuration see postcss-modules\n\n\nstyle.tailwindcss#\n\nUsed to modify the configuration of Tailwind CSS.\n\n * Type: object | Function\n * Default:\n\nconst tailwind = {\n content: [\n './src/**/*.{js,jsx,ts,tsx}',\n './config/html/**/*.{html,ejs,hbs}',\n './storybook/**/*',\n ],\n};\n\n\n\nEnabling Tailwind CSS#\n\nBefore using style.tailwindcss, you need to enable the Tailwind CSS plugin for\nModern.js Module.\n\nPlease refer to the section Using Tailwind CSS for instructions on how to enable\nit.\n\n\nType#\n\nWhen the value is of type object, it is merged with the default configuration\nvia Object.assign.\n\nWhen the value is of type Function, the object returned by the function is\nmerged with the default configuration via Object.assign.\n\nThe rest of the usage is the same as Tailwind CSS: Quick Portal.\n\n\nNotes#\n\nPlease note that:\n\n * If you are using both the tailwind.config.{ts,js} file and tools.tailwindcss\n option, the configuration defined in tools.tailwindcss will take precedence\n and override the content defined in tailwind.config.{ts,js}.\n * If you are using the designSystem configuration option simultaneously, the\n theme configuration of Tailwind CSS will be overridden by the value of\n designSystem.\n\nThe usage of other configurations follows the same approach as the official\nusage of Tailwind CSS. Please refer to tailwindcss - Configuration for more\ndetails.\n\n\ntarget#\n\ntarget is used to set the target environment for the generated JavaScript code.\nIt enables Modern.js Module to transform JavaScript syntax that is not\nrecognized by the target environment into older versions of JavaScript syntax\nthat are compatible with these environments.\n\n * Type:\n\ntype Target =\n | 'es5'\n | 'es6'\n | 'es2015'\n | 'es2016'\n | 'es2017'\n | 'es2018'\n | 'es2019'\n | 'es2020'\n | 'es2021'\n | 'es2022'\n | 'esnext';\n\n\n * Default: 'es6'\n\nFor example, compile the code to es5 syntax:\n\nexport default defineConfig({\n buildConfig: {\n target: 'es5',\n },\n});\n\n\n\ntransformImport#\n\nUsing SWC provides the same ability and configuration as babel-plugin-import.\nWith this configuration, the code will be converted using SWC.\n\n * Type: object[]\n * Default: []\n\nThe elements of the array are configuration objects for babel-plugin-import,\nwhich can be referred to options。\n\nExample:\n\nexport default defineConfig({\n buildConfig: {\n transformImport: [\n // babel-plugin-import`s options config\n {\n libraryName: 'foo',\n style: true,\n },\n ],\n },\n});\n\n\nReference the Import Plugin - Notes\n\n\ntransformLodash#\n\nSpecifies whether to modularize the import of lodash and remove unused lodash\nmodules to reduce the code size of lodash.\n\nThis optimization is implemented using babel-plugin-lodash and swc-plugin-lodash\nunder the hood.\n\nWith this configuration, the code will be converted using SWC.\n\n * Type: boolean\n * Default: false\n\nWhen you enable this, Modern.js Module will automatically redirects the code\nreferences of lodash to sub-paths.\n\nFor example:\n\n\n\n\nconst addOne = add(1);\n_.map([1, 2, 3], addOne);\n\n\nThe transformed code will be:\n\n\n\n\nconst addOne = _add(1);\n_map([1, 2, 3], addOne);\n\n\n\ntsconfig#\n\nPath to the tsconfig file\n\n * Type: string\n * Default: tsconfig.json\n * Version: v2.36.0\n\nexport default defineConfig({\n buildConfig: {\n tsconfig: 'tsconfig.build.json',\n },\n});\n\n\n\numdGlobals#\n\nSpecify global variables for external import of umd artifacts\n\n * Type: Record\n * Default: {}\n\nexport default {\n buildConfig: {\n umdGlobals: {\n react: 'React',\n 'react-dom': 'ReactDOM',\n },\n },\n};\n\n\nAt this point, react and react-dom will be seen as global variables imported\nexternally and will not be packed into the umd product, but will be accessible\nby way of global.React and global.ReactDOM\n\n\numdModuleName#\n\nSpecifies the module name of the umd product\n\n * Type: string | Function\n * Default: name => name\n\nexport default {\n buildConfig: {\n format: 'umd',\n umdModuleName: 'myLib',\n },\n};\n\n\nAt this point the umd artifact will go to mount on global.myLib\n\n:::tip\n\n * The module name of the umd artifact must not conflict with the global\n variable name.\n * Module names will be converted to camelCase, e.g. my-lib will be converted to\n myLib, refer to toIdentifier. :::\n\nAlso the function form can take one parameter, which is the output path of the\ncurrent package file\n\nexport default {\n buildConfig: {\n format: 'umd',\n umdModuleName: path => {\n if (path.includes('index')) {\n return 'myLib';\n } else {\n return 'myLib2';\n }\n },\n },\n};\n","frontmatter":{"sidebar_position":1},"version":""},{"id":1,"title":"buildPreset","routePath":"/module-tools/en/api/config/build-preset","lang":"en","toc":[{"text":"npm-library","id":"npm-library","depth":3,"charIndex":118},{"text":"npm-library-with-umd","id":"npm-library-with-umd","depth":3,"charIndex":827},{"text":"npm-component","id":"npm-component","depth":3,"charIndex":1685},{"text":"npm-component-with-umd","id":"npm-component-with-umd","depth":3,"charIndex":2617},{"text":"npm-library-{es5...esnext}","id":"npm-library-es5esnext","depth":3,"charIndex":3476},{"text":"string / function","id":"string--function","depth":2,"charIndex":3911}],"domain":"","content":"#\n\nA build preset string or preset function. Provides out-of-the-box build\nconfiguration\n\n * Type: string | Function\n\n\nnpm-library#\n\nLibrary generic schema used under class NPM package manager, contains esm and\ncjs Bundle products, and includes a type file.\n\nINFO\n\nAbout the class NPM Package Manager\n\n * npm\n * yarn\n * pnpm\n\n{\n \"main\": \". /dist/lib/index.js\",\n \"module\": \". /dist/es/index.js\",\n \"types\": \". /dist/types/index.d.ts\"\n}\n\n\nThe build configuration corresponding to the preset string.\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/es',\n },\n {\n buildType: 'bundle',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-library-with-umd#\n\nUsed under class NPM package manager, and Library supports a similar pattern to\nunpkg. Additional umd artifacts are provided on top of the pre-defined\nnpm-library.\n\n{\n \"main\": \". /dist/lib/index.js\",\n \"module\": \". /dist/es/index.js\",\n \"types\": \". /dist/types/index.d.ts\",\n \"unpkg\": \". /dist/umd/index.js\",\n};\n\n\nThe build configuration corresponding to the preset string.\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/es',\n },\n {\n format: 'umd',\n target: 'es6',\n platform: 'browser',\n buildType: 'bundle',\n outDir: './dist/umd',\n },\n {\n buildType: 'bundle',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-component#\n\nA generic pattern for components (libraries) used under the class NPM package\nmanager. Contains both esm and cjs Bundleless artifacts (for easy Tree shaking\noptimization), as well as including a copy of the type file.\n\nFor style files included in the source code, the artifacts provide the compiled\nfiles of the style and the source file of the style.\n\n{\n \"main\": \". /dist/lib/index.js\", // bundleless type\n \"module\": \". /dist/es/index.js\", // bundleless type\n \"types\": \". /dist/types/index.d.ts\",\n};\n\n\nThe pre-defined strings correspond to the build configuration.\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/es',\n },\n {\n buildType: 'bundleless',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-component-with-umd#\n\nComponent (library) used under class NPM package manager, with support for class\nunpkg schema. Additional umd artifacts are provided on top of the pre-defined\nnpm-component.\n\n{\n \"main\": \". /dist/lib/index.js\", // bundleless type\n \"module\": \". /dist/es/index.js\", // bundleless type\n \"types\": \". /dist/types/index.d.ts\",\n \"unpkg\": \". /dist/umd/index.js\",\n};\n\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/es',\n },\n {\n format: 'umd',\n target: 'es6',\n platform: 'browser',\n buildType: 'bundle',\n outDir: './dist/umd',\n },\n {\n buildType: 'bundleless',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-library-{es5...esnext}#\n\nWhen you want to use a buildPreset preset that supports other ECMAScript\nversions, you can directly add the supported versions to the 'npm-library',\n'npm-library-with-umd', 'npm-component', 'npm-component-with-umd' presets.\n\nFor example, if you want the 'npm-library' preset to support 'es2017', you can\nconfigure it as follows.\n\n\n\nexport default defineConfig({\n buildPreset: 'npm-library-es2017',\n});\n\n\n\nstring / function#\n\nThe buildPreset not only supports basic string forms, but also function forms,\nwhich can obtain the default values we provide through the preset or extend\nPreset parameter and then modify them.\n\nHere are two examples using preset and extend Preset:\n\n\n\nexport default defineConfig({\n buildPreset({ preset }) {\n const { NPM_LIBRARY } = preset;\n return NPM_LIBRARY.map(config => {\n config.define = {\n VERSION: '1.0.1',\n };\n return config;\n });\n },\n});\n\n\nIn the extend Preset, lodash.merge is used for configuration merge.\n\n\n\nexport default defineConfig({\n buildPreset({ extendPreset }) {\n return extendPreset('npm-library', {\n define: {\n VERSION: '1.0.1',\n },\n });\n },\n});\n","frontmatter":{"sidebar_position":2},"version":""},{"id":2,"title":"dev","routePath":"/module-tools/en/api/config/dev","lang":"en","toc":[{"text":"storybook","id":"storybook","depth":2,"charIndex":182},{"text":"storybook.webpack","id":"storybookwebpack","depth":3,"charIndex":440},{"text":"Configure Manager App","id":"configure-manager-app","depth":4,"charIndex":821},{"text":"storybook.webpackChain","id":"storybookwebpackchain","depth":3,"charIndex":1194}],"domain":"","content":"#\n\nThis section describes all configuration of Modern.js Module related to\ndebugging tools.\n\nexport default {\n dev: {\n storybook: {\n /* Storybook Config */\n },\n },\n};\n\n\n\nstorybook#\n\nRequirements:\n\n * Turn on Storybook debugging or install the @modern-js/plugin-storybook\n plugin.\n * Register the @modern-js/plugin-storybook plugin。\n\n> For more information on how to enable Storybook debugging, please refer\n> to:\"Storybook\"\n\n\nstorybook.webpack#\n\n * Type: object | Function | undefined\n * Default: undefined\n\nexport default {\n dev: {\n storybook: {\n webpack(config) {\n return config;\n },\n },\n },\n};\n\n\nYou can modify the webpack configuration of the Storybook Preview-iframe via\ndev.storybook.webpack. The usage can be found in the tools.webpack configuration\nof Modern.js Builder.\n\n\n\nConfigure Manager App#\n\nFor the webpack configuration of the Storybook Manager app section, you can\nconfigure it by adding the ./config/storybook/main.js file to configure it.\n\n// ./config/storybook/main.js\n\nmodule.exports = {\n // it controls the Storybook manager app\n managerWebpack: async (config, options) => {\n // update config here\n return config;\n },\n};\n\n\n\nstorybook.webpackChain#\n\n * Type: Function | undefined\n * Default: undefined\n\nexport default {\n dev: {\n storybook: {\n webpackChain(chain) {\n return chain;\n },\n },\n },\n};\n\n\nYou can modify the webpack configuration of the Storybook Preview-iframe via\ndev.storybook.webpackChain. You can refer to Modern.js Builder's\ntools.webpackChain configuration for how to use it.","frontmatter":{"sidebar_position":3},"version":""},{"id":3,"title":"plugins","routePath":"/module-tools/en/api/config/plugins","lang":"en","toc":[{"text":"Plugin Execution Order","id":"plugin-execution-order","depth":2,"charIndex":140},{"text":"Developing Plugins","id":"developing-plugins","depth":2,"charIndex":584},{"text":"Example","id":"example","depth":2,"charIndex":680},{"text":"Using Plugins from npm","id":"using-plugins-from-npm","depth":3,"charIndex":691},{"text":"Using Local Plugins","id":"using-local-plugins","depth":4,"charIndex":898},{"text":"Plugin Configuration","id":"plugin-configuration","depth":3,"charIndex":1082}],"domain":"","content":"#\n\nThis chapter describes the configuration of the registered Modern.js Module\nplugin.\n\n * Type: ModuleToolsPlugin[]\n * Default: undefined\n\n\nPlugin Execution Order#\n\nBy default, custom plugins are executed in the order specified in the plugins\narray. The execution of built-in plugins provided by Modern.js Module happens\nbefore the execution of custom plugins.\n\nWhen plugins use fields that control the execution order, such as pre and post,\nthe execution order is adjusted based on the declared fields. For more\ninformation, please refer to the Relationship Between Plugins guide.\n\n\nDeveloping Plugins#\n\nTo learn how to write plugins, please refer to the Plugin Writing Guide.\n\n\nExample#\n\n\nUsing Plugins from npm#\n\nTo use plugins from npm, you need to install them using a package manager and\nimport them in your configuration file.\n\n\n\nexport default defineConfig({\n plugins: [myPlugin()],\n});\n\n\nUsing Local Plugins#\n\nTo use plugins from a local code repository, you can directly import them using\na relative path.\n\n\n\nexport default defineConfig({\n plugins: [myPlugin()],\n});\n\n\n\nPlugin Configuration#\n\nIf a plugin provides custom configuration options, you can pass the\nconfiguration through the plugin function's parameters.\n\n\n\nexport default defineConfig({\n plugins: [\n myPlugin({\n foo: 1,\n bar: 2,\n }),\n ],\n});\n","frontmatter":{"sidebar_position":4},"version":""},{"id":4,"title":"testing","routePath":"/module-tools/en/api/config/testing","lang":"en","toc":[{"text":"jest","id":"jest","depth":2,"charIndex":133},{"text":"transformer","id":"transformer","depth":2,"charIndex":736}],"domain":"","content":"#\n\nThis chapter describes the test-related configuration\n\nTIP\n\nYou need to enable the unit testing feature with pnpm run new first.\n\n\njest#\n\n * Type: object | Function\n * Default: {}\n\nThe configuration corresponding to Jest, when of type object, can be configured\nwith all the underlying configurations supported by Jest .\n\n\n\nexport default defineConfig({\n testing: {\n jest: {\n testTimeout: 10000,\n },\n },\n});\n\n\nWhen the value is of type Function, the default configuration is passed as the\nfirst parameter and a new Jest configuration object needs to be returned.\n\n\n\nexport default defineConfig({\n testing: {\n jest: options => {\n return {\n ... . options,\n testTimeout: 10000\n }\n }\n }\n});\n\n\n\ntransformer#\n\n * Type: 'babel-jest' | 'ts-jest'\n * Default: 'babel-jest'\n\nConfigure the compilation tool for the source code when executing tests:\nbabel-jest or ts-jest. The default is babel-jest.\n\nINFO\n\nbabel-jest can also compile TS files without type errors, so use ts-jest if you\nneed to check the TS type when running tests.","frontmatter":{"sidebar_position":5},"version":""},{"id":5,"title":"Overview","routePath":"/module-tools/en/api/","lang":"en","toc":[],"domain":"","content":"#","frontmatter":{"overview":true,"sidebar_label":"Overview","sidebar_position":1},"version":""},{"id":6,"title":"Plugin Hooks","routePath":"/module-tools/en/api/plugin-api/plugin-hooks","lang":"en","toc":[{"text":"build hooks","id":"build-hooks","depth":2,"charIndex":424},{"text":"beforeBuild","id":"beforebuild","depth":3,"charIndex":586},{"text":"beforeBuildTask","id":"beforebuildtask","depth":3,"charIndex":1223},{"text":"afterBuildTask","id":"afterbuildtask","depth":3,"charIndex":1699},{"text":"afterBuild","id":"afterbuild","depth":3,"charIndex":2103},{"text":"buildPlatform hooks","id":"buildplatform-hooks","depth":2,"charIndex":2558},{"text":"registerBuildPlatform","id":"registerbuildplatform","depth":3,"charIndex":3057},{"text":"beforeBuildPlatform","id":"beforebuildplatform","depth":3,"charIndex":3779},{"text":"buildPlatform","id":"buildplatform","depth":3,"charIndex":4503},{"text":"afterBuildPlatform","id":"afterbuildplatform","depth":3,"charIndex":4998},{"text":"Dev Hooks","id":"dev-hooks","depth":2,"charIndex":5702},{"text":"registerDev.","id":"registerdev","depth":3,"charIndex":6177},{"text":"beforeDev","id":"beforedev","depth":3,"charIndex":7287},{"text":"(before|after)DevMenu","id":"beforeafterdevmenu","depth":3,"charIndex":7889},{"text":"beforeDevTask","id":"beforedevtask","depth":3,"charIndex":9070},{"text":"afterDev","id":"afterdev","depth":3,"charIndex":9640}],"domain":"","content":"#\n\nThis chapter describes the lifecycle hooks supported by module-tools.\n\nCurrently there are two main types of lifecycle hooks.\n\n * Build hooks: triggered only when the build command is executed to build the\n source code product.\n * buildPlatform hook: triggered only when the build --platform command is\n executed to generate other build products.\n * dev hooks: hooks that are triggered when running the dev command.\n\n\nbuild hooks#\n\nThe following Hooks are triggered in order when the build command is executed.\n\n * beforeBuild\n * beforeBuildTask\n * afterBuildTask\n * afterBuild\n\n\nbeforeBuild#\n\nTriggered before the execution of the overall build process.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuild(options: Options): Return {\n return options.config;\n }\n }\n },\n});\n\n\nParameters and return value types.\n\ntype Options = { options: { config: BuildConfig; cliOptions: BuildCommandOptions } }\n\nexport interface BuildCommandOptions {\n config: string;\n clear?: boolean;\n dts?: boolean;\n platform?: boolean | string[];\n tsconfig: string;\n watch?: boolean;\n}\n\ntype Return = BuildConfig;\n\n\n> BuildConfig type reference API configuration\n\n\nbeforeBuildTask#\n\nBased on the build configuration, Modern.js Module will split the overall build\ninto multiple sub-build tasks. The Hook will be triggered before each build\nsubtask.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuildTask(config: BaseBuildConfig): BaseBuildConfig {\n return config;\n }\n }\n },\n});\n\n\nParameters and return value types.\n\nBaseBuildConfig type reference API configuration\n\n\nafterBuildTask#\n\nTriggered after the end of each build subtask.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuildTask(options: BuildTaskResult): void {\n // ...\n }\n }\n },\n});\n\n\nParameters and return value types.\n\nexport interface BuildTaskResult {\n status: 'success' | 'fail';\n message?: string;\n config: BaseBuildConfig;\n}\n\n\n\nafterBuild#\n\nTriggered after the end of the overall build process.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuild(options: BuildResult): void {\n // ...\n }\n }\n },\n});\n\n\nParameters and return value types.\n\nexport interface BuildResult {\n status: 'success' | 'fail';\n message?: string;\n config: BuildConfig;\n commandOptions: BuildCommandOptions;\n totalDuration: number;\n}\n\n\n\nbuildPlatform hooks#\n\nmodule-tools also provides the build --platform command to perform specific\nbuild tasks.\n\nFor example, after installing the Storybook plugin, you can run build --platform\nor build --platform storybook to perform Storybook build tasks. This is because\nthe Storybook plugin is based on the buildPlatform Hooks.\n\nHooks are triggered in the following order after executing build --platform.\n\n * registerBuildPlatform\n * beforeBuildPlatform\n * buildPlatform\n * afterBuildPlatform\n\n\nregisterBuildPlatform#\n\nGets information about the tasks that need to be run when executing the build\n--platform command.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n registerBuildPlatform(): RegisterBuildPlatformResult {\n // ...\n return {\n platform: 'stroybook',\n build() {\n // run storybook logic\n },\n }, };\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface RegisterBuildPlatformResult {\n platform: string | string[];\n build: (\n currentPlatform: string, // the currently running platform build task\n context: { isTsProject: boolean },\n ) => void | Promise;\n}\n\n\n\nbeforeBuildPlatform#\n\nTriggers all registered build tasks when the build --platform command is\nexecuted. beforeBuildPlatform will be triggered before the execution of the\noverall build task.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuildPlatform(platforms: RegisterBuildPlatformResult[]): void {\n console.info(`have ${platforms.length} platform tasks`);\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface RegisterBuildPlatformResult {\n platform: string | string[];\n build: (\n currentPlatform: string, // the currently running platform build task\n context: { isTsProject: boolean },\n ) => void | Promise;\n}\n\n\n\nbuildPlatform#\n\nWhen the build --platform command is executed, all registered build tasks will\nbe triggered. buildPlatform will be triggered before each build task is\nexecuted.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n buildPlatform({ platform }: Options): void {\n console.info(`current task is ${platform}`);\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface Options {\n platform: string;\n}\n\n\n\nafterBuildPlatform#\n\nWhen the build --platform command is executed, all registered build tasks will\nbe triggered. afterBuildPlatform will be triggered after the overall platform\nbuild task is finished.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuildPlatform(result: BuildPlatformResult): void {\n if (result.status === 'success') {\n console.info(`all platform build task success`);\n } else {\n console.error(result.message);\n }\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface BuildPlatformResult {\n status: 'success' | 'fail';\n message: string | Error | null;\n}\n\n\n\nDev Hooks#\n\nThe following Hooks are triggered in order when the dev command is executed.\n\n * registerDev: triggered when getting dev function information.\n * beforeDev: Triggered before starting the dev process as a whole.\n * beforeDevMenu: triggered before the dev list/menu appears.\n * afterDevMenu: triggered after dev list/menu option is selected.\n * beforeDevTask: Triggered before executing the dev task.\n * afterDev: Triggered at the end of the overall dev process.\n\n\nregisterDev.#\n\nRegister dev tool related data. Mainly contains.\n\n * the name of the dev tool\n * The name of the item displayed in the menu list and the corresponding value.\n * The definition of the dev subcommand.\n * Whether to execute the source code build before running the dev task\n * The function to execute the dev task.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n registerDev() {\n return {\n // Dev tool name\n name: 'storybook',\n // Menu content\n menuItem: {\n name: 'Storybook',\n value: 'storybook',\n },\n // Defined dev subcommands\n subCommands: ['storybook', 'story'],\n async action() {\n // dev logic\n },\n };\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\nbeforeDev#\n\nTriggered before the dev task is executed after all dev tool metadata has been\ncollected.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDev(metas: DevToolData[]) {\n console.info(`have ${metas.length} dev tools`);\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\n(before|after)DevMenu#\n\nbeforeDevMenu is triggered before the dev list/menu appears. Receives inquirer\nquestion as argument. Default value is.\n\nconst question = [\n {\n name: 'choiceDevTool',\n message: 'Select dev tool',\n type: 'list',\n // Registered dev messages\n choices,\n },\n];\n\n\nafterDevMenu Triggered after selecting dev list/menu options.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDevMenu(questions) {\n questions[0].message += '!' ;\n return questions; // required\n },\n afterDevMenu(options: Options) {\n console.info(`choise ${options.result.choiceDevTool} dev tools`);\n }\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport type { QuestionCollection } from 'inquirer';\n\nexport interface Options {\n result: PromptResult;\n devTools: DevToolData[];\n}\n\nexport type PromptResult = { choiceDevTool: string }\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\nbeforeDevTask#\n\nTriggered before the dev task is executed.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDevTask(currentDevData: DevToolData) {\n console.info(`${currentDevData.name} running`);\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\nafterDev#\n\nTriggered when the dev task process is interrupted.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterDev() {\n console.info(`exit!`);\n },\n };\n },\n});\n","frontmatter":{},"version":""},{"id":7,"title":"","routePath":"/module-tools/en/components/faq-build-exception","lang":"en","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":8,"title":"","routePath":"/module-tools/en/components/faq-build-other","lang":"en","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":9,"title":"","routePath":"/module-tools/en/components/faq-build-product","lang":"en","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":10,"title":"","routePath":"/module-tools/en/components/faq-storybook","lang":"en","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":11,"title":"","routePath":"/module-tools/en/components/faq-test","lang":"en","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":12,"title":"","routePath":"/module-tools/en/components/register-esbuild-plugin","lang":"en","toc":[],"domain":"","content":"\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.plugins = [myEsbuildPlugin, ...options.plugins];\n return options;\n },\n },\n});\n\n\nWhen adding an esbuild plugin, please note that you need to add the plugin at\nthe beginning of the plugins array. This is because the Modern.js Module is also\nintegrated into the entire build process through an esbuild plugin. Therefore,\ncustom plugins need to be registered with higher priority.","frontmatter":{},"version":""},{"id":13,"title":"Handle static assets","routePath":"/module-tools/en/guide/advance/asset","lang":"en","toc":[{"text":"Default behavior","id":"default-behavior","depth":2,"charIndex":139},{"text":"Example","id":"example","depth":2,"charIndex":571}],"domain":"","content":"#\n\nModern.js Module will handle static assets used in the code. If configuration is\nrequired, then the buildConfig.asset API can be used.\n\n\nDefault behavior#\n\nBy default, Modern.js Module handles the following static assets:\n\n * '.svg'、'.png'、'.jpg'、'.jpeg'、'.gif'、'.webp'\n * '.ttf'、'.otf'、'.woff'、'.woff2'、'.eot'\n * '.mp3'、'.mp4'、'.webm'、'.ogg'、'.wav'、'.flac'、'.aac'、'.mov'\n\nFor the handling of static files, Modern.js Module currently supports the\nfollowing functions.\n\n * Set the static asset path to . /assets.\n * Files less than 10kb will be inlined into the code.\n\n\nExample#\n\nLet us look at the following example:\n\n * Project source code:\n\n\n//...\n\n\n * If the size of bg.png is less than 10 kb, then the output directory structure\n and file content are.\n\n./dist\n└── asset.js\n\n\nvar bg_default = 'data:image/png;base64,';\nconsole.info(bg_default);\n\n\n * If the size of bg.png is larger than 10 kb, then the output directory\n structure and file content are.\n\n./dist\n├── asset.js\n└── assets\n └── bg.13e2aba2.png\n\n\n\nconsole.info(img);\n\n\nWhen wanting to modify the default behavior, the following API can be used:\n\n * asset.path: modify the output path of the static assets.\n * asset.limit: modify the threshold value for inline assets.","frontmatter":{"sidebar_position":6},"version":""},{"id":14,"title":"Build umd artifacts","routePath":"/module-tools/en/guide/advance/build-umd","lang":"en","toc":[{"text":"Third-party dependency handling for umd artifacts","id":"third-party-dependency-handling-for-umd-artifacts","depth":2,"charIndex":487},{"text":"Example","id":"example","depth":3,"charIndex":791},{"text":"Global variable names of third-party dependencies","id":"global-variable-names-of-third-party-dependencies","depth":3,"charIndex":2178},{"text":"Changing the name of a global variable in a project","id":"changing-the-name-of-a-global-variable-in-a-project","depth":2,"charIndex":3607}],"domain":"","content":"#\n\nThe full name of umd is Universal Module Definition, and JS files in this format\ncan run in multiple runtime environments: the\n\n * Browser environment: module loading based on AMD specification\n * Node.js environment: module loading based on CommonJS\n * Other cases: mount the module on a global object.\n\nWe can therefore specify the build artifacts of the project as an umd artifact\nin the following way:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n },\n});\n\n\n\nThird-party dependency handling for umd artifacts#\n\nIn the \"How to handle third-party dependencies\" chapter, we know that we can\ncontrol whether or not the project packages third-party dependencies via the\nautoExternals and externals APIs. So when building umd artifacts, we can also\nuse it like this:\n\n\nExample#\n\n * If the project depends on react:\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n * modern.config.ts:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n autoExternal: false,\n externals: ['react'],\n },\n});\n\n\n * When a react dependency is used in the source code:\n\n\nconsole.info(React);\n\n\n * The react code is not bundled into the artifact at this point:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports, require('react'));\n else if (typeof define === 'function' && define.amd)\n define(['exports', 'react'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.index = {}), global.react);\n})(this, function (exports, _react) {\n 'use strict';\n Object.defineProperty(exports, '__esModule', {\n value: true,\n });\n _react = /*#__PURE__*/ _interopRequireDefault(_react);\n function _interopRequireDefault(obj) {\n return obj && obj.__esModule\n ? obj\n : {\n default: obj,\n };\n }\n console.info(_react.default);\n});\n\n\nWe know from the above example that when using the autoExternal and externals\nAPIs.\n\n * In a Node.js environment, you can get the react dependency with\n require('react').\n * In a browser environment, you can get the react dependency via global.react.\n\n\nGlobal variable names of third-party dependencies#\n\nHowever, in the browser environment, when getting third-party dependencies,\nglobal variable names are not necessarily identical to the dependency names, so\nyou have to use the buildConfig.umdGlobals API.\n\nAgain using the previous example, when the react dependency exists in the\nbrowser environment as a windows.React or global.React global variable, then:\n\n * modern.config.ts config file:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdGlobals: {\n react: 'React',\n },\n },\n});\n\n\nWhen a react dependency is used in the source code:\n\n\nconsole.info(React);\n\n\nAt this point we will see the output code like this:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory();\n else if (typeof define === 'function' && define.amd) define([], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory();\n})(this, function () {\n // ...\n // libuild:globals:react\n var require_react = __commonJS({\n 'libuild:globals:react'(exports, module1) {\n module1.exports = Function('return this')()['React'];\n },\n });\n // src/index.ts\n var import_react = __toESM(require_react());\n console.info(import_react.default);\n});\n\n\nThe project can then run in the browser and use the React variables that exist\non the global object.\n\n\nChanging the name of a global variable in a project#\n\nWhen we package the following code into an umd artifact and run it in the\nbrowser, we can use the module via window.index.\n\nexport default () => {\n console.info('hello world');\n};\n\n\n** By default, the name of the source file is used as the name of the module's\nglobal variable in the browser. **For the above example, the artifact would read\nas follows:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports);\n else if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.index = {}));\n})(this, function (exports) {\n //...\n});\n\n\nIf you need to modify it, you need to use the buildConfig.umdModuleName API.\n\nWhen this API is used:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdModuleName: 'myLib',\n },\n});\n\n\nThe build artifact at this point are:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports);\n else if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.myLib = {}));\n})(this, function (exports) {\n //...\n});\n","frontmatter":{"sidebar_position":5},"version":""},{"id":15,"title":"Use the Copy Tools","routePath":"/module-tools/en/guide/advance/copy","lang":"en","toc":[{"text":"Understanding the Copy API","id":"understanding-the-copy-api","depth":2,"charIndex":171},{"text":"API Description","id":"api-description","depth":2,"charIndex":335},{"text":"Examples of Different Scenarios","id":"examples-of-different-scenarios","depth":2,"charIndex":2449},{"text":"Copying Files","id":"copying-files","depth":3,"charIndex":2484},{"text":"Copying Files to a Directory","id":"copying-files-to-a-directory","depth":3,"charIndex":2834},{"text":"Copying from Directory to Directory","id":"copying-from-directory-to-directory","depth":3,"charIndex":3192},{"text":"Copying from Directory to File","id":"copying-from-directory-to-file","depth":3,"charIndex":3613},{"text":"Using Glob","id":"using-glob","depth":3,"charIndex":4042}],"domain":"","content":"#\n\nModern.js Module provides the Copy utility for copying already existing\nindividual files or entire directories into the output directory. Next we learn\nhow to use it.\n\n\nUnderstanding the Copy API#\n\nWe can use the Copy tool via the buildConfig.copy API, which contains the\nfollowing two main configurations.\n\n * patterns\n * options\n\n\nAPI Description#\n\ncopy.patterns is used to find files to be copied and configure the output path.\n\nThe patterns.from parameter is used to specify the file or directory to be\ncopied. It accepts either a Glob pattern string or a specific path. A Glob\npattern string refers to the fast-glob pattern syntax. Therefore, we can use it\nin two ways as follows:\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n { from: './index.html', to: '' },\n { from: './*.html', to: '' },\n ],\n },\n },\n});\n\n\nThe patterns.context parameter is generally used in conjunction with\npatterns.from. By default, its value is the same as buildConfig.sourceDir.\nTherefore, we can specify the file src/data.json to be copied in the following\nway:\n\n> By default, buildConfig.sourceDir is set to src.\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n { from: './data.json' to: ''},\n ],\n },\n },\n});\n\n\nWhen the specified file is not in the source code directory, you can modify the\ncontext configuration. For example, to specify the file temp/index.html in the\nproject directory to be copied:\n\n\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n {\n from: './index.html',\n context: path.join(__dirname, './temp')\n to: '',\n }\n ],\n },\n },\n});\n\n\nThe patterns.to parameter is used to specify the output path for the copied\nfiles. By default, its value corresponds to buildConfig.outDir. Therefore, we\ncan copy src/index.html to the dist directory as follows:\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [{ from: './index.html' }],\n },\n },\n});\n\n\nWhen we configure patterns.to:\n\n * If it is a relative path, the path will be calculated relative to\n buildConfig.outDir to determine the absolute path for copying the files.\n * If it is an absolute path, the value will be used directly.\n\nFinally, patterns.globOptions is used to configure the globby object for finding\nfiles to copy. Its configuration can be referenced from:\n\n * globby.options\n\n\nExamples of Different Scenarios#\n\n\nCopying Files#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy file to file\n */\n {\n from: './temp-1/a.png',\n context: __dirname,\n to: './temp-1/b.png',\n },\n ],\n },\n },\n ],\n});\n\n\n\nCopying Files to a Directory#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy file to dir\n */\n {\n from: './temp-2/a.png',\n context: __dirname,\n to: './temp-2',\n },\n ],\n },\n },\n ],\n});\n\n\n\nCopying from Directory to Directory#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy dir to dir\n */\n {\n from: './temp-3/',\n to: './temp-3',\n context: __dirname,\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n\n\n\nCopying from Directory to File#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy dir to file\n */\n {\n from: './temp-4/',\n context: __dirname,\n to: './temp-4/_index.html',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n\n\n\nUsing Glob#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy glob to dir\n */\n {\n from: './*.html',\n to: './temp-5',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n {\n copy: {\n patterns: [\n /**\n * copy glob to file\n */\n {\n from: './*.html',\n to: './temp-6/index.html',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n","frontmatter":{"sidebar_position":3},"version":""},{"id":16,"title":"Handle third-party dependencies","routePath":"/module-tools/en/guide/advance/external-dependency","lang":"en","toc":[{"text":"Default handling of third-party dependencies","id":"default-handling-of-third-party-dependencies","depth":2,"charIndex":861},{"text":"Example","id":"example","depth":3,"charIndex":1423},{"text":"Exclude specified third-party dependencies","id":"exclude-specified-third-party-dependencies","depth":2,"charIndex":1840}],"domain":"","content":"#\n\nGenerally, third-party dependencies required by a project can be installed via\nthe install command in the package manager. After the third-party dependencies\nare successfully installed, they will generally appear under dependencies and\ndevDependencies in the project package.json.\n\n{\n \"dependencies\": {},\n \"devDependencies\": {}\n}\n\n\nDependencies under \"dependencies\" are generally related to project code and\nbuilds, and if these third-party dependencies are declared under\n\"devDependencies\", then there will be missing dependencies in production\nenvironments.\n\nIn addition to \"dependencies\", \"peerDependencies\" can also declare dependencies\nthat are needed in the production environment, but it puts more emphasis on the\nexistence of these dependencies declared by \"peerDependencies\" in the project's\nruntime environment, similar to the plugin mechanism.\n\n\nDefault handling of third-party dependencies#\n\nBy default, third-party dependencies under \"dependencies\" and \"peerDependencies\"\nare not bundled by Modern.js Module.\n\nThis is because when the npm package is installed, its \"dependencies\" will also\nbe installed. By not packaging \"dependencies\", you can reduce the size of the\npackage product.\n\nIf you need to package some dependencies, it is recommended to move them from\n\"dependencies\" to \"devDependencies\", which is equivalent to prebundle the\ndependencies and reduces the size of the dependency installation.\n\n\nExample#\n\nIf the project has a dependency on react.\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n },\n // or\n \"peerDependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\nWhen a react dependency is used in the source code:\n\n\nconsole.info(React);\n\n\nThe react code is not bundled into the artifact:\n\n\nconsole.info(React);\n\n\nIf you want to modify the default processing, you can use the following API.\n\n * buildConfig.autoExternal\n\n\nExclude specified third-party dependencies#\n\nWe mentioned above the use of the buildConfig.autoExternal API, and\nbuildConfig.externals can control which third-party dependencies to handle the\nproject's dependencies in a more granular way.\n\nFor example, when we need to leave only certain dependencies unpacked, we can\nconfigure it as follows.\n\n> In this case, it is likely that some dependencies are not suitable for\n> packaging. If this is the case, then you can handle it as follows.\n\nepxort default defineConfig({\n buildConfig: {\n autoExternal: false,\n externals: ['pkg-1', /pkg-2/],\n }\n});\n","frontmatter":{"sidebar_position":4},"version":""},{"id":17,"title":"In-depth understanding of build","routePath":"/module-tools/en/guide/advance/in-depth-about-build","lang":"en","toc":[{"text":"bundle / bundleless","id":"bundle--bundleless","depth":2,"charIndex":497},{"text":"input / sourceDir","id":"input--sourcedir","depth":2,"charIndex":1630},{"text":"use swc","id":"use-swc","depth":2,"charIndex":2902},{"text":"Using Hooks to Intervene in the Build Process","id":"using-hooks-to-intervene-in-the-build-process","depth":2,"charIndex":3852},{"text":"Hook type","id":"hook-type","depth":3,"charIndex":4232},{"text":"AsyncSeriesBailHook","id":"asyncseriesbailhook","depth":4,"charIndex":4244},{"text":"AsyncSeriesWaterFallHooks","id":"asyncserieswaterfallhooks","depth":4,"charIndex":4383},{"text":"Hook API","id":"hook-api","depth":3,"charIndex":4480},{"text":"load","id":"load","depth":4,"charIndex":4491},{"text":"transform","id":"transform","depth":4,"charIndex":5185},{"text":"renderChunk","id":"renderchunk","depth":4,"charIndex":5696},{"text":"dts","id":"dts","depth":2,"charIndex":6675},{"text":"Turn off type generation","id":"turn-off-type-generation","depth":3,"charIndex":6758},{"text":"Build type files","id":"build-type-files","depth":3,"charIndex":7035},{"text":"Alias Conversion","id":"alias-conversion","depth":3,"charIndex":7729},{"text":"Some examples of the use of dts","id":"some-examples-of-the-use-of-dts","depth":3,"charIndex":8305},{"text":"Build process","id":"build-process","depth":2,"charIndex":9002},{"text":"Build errors","id":"build-errors","depth":2,"charIndex":9295},{"text":"Debug mode","id":"debug-mode","depth":2,"charIndex":10045}],"domain":"","content":"#\n\nIn the \"Basic Usage\" section, we already knew that you can modify the output\nfiles of a project through the buildConfig configuration. buildConfig not only\ndescribes some of the features of the product, but also provides some\nfunctionality for building the product.\n\nTIP\n\nIf you are not familiar with buildConfig, please read modify-output-product.\n\nIn this chapter we'll dive into the use of certain build configurations and\nunderstand what happens when the modern build command is executed.\n\n\nbundle / bundleless#\n\nSo first let's understand bundle and bundleless.\n\nA bundle is a package of build products, which may be a single file or multiple\nfiles based on a certain code splitting strategy.\n\nbundleless, on the other hand, means that each source file is compiled and built\nseparately, but not bundled together. Each output file can be found with its\ncorresponding source code file. The process of bundleless build can also be\nunderstood as the process of code conversion of source files only.\n\nThey have their own benefits.\n\n * bundle can reduce the size of build artifacts and also pre-package\n dependencies to reduce the size of installed dependencies. Packaging\n libraries in advance can speed up application project builds.\n * bundleless maintains the original file structure and is more conducive to\n debugging and tree shaking.\n\nWARNING\n\nbundleless is a single file compilation mode, so for type references and exports\nyou need to add the type field, e.g. import type { A } from '. /types\n\nIn buildConfig you can specify whether the current build task is bundle or\nbundleless by using buildConfig.buildType.\n\n\ninput / sourceDir#\n\nbuildConfig.input is used to specify the path to a file or directory from which\nto read the source code, the default value of which varies between bundle and\nbundleless builds:\n\n * When buildType: 'bundle', input defaults to src/index.(j|t)sx?.\n * When buildType: 'bundleless', input defaults to ['src'].\n\nFrom the default value, we know that building in bundle mode usually specifies\none or more files as the entry point for the build, while building in bundleless\nmode specifies a directory and uses all the files in that directory as the entry\npoint.\n\nsourceDir is used to specify the source directory, which is only related to the\nfollowing two elements:\n\n * Type file generation\n * outbase for specifying the build process\n\nSo we can get its best practices:\n\n * Only specify input during the bundle build.\n * In general, bundleless only needs to specify sourceDir (where input will be\n aligned with sourceDir). If we want to use the input in bundleless, we only\n need to specify sourceDir.\n\nIf you want to convert only some of the files in bundleless, e.g. only the files\nin the src/runtime directory, you need to configure input:\n\n\n\nexport default defineConfig({\n buildConfig: {\n input: ['src/runtime'],\n sourceDir: 'src',\n },\n});\n\n\n\nuse swc#\n\nIn some scenarios, esbuild is not enough to meet our needs, and we will use swc\nto do the code conversion.\n\nStarting from version 2.36.0, the Modern.js Module will use swc by default when\nit comes to the following functionality, but that doesn't mean we don't use\nesbuild any more, the rest of the functionality will still use esbuild.\n\n * transformImport\n * transformLodash\n * externalHelpers\n * format: umd\n * target: es5\n * emitDecoratorMetadata: true\n\nIn fact, we've been using swc for full code conversion since 2.16.0. However,\nswc also has some limitations, so we added sourceType to turn off swc when the\nsource is formatted as 'commonjs', which isn't really user-intuitive, and the\ncjs mode of the swc formatted outputs don't have annotate each export name,\nwhich can cause problems in node. So we deprecated this behaviour and went back\nto the original design - using swc as a supplement only in situations where it\nwas needed.\n\n\nUsing Hooks to Intervene in the Build Process#\n\nThe Modern.js Module provides a Hook mechanism that allows us to inject custom\nlogic at different stages of the build process. The Modern.js Module Hook is\nimplemented using tapable, which extends esbuild's plugin mechanism, and is\nrecommended to be used directly if esbuild plugins already meet your needs.\nHere's how to use it:\n\n\nHook type#\n\nAsyncSeriesBailHook#\n\nSerial hooks that stop the execution of other tapped functions if a tapped\nfunction returns a non-undefined result.\n\nAsyncSeriesWaterFallHooks#\n\nSerial hooks whose results are passed to the next tapped function.\n\n\nHook API#\n\nload#\n\n * AsyncSeriesBailHook\n * Triggered at esbuild onLoad callbacks to fetch module content based on the\n module path\n * Input parameters\n\ninterface LoadArgs {\n path: string;\n namespace: string;\n suffix: string;\n}\n\n\n * Return parameters\n\ntype LoadResult =\n | {\n contents: string; // module contents\n map?: SourceMap; // https://esbuild.github.io/api/#sourcemap\n loader?: Loader; // https://esbuild.github.io/api/#loader\n resolveDir?: string;\n }\n | undefined;\n\n\n * Example\n\ncompiler.hooks.load.tapPromise('load content from memfs', async args => {\n const contents = memfs.readFileSync(args.path);\n return {\n contents: contents,\n loader: 'js',\n };\n});\n\n\ntransform#\n\n * AsyncSeriesWaterFallHooks\n * Triggered at esbuild onLoad callbacks. Transforms the contents of the module\n fetched during the load phase\n * Input parameters (return parameters)\n\nexport type Source = {\n code: string;\n map?: SourceMap;\n path: string;\n loader?: string;\n};\n\n\n * Example\n\ncompiler.hooks.transform.tapPromise('6to5', async args => {\n const result = babelTransform(args.code, { presets: ['@babel/preset-env'] });\n return {\n code: result.code,\n map: result.map,\n };\n});\n\n\nrenderChunk#\n\n * AsyncSeriesWaterFallHooks\n * Triggered at esbuild onEnd callbacks. This is similar to the transform hook,\n but works on the products generated by esbuild.\n * Input parameters (return parameters)\n\nexport type AssetChunk = {\n type: 'asset';\n contents: string | Buffer;\n entryPoint?: string;\n /**\n * absolute file path\n */\n fileName: string;\n originalFileName?: string;\n};\n\nexport type JsChunk = {\n type: 'chunk';\n contents: string;\n entryPoint?: string;\n /**\n * absolute file path\n */\n fileName: string;\n map?: SourceMap;\n modules?: Record;\n originalFileName?: string;\n};\n\nexport type Chunk = AssetChunk | JsChunk;\n\n\n * Examples\n\ncompiler.hooks.renderChunk.tapPromise('minify', async chunk => {\n if (chunk.type === 'chunk') {\n const code = chunk.contents.toString();\n const result = await minify.call(compiler, code);\n return {\n ...chunk,\n contents: result.code,\n map: result.map,\n };\n }\n return chunk;\n});\n\n\n\ndts#\n\nThe buildConfig.dts configuration is mainly used for type file generation.\n\n\nTurn off type generation#\n\nType generation is turned on by default, if you need to turn it off, you can\nconfigure it as follows:\n\n\n\nexport default defineConfig({\n buildConfig: {\n dts: false,\n },\n});\n\n\nTIP\n\nThe build speed is generally improved by closing the type file.\n\n\nBuild type files#\n\nWith buildType: 'bundleless', type files are generated using the project's tsc\ncommand to complete production.\n\nThe Modern.js Module also supports bundling of type files, although care needs\nto be taken when using this feature.\n\n * Some third-party dependencies have incorrect syntax that can cause the\n bundling process to fail. So in this case, you need to exclude such\n third-party packages manually with buildConfig.externals.\n * It is not possible to handle the case where the type file of a third-party\n dependency points to a .ts file. For example, the package.json of a\n third-party dependency contains something like this: {\"types\": \".\n /src/index.ts\"}.\n\n\nAlias Conversion#\n\nDuring the bundleless build process, if an alias appears in the source code,\ne.g.\n\n\n\n\nNormally, the type files generated with tsc will also contain these aliases.\nHowever, Modern.js Module will convert the aliases in the type file generated by\ntsc to:\n\n * Alias conversion is possible for code of the form ``.\n * Aliasing is possible for code of the form export { utils } from\n '@common/utils'.\n\nHowever, there are some cases that cannot be handled at this time.Output types\nof the form Promise cannot be converted at this time. You can discuss it here\n\n\nSome examples of the use of dts#\n\nGeneral usage:\n\n\n\nexport default defineConfig({\n // The output path of the bundled type file at this point is `./dist/types`\n buildConfig: {\n buildType: 'bundle',\n dts: {\n tsconfigPath: './other-tsconfig.json',\n distPath: './types',\n },\n outDir: './dist',\n },\n});\n\n\nFor the use of dts.only:\n\n\n\nexport default defineConfig({\n // At this moment the type file is not bundled and the output path is `./dist/types`\n buildConfig: [\n {\n buildType: 'bundle',\n dts: false,\n outDir: './dist',\n },\n {\n buildType: 'bundleless',\n dts: {\n only: true,\n },\n outDir: './dist/types',\n },\n ],\n});\n\n\n\nBuild process#\n\nWhen the modern build command is executed, the\n\n * Clear the output directory according to buildConfig.outDir.\n * Compile js/ts source code to generate the JS build artifacts for\n bundle/bundleless.\n * Generate bundle/bundleless type files using tsc.\n * Handle Copy tasks.\n\n\nBuild errors#\n\nWhen a build error occurs, based on the information learned above, it is easy to\nunderstand what error appears in the terminal.\n\nErrors reported for js or ts builds:\n\nerror ModuleBuildError:\n\n╭───────────────────────╮\n│ bundle failed: │\n│ - format is \"cjs\" │\n│ - target is \"esnext\" │\n╰───────────────────────╯\n\nDetailed Information:\n\n\nErrors reported for the type file generation process:\n\nerror ModuleBuildError:\n\nbundle DTS failed:\n\n\nFor js/ts build errors, we can tell from the error message.\n\n * By 'bundle failed:' to determine if the error is reported for a bundle build\n or a bundleless build\n * What is the format of the build process\n * What is the target of the build process\n * The specific error message\n\n\nDebug mode#\n\nFrom 2.36.0, For troubleshooting purposes, the Modern.js Module provides a debug\nmode, which you can enable by adding the DEBUG=module environment variable when\nexecuting a build.\n\nDEBUG=module modern build\n\n\nIn debug mode, you'll see more detailed build logs output in Shell, which are\nmainly process logs:\n\nmodule run beforeBuildTask hooks +6ms\nmodule run beforeBuildTask hooks done +0ms\nmodule [DTS] Build Start +139ms\nmodule [CJS] Build Start +1ms\n\n\nIn addition, Module provides the ability to debug internal workflows. You can\nenable more detailed debugging logging by setting the DEBUG=module:* environment\nvariable.\n\nCurrently, only DEBUG=module:resolve is supported, which allows you to see a\ndetailed log of module resolution within the Module.\n\n module:resolve onResolve args: {\n path: './src/hooks/misc.ts',\n importer: '',\n namespace: 'file',\n resolveDir: '/Users/bytedance/modern.js/packages/solutions/module-tools',\n kind: 'entry-point',\n pluginData: undefined\n} +0ms\n module:resolve onResolve result: {\n path: '/Users/bytedance/modern.js/packages/solutions/module-tools/src/hooks/misc.ts',\n external: false,\n namespace: 'file',\n sideEffects: undefined,\n suffix: ''\n} +0ms\n","frontmatter":{"sidebar_position":1},"version":""},{"id":18,"title":"In-depth understanding of the dev command","routePath":"/module-tools/en/guide/advance/in-depth-about-dev-command","lang":"en","toc":[{"text":"The overall flow of the command run","id":"the-overall-flow-of-the-command-run","depth":2,"charIndex":92},{"text":"Extending the dev command","id":"extending-the-dev-command","depth":2,"charIndex":805}],"domain":"","content":"#\n\nThe dev command provided by the Modern.js Module is mainly used for debugging\nthe code.\n\n\nThe overall flow of the command run#\n\n 1. When the dev command is executed, Modern.js Module starts looking for\n debugging tools or tasks that can be executed. A debugging tool or task is a\n Modern.js Module debugging tool plugin like Storybook.\n 2. When a debugging tool is found, it is executed immediately.\n 3. When multiple debugging tools are found, the debugging tools list menu is\n displayed. A debug tool can be started by selecting the name option\n corresponding to it.\n 4. When no debug tool is found, the user is informed that no debug tool is\n available.\n\nIn addition to the dev command, you can also start a debugging tool or task\ndirectly by using the dev [debug tool name] option.\n\n\nExtending the dev command#\n\nIf you need to extend the dev command, or rather provide your own Modern.js\nModule debugging tool plugin, then you will need to know the following first.\n\n * Development of plugins\n * Debugging Tools Plugin API\n\nIn general, the code to implement a debugging tool that does nothing and the\nassociated configuration is as follows.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'do-nothing',\n setup() {\n return {\n registerDev() {\n return {\n // Debugging tool name\n name: 'do-nothing',\n // Menu display content\n menuItem: {\n name: 'DoNothing',\n value: 'do-nothing',\n },\n // The defined dev subcommand\n subCommands: ['donothing', 'dn'],\n async action() {\n // dev logic\n console.info('Run build --watch, and do nothing.');\n },\n };\n },\n };\n },\n});\n\n\nIf this debugging tool plugin is required, it needs to be added to the\nconfiguration file.\n\n\n\nexport default defineConfig({\n plugins: [\n //..\n doNothingPlugin()\n ],\n});\n\n\nAt this point we can execute it when we execute the dev or dev do-nothing\ncommand. After execution, it will first execute the source build task in\nlistening mode and print the log messages immediately afterwards.\n\nFor currently officially supported debugging tools and third-party supported\ndebugging tools, you can view them in plugins list.","frontmatter":{"sidebar_position":2},"version":""},{"id":19,"title":"Before you start","routePath":"/module-tools/en/guide/basic/before-getting-started","lang":"en","toc":[{"text":"Environment preparation","id":"environment-preparation","depth":2,"charIndex":3},{"text":"Getting Started with npm","id":"getting-started-with-npm","depth":2,"charIndex":425},{"text":"npm package type project","id":"npm-package-type-project","depth":2,"charIndex":907},{"text":"Using third-party npm packages","id":"using-third-party-npm-packages","depth":2,"charIndex":2127},{"text":"Other npm bits and pieces to know","id":"other-npm-bits-and-pieces-to-know","depth":2,"charIndex":3994},{"text":"Program entry for npm packages","id":"program-entry-for-npm-packages","depth":3,"charIndex":4031},{"text":"scripts","id":"scripts","depth":3,"charIndex":4916},{"text":"npm install","id":"npm-install","depth":4,"charIndex":5729},{"text":"npm publish","id":"npm-publish","depth":4,"charIndex":6090},{"text":"peerDependencies","id":"peerdependencies","depth":3,"charIndex":6360},{"text":"npm package manager","id":"npm-package-manager","depth":2,"charIndex":7062},{"text":"Modern.js Module configuration file","id":"modernjs-module-configuration-file","depth":2,"charIndex":7347}],"domain":"","content":"#\n\n\nEnvironment preparation#\n\nIn order to use the Modern.js Module, you first need NodeJS engine, we recommend\nthe latest LTS version, and make sure the Node version is >=14.18.0. because\nnon-stable NodeJS releases frequently have bugs. You might consider installing\nvia nvm-windows and nvm (Mac / Linux), so you can easily switch to different\nNodeJS versions that might be required for different projects that you work on.\n\n\nGetting Started with npm#\n\nOnce NodeJS is installed, not only can you access the node executable from the\ncommand line, but you can also execute the npm command.\n\nNpm is the standard package manager for NodeJS. It started out as a tool for\ndownloading and managing NodeJS package dependencies, but it has since evolved\ninto a tool for front-end JavaScript.\n\nIf you already know something about usage of npm and npm packages, then you can\ndirectly see npm package manager section.\n\n\nnpm package type project#\n\nSo what is an npm package type project? When we execute the npm init command in\nan empty project directory, it creates a JSON file with the file name\npackage.json under the current directory. During the creation process, we will\nneed to fill in information including but not limited to the name, version\nnumber, description, etc. of the npm package, which will be found in the\nresulting package.json file as follows\n\n{\n \"name\": \"npm-demo\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"index.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n },\n \"author\": \"\",\n \"license\": \"ISC\"\n}\n\n\nAt this point the project containing the initialized package.json file is an npm\npackage type project, and you can execute the npm publish command to publish the\nproject to the npm Registry.\n\nThe npm Registry is a npm package store where developers can not only publish\ntheir own npm packages to the npm Registry, but also use npm packages published\nby other developers through the npm Registry.\n\nA quality npm package will be used by more people because it not only saves a\nlot of code implementation work, but is also less likely to cause problems with\nthe project.\n\n\nUsing third-party npm packages#\n\nWhen adding a third-party npm package to an initial project, we can call this\nprocess \"installing dependencies for the project\" or \"adding dependencies to the\nproject\". Before adding dependencies, we need to know one thing in particular --\nthe types of packages npm depends on.\n\n * \"dependencies\": a type of package that your application will need in a\n production environment.\n * \"devDependencies\": another type of package that is only needed for local\n development and testing.\n \n > packages can be understood as third-party npm packages.\n\nYou can install the packages you need in a production environment by running npm\ninstall npm-package-name or npm add npm-package-name, or you can manually write\nthe packages you need to install and the corresponding semantic version in\n\"dependencies\" in the package.json file, and run the npm install command to.\n\n{\n \"name\": \"your-npm-project\",\n \"dependencies\": {\n \"npm-package-name\": \"0.1.0\"\n }\n}\n\n\nSimilarly, you can install only packages needed for local development and\ntesting by running npm install npm-package-name --save-dev or npm add\nnpm-package-name --save-dev, or you can manually write the packages to be\ninstalled and the corresponding semantic version in \"devDependencies\" in the\npackage.json file, and run the npm install command as follows\n\n{\n \"name\": \"your-npm-project\",\n \"devDependencies\": {\n \"npm-package-name\": \"0.1.0\"\n }\n}\n\n\nWhen installing or using third-party npm packages be sure to determine what they\nare for and whether they should be placed in \"dependencies\" or \"devDependencies\"\nby distinguishing between their types.\n\nTIP\n\nIn general, packages that need to be used in source code are dependencies\ndependencies. Unless you are exporting dependent code locally via packaging, in\nwhich case it can be treated as a devDependencies dependency.\n\n\nOther npm bits and pieces to know#\n\n\nProgram entry for npm packages#\n\nThere is a \"main\" attribute in package.json that corresponds to a module ID or,\nmore intuitively, a NodeJS file path, which is the main entry point for your\napplication.\n\nFor example, if your package is named foo and the user installs it, and then\nexecutes the require(\"foo\") code, then the file corresponding to the \"main\"\nfield of the npm package foo will be exported.\n\nIt is recommended to set the \"main\" field in your npm package. If \"main\" is not\nset, the default entry will be the index.js file in the root of the package.\n\nIn addition to the \"main\" attribute, the \"module\" attribute is usually set. It\nis similar to the \"main\" attribute in that it is mainly used in webpack\nscenarios. webpack reads the npm package entry (file) in most cases in the order\n\"module\" -> \"main \".\n\n> To learn more about how webpack does this, check out this link.\n\n\nscripts#\n\nThe \"scripts\" attribute of the package.json file supports a number of built-in\nscripts and npm-preset lifecycle events, as well as arbitrary scripts.\n\nThese can be executed by running npm run-script or simply npm run .\n\nName matching pre and post commands will also be run (e.g. premyscript,\nmyscript, postmyscript ).\n\n{\n \"scripts\": {\n \"premyscript\": \"\",\n \"myscript\": \"\",\n \"postmyscript\": \"\"\n }\n}\n\n\nWhen npm run myscripts is executed, the script corresponding to premyscripts\nwill be executed before it, and the script corresponding to postmyscripts will\nbe executed after it.\n\nScript commands from dependencies can be run with npm explore -- npm run .\n\nThere are also special lifecycle scripts that occur only under certain\ncircumstances. Here are a few that are usually necessary to know.\n\nnpm install#\n\nWhen you run npm install -g , the following scripts will run.\n\n * preinstall\n * install\n * postinstall\n * prepublish\n * preprepare\n * prepare\n * postprepare\n\nIf your package root has a binding.gyp file and you don't define an install or\npreinstall script, then npm will build with node-gyp rebuild as the default\ninstall command, using node-gyp.\n\nnpm publish#\n\nWhen publishing a project, executing this command will trigger the following\nscript.\n\n * prepublishOnly\n * prepack\n * prepare\n * postpack\n * publish\n * postpublish\n\nWhen running in -dry-run mode, the script corresponding to prepare will not be\nexecuted.\n\n\npeerDependencies#\n\nIn some cases, your npm project has a compatibility relationship with its host\ntool or library (e.g. a webpack plugin project and webpack), and your npm\nproject does not want to use the host as a necessary dependency, which usually\nmeans that your project is probably a plugin for that host tool or library. Your\nnpm project will have certain requirements for the version of the host package,\nas only the APIs required by the npm project will be exposed under a specific\nversion.\n\nFor more explanation of peerDependencies, you can learn about the different ways\nnpm, pnpm, and Yarn handle it at the following links.\n\n * npm's explanation of peerDependencies\n * pnpm vs npm vs Yarn\n\n\nnpm package manager#\n\nIn addition to the standard package manager like npm, the mainstream ones are\npnpm and Yarn, both of which are good alternatives to npm cli.\n\nIt is recommended to use pnpm to manage project dependencies, which can be\ninstalled as follows.\n\nnpm install -g pnpm\n\n\n\nModern.js Module configuration file#\n\nThe Modern.js Module configuration file - modern.config.(j|t)s - is provided in\nthe project directory of the module project created with @modern-js/create.\nHowever, the modern.config configuration file is not required to exist.\n\nBy default, the contents of the generated configuration file are as follows.\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n});\n\n\nWe recommend using the defineConfig function, but it is not mandatory to use it.\nSo you can also return an object directly in the config file: the\n\n\n\nexport default {\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n};\n","frontmatter":{"sidebar_position":1},"version":""},{"id":20,"title":"CLI Commands","routePath":"/module-tools/en/guide/basic/command-preview","lang":"en","toc":[{"text":"modern build","id":"modern-build","depth":2,"charIndex":73},{"text":"modern new","id":"modern-new","depth":2,"charIndex":2087},{"text":"modern dev","id":"modern-dev","depth":2,"charIndex":2866},{"text":"modern test","id":"modern-test","depth":2,"charIndex":3439},{"text":"modern lint","id":"modern-lint","depth":2,"charIndex":3747},{"text":"modern change","id":"modern-change","depth":2,"charIndex":4183},{"text":"modern pre","id":"modern-pre","depth":2,"charIndex":4511},{"text":"modern bump","id":"modern-bump","depth":2,"charIndex":4742},{"text":"modern release","id":"modern-release","depth":2,"charIndex":5261},{"text":"modern gen-release-note","id":"modern-gen-release-note","depth":2,"charIndex":5741},{"text":"modern upgrade","id":"modern-upgrade","depth":2,"charIndex":6237}],"domain":"","content":"#\n\nCLI Commands available for Modern.js Module projects are as follows:\n\n\nmodern build#\n\nUsage: modern build [options]\n\nBuild module command\n\nOptions:\n -w, --watch Build code in listening mode\n --tsconfig [tsconfig] Specify the path to the tsconfig.json file (default:\n \". /tsconfig.json\")\n --platform [platform] Build products for all or specified platforms\n --no-dts disables DTS type file generation and type checking\n --no-clear disables automatic clearing of output directories\n -h, --help Show information about the current command\n\n\nWhen you want to start a project build, you can execute the modern build\ncommand. When using this command, we can:\n\n * When wanting to start a build in watch mode, use the --watch option.\n * When you want to specify the path to the TypeScript configuration file read\n by the project build, use -build --tsconfig . /path/config.json option. This\n option overrides all buildConfig configurations in dts.tsconfigPath.\n * The -no-dts option can be used when the DTS type file generation and type\n checking behavior of the project needs to be turned off. Note: The generation\n of type files depends on the results of type checking. If type checking is\n turned off, then type files will not be generated either.\n * The --no-clear option can be used when the automatic clearing of the output\n directory needs to be turned off.\n\nIn addition to the above, Modern.js Module also support platform build mode,\nwhich can be used to perform build tasks for other tools. For example, it is\ncurrently officially supported to start a Storybook build task to generate\nStorybook artifacts by executing the modern build --platform or modern build\n--platform storybook commands after installing the @modern-js/plugin-storybook\nplugin.\n\nTIP\n\nWhen executing a Storybook build, if you need to read the build artifacts of the\nproject. Then don't forget to execute the modern build command to ensure the\nexistence of the project's build artifacts before executing the modern build\n--platform command to start the Storybook build.\n\n\nmodern new#\n\nUsage: modern new [options]\n\nExecute the generator in a modular project scenario\n\nOptions:\n -d, --debug Enable Debug mode, print debug log messages (default: false)\n -c, --config Generators run default configuration (JSON string)\n --dist-tag Generator uses a special version of npm Tag\n --registry customize npm Registry during generator runtime\n -h, --help display help for command\n\n\nThe modern new command is used to start the microgenerator functionality, which\nenables features for the project that are not provided by default.\n\nThe following features can currently be enabled.\n\n * Testing support\n * Storybook debugging\n * Tailwind CSS support\n * Modern.js Runtime API\n\nYou can learn more about these features in the Using the micro generator\nsection.\n\n\nmodern dev#\n\nUsage: modern dev [options]\n\nLocal development commands\n\nOptions:\n -h, --help display help for command\n\nCommands:\n[dev-tools-subCommand]\n\n\nThe Modern.js Module provides the ability to use debugging tools, which can be\nstarted with the modern dev command. Note, however, that no debugging-related\nplugins are provided by default, so executing modern dev will prompt: \"No dev\ntools found available \".\n\nThe officially supported debugging tool is Storybook, so you can run modern dev\nor modern dev storybook to execute it after you run modern new to enable it.\n\n\nmodern test#\n\nUsage: modern test [options]\n\nOptions:\n -h, --help display help for command\n\n\nYou need to execute modern new to turn on the test function before you can\nexecute the modern test command. The modern test command will automatically run\nthe src/tests/*.test.(js|ts|jsx|tsx) file as a test case.\n\n\nmodern lint#\n\nUsage: modern lint [options] [. .files]\n\nlint and fix source files\n\nOptions:\n --no-fix disable auto fix source file\n -h, --help display help for command\n\n\nRun ESLint to check the syntax of the code. Usually, we only need to check the\npart of the code that was changed in this commit with lint-staged during the\n-git commit phase.\n\n * The -no-fix argument turns off the ability to automatically fix lint error\n code.\n\n\nmodern change#\n\nUsage: modern change [options]\n\nCreate a changeset\n\nOptions:\n --empty Create an empty changeset (default: false)\n --open Open the created changeset in the editor (default: false)\n -h, --help display help for command\n\n\nThe modern change command is used to generate the required Markdown file for\nchangesets.\n\n\nmodern pre#\n\nUsage: modern pre [options] [tag]\n\nEntering and exiting pre-publishing mode\n\nOptions:\n -h, --help display help for command\n\n\nYou can use the modern pre command to pre-release a version before the official\nrelease.\n\n\nmodern bump#\n\nUsage: modern bump [options]\n\nUse changesets to automatically update releases and changelogs\n\nOptions:\n --canary Create a pre-release for testing (default: false)\n --preid Specify an identifier when versioning a pre-release (default: \"next\")\n --snapshot Create a special version for testing (default: false)\n -h, --help display help for command\n\n\nModify the version number in package.json according to the Markdown file of the\nchangelog generated by changesets, and generate the CHANGELOG.md file.\n\n\nmodern release#\n\nUsage: modern release [options]\n\nRelease npm packages\n\nOptions:\n --tag Release npm packages with a specific tag (default: \"\")\n --ignore-scripts release ignores the scripts command in package.json, only supported in pnpm monorepo\n (default: \"\")\n -h, --help display help for command\n\n\nThe -modern release command releases the module to the npm Registry.\n\n * The -tag argument specifies the specific dist tags to be used for the\n release.\n\n\nmodern gen-release-note#\n\nUsage: modern gen-release-note [options]\n\nGenerate Release Note based on current repository changeset information\n\nOptions:\n --repo The name of the repository to generate the Pull Request link, e.g.: web-infra-dev/modern.js\n --custom Custom Release Note generation function\n -h, --help display help for command\n\n\nAutomatically generate Release Note based on the changeset information of the\ncurrent repository.\n\nTIP\n\nneeds to be executed before the bump command.\n\n\nmodern upgrade#\n\nUsage: modern upgrade [options]\n\nUpgrade Modern.js to the latest version\n\nOptions:\n --registry customize npm registry (default: \"\")\n -d,--debug Enable Debug mode to print debug log messages (default: false)\n --cwd project path (default: \"\")\n -h, --help display help for command\n\n\nThe modern upgrade command is used to upgrade the project Modern.js related\ndependencies to the latest version.\n\nExecuting the command npx modern upgrade in the project root directory will\nupdate the Modern.js dependencies in package.json of the currently executing\nproject to the latest version by default.","frontmatter":{"sidebar_position":2},"version":""},{"id":21,"title":"Modify the output product","routePath":"/module-tools/en/guide/basic/modify-output-product","lang":"en","toc":[{"text":"Default output products","id":"default-output-products","depth":2,"charIndex":3},{"text":"buildPreset","id":"buildpreset","depth":2,"charIndex":1002},{"text":"buildConfig","id":"buildconfig","depth":2,"charIndex":1823},{"text":"Combining Configuration and Presets","id":"combining-configuration-and-presets","depth":2,"charIndex":4571}],"domain":"","content":"#\n\n\nDefault output products#\n\nWhen you use the modern build command in an initialized project, Modern.js\nModule will generate corresponding build artifacts based on the current\nconfiguration.\n\nThe default configuration is as follows:\n\n\n\nexport default defineConfig({\n // Register the CLI tool of Modern.js Module\n plugins: [moduleTools()],\n // Specify the build preset configuration\n buildPreset: 'npm-library',\n});\n\n\nThe default output files has the following characteristics.\n\n * will generate CommonJS and ESM.\n * The code syntax is supported up to ES6 , and more advanced syntax will be\n converted.\n * All code is bundled into one file, i.e. bundle processing is performed.\n * The output root directory is the dist directory under the project, and the\n type file output directory is dist/types.\n\nYou may have the following questions when you see this.\n\n 1. what is buildPreset?\n 2. what determines these characteristics of the product?\n\nThen the next step is to first explain buildPreset.\n\n\nbuildPreset#\n\nThe buildPreset represents a prepared set or sets of build-related\nconfigurations that can be used to eliminate the trouble and complexity of\nconfiguration by using the default values corresponding to the build Preset,\nresulting in the expected product.\n\nModern.js Module mainly comes with two built-in build presets, including:\n\n * npm-component: Used to build component libraries.\n * npm-library: Used to package projects of other library types, such as tool\n libraries.\n\nIt also provides some variations, such as npm-library-with-umd and\nnpm-library-es5, which, as their names suggest, correspond to library presets\nwith umd output and support for es5 syntax, respectively. For more detailed\nconfiguration, you can refer to its API.\n\nIn addition, we can also fully customize the build configuration:\n\n\nbuildConfig#\n\nbuildConfig is a configuration option that describes how to compile and generate\nbuild artifacts. What was mentioned at the beginning about \"features of build\nproducts\" are actually properties supported by buildConfig. The currently\nsupported properties cover the needs of most module type projects when building\nproducts. buildConfig not only contains some properties that artifacts have, but\nalso contains some features needed to build products. The following is a brief\nlist from a classification point of view.\n\nThe basic attributes of a build artifacts include:\n\n * Whether the artifact is bundled or not: the corresponding API is\n buildConfig.buildType.\n * Product support for syntax: the corresponding API is buildConfig.target.\n * Output format: the corresponding API is buildConfig.format.\n * How the output type file is handled: the corresponding API is\n buildConfig.dts.\n * How the sourceMap of the artifact is handled: the corresponding API is\n buildConfig.sourceMap.\n * The input (or source file) corresponding to the output: the corresponding API\n is buildConfig.input.\n * The directory of the output of the artifact: the corresponding API is\n buildConfig.outDir.\n * Build source directory: the corresponding API is buildConfig.sourceDir.\n\nCommon functions required for build artifacts include:\n\n * Alias: The corresponding API is buildConfig.alias.\n * Static resource handling: the corresponding API is buildConfig.asset.\n * Third-party dependency handling: The corresponding APIs are\n * buildConfig.autoExternal.\n * buildConfig.externals.\n * Copy: The corresponding API is buildConfig.copy.\n * Global variable substitution: the corresponding API is buildConfig.define.\n * Specify JSX compilation method, the corresponding API is\n [buildConfig.jsx](/api/config/ build-config#jsx).\n\nSome advanced properties or less frequently used functions:\n\n * Product code compression: The corresponding API is buildConfig.minify.\n * Code splitting: buildConfig.splitting\n * Specify whether the build artifacts is for the NodeJS environment or the\n browser environment: the corresponding API is buildConfig.platform.\n * umd product-related.\n * Specifies the global variables imported externally to the umd product: the\n corresponding API is buildConfig.umdGlobals.\n * Specify the module name of the umd product: the corresponding API is\n buildConfig.umdModuleName.\n\nIn addition to the above categories, frequently asked questions and best\npractices about these APIs can be found at the following links\n\n * About bundle and bundleless?\n * About input and sourceDir\n * About d.ts.\n * How to use define\n * How to handle third-party dependencies?\n * How to use copy?\n * How to use umd\n * How to use asset\n\n\nCombining Configuration and Presets#\n\nOnce we understand buildPreset and buildConfig, we can use them together.\n\nIn a real project, we can use buildPreset to quickly get a set of default build\nconfigurations. If you need to customise it, you can use buildConfig to override\nand extend it.\n\nThe extension logic is as follows.\n\n * When buildConfig is an array, new configuration items are added to the\n original preset.\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n buildConfig: [\n {\n format: 'iife',\n target: 'es2020',\n outDir: '. /dist/global'\n }\n ]\n});\n\n\nThis will generate an additional IIFE-formatted product that supports up to\nES2020 syntax on top of the original preset, in the dist/global directory under\nthe project.\n\n * When buildConfig is an object, the configuration items in the object are\n overwritten in the preset.\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n buildConfig: {\n sourceMap: true,\n },\n}).\n\n\nThis will cause a sourceMap file to be generated for each build task.","frontmatter":{"sidebar_position":3},"version":""},{"id":22,"title":"Versioning and Publishing","routePath":"/module-tools/en/guide/basic/publish-your-project","lang":"en","toc":[{"text":"Tracking changes","id":"tracking-changes","depth":2,"charIndex":406},{"text":"Version update","id":"version-update","depth":2,"charIndex":1748},{"text":"Publish","id":"publish","depth":2,"charIndex":2227},{"text":"Pre-releases","id":"pre-releases","depth":2,"charIndex":2941}],"domain":"","content":"#\n\nAn npm-type module project release process consists of two phases.\n\n * The first phase is during development, where the developer needs to provide a\n change file to record changes that need to be released.\n * The second phase is during release, where Modern.js Module can collect all\n the change files to update the version, update the release log, and release\n new packages to the npm Registry.\n\n\nTracking changes#\n\nChanges need to be logged when they happen to the project. Changes that occur in\na project are typically.\n\n * New features\n * Fixes to issues\n * Configuration file changes\n * ...\n\nOnce these changes have been made, the current changes need to be documented\nwith the following command.\n\n * modern change\n\nExecuting the modern change command asks the developer several questions and\ngenerates a change log based on the developer's answers. The changelog file\ncontains the type of change and its description, and is committed to the git\nrepository.\n\n$ npx modern change\n🦋 What kind of change is this for module-example? (current version is 0.1.0) - patch\n🦋 Please enter a summary for this change (this will be in the changelogs). Submit empty line to open external editor\n🦋 Summary - publish test\n🦋 === Releasing the following packages ===\n🦋 [Patch]\n🦋 module\n🦋 Is this your desired changeset? (Y/n) - true\n🦋 Changeset added! - you can now commit it\n🦋\n🦋 If you want to modify or expand on the changeset summary, you can find it here\n🦋 info /xxxxxx/module/.changeset/brave-dryers-agree.md\n\n\nWhen executed successfully, the resulting Markdown file containing the change\nlog is saved in the project's .changeset directory. The contents will look like\nthe following.\n\n---\n\"``module-example'': patch\n---\n\npublish test\n\n\n\nVersion update#\n\nWhen the project version needs to be updated, execute the following command.\n\n * modern bump\n\nExecuting modern bump will modify the version number in package.json based on\nthe contents of the Markdown file in the .changeset/ directory where the changes\nwere recorded, and generate the CHANGELOG.md file. These Markdown files are also\ndeleted when the version update is complete, so they are \"consumed \".\n\n# module\n\n## 0.1.1\n\n### Patch Changes\n\n- publish test\n\n\n\nPublish#\n\nTo publish a project, you can execute the following command.\n\n * modern publish\n\nThe modern release command publishes the project to the npm Registry.\n\nThe release is the latest version, which is also the official version. If you\nwant to change the dist-tag, you can specify it with the modern release --tag\ncommand. For example.\n\nmodern release --tag beta\n\n\nHowever, if you want to change the version number of the current project to a\npre-release as well, you need to use the modern pre command.\n\n> dist-tag can be understood as: tagging the current release. Generally\n> speaking, the dist-tag for the default release is latest, so you can consider\n> latest as the dist-tag for the official release.\n\n\nPre-releases#\n\nWhen a pre-release is needed before the official release, the following command\nis executed.\n\n * modern pre\n\nFirst modern pre enter to enter pre-release mode, can be the same as the tag\nspecified with the modern release --tag command when releasing the project.\n\n$ npx modern pre enter next\n🦋 success Entered pre mode with tag next\n🦋 info Run `changeset version` to version packages with prerelease versions\n✨ Done in 5.30s.\nDone in 5.30s.\n\n\nThen you can update the specific version number with the modern bump command,\nwhich doesn't actually \"consume\" the Markdown file that records the changes:\n\n$ npx modern bump\n🦋 warn ===============================IMPORTANT!===============================\n🦋 warn You are in prerelease mode\n🦋 warn If you meant to do a normal release you should revert these changes and run `changeset pre exit`\n🦋 warn You can then run `changeset version` again to do a normal release\n🦋 warn ----------------------------------------------------------------------\n🦋 All files have been updated. review them and commit at your leisure\n\n\nThen you can see that the updated version number in package.json will look like\nthis: 0.1.2-next.0.\n\nFinally, if you don't need to do a pre-release anymore, be sure to run the\nmodern pre exit command to exit the pre-release state and to release the\nofficial version when you run the modern bump command again.","frontmatter":{"sidebar_position":7},"version":""},{"id":23,"title":"Testing Projects","routePath":"/module-tools/en/guide/basic/test-your-project","lang":"en","toc":[{"text":"Prerequisites and conventions","id":"prerequisites-and-conventions","depth":2,"charIndex":52},{"text":"Run the tests","id":"run-the-tests","depth":2,"charIndex":745},{"text":"Usage Configuration","id":"usage-configuration","depth":2,"charIndex":1015},{"text":"Test example","id":"test-example","depth":2,"charIndex":1160},{"text":"Common modules","id":"common-modules","depth":3,"charIndex":1176},{"text":"Components","id":"components","depth":3,"charIndex":1781}],"domain":"","content":"#\n\nThis chapter will describe how to test modules.\n\n\nPrerequisites and conventions#\n\nTo use the testing features of the project, you need to make sure that the\nproject contains the dependency: \"@modern-js/plugin-testing\" , which can be done\nwith modern new.\n\nIn Modern.js Module, the following conventions are in place for test cases, or\nfiles for writing tests:\n\n * The tests directory in the project directory is the directory for test cases\n and test files, no support for changing the directory for running test cases.\n * Files with the suffix .test.[tj]sx? are automatically recognized as test\n files by default.\n * Other . [tj]sx? suffixes are recognized as normal files that can be used as\n test utils files or for other purposes.\n\n\nRun the tests#\n\nOnce the dependencies are prepared and we know where to write the test cases, we\ncan execute the tests with the following command:\n\nmodern test\n\n// Update snapshot\nmodern test --updateSnapshot\n\n\nAfter execution, you will see the results of the test:\n\n\n\n\nUsage Configuration#\n\nModern.js Module provides the following configurations for testing.\n\n * testing\n\nYou can add it in modern.config.(j|t)s.\n\n\nTest example#\n\n\nCommon modules#\n\nFor common modules, we can use the test function as follows:\n\n * First is the code of the module:\n\nexport default function () {\n return 'hello world';\n}\n\n\n * Then in the test file, we can import source code as the following way. Where\n @ points to the source directory, defined in tests/tsconfig.json in the\n initialization project.\n\n\n\ndescribe('default cases', () => {\n test('Have returns', () => {\n const drink = jest.fn(main);\n drink();\n expect(drink).toHaveReturned();\n });\n});\n\n\n * Finally we can execute modern test.\n\npnpm test\n## or\nyarn test\n## or\nnpm run test\n\n\n\nComponents#\n\nFor components, Modern.js's Runtime API provides functionality for testing UI\ncomponents, which is provided by @modern-js/runtime/testing.\n\nTIP\n\nIf you need to use the Runtime API, then you can turn it on via microgenerator.\n\n * First is the code of the component:\n\nexport const default () {\n return (\n \nThis is a UI Component\n );\n}\n\n\n * Then in the test file, we can import source code as the following way. Where\n @ points to the source directory, defined in tests/tsconfig.json in the\n initialization project.\n\n\n\n\n\ndescribe('default cases', () => {\n test('Rendered', () => {\n render();\n expect(screen.getByText('This is a UI Component')).toBeInTheDocument();\n });\n});\n\n\n * Finally we can execute modern test.\n\npnpm test\n## or\nyarn test\n## or\nnpm run test\n","frontmatter":{"sidebar_position":6},"version":""},{"id":24,"title":"Using the Microgenerator","routePath":"/module-tools/en/guide/basic/use-micro-generator","lang":"en","toc":[{"text":"Test","id":"test","depth":2,"charIndex":431},{"text":"Storybook","id":"storybook","depth":2,"charIndex":908},{"text":"Tailwind CSS Support","id":"tailwind-css-support","depth":2,"charIndex":1544},{"text":"Modern.js Runtime API","id":"modernjs-runtime-api","depth":2,"charIndex":1829}],"domain":"","content":"#\n\nModern.js Module provides the Microgenerator tool, which allows for the current\nproject to.\n\n * add new directories and files\n * Modify the contents of the package.json file\n * Execute commands\n\nThus with these capabilities, Microgenerator can enable additional feature\nfunctionality for the project.\n\nThe microgenerator can be started via modern new. The current Microgenerator\nfeatures supported by the Modern.js Module are:\n\n\nTest#\n\nWhen we want to test some modules, we can enable the test feature. When this\nfeature is enabled, a tests directory and related files will be created in the\nproject directory, and a new \"@modern-js/plugin-testing\" dependency will be\nadded to package.json.\n\nTIP\n\nAfter successfully enabling it, you will be prompted to manually add a code\nsimilar to the one below to the configuration.\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), testingPlugin()],\n});\n\n\n\nStorybook#\n\nThe Storybook feature can be enabled when we want to debug a component or a\ncommon module. When this feature is enabled, the stories directory and related\nfiles are created in the project directory, and a new\n\"@modern-js/plugin-storybook\" dependency is added to package.json.\n\nTIP\n\nAfter successfully enabling it, you will be prompted to manually add a code\nsimilar to the one below to the configuration.\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), storybookPlugin()],\n});\n\n\nFor more information on how to start Storybook and how to use it, check out the\nfollowing link.\n\n * modern dev\n * using Storybook\n\n\nTailwind CSS Support#\n\nTailwind CSS is a CSS framework and design system based on Utility Class, which\ncan quickly add common styles to components, and support flexible extension of\ntheme styles.\n\nIf you want to use Tailwind CSS for a project, you can refer to \"Using Tailwind\nCSS\".\n\n\nModern.js Runtime API#\n\nModern.js provides Runtime API capabilities that can only be used in the\nModern.js application project environment. If you need to develop a component\nfor use in a Modern.js application environment, then you can turn on this\nfeature and the microgenerator will add the \"@modern-js/runtime\" dependency.\n\nAlso, the Storybook debugging tool will determine if the project needs to use\nthe Runtime API by checking the project's dependencies and providing the same\nRuntime API runtime environment as the Modern.js application project.\n\nTIP\n\nAfter successfully enabling it, you will be prompted to manually add a code\nsimilar to the one below to the configuration.\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), runtime()],\n});\n","frontmatter":{"sidebar_position":4},"version":""},{"id":25,"title":"Using Storybook","routePath":"/module-tools/en/guide/basic/using-storybook","lang":"en","toc":[{"text":"Debugging code","id":"debugging-code","depth":2,"charIndex":682},{"text":"Referencing component products","id":"referencing-component-products","depth":3,"charIndex":1322},{"text":"Referencing component source code","id":"referencing-component-source-code","depth":3,"charIndex":3382},{"text":"Configure Storybook","id":"configure-storybook","depth":2,"charIndex":4225},{"text":"Building Storybook Products","id":"building-storybook-products","depth":2,"charIndex":5155},{"text":"Use Tailwind CSS with Storybook","id":"use-tailwind-css-with-storybook","depth":2,"charIndex":5542}],"domain":"","content":"#\n\nFirst of all, if you haven't read the following, take a few minutes to\nunderstand it first.\n\n * use micro-generator to enable Storybook debugging\n * modern dev\n\nStorybook is a tool dedicated to component debugging, providing around component\ndevelopment.\n\n * Develop UIs that are more durable\n * Test UIs with less effort and no flakes\n * Document UI for your team to reuse\n * Share how the UI actually works\n * Automate UI workflows\n\nSo Storybook is a complex and powerful tool.\n\nModern.js Module is integrated with Storybook, so you can pretty much follow the\nofficial Storybook documentation. However, there are still a few things to keep\nin mind, which are explained below.\n\n\nDebugging code#\n\nThe project code needs to be introduced during the debugging process and can\ncurrently be introduced in two ways:\n\n * Use of project products\n * Using the project source code\n\nWe recommend using the first \"referenced project product\" approach. Because it\nis closer to the real usage scenario, not only can we debug the component\nfunctionality, but also verify the correctness of the build product. However, we\ncan also refer to the source code when testing the project functionality and\nrefer to the project package name when verifying the project product.\n\nNext, we will talk about how to use each of these two methods.\n\n\nReferencing component products#\n\nIf the TypeScript project foo exists. Make sure the main and types of\npackage.json values are real paths.\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/types/index.d.ts\"\n}\n\n\nThe source code of the foo project:\n\nexport const content = 'hello world';\n\n\nMake sure that the paths configuration pointing to the project root is set in\nstories/tsconfig.json. The key of paths is the same as the project name.\n\n{\n \"extends\": \"../tsconfig.json\",\n \"include\": [\"./\"],\n \"compilerOptions\": {\n \"jsx\": \"preserve\",\n \"baseUrl\": \".\",\n \"paths\": {\n \"foo\": [\"../\"]\n }\n }\n}\n\n\nReferenced directly in Story code by the project name:\n\n\n\nconst Component = () => \nthis is a Story Component {content};\n\nexport const YourStory = () => ;\n\nexport default {\n title: 'Your Stories',\n};\n\n\nFinally, when executing the command, first start the source build in listening\nmode and then start Storybook debugging.\n\n## Source Code Build\nmodern build --watch\n\n\n## Storybook Debug\nmodern dev storybook\n\n\nIf, during development, you encounter a situation where the type definition is\nnot available in real time, at that point.\n\nFor pnpm projects, package.json can be modified as follows.\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./src/index.ts\",\n \"publishConfig\": {\n \"types\": \"./dist/index.d.ts\",\n }\n}\n\n\n> For the use of pnpm's publishConfig, you can read the following link.\n\nFor npm and Yarn projects, the values of types of package.json can only be\nchanged manually in development phase and release phase.\n\nSo why is it possible to reference the product directly?\n\n 1. execute modern build --watch command before executing modern dev storybook\n command to ensure the existence of project build products.\n 2. Add processing logic inside Storybook to ensure that the project's product\n paths can be parsed according to package.json, based on the\n compilerOptions.paths configuration in the tsconfig.json file or (in JS\n projects) directly with the project name as an alias.\n\n\nReferencing component source code#\n\nReferencing component source code can be done by means of relative paths to:\n\n\n\nconst Component = () => \nthis is a Story Component {content};\n\nexport const YourStory = () => ;\n\nexport default {\n title: 'Your Stories',\n};\n\n\nWhy is the source code approach not recommended\n\nNot only is it impossible to verify that the component product is correct using\nthe component source code, but also some of the configurations supported by\nModern.js Module for building the product cannot be fully translated into\nStorybook internal configuration. If some of the configurations cannot be\nconverted to each other, there will be unintended results during Storybook\ndebugging.\n\nModern.js Module is based on esbuild, while Storybook is based on Webpack, and\nesbuild's configuration is not fully compatible with Webpack.\n\n\nConfigure Storybook#\n\nStorybook is officially configured for projects through a folder called\n.storybook, which contains various configuration files. In Modern.js Module,\nStorybook configuration files can be added to the config/storybook directory of\nthe project.\n\nFor more information on how to use the various Storybook configuration files,\nsee the following links:\n\n * Configure Storybook\n\nBut there are some limitations to Storybooking in a module project:\n\n * It is currently not possible to change the location of the Story file, i.e.,\n you cannot change the stories configuration in the main.js file.\n * Currently you cannot modify Webpack and Babel related configuration, i.e. you\n cannot modify webpackFinal and babel configuration in the main.js file.\n\nIn the future we will consider whether these configurations can be allowed to be\nmodified, but for now we are limiting their use to reduce unpredictable issues.\n\n\nBuilding Storybook Products#\n\nIn addition to Storybook debugging of components or common modules, you can also\nperform Storybook build tasks with the following commands.\n\nmodern build --platform storybook\n\n\nFor the modern build --platform command you can see.\n\n * modern build\n\nAfter the build is complete, you can see the build artifacts files in the\ndist/storybook-static directory.\n\n\nUse Tailwind CSS with Storybook#\n\nIf you need to use Tailwind CSS in the stories directory, make sure that the\nTailwind CSS configuration for your current project includes the stories\ndirectory.\n\nTaking the tailwind.config.ts file as an example, you need to configure the\nfollowing content:\n\nexport default {\n content: [\n './src/**/*.{js,jsx,ts,tsx}',\n+ './stories/**/*.{js,jsx,ts,tsx}',\n ],\n};\n","frontmatter":{"sidebar_position":5},"version":""},{"id":26,"title":"Developing Components","routePath":"/module-tools/en/guide/best-practices/components","lang":"en","toc":[{"text":"Initialize the project","id":"initialize-the-project","depth":2,"charIndex":93},{"text":"Debugging code with Storybook","id":"debugging-code-with-storybook","depth":2,"charIndex":881},{"text":"Developing Styles","id":"developing-styles","depth":2,"charIndex":980},{"text":"CSS/PostCSS","id":"csspostcss","depth":3,"charIndex":1186},{"text":"Less","id":"less","depth":3,"charIndex":1831},{"text":"Sass/Scss","id":"sassscss","depth":3,"charIndex":2144},{"text":"Tailwind CSS","id":"tailwind-css","depth":3,"charIndex":2486},{"text":"CSS Modules","id":"css-modules","depth":3,"charIndex":2560},{"text":"Configuring build products","id":"configuring-build-products","depth":2,"charIndex":2999},{"text":"Testing components","id":"testing-components","depth":2,"charIndex":3933},{"text":"Releasing components","id":"releasing-components","depth":2,"charIndex":4036}],"domain":"","content":"#\n\nThis chapter will describe how to develop component projects using the Modern.js\nModule.\n\n\nInitialize the project#\n\n 1. It is recommended to use the @modern-js/create command to initialize an npm\n project.\n\nnpx @modern-js/create@latest components-project\n\n? Please select the type of project you want to create: Npm Module\n? Please fill in the project name: components-demo\n? Please select the programming language: TS\n? Please select the package manager: pnpm\n\n\n 2. The initialized directory structure:\n\n.\n├── README.md\n├── node_modules/\n├── dist/\n├── modern.config.ts\n├── package.json\n├── pnpm-lock.yaml\n├── src\n│ ├── index.ts\n│ └── modern-app-env.d.ts\n└── tsconfig.json\n\n\n 3. Finally, modify the file suffix and content of ./src/index.ts as follows,\n and the initialization of the component project is completed.\n\nexport default () => {\n return \nhello world;\n};\n\n\n\nDebugging code with Storybook#\n\nPlease refer to \"Using Storybook\" to debug code using Storybook.\n\n\nDeveloping Styles#\n\nNext we can add styles to the component.\n\nThe following capabilities are currently supported for developing styles.\n\n * CSS/PostCSS\n * Less\n * Scss/Sass\n * Tailwind CSS\n * CSS Modules\n\n\nCSS/PostCSS#\n\nModern.js Module supports PostCSS and has the following built-in PostCSS\nplugins.\n\n * flexbugs-fixes\n * custom-properties\n * initial\n * page-break\n * font-variant\n * media-minmax\n * nesting\n\nSo we can create .css files in our projects and use the syntax support and\ncapabilities provided by these plugins directly in our css files.\n\n * Source Code:\n\na,\nb {\n color: red;\n\n /* \"&\" comes first */\n & c,\n & d {\n color: white;\n }\n\n /* \"&\" comes later, requiring \"@nest\" */\n @nest e & {\n color: yellow;\n }\n}\n\n\n * CSS artifact:\n\na,\nb {\n color: red;\n}\na c,\nb c,\na d,\nb d {\n color: white;\n}\ne a,\ne b {\n color: yellow;\n}\n\n\n\nLess#\n\nModern.js Module supports development styles using Less.\n\n> The current built-in Less version is v4.1.3\n\n * Source Code:\n\n@bg: black;\n@bg-light: boolean(luma(@bg) > 50%);\n\ndiv {\n background: @bg;\n color: if(@bg-light, black, white);\n}\n\n\n * Less artifact:\n\ndiv {\n background: black;\n color: white;\n}\n\n\n\nSass/Scss#\n\nModern.js Module supports developing styles using Scss/Sass.\n\n> The current built-in Sass version is v1.54.4\n\n * Source code:\n\n$font-stack: Helvetica, sans-serif;\n$primary-color: #333;\n\nbody {\n font: 100% $font-stack;\n color: $primary-color;\n}\n\n\n * Less artifact:\n\nbody {\n font: 100% Helvetica, sans-serif;\n color: #333;\n}\n\n\n\nTailwind CSS#\n\nPlease refer to \"Using Tailwind CSS\" for detailed usage.\n\n\nCSS Modules#\n\nModern.js Module supports the development of styles using CSS Modules. By\ndefault, the following files are recognized as CSS Module files.\n\n * .module.css\n * .module.less\n * .module.scss\n * .module.sass\n\nIf you need to configure CSS Modules, you can check out the API at\n\n * style.autoModules\n * style.modules\n\nThe following is a code example.\n\n\n\nexport default () => {\n return \nhello world;\n};\n\n\n.btn {\n color: blue;\n}\n\n\n\nConfiguring build products#\n\nBased on most scenarios of component project usage, it is recommended to use the\nnpm-component build preset. This preset yields a output directory structure of\n\n.\n├── dist\n│ ├── es\n│ ├── lib\n│ └── types\n\n\n * . /dist/es: Contains bundleless artifacts in ES modules format that support\n the es6 syntax.\n * . /dist/lib: Contains bundleless artifacts in CommonJS format with support\n for es6 syntax.\n * . /dist/types: Contains the types file.\n\nThe buildPreset can be configured manually if there is a requirement to use\nsyntax support, and supports modifying the supported syntax by adding a suffix\nto npm-component.\n\nexport default defineConfig({\n buildPreset: 'npm-component-es2019',\n});\n\n\nIf you have special needs for the build artifacts directory structure, you can\nuse the buildConfig API, which can be used by the following documentation.\n\n * modify-output-product\n * in-depth-about-build\n\n\nTesting components#\n\nFor more information on how to test components, please refer to \"Test project\".\n\n\nReleasing components#\n\nIt is recommended to use the version release feature provided by Modern.js\nModule. You can refer to the \"Version Management and Release\" section for more\ninformation.","frontmatter":{"sidebar_position":1},"version":""},{"id":27,"title":"Using Tailwind CSS","routePath":"/module-tools/en/guide/best-practices/use-tailwindcss","lang":"en","toc":[{"text":"Enabling Tailwind CSS","id":"enabling-tailwind-css","depth":2,"charIndex":252},{"text":"Configuring Tailwind CSS","id":"configuring-tailwind-css","depth":2,"charIndex":1573},{"text":"Tailwind CSS Autocomplete","id":"tailwind-css-autocomplete","depth":3,"charIndex":2541},{"text":"Build Modes","id":"build-modes","depth":2,"charIndex":3112},{"text":"Bundle Mode","id":"bundle-mode","depth":3,"charIndex":3380},{"text":"Bundleless Mode","id":"bundleless-mode","depth":3,"charIndex":4149},{"text":"Class Name Prefix","id":"class-name-prefix","depth":2,"charIndex":4450},{"text":"Usage Guide","id":"usage-guide","depth":2,"charIndex":5064},{"text":"HTML Class Names","id":"html-class-names","depth":3,"charIndex":5126},{"text":"@apply","id":"apply","depth":3,"charIndex":5562},{"text":"Sass","id":"sass","depth":4,"charIndex":5866},{"text":"Less","id":"less","depth":4,"charIndex":6157},{"text":"About designSystem config","id":"about-designsystem-config","depth":2,"charIndex":6796}],"domain":"","content":"#\n\nTailwind CSS is a CSS framework and design system based on Utility Class, which\ncan quickly add common styles to components, and support flexible extension of\ntheme styles.\n\nModern.js Module supports developing component styles using Tailwind CSS.\n\n\nEnabling Tailwind CSS#\n\nTo use Tailwind CSS in Modern.js Module, you can follow the steps below:\n\n 1. Run pnpm run new in the root directory of your project and make the\n following selections:\n\n? Please select the operation you want: Enable features\n? Please select the feature name: Enable Tailwind CSS\n\n\nAfter successful initialization, you will see the following additions to the\npackage.json file:\n\n{\n \"dependencies\": {\n \"tailwindcss\": \"^3.0.0\"\n },\n \"devDependencies\": {\n \"@modern-js/plugin-tailwindcss\": \"^2.0.0\"\n }\n}\n\n\n 2. Register the Tailwind plugin in modern.config.ts:\n\n\n\nexport default defineConfig({\n plugins: [..., tailwindcssPlugin()],\n});\n\n\n 3. Create a index.css file and add the following code:\n\n/* base and components are optional, please add as appropriate */\n@tailwind base;\n@tailwind components;\n@tailwind utilities;\n\n\nINFO\n\nDepending on your needs, you can selectively import the CSS styles provided by\nTailwind CSS. Please refer to the @tailwind documentation for detailed usage of\nthe @tailwind directive.\n\n 4. Import the index.css file, for example, add the following code in the root\n component src/index.jsx:\n\nimport './index.css';\n\n\n 5. Now you can use the Utility Classes provided by Tailwind CSS in your\n components:\n\nconst Hello = () => (\n \n\n \n\nhello world\n \n);\n\n\n\nConfiguring Tailwind CSS#\n\nIn Modern.js Module, you have two ways to configure Tailwind CSS:\n\n 1. Using the tailwind.config.{ts,js} file, which follows the official usage of\n Tailwind CSS. Please refer to \"Tailwind CSS - Configuration\" for more\n details.\n\n\n\nexport default {\n content: ['./src/**/*.{js,jsx,ts,tsx}'],\n} as Config;\n\n\nTIP\n\nPlease upgrade Modern.js to version >= 2.33.0 to support automatic reading of\ntailwind.config.{ts,js} files.\n\n 2. Using the style.tailwindcss configuration option. This is the old way of\n configuring Tailwind CSS, and we recommend using the tailwind.config.{ts,js}\n file for configuration.\n\nexport default {\n tools: {\n tailwindcss: {\n content: ['./src/**/*.{js,jsx,ts,tsx}'],\n },\n },\n};\n\n\nIf you are using both the tailwind.config.{ts,js} file and style.tailwindcss\noption, the configuration defined in style.tailwindcss will take precedence and\noverride the content defined in tailwind.config.{ts,js}.\n\n\nTailwind CSS Autocomplete#\n\nTailwind CSS provides an official extension called Tailwind CSS IntelliSense for\nautocompletion of Tailwind CSS class names, CSS functions, and directives in VS\nCode.\n\nYou can follow the steps below to enable the autocomplete feature:\n\n 1. Install the Tailwind CSS IntelliSense extension in VS Code.\n 2. If the root directory of your project does not have a\n tailwind.config.{ts,js} file, you need to create one and write the Tailwind\n CSS configuration for your current project. Otherwise, the IDE plugin will\n not work correctly.\n\n\nBuild Modes#\n\nWhen using Tailwind CSS, please note that there are significant differences\nbetween the bundle and bundleless modes in terms of the build artifacts.\n\nTIP\n\nFor definitions of bundle and bundleless, please refer to the \"In-depth\nunderstanding of build\".\n\n\nBundle Mode#\n\nIn Bundle mode, a separate CSS file is generated, and the JS output does not\nautomatically reference the CSS output file.\n\n * Source code:\n\nimport './index.css';\n\nexport default () => {\n return \nhello world;\n};\n\n\n * Output code:\n\n// src/index.tsx\n\nvar src_default = () => {\n return /* @__PURE__ */ jsx('div', {\n className: 'bg-black',\n children: 'hello world',\n });\n};\nexport { src_default as default };\n\n\n.bg-black {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity));\n}\n/** some more... */\n\n\nIf you need to inject styles into the JS artifact, you can enable the\nstyle.inject option.\n\nIf you haven't enabled style.inject, you can also let users manually import the\nCSS file:\n\nimport 'your-package/dist/es/index.css';\n\n\n\nBundleless Mode#\n\nIn bundleless mode, the CSS file is automatically imported in the artifact code\nwithout the need for additional processing.\n\n * Output code:\n\n\nimport './index.css';\nexport default () =>\n /* @__PURE__ */ _jsx('div', {\n className: 'bg-black',\n children: 'hello world',\n });\n\n\n\nClass Name Prefix#\n\nYou can add a class name prefix using the prefix option provided by Tailwind\nCSS. This helps avoid potential class name conflicts, such as when different\nversions of Tailwind CSS are used in different parts of an application or\nmodule.\n\nFor example, you can add the foo- prefix using the prefix option in\ntailwind.config.js:\n\nmodule.exports = {\n prefix: 'foo-',\n};\n\n\n * Source Code:\n\nimport './index.css';\n\nexport default () => {\n return \nhello world;\n};\n\n\n * Output Code:\n\n.foo-bg-black {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity));\n}\n/** some more... */\n\n\n\nUsage Guide#\n\nHere are some usage examples of Tailwind CSS.\n\n\nHTML Class Names#\n\nTailwind CSS supports adding styles to HTML tags through class names. When using\nHTML class names, please note that the corresponding CSS styles of Tailwind CSS\nmust be imported in advance.\n\nimport './index.css';\n\nexport default () => {\n return \nhello world;\n};\n\n\nGenerated styles (after bundling):\n\n.bg-black {\n --tw-bg-opacity: 1;\n background-color: rgba(0, 0, 0, var(--tw-bg-opacity));\n}\n/** some more... */\n\n\n\n@apply#\n\nTailwind CSS provides the @apply directive, which allows us to inline the styles\nprovided by Tailwind CSS into our own styles.\n\n@apply can be used in CSS, Less, and Sass.\n\n.btn {\n @apply font-bold py-2 px-4 rounded;\n}\n\n\nHowever, there are some considerations when using it with Less and Sass:\n\nSass#\n\nWhen using Tailwind with Sass and there is an !important after @apply,\ninterpolation should be used to ensure Sass compiles correctly.\n\n * Won't work as expected:\n\n.alert {\n @apply bg-red-500 !important;\n}\n\n\n * Will work as expected:\n\n.alert {\n @apply bg-red-500 #{!important};\n}\n\n\nLess#\n\nWhen using Tailwind with Less, you cannot nest Tailwind's @screen directive.\n\n * Won't work as expected:\n\n.card {\n @apply rounded-none;\n\n @screen sm {\n @apply rounded-lg;\n }\n}\n\n\n * Instead, use regular media queries and the theme() function to reference your\n screen sizes or simply avoid nesting your @screen directive.\n\n// Use a regular media query and theme()\n.card {\n @apply rounded-none;\n\n @media (min-width: theme('screens.sm')) {\n @apply rounded-lg;\n }\n}\n\n\n// Use the @screen directive at the top-level\n.card {\n @apply rounded-none;\n\n @media (min-width: theme('screens.sm')) {\n @apply rounded-lg;\n }\n}\n\n\n\nAbout designSystem config#\n\ndesignSystem is a deprecated configuration option in Modern.js Module.\n\nStarting from Modern.js Module v2.33.0, you can use the theme configuration\noption of Tailwind CSS as a replacement for designSystem. It is no longer\nnecessary to split the theme configuration and set it on designSystem.\n\n * Previous usage:\n\nconst { theme, ...rest } = tailwindConfig;\n\nexport default {\n style: {\n tailwindcss: rest,\n },\n designSystem: theme,\n};\n\n\n * Current usage:\n\nexport default {\n style: {\n tailwindcss: tailwindConfig,\n },\n};\n","frontmatter":{"sidebar_position":2},"version":""},{"id":28,"title":"Build FAQ","routePath":"/module-tools/en/guide/faq/build","lang":"en","toc":[{"text":"Product FAQ","id":"product-faq","depth":2,"charIndex":3},{"text":"Initialization of Class Fields","id":"initialization-of-class-fields","depth":3,"charIndex":18},{"text":"babel-plugin-lodash treats the introduced lodash as undefined","id":"babel-plugin-lodash-treats-the-introduced-lodash-as-undefined","depth":3,"charIndex":2081},{"text":"Exceptions FAQ","id":"exceptions-faq","depth":2,"charIndex":2772},{"text":"Dynamic require of \\\"react\\\" is not supported","id":"dynamic-require-of-react-is-not-supported","depth":3,"charIndex":-1},{"text":"Problem Description","id":"problem-description","depth":4,"charIndex":2836},{"text":"Solution","id":"solution","depth":4,"charIndex":3139},{"text":"Reference Links","id":"reference-links","depth":4,"charIndex":3735},{"text":"During compilation, an error was reported in the less file of a component library:\\'Operation on an invalid type\\'","id":"during-compilation-an-error-was-reported-in-the-less-file-of-a-component-libraryoperation-on-an-invalid-type","depth":3,"charIndex":-1},{"text":"Bundle DTS failed","id":"bundle-dts-failed","depth":3,"charIndex":5274},{"text":"Error reported for defineConfig function type: If there is no reference to \\\"...\\\" then the inferred type of \\\"default\\\" cannot be named","id":"error-reported-for-defineconfig-function-type-if-there-is-no-reference-to--then-the-inferred-type-of-default-cannot-be-named","depth":3,"charIndex":-1},{"text":"Other FAQ","id":"other-faq","depth":2,"charIndex":6300},{"text":"Add additional compilation feature","id":"add-additional-compilation-feature","depth":3,"charIndex":6313},{"text":"Support for generating TypeScript declaration files for CSS Modules","id":"support-for-generating-typescript-declaration-files-for-css-modules","depth":3,"charIndex":7224}],"domain":"","content":"#\n\n\nProduct FAQ#\n\n\nInitialization of Class Fields#\n\nTypeSript provides the useDefineForClassFields configuration to control the\nconversion handling for public class fields.\n\nIf we have a piece of code:\n\nclass C {\n foo = 100;\n bar: string;\n}\n\n\nWhen useDefineForClassFields is false, then the compiled code will look like:\n\nclass C {\n constructor() {\n this.foo = 100;\n }\n}\n\n\nWhen useDefineForClassFields is true, then the compiled code will look like:\n\nclass C {\n constructor() {\n Object.defineProperty(this, 'foo', {\n enumerable: true,\n configurable: true,\n writable: true,\n value: 100,\n });\n Object.defineProperty(this, 'bar', {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0,\n });\n }\n}\n\n\nAlso the default value of this configuration will change depending on the target\nconfiguration of tsconfig.json: When target is ES2022 or higher, then\nuseDefineForClassFields is configured to true by default, otherwise it defaults\nto false.\n\nFor more information on this configuration of TypeScript, you can refer to the\nfollowing link:\n\n * The useDefineForClassFields Flag and The declare Property Modifier\n\nThe Modern.js Module will currently process according to the following logic:\n\n 1. The first decision to enable this feature inside Modern.js Module is based\n on the useDefineForClassFields configuration in tsconfig.json of the current\n project. Currently, only the contents of the tsconfig.json file under the\n current project path will be read, and the final tsconfig configuration\n based on the extends configuration is not supported at this time.\n 2. If the useDefineForClassFields configuration of tsconfig.json is not\n detected, the default value is determined based on the target configuration\n of tsconfig.json. If target is greater than ES2022 (including EsNext), then\n useDefineForClassFields defaults to true, otherwise it is false.\n 3. If the target of tsconfig.json is not detected, it is processed according to\n the value of useDefineForClassFields as true.\n\n\nbabel-plugin-lodash treats the introduced lodash as undefined#\n\nThis problem occurs when using something like the following:\n\n\n\nexport const libs = {\n _: Lodash,\n};\n\n\nCurrent related issues on the babel-plugin-lodash Github:\n\n * #235\n\nThe solution to this problem is to remove babel-plugin-lodash, since the plugin\nis not needed for on-demand referencing at this point and using it would have\nside effects.\n\nA similar situation occurs with babel-plugin-import. If there is code like the\nfollowing:\n\n\n\nexport const libs = {\n comps: Comps,\n};\n\n\nIn this case babel-plugin-import may also cause Comps to become undefined. So\nyou need to remove the corresponding babel-plugin-import as well.\n\n\nExceptions FAQ#\n\n\nDynamic require of \"react\" is not supported#\n\nProblem Description#\n\nWhen the product format in the product configuration of the build is ES modules.\n\nexport default defineConfig({\n buildConfig: {\n format: 'esm',\n },\n});\n\n\nIf you import a cjs product from a third-party npm package, the resulting\nproduct may not work properly under webpack.\n\n\n\nSolution#\n\n 1. First you need to find which third-party package is causing the problem. For\n example, if the error message points to the react package, then look for a\n third-party package that has code like require('react') in it. For example\n react-draggable, which only contains cjs products, then the problem is\n localized to the react-draggable package.\n 2. Then we need to exclude this package with the following configuration, i.e.\n not package problematic third-party packages.\n\nexport default defineConfig({\n buildConfig: {\n externals: ['react-draggable'],\n },\n});\n\n\nReference Links#\n\n * When using esbuild with external react I get Dynamic require of \"react\" is\n not supported\n\n\nDuring compilation, an error was reported in the less file of a component\nlibrary:'Operation on an invalid type'#\n\nThis is probably because the component library depends on Less version v3, while\nModern.js Module defaults to v4. v3 and v4 have a Break Change in the math\nconfiguration, check this link for details.\n\nTherefore, if a component library like this is used in the source code:\n\nbuildPreset is used in the build configuration, make the following changes:\n\nmodule.exports = {\n buildPreset({ extendPreset }) {\n return extendPreset('your-build-preset', {\n style: {\n less: {\n lessOptions: {\n math: 'always',\n },\n },\n },\n });\n },\n};\n\n\nOr, if a custom buildConfig is used, modify it as follows:\n\nmodule.exports = {\n buildConfig: {\n style: {\n less: {\n lessOptions: {\n math: 'always',\n },\n },\n },\n },\n};\n\n\nIf you are using a component like this in Storybook, you will need to modify the\ndebugging configuration of Storybook:\n\nmodule.exports = {\n dev: {\n storybook: {\n webpackChain(chain, { CHAIN_ID }) {\n chain.module\n .rule(CHAIN_ID.RULE.LESS)\n .use(CHAIN_ID.USE.LESS)\n .tap(options => {\n options.lessOptions = {\n ...options.lessOptions,\n math: 'always',\n };\n return options;\n });\n },\n },\n },\n};\n\n\n\nBundle DTS failed#\n\nNormally, the type file output with tsc is loose. Modern.js Module not only\nsupports outputting loose type file products, but also supports packing type\nfiles, which allows you to package these loose type files and third-party\ndependent type files into one file.\n\nHowever, there is a risk in packaging the type files of third-party\ndependencies, because there are cases where the type files of third-party\ndependencies cannot be packaged.\n\nSo when you encounter a Bundle DTS failed error message during the Modern.js\nModule build, you can observe that the error message comes from a third-party\ndependency. Try setting dts.respectExternal to false to disable the behavior of\npacking type files of third-party dependencies.\n\n\nError reported for defineConfig function type: If there is no reference to \"...\"\nthen the inferred type of \"default\" cannot be named#\n\nCheck if the include configuration exists in the project's tsconfig.json file,\nand if not, try adding the following:\n\n{\n \"include\": [\"src\"]\n}\n\n\n\nOther FAQ#\n\n\nAdd additional compilation feature#\n\nThe Modern.js Module is based on the esbuild implementation, so if you have\nspecial needs or want to add additional compilation capabilities, you can do so\nby implementing the esbuild plugin.\n\nThe Modern.js Module provides esbuildOptions configuration to allow modification\nof Modern.js's internal esbuild configuration, so that custom esbuild plugins\ncan be added via this configuration:\n\n\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.plugins = [myEsbuildPlugin, ...options.plugins];\n return options;\n },\n },\n});\n\n\nWhen adding an esbuild plugin, please note that you need to add the plugin at\nthe beginning of the plugins array. This is because the Modern.js Module is also\nintegrated into the entire build process through an esbuild plugin. Therefore,\ncustom plugins need to be registered with higher priority.\n\n\nSupport for generating TypeScript declaration files for CSS Modules#\n\n * First Solution: typed-css-modules\n * Second Solution: postcss-modules-dts\n\n\n\nexport default defineConfig(async () => {\n const { dts } = await import(\"@guanghechen/postcss-modules-dts\");\n return {\n buildConfig: {\n style: {\n modules: { ...dts },\n },\n },\n // custom config\n }\n});\n","frontmatter":{},"version":""},{"id":29,"title":"FAQ","routePath":"/module-tools/en/guide/faq/","lang":"en","toc":[],"domain":"","content":"#\n\nHere is a list of all frequently asked questions about Modern.js Module.\n\n * Build FAQ\n * Test FAQ\n * Storybook FAQ","frontmatter":{},"version":""},{"id":30,"title":"Storybook FAQ","routePath":"/module-tools/en/guide/faq/storybook","lang":"en","toc":[{"text":"Storybook v7 Support","id":"storybook-v7-support","depth":2,"charIndex":3},{"text":"Using Storybook Addon or other configurations does not work","id":"using-storybook-addon-or-other-configurations-does-not-work","depth":2,"charIndex":186},{"text":"Cannot find module \\'react-dom/package.json","id":"cannot-find-module-react-dompackagejson","depth":2,"charIndex":-1},{"text":"Unable to locate the specific error message","id":"unable-to-locate-the-specific-error-message","depth":2,"charIndex":880},{"text":"Can`t find any stories is your Storybook","id":"cant-find-any-stories-is-your-storybook","depth":2,"charIndex":1653},{"text":"Storybook Adds Proxy Functionality","id":"storybook-adds-proxy-functionality","depth":2,"charIndex":1953},{"text":"Modify the directory where the Story file exists","id":"modify-the-directory-where-the-story-file-exists","depth":2,"charIndex":2800}],"domain":"","content":"#\n\n\nStorybook v7 Support#\n\nStorybook v7 does not support it yet. Rspack builds are currently planned to be\nsupported in Storybook v7, so progress will be slower.\n\nRelated Issue: #3376.\n\n\nUsing Storybook Addon or other configurations does not work#\n\nModern.js Module is currently using Storybook version v6, if you are using Addon\nversion v7 you may not be able to get the addon to work.\n\nIn addition to the Addon, other configurations may also have differences. For\nexample, if you modify the preview.js configuration file, Storybook v6 is\nwritten differently than v7:\n\n * v6:Document\n * v7:Document\n\n\nCannot find module 'react-dom/package.json#\n\nWhen debug Storybook, the following problem occurs:\n\nERR! Error: Cannot find module 'react-dom/package.json'\n\n\nYou can install the react-dom dependency in the project.\n\n{\n \"devDependencies\": {\n \"react-dom\": \"^17\"\n }\n}\n\n\n\nUnable to locate the specific error message#\n\nSolutions:\n\n 1. Find @storybook/core-server/dist/cjs/dev-server.js\n 2. Find this code: var _await$Promise$all = await Promise.all([preview,\n manager,.\n 3. Modify it:\n\nvar _await$Promise$all = await Promise.all([\n preview.catch(e => console.info(e)),\n manager // TODO #13083 Restore this when compiling the preview is fast enough\n // .then((result) => {\n // if (!options.ci && !options.smokeTest) openInBrowser(address);\n // return result;\n // })\n .catch(previewBuilder.bail)]),\n _await$Promise$all2 = _slicedToArray(_await$Promise$all, 2),\n previewResult = _await$Promise$all2[0],\n managerResult = _await$Promise$all2[1]; // TODO #13083 Remove this when compiling the preview is fast enough\n\n\n\nCan`t find any stories is your Storybook#\n\n\n\nWhen you get a problem like this, you can first open the browser console and\nthere should be some error messages. You can use the error messages to deduce if\nthere is a problem in the code you are writing that is causing Storybook to not\nwork properly.\n\n\nStorybook Adds Proxy Functionality#\n\nStorybook does not provide a solution for this, but there is one in the\nStorybook Issue. In the Modern.js Module, you can:\n\n 1. Add the config/storybook/middleware.js file and initialize the following:\n\n/* eslint-disable filenames/match-exported */\nmodule.exports = function expressMiddleware(router) {\n // router is express router\n // \n // router = new Router();\n};\n\n\n 2. add http-proxy-middleware dependency\n 3. Add proxy routing-related configuration\n\n/* eslint-disable filenames/match-exported */\nconst { createProxyMiddleware } = require(\"http-proxy-middleware\");\n\nmodule.exports = function expressMiddleware (router) {\n router.use('/api', createProxyMiddleware({\n target: \"http://localhost:8000\",\n changeOrigin: true\n }))\n}\n\n\nLink:https://github.com/storybookjs/storybook/issues/11551\n\n\nModify the directory where the Story file exists#\n\nThe directory where Story files are stored cannot be modified at the moment,\nonly the *.stories.(t|j)s(x) and *.stories.md(x) files in the\nyour-project/stories directory are recognized as Story files.","frontmatter":{},"version":""},{"id":31,"title":"Test FAQ","routePath":"/module-tools/en/guide/faq/test","lang":"en","toc":[{"text":"Execute test command with an error TypeError: Cannot read property \\'testEnvironmentOptions\\' of undefined","id":"execute-test-command-with-an-error-typeerror-cannot-read-property-testenvironmentoptions-of-undefined","depth":3,"charIndex":-1}],"domain":"","content":"#\n\n\nExecute test command with an error TypeError: Cannot read property\n'testEnvironmentOptions' of undefined#\n\n\n\nYou can check whether other projects in Monorepo have jest-environment-jsdom\ndependencies and unify them with the overrides provided by Monorepo.","frontmatter":{},"version":""},{"id":32,"title":"Quick Start","routePath":"/module-tools/en/guide/intro/getting-started","lang":"en","toc":[{"text":"3 minute demo","id":"3-minute-demo","depth":2,"charIndex":3},{"text":"Create new project","id":"create-new-project","depth":3,"charIndex":210},{"text":"Add to an existing project","id":"add-to-an-existing-project","depth":3,"charIndex":1097},{"text":"Core npm Package","id":"core-npm-package","depth":3,"charIndex":1934},{"text":"View official example","id":"view-official-example","depth":3,"charIndex":2693},{"text":"Let\\'s get started","id":"lets-get-started","depth":2,"charIndex":-1}],"domain":"","content":"#\n\n\n3 minute demo#\n\nWant to experience Modern.js Module in action? The only prerequisite you need is\nNode.js LTS and make sure your Node version is >= 14.18.0.We recommend using the\nLTS version of Node.js 18.\n\n\nCreate new project#\n\nIf you want to create a complete Modern.js Module, you can execute the following\ncommand:\n\nnpx @modern-js/create your-project-dir-name\n\n\nINFO\n\nExecute npx @modern-js/create -h for more command line arguments\n\nNext, in the issue interaction, follow the options below.\n\n? Please select the type of project you want to create: Npm Module\n? Please fill in the project name: library\n? Please select the programming language: TS\n? Please select the package manager: pnpm\n\n\n> The project name is the value of the \"name\" field in package.json.\n\nThen the process of initializing the project will start. After the project\ndirectory and files are generated and the dependencies are installed, a complete\nmodule project is created.\n\nWe can start the project build directly with the pnpm build command, and start\nthe build in watching mode with the pnpm build --watch command.\n\n\nAdd to an existing project#\n\nFrom your shell, install the following dependencies in your project.\n\n * @modern-js/module-tools\n * \"typescript\" (omitted if not a TypeScript project)\n\n> If it's a TypeScript project, add the \"typescript\" dependency.\n\n> For projects that use pnpm or the Yarn package manager, just replace npm. pnpm\n> is recommended.\n\nNext, create the modern.config.(t|j)s file in the root of the project.\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n});\n\n\nFinally, add the command \"build\": \"modern build\" to the project's package.json\nfile.\n\n{\n \"scripts\": {\n \"build\": \"modern build\"\n }\n}\n\n\nIf your project has a src/index.(js|jsx) file or both src/index.(ts|tsx) and\ntsconfig.json files, then congratulations you can run the npm run build command\ndirectly to build your project with Modern.js Module.\n\n\nCore npm Package#\n\n@modern-js/module-tools is the core npm package of Modern.js Module, providing\nthe following capabilities:\n\n * It offers commonly used CLI commands such as modern dev, modern build, and\n more.\n * It integrates Modern.js Core, providing capabilities for configuration\n parsing, plugin loading, and more.\n * It integrates esbuild and SWC, providing build capabilities.\n * It integrates some commonly used plugins, such as plugin-lint,\n plugin-changeset, and others.\n\n@modern-js/module-tools is implemented based on the plugin system of Modern.js.\nEssentially, it is a plugin. Therefore, you need to register moduleTools in the\nplugins field of the configuration file:\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n});\n\n\n\nView official example#\n\nIf you want to see the complete project using the Modern.js Module, you can\nexecute the following command.\n\ngit clone https://github.com/web-infra-dev/module-tools-examples\ncd module-tools-example/base\n\n## Execute the build.\npnpm build\n\n## Execute the build in listening mode.\npnpm build --watch\n\n## Start Storybook\npnpm dev storybook\n\n## Test\npnpm test\n\n\n\nLet's get started#\n\nChoose your tutorial scenario...\n\n * I'm a beginner and need to learn basic usage of Modern.js Module.\n * I have learned the basic usage of Modern.js Module and can learn advanced\n usage of Modern.js Module.\n * I need to expand my project capabilities and need to learn how to develop\n plugins for Modern.js Module.","frontmatter":{"sidebar_position":3},"version":""},{"id":33,"title":"Welcome to Modern.js Module","routePath":"/module-tools/en/guide/intro/welcome","lang":"en","toc":[],"domain":"","content":"#\n\nModern.js Module is a modules engineering solution for Modern.js, as well as a\ncore dependency. It allows developers to build, debug, and publish module type\nproject more easily. A module type project can mostly be thought of as an npm\npackage type project, which may be a component, component library or tool\nlibrary project.\n\nIf you are planning to develop a project of the npm package type, then you came\nto the right place! Modern.js provides a professional Modern.js Module. It gives\nyou:\n\n * Simple project initialization: simply execute the npx @modern-js/create\n project-dir command, followed by a few interactive questions, to create a\n complete module type project. The created project also supports the choice of\n two package managers, pnpm and Yarn.\n * Code formatting: In Modern.js Module, you can execute modern lint to format\n the code. The initialized module project includes the ESLint ruleset for\n Modern.js for most scenarios.\n * Comprehensive build capabilities and faster builds: Modern.js Module provides\n high-performance build capabilities based on esbuild and SWC, and provides\n rich configurations for different build scenarios.\n * Storybook debugging tools: Modern.js Module provides Storybook debugging\n tools for debugging module projects. After installing the Storybook plugin\n for Modern.js Module, you can start it with the modern dev storybook command.\n You can use Storybook not only for debugging components, but also for other\n types of modules.\n * Testing capabilities with Jest: When you need to test a module, you can use\n the modern test command of Modern.js Module, which not only integrates with\n Jest, but also provides an API for configuring Jest.\n * Versioning based on Changesets: When you need to record changes to a project,\n you can use the modern change command to generate a Markdown file containing\n the changes; when you need to upgrade a project, you can use the modern bump\n command to analyze and upgrade the version through the Markdown file; when\n you need to release a project, you can use the modern release command to\n release the project; Modern.js Module implements these commands based on\n Changesets.\n * Extensible plugin mechanism: Want to integrate additional debugging tools for\n your project? Or maybe you want to do some extra processing during the build\n process, Modern.js Module provides a plugin mechanism and plugin hooks that\n cover both the dev command and the build command process. You can use them to\n extend the capabilities of your project.\n * Lots more! Modern.js Module will continue to optimize its build and debug\n features in the future. If there are important issues to be solved in module\n project building, or if a mainstream module project debugging tool or pattern\n emerges, then they will probably be supported by Modern.js Module.","frontmatter":{"sidebar_position":1},"version":""},{"id":34,"title":"Why you need Modern.js Module","routePath":"/module-tools/en/guide/intro/why-module-engineering-solution","lang":"en","toc":[],"domain":"","content":"#\n\nYou've probably all experienced it: when developing a component library or tool\nlibrary from scratch, we have to consider not only how to write the code logic\nof the project itself, but also how to build, debug, test, format the code, and\nother things that have nothing to do with the code logic.\n\nFor example, when we consider which builder is used to build the code for a\nmodule project, we might previously consider webpack or Rollup, but now we might\nalso consider esbuild or SWC.\n\nRegardless of which builder is chosen, this is going to be a costly learning\ncurve for developers who are not skilled in the use of these build tools. Even\nif you want to use them quickly, it will take a lot of time and effort.\n\nIn addition to the build, things like providing debugging tools for projects,\nsupporting testing capabilities, adding code format validation, etc. can take a\nlong time and effort for a novice to understand or master them and actually\nserve the current project.\n\nTo ensure the quality of the code and the integrity of the project, we often\nneed to do these things that are not related to the logical implementation of\nthe code. However, these things are likely to affect the overall project\ndevelopment progress, reduce the developer's development experience, and make\nthe developer feel that the development threshold of the module project is very\nhigh.\n\nIf you have to go through all this work every time you develop a module type\nproject, you will spend most of your development time in the beginning on these\nthings that are not related to code implementation. If we could provide a module\nengineering solution that would help developers to solve the project engineering\nissues and allow them to focus more on code implementation, it would greatly\nimprove the module type project development experience.\n\n\n\nModern.js, in order to make developing module type projects easier, provides a\nmodule engineering solution in order to solve the above mentioned problems and\nprovides the main features using Modern.js Module. Modern.js Module can be\nunderstood as a tool dedicated to the development of module type projects.","frontmatter":{"sidebar_position":2},"version":""},{"id":36,"title":"Quick Start","routePath":"/module-tools/en/plugins/guide/getting-started","lang":"en","toc":[],"domain":"","content":"#\n\nModern.js Module not only provides a rich set of features, but also supports\nextending the capabilities of the current project by way of plugins.\n\nWe can quickly see how to write a Modern.js Module plugin by using the following\nexample.\n\n 1. First we create . /plugins/example.ts file under the initialized project.\n\n. /project .\n├── plugins\n│ └── example.ts\n├── src/\n└── modern.config.ts\n\n\n 2. Next add the code for the plugin to the example.ts file.\n\n\n\nexport const ExamplePlugin = (): CliPlugin => {\n return {\n name: 'example',\n setup() {\n console.info('this is example plugin');\n return {\n // use hooks\n afterBuild() {\n console.info('build over');\n },\n };\n },\n };\n};\n\n\n 3. Then we register the plugin we just wrote via the plugins API.\n\n\nexport default defineConfig({\n plugins: [examplePlugin()],\n});\n\n\n 4. Finally, run modern build and you will see:\n\nThis is example plugin\nBuild succeed: 510.684ms\nbuild over\n\n\nWith the above example, we learned the following things.\n\n * The recommended plugin directory structure\n * The initialization code of the plugin\n * Plugin registration\n\nIn addition to the above, we also need to understand.\n\n * plugin objects, type definitions and recommended configuration options\n * setup functions, api object parameters, lifecycle hooks","frontmatter":{"sidebar_position":1},"version":""},{"id":37,"title":"Plugin Object","routePath":"/module-tools/en/plugins/guide/plugin-object","lang":"en","toc":[{"text":"Plugin type definitions","id":"plugin-type-definitions","depth":2,"charIndex":805},{"text":"Plugin configuration options","id":"plugin-configuration-options","depth":2,"charIndex":1163}],"domain":"","content":"#\n\nThe Modern.js Module plugin is an object, and the object contains the following\nproperties.\n\n * name: The name of the plugin, a unique identifier.\n * setup: plugin initialization function, which will be executed only once.\n setup function can return a Hooks object, and Modern.js Module will execute\n the function corresponding to the Hook defined on the Hooks object at a\n specific time.\n\nFor example, in the following plugin code example, the beforeBuild function is\ntriggered before the project starts the build task and the build start log is\nprinted.\n\n\n\nconst myPlugin: CliPlugin = {\n name: 'my-plugin',\n\n setup() {\n return {\n // this is hook\n beforeBuild: () => {\n console.info('build start');\n },\n };\n },\n};\n\n\n\nexport default {\n plugins: [myPlugin()],\n};\n\n\n\nPlugin type definitions#\n\nWhen using TypeScript, you can introduce the built-in CliPlugin and ModuleTools\ntypes to provide the correct type derivation for plugins: ``\n\n\n\nconst myPlugin: CliPlugin = {\n name: 'my-plugin',\n\n setup() {\n const foo = '1';\n\n return {\n // this is hook\n afterBuild: () => {\n //...\n },\n };\n },\n};\n\n\n\nPlugin configuration options#\n\nIt is recommended to write the plugin as a function, so that the plugin can\nreceive configuration options via function entry.\n\n\n\ntype MyPluginOptions = {\n foo: string;\n};\n\nconst myPlugin = (options: MyPluginOptions): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n console.log(options.foo);\n },\n});\n","frontmatter":{"sidebar_position":2},"version":""},{"id":38,"title":"Setup function","routePath":"/module-tools/en/plugins/guide/setup-function","lang":"en","toc":[{"text":"Plugin API objects","id":"plugin-api-objects","depth":2,"charIndex":173},{"text":"api.useAppContext","id":"apiuseappcontext","depth":3,"charIndex":783},{"text":"api.useResolvedConfigContext","id":"apiuseresolvedconfigcontext","depth":3,"charIndex":1343},{"text":"api.useHookRunners","id":"apiusehookrunners","depth":3,"charIndex":1811},{"text":"Asynchronous setup","id":"asynchronous-setup","depth":2,"charIndex":2132},{"text":"Life cycle hooks","id":"life-cycle-hooks","depth":2,"charIndex":2694}],"domain":"","content":"#\n\nIn the \"Plugin object\" section we know that the plugin object contains a setup\nfunction that not only contains an api object parameter, but also returns a\nHooks object.\n\n\nPlugin API objects#\n\nThe setup function of the plugin will provide an api object parameter, and you\ncan call some of the methods provided on this object to get information about\nthe configuration, project context, etc.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup(api) {\n // Get the original configuration of the application\n const config = api.useConfigContext();\n // Get the application runtime context\n const appContext = api.useAppContext();\n // Get the final configuration after resolving\n const resolvedConfig = api.useResolvedConfigContext();\n },\n});\n\n\n\napi.useAppContext#\n\nUsed to get project context information.\n\nconst useAppContext: () => IAppContext;\n\ninterface IAppContext {\n appDirectory: string;\n configFile: string | false;\n packageName: string;\n nodeModulesDirectory: string;\n internalDirectory: string;\n plugins: {\n cli?: any;\n server?: any;\n }[];\n}\n\n\nINFO\n\nThrough the actual type file, we can see that there are some additional fields.\nHowever, for Modern.js Module, the fields mentioned above are the only ones that\nare meaningful. The same applies to other methods of the api object.\n\n\napi.useResolvedConfigContext#\n\nUsed to get the final configuration after parsing.\n\nINFO\n\nIf you need to get the build-related final configuration, you need to use the\nbeforeBuild Hook.\n\nconst useResolvedConfigContext: () => NormalizedConfig;\n\ninterface NormalizedConfig {\n buildConfig: PartialBuildConfig;\n buildPreset: BuildPreset;\n dev: Dev;\n plugins: PluginConfig;\n runtime: RuntimeConfig;\n runtimeByEntries?: RuntimeByEntriesConfig;\n _raw: UserConfig;\n}\n\n\n\napi.useHookRunners#\n\nUsed to get the executors of Hooks and trigger the execution of a specific Hook.\n\n\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n async setup(api) {\n const hookRunners = api.useHookRunners();\n // trigger the afterBuild Hook\n await hookRunners.afterBuild();\n },\n});\n\n\n\nAsynchronous setup#\n\nThe setup of a CLI plugin can be an asynchronous function that performs\nasynchronous logic during the initialization process.\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n async setup(api) {\n await doSomething();\n },\n});\n\n\nNote that the setup function of the next plugin is not executed until the async\nsetup function of the current plugin has finished. Therefore, you should avoid\nperforming time-consuming asynchronous operations in the setup function to avoid\nslowing down the startup performance of the CLI.\n\n\nLife cycle hooks#\n\nWe know that the setup function returns a Hooks object, which can also be\nunderstood as an object with Modern.js Module lifecycle hooks.\n\nCurrently there are two main types of hooks.\n\n * build hooks: triggered only when the build command is executed to build the\n source code product.\n * buildPlatform hook: triggered only when the build --platform command is\n executed to generate other build products.\n * debug hooks: hooks that are triggered when running the dev command.\n\nSee the API documentation for a full list of lifecycle hooks.","frontmatter":{"sidebar_position":3},"version":""},{"id":39,"title":"Overview","routePath":"/module-tools/en/plugins/official-list/overview","lang":"en","toc":[{"text":"Official Plugin","id":"official-plugin","depth":2,"charIndex":3}],"domain":"","content":"#\n\n\nOfficial Plugin#\n\n * @modern-js/plugin-module-import:Use SWC to provide the same ability as\n babel-plugin-import.\n * @modern-js/plugin-module-banner:Add custom content, such as copyright\n information, to the top and bottom of each JS and CSS file.\n * @modern-js/plugin-module-node-polyfill: Inject Polyfills of Node core modules\n in the browser side.\n * @modern-js/plugin-module-polyfill:Inject polyfill for unsupported features\n used in your code.\n * @modern-js/plugin-module-babel:Use Babel to transform your code.","frontmatter":{},"version":""},{"id":40,"title":"Babel Plugin","routePath":"/module-tools/en/plugins/official-list/plugin-babel","lang":"en","toc":[{"text":"Quick start","id":"quick-start","depth":2,"charIndex":110},{"text":"Install","id":"install","depth":3,"charIndex":125},{"text":"Register","id":"register","depth":3,"charIndex":136},{"text":"Config","id":"config","depth":2,"charIndex":708}],"domain":"","content":"#\n\nTIP\n\nNormally, we don't need to use Babel to transform our code, this plugin is only\nused as a downgrade.\n\n\nQuick start#\n\n\nInstall#\n\n\nRegister#\n\nYou can install the plugin with the following command:\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginBabel()],\n});\n\n\nYou can also configure the registration via hooks, for example, if you need to\nbundle two files A and B at the same time and only need to use babel when bundle\nA:\n\n\n\n\nconst babelHook = getBabelHook({\n // babel options\n});\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildConfig: [\n {\n hooks: [babelHook],\n input: ['src/a.ts'],\n },\n {\n input: ['src/b.ts'],\n },\n ],\n});\n\n\n\nConfig#\n\nSee babel options.\n\nHere is an example with @babel/preset-env configured\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBabel({\n presets: [['@babel/preset-env']],\n }),\n ],\n});\n","frontmatter":{},"version":""},{"id":41,"title":"Banner Plugin","routePath":"/module-tools/en/plugins/official-list/plugin-banner","lang":"en","toc":[{"text":"Quick Start","id":"quick-start","depth":2,"charIndex":89},{"text":"Install","id":"install","depth":3,"charIndex":104},{"text":"Register","id":"register","depth":3,"charIndex":115},{"text":"Example","id":"example","depth":2,"charIndex":456},{"text":"Add copyright information at the top of a JS file","id":"add-copyright-information-at-the-top-of-a-js-file","depth":3,"charIndex":467},{"text":"Configuration","id":"configuration","depth":2,"charIndex":967},{"text":"banner","id":"banner","depth":3,"charIndex":1126},{"text":"footer","id":"footer","depth":3,"charIndex":1266}],"domain":"","content":"#\n\nProvide the ability to inject content at the top and bottom of each JS and CSS\nfile.\n\n\nQuick Start#\n\n\nInstall#\n\n\nRegister#\n\nYou can install the plugin with the following command:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBanner({\n banner: {\n js: '//comment',\n css: '/*comment*/',\n },\n }),\n ],\n});\n\n\nTIP\n\nNote: CSS comments do not support the //comment syntax. Refer to \"CSS Comments\"\n\n\nExample#\n\n\nAdd copyright information at the top of a JS file#\n\n\n\n\nconst copyRight = `/*\n © Copyright 2020 xxx.com or one of its affiliates.\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n*/`;\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBanner({\n banner: {\n js: copyRight,\n },\n }),\n ],\n});\n\n\n\nConfiguration#\n\n * Type\n\ntype BannerOptions = {\n banner: {\n js?: string;\n css?: string;\n };\n footer?: {\n js?: string;\n css?: string;\n };\n};\n\n\n\nbanner#\n\nAdd content at the top.\n\n * banner.js: Add content at the top of a JS file.\n * banner.css: Add content at the top of a CSS file.\n\n\nfooter#\n\nAdd content at the bottom.\n\n * footer.js: Add content at the bottom of a JS file.\n * footer.css: Add content at the bottom of a CSS file.","frontmatter":{},"version":""},{"id":42,"title":"Import Plugin","routePath":"/module-tools/en/plugins/official-list/plugin-import","lang":"en","toc":[{"text":"Quick Start","id":"quick-start","depth":2,"charIndex":231},{"text":"Install","id":"install","depth":3,"charIndex":246},{"text":"Register","id":"register","depth":3,"charIndex":257},{"text":"Configurations","id":"configurations","depth":2,"charIndex":627},{"text":"pluginImport","id":"pluginimport","depth":3,"charIndex":708},{"text":"Notes","id":"notes","depth":2,"charIndex":1127}],"domain":"","content":"#\n\nUsing SWC provides the same ability and configuration as babel-plugin-import.\n\nTIP\n\nSince @modern-js/module-tools version >= v2.16.0, this plugin functionality is\nbuilt into Modern.js Module and is provided by transformImport.\n\n\nQuick Start#\n\n\nInstall#\n\n\nRegister#\n\nIn Modern.js Module, you can register plugins in the following way:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginImport({\n pluginImport: [\n {\n libraryName: 'antd',\n style: true,\n },\n ],\n }),\n ],\n});\n\n\nThis way we can use the ability of automatic import in Modern.js Module.\n\n\nConfigurations#\n\n * Type:\n\ntype Options = {\n pluginImport?: ImportItem[];\n};\n\n\n\npluginImport#\n\n * Type: object[]\n\nThe elements of the array are configuration objects for babel-plugin-import,\nwhich can be referred to options。\n\nExample:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginImport({\n pluginImport: [\n // babel-plugin-import`s options config\n {\n libraryName: 'foo',\n style: true,\n },\n ],\n }),\n ],\n});\n\n\n\nNotes#\n\nSWC (Speedy Web Compiler) is written in Rust, and this plugin is based on SWC\nand ported from babel-plugin-import. The configuration options remain\nconsistent.\n\nSome configurations can accept functions, such as customName, customStyleName,\netc. These JavaScript functions are called by Rust through Node-API, which can\ncause some performance degradation.\n\nSimple function logic can be replaced by template language. Therefore, for\nconfigurations such as customName, customStyleName, etc., instead of passing\nfunctions, you can also pass a string as a template to replace the function,\nimproving performance.\n\nWe will use the following code as example:\n\n\n\n\nAdd the following configuration on the right-hand side:\n\nmodulePluginImport({\n pluginImport: [\n {\n libraryName: 'foo',\n customName: 'foo/es/{{ member }}',\n },\n ],\n});\n\n\nThe {{ member }} in it will be replaced with the corresponding import member.\nAfter transformation:\n\n\n\n\nTemplate customName: 'foo/es/{{ member }}' is the same as customName: (member)\n=> `foo/es/${member}` , but template value has no performance overhead of\nNode-API.\n\nThe template used here is handlebars. There are some useful builtin tools, Take\nthe above import statement as an example:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginImport({\n pluginImport: [\n {\n libraryName: 'foo',\n customName: 'foo/es/{{ kebabCase member }}',\n },\n ],\n }),\n ],\n});\n\n\nTransformed to:\n\n\n\n\nIn addition to kebabCase, there are cameraCase, snakeCase, upperCase and\nlowerCase can be used as well.","frontmatter":{},"version":""},{"id":43,"title":"Node Polyfill Plugin","routePath":"/module-tools/en/plugins/official-list/plugin-node-polyfill","lang":"en","toc":[{"text":"Quick Start","id":"quick-start","depth":2,"charIndex":460},{"text":"Install","id":"install","depth":3,"charIndex":475},{"text":"Register","id":"register","depth":3,"charIndex":486},{"text":"Configurations","id":"configurations","depth":2,"charIndex":662},{"text":"exclude","id":"exclude","depth":3,"charIndex":768},{"text":"overrides","id":"overrides","depth":3,"charIndex":965},{"text":"Node Polyfills","id":"node-polyfills","depth":2,"charIndex":1211},{"text":"Globals","id":"globals","depth":3,"charIndex":1229},{"text":"Modules","id":"modules","depth":3,"charIndex":1420},{"text":"Fallbacks","id":"fallbacks","depth":3,"charIndex":1921}],"domain":"","content":"#\n\nAbout Node Polyfill\n\nNormally, we don't need to use Node libs on the browser side. However, it is\npossible to use some Node libs when the code will run on both the Node side and\nthe browser side, and Node Polyfill provides browser versions of polyfills for\nthese Node libs.\n\nBy using the Node Polyfill plugin, Node core libs polyfills are automatically\ninjected into the browser-side, allowing you to use these modules on the browser\nside with confidence.\n\n\nQuick Start#\n\n\nInstall#\n\n\nRegister#\n\nIn Modern.js Module, you can register plugins in the following way:\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginNodePolyfill()],\n});\n\n\n\nConfigurations#\n\n * Type:\n\ntype NodePolyfillOptions = {\n exclude?: string[];\n overrides?: Record;\n};\n\n\n\nexclude#\n\nExclude the Node Polyfill to be injected.\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginNodePolyfill({\n exclude: ['console'],\n }),\n ],\n});\n\n\n\noverrides#\n\nOverride the built-in Node Polyfill.\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginNodePolyfill({\n overrides: {\n fs: path.join(__dirname, './custom-fs.js'),\n },\n }),\n ],\n});\n\n\n\nNode Polyfills#\n\n\nGlobals#\n\n * Buffer\n * process\n * console\n\nWhen the above global variables are used directly in code, the corresponding\npolyfill will be injected.\n\nconst bufferData = Buffer.from('xxxx');\n\n\n\nModules#\n\n * assert\n * buffer\n * console\n * constants\n * crypto\n * domain\n * events\n * http\n * https\n * os\n * path\n * punycode\n * process\n * querystring\n * stream\n * _stream_duplex\n * _stream_passthrough\n * _stream_readable\n * _stream_transform\n * _stream_writable\n * string_decoder\n * sys\n * timers\n * tty\n * url\n * util\n * vm\n * zlib\n\nWhen the above module is referenced in code via import / require syntax, the\ncorresponding polyfill will be injected.\n\n\n\nconst bufferData = Buffer.from('xxxx');\n\n\n\nFallbacks#\n\n * child_process\n * cluster\n * dgram\n * dns\n * fs\n * module\n * net\n * readline\n * repl\n * tls\n\nCurrently there is no polyfill for the above modules on the browser side, so\nwhen you import the above modules, it will automatically fallback to an empty\nobject.\n\n\n\nconsole.log(fs); // -> {}\n","frontmatter":{},"version":""},{"id":44,"title":"Polyfill Plugin","routePath":"/module-tools/en/plugins/official-list/plugin-polyfill","lang":"en","toc":[{"text":"Quick start","id":"quick-start","depth":2,"charIndex":497},{"text":"Install","id":"install","depth":3,"charIndex":512},{"text":"Register","id":"register","depth":3,"charIndex":523},{"text":"Config","id":"config","depth":2,"charIndex":1108},{"text":"targets","id":"targets","depth":3,"charIndex":1178}],"domain":"","content":"#\n\nTIP\n\nNormally, we don't need to inject polyfill for npm packages, this step should be\ndone on the web application framework side, but in some scenarios we need to\ninject polyfill in order to make our library run directly in low version\nbrowsers.\n\nNote that this plugin does not transform your code syntax, it only injects\npolyfill for unsupported functions used in your code, importing them as normal\nfunctions instead of polluting the global. You need to install the core-js-pure\ndependency.\n\n\nQuick start#\n\n\nInstall#\n\n\nRegister#\n\nIn Modern.js Module, you can register plugins in the following way:\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginPolyfill()],\n});\n\n\nYou can also configure registration via hooks, for example, if you have multiple\nbuild configurations at the same time and only need to inject the polyfill when\nbundle:\n\n\n\n\nconst polyfillHook = getPolyfillHook();\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildConfig: [\n {\n buildType: 'bundle',\n hooks: [polyfillHook],\n },\n {\n buildType: 'bundleless',\n },\n ],\n});\n\n\n\nConfig#\n\n * Type\n\ntype options = {\n targets?: Record | string;\n};\n\n\n\ntargets#\n\nSee Babel target.\n\nThis is a example.\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginPolyfill({\n targets: '> 0.25%, not dead',\n }),\n ],\n});\n","frontmatter":{},"version":""}] \ No newline at end of file diff --git a/modern-js/module-tools/static/search_index.zh.bb85d2f3.json b/modern-js/module-tools/static/search_index.zh.210bb6fa.json similarity index 93% rename from modern-js/module-tools/static/search_index.zh.bb85d2f3.json rename to modern-js/module-tools/static/search_index.zh.210bb6fa.json index e35db5ae78..71715d716f 100644 --- a/modern-js/module-tools/static/search_index.zh.bb85d2f3.json +++ b/modern-js/module-tools/static/search_index.zh.210bb6fa.json @@ -1 +1 @@ -[{"id":45,"title":"buildConfig","routePath":"/module-tools/api/config/build-config","lang":"zh","toc":[{"text":"alias","id":"alias","depth":2,"charIndex":141},{"text":"asset","id":"asset","depth":2,"charIndex":862},{"text":"asset.path","id":"assetpath","depth":2,"charIndex":885},{"text":"asset.limit","id":"assetlimit","depth":2,"charIndex":956},{"text":"asset.publicPath","id":"assetpublicpath","depth":2,"charIndex":1276},{"text":"asset.svgr","id":"assetsvgr","depth":2,"charIndex":1493},{"text":"asset.svgr.include","id":"assetsvgrinclude","depth":2,"charIndex":1889},{"text":"asset.svgr.exclude","id":"assetsvgrexclude","depth":2,"charIndex":1988},{"text":"autoExternal","id":"autoexternal","depth":2,"charIndex":2089},{"text":"autoExternal.dependencies","id":"autoexternaldependencies","depth":2,"charIndex":2588},{"text":"autoExternal.peerDependencies","id":"autoexternalpeerdependencies","depth":2,"charIndex":2676},{"text":"banner","id":"banner","depth":2,"charIndex":2772},{"text":"buildType","id":"buildtype","depth":2,"charIndex":3278},{"text":"copy","id":"copy","depth":2,"charIndex":3381},{"text":"copy.patterns","id":"copypatterns","depth":2,"charIndex":3549},{"text":"copy.options","id":"copyoptions","depth":2,"charIndex":3716},{"text":"define","id":"define","depth":2,"charIndex":3949},{"text":"dts","id":"dts","depth":2,"charIndex":4761},{"text":"dts.abortOnError","id":"dtsabortonerror","depth":2,"charIndex":4882},{"text":"dts.distPath","id":"dtsdistpath","depth":2,"charIndex":5216},{"text":"dts.only","id":"dtsonly","depth":2,"charIndex":5416},{"text":"dts.respectExternal","id":"dtsrespectexternal","depth":2,"charIndex":5588},{"text":"dts.tsconfigPath","id":"dtstsconfigpath","depth":2,"charIndex":5911},{"text":"esbuildOptions","id":"esbuildoptions","depth":2,"charIndex":6102},{"text":"externalHelpers","id":"externalhelpers","depth":2,"charIndex":6954},{"text":"externals","id":"externals","depth":2,"charIndex":7553},{"text":"footer","id":"footer","depth":2,"charIndex":7807},{"text":"format","id":"format","depth":2,"charIndex":7845},{"text":"format: esm","id":"format-esm","depth":3,"charIndex":7970},{"text":"format: cjs","id":"format-cjs","depth":3,"charIndex":8124},{"text":"format: iife","id":"format-iife","depth":3,"charIndex":8297},{"text":"format: umd","id":"format-umd","depth":3,"charIndex":8474},{"text":"hooks","id":"hooks","depth":2,"charIndex":8702},{"text":"input","id":"input","depth":2,"charIndex":9321},{"text":"jsx","id":"jsx","depth":2,"charIndex":10360},{"text":"metafile","id":"metafile","depth":2,"charIndex":10761},{"text":"minify","id":"minify","depth":2,"charIndex":11100},{"text":"outDir","id":"outdir","depth":2,"charIndex":11352},{"text":"platform","id":"platform","depth":2,"charIndex":11488},{"text":"redirect","id":"redirect","depth":2,"charIndex":11679},{"text":"resolve","id":"resolve","depth":2,"charIndex":12046},{"text":"resolve.mainFields","id":"resolvemainfields","depth":3,"charIndex":12068},{"text":"resolve.jsExtentions","id":"resolvejsextentions","depth":3,"charIndex":12513},{"text":"sideEffects","id":"sideeffects","depth":2,"charIndex":12883},{"text":"sourceDir","id":"sourcedir","depth":2,"charIndex":13689},{"text":"sourceMap","id":"sourcemap","depth":2,"charIndex":13785},{"text":"sourceType","id":"sourcetype","depth":2,"charIndex":13872},{"text":"splitting","id":"splitting","depth":2,"charIndex":14030},{"text":"style","id":"style","depth":2,"charIndex":14084},{"text":"style.less","id":"styleless","depth":2,"charIndex":14105},{"text":"style.less.lessOptions","id":"stylelesslessoptions","depth":2,"charIndex":14131},{"text":"style.less.additionalData","id":"stylelessadditionaldata","depth":2,"charIndex":14222},{"text":"style.less.implementation","id":"stylelessimplementation","depth":2,"charIndex":14454},{"text":"sass","id":"sass","depth":2,"charIndex":14917},{"text":"style.sass.sassOptions","id":"stylesasssassoptions","depth":2,"charIndex":14937},{"text":"style.sass.additionalData","id":"stylesassadditionaldata","depth":2,"charIndex":15007},{"text":"style.sass.implementation","id":"stylesassimplementation","depth":2,"charIndex":15299},{"text":"style.postcss","id":"stylepostcss","depth":2,"charIndex":15763},{"text":"style.inject","id":"styleinject","depth":2,"charIndex":16502},{"text":"style.autoModules","id":"styleautomodules","depth":2,"charIndex":17446},{"text":"style.modules","id":"stylemodules","depth":2,"charIndex":17680},{"text":"style.tailwindcss","id":"styletailwindcss","depth":2,"charIndex":18033},{"text":"启用 Tailwind CSS","id":"启用-tailwind-css","depth":3,"charIndex":18254},{"text":"类型","id":"类型","depth":3,"charIndex":18374},{"text":"注意事项","id":"注意事项","depth":3,"charIndex":18505},{"text":"target","id":"target","depth":2,"charIndex":18795},{"text":"transformImport","id":"transformimport","depth":2,"charIndex":19188},{"text":"transformLodash","id":"transformlodash","depth":2,"charIndex":19578},{"text":"tsconfig","id":"tsconfig","depth":2,"charIndex":19924},{"text":"umdGlobals","id":"umdglobals","depth":2,"charIndex":20104},{"text":"umdModuleName","id":"umdmodulename","depth":2,"charIndex":20398}],"domain":"","content":"#\n\nbuildConfig 是一个用来描述如何编译、生成构建产物的配置项,它包含了构建的所有配置。\n\n * 类型:object | object[]\n\nTIP\n\n在开始使用 buildConfig 之前,请先阅读以下文档来了解其作用:\n\n * 修改输出产物\n * 深入理解构建\n\n\nalias#\n\n * 类型:Record | Function\n * 默认值:{'@': 'src',}\n\nTIP\n\n对于 TypeScript 项目,只需要在 tsconfig.json 中配置 compilerOptions.paths, Modern.js Module\n会自动识别 tsconfig.json 里的别名,因此不需要额外配置 alias 字段。\n\nexport default defineConfig({\n buildConfig: {\n alias: {\n '@common': './src/common',\n },\n },\n});\n\n\n以上配置完成后,如果在代码中引用 @common/Foo.tsx, 则会映射到 /src/common/Foo.tsx 路径上。\n\nalias 的值定义为函数时,可以接受预设的 alias 对象,并对其进行修改。\n\nexport default defineConfig({\n buildConfig: {\n alias: alias => {\n alias['@common'] = './src/common';\n },\n },\n});\n\n\n也可以在函数中返回一个新对象作为最终结果,新对象会覆盖预设的 alias 对象。\n\nexport default defineConfig({\n buildConfig: {\n alias: alias => {\n return {\n '@common': './src/common',\n };\n },\n },\n});\n\n\n\nasset#\n\n包含静态资源相关的配置。\n\n\nasset.path#\n\n静态资源输出路径,会基于 outDir 进行输出。\n\n * 类型: string\n * 默认值: assets\n\n\nasset.limit#\n\n用于设置静态资源被自动内联为 base64 的体积阈值。\n\nModern.js Module 在进行打包时,默认会内联体积小于 10KB 的图片、字体、媒体等资源,将它们通过 Base64\n编码,并内联到产物中,不再会发送独立的 HTTP 请求。\n\n你可以通过修改 limit 参数来调整这个阈值。\n\n * 类型: number\n * 默认值: 10 * 1024\n\n例如,将 limit 设置为 0 来避免资源内联:\n\nexport default defineConfig({\n buildConfig: {\n asset: {\n limit: 0,\n },\n },\n});\n\n\n\nasset.publicPath#\n\n打包时给未内联资源的 CDN 前缀。\n\n * 类型: string\n * 默认值: undefined\n\nexport default defineConfig({\n buildConfig: {\n asset: {\n publicPath: 'https://xxx/',\n },\n },\n});\n\n\n此时,所有静态资源都会添加 https://xxx/ 前缀。\n\n\nasset.svgr#\n\n打包时将 SVG 作为一个 React 组件处理,options 参考 svgr,另外还支持了 include 和 exclude\n两个配置项,用于匹配需要处理的 SVG 文件。\n\n * 类型: boolean | object\n * 默认值: false\n\n开启 svgr 功能后,可以使用默认导出的方式将 SVG 当做组件使用。\n\n// true\n\n\nexport default () => ;\n\n\nWARNING\n\n目前不支持下面的用法:\n\n\n\n\n当开启功能后,可以通过在 modern-app-env.d.ts 文件中增加类型定义,修改使用 SVG 的类型:\n\ndeclare module '*.svg' {\n const src: React.FunctionComponent>;\n export default src;\n}\n\n/// \n\n\n\nasset.svgr.include#\n\n设定匹配的 SVG 文件\n\n * 类型: string | RegExp | (string | RegExp)[]\n * 默认值: /\\.svg$/\n\n\nasset.svgr.exclude#\n\n设定不匹配的 SVG 文件\n\n * 类型: string | RegExp | (string | RegExp)[]\n * 默认值: undefined\n\n\nautoExternal#\n\n自动外置项目的 \"dependencies\" 和 \"peerDependencies\",不会将其打包到最终的 bundle 产物中。\n\n * 类型: boolean | object\n * 默认值: true\n\n当我们希望关闭对于第三方依赖的默认处理行为时候,可以通过以下方式来实现:\n\nexport default defineConfig({\n buildConfig: {\n autoExternal: false,\n },\n});\n\n\n这样对于 \"dependencies\" 和 \"peerDependencies\" 下面的依赖都会进行打包处理。如果只想要关闭其中某个下面的依赖处理,则可以使用\nbuildConfig.autoExternal 的对象形式:\n\nexport default defineConfig({\n buildConfig: {\n autoExternal: {\n dependencies: false,\n peerDependencies: false,\n },\n },\n});\n\n\n\nautoExternal.dependencies#\n\n是否需要外置项目的 \"dependencies\" 依赖。\n\n * 类型: boolean\n * 默认值: true\n\n\nautoExternal.peerDependencies#\n\n是否需要外置项目的 \"peerDependencies\" 依赖。\n\n * 类型: boolean\n * 默认值: true\n\n\nbanner#\n\n提供为每个 JS , CSS 和 DTS 文件的顶部和底部注入内容的能力。\n\ninterface BannerAndFooter {\n js?: string;\n css?: string;\n dts?: string;\n}\n\n\n * 类型: BannerAndFooter\n * 默认值: {}\n * 版本: v2.36.0\n\n例如你想为 JS 和 CSS 文件添加版权信息:\n\n\n\nconst copyRight = `/*\n © Copyright 2020 xxx.com or one of its affiliates.\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n*/`;\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildConfig: {\n banner: {\n js: copyRight,\n css: copyRight,\n },\n },\n});\n\n\n\nbuildType#\n\n构建类型,bundle 会打包你的代码,bundleless 只做代码的转换。\n\n * 类型: 'bundle' | 'bundleless'\n * 默认值: 'bundle'\n\n\ncopy#\n\n将文件或目录拷贝到指定位置。\n\n * 类型: object\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [{ from: './src/assets', to: '' }],\n },\n },\n});\n\n\n\ncopy.patterns#\n\n * 类型: CopyPattern[]\n * 默认值: []\n\ninterface CopyPattern {\n from: string;\n to?: string;\n context?: string;\n globOptions?: globby.GlobbyOptions;\n}\n\n\n\ncopy.options#\n\n * 类型:\n\ntype Options = {\n concurrency?: number;\n enableCopySync?: boolean;\n};\n\n\n * 默认值: { concurrency: 100, enableCopySync: false }\n\n * concurrency: 指定并行执行多少个复制任务。\n\n * enableCopySync: 使用 fs.copySync,默认情况下 fs.copy。\n\n\ndefine#\n\n定义全局变量,注入到代码中\n\n * 类型: Record\n * 默认值: {}\n\n由于 define 功能是由全局文本替换实现的,所以需要保证全局变量值为字符串,更为安全的做法是将每个全局变量的值转化为字符串,使用\nJSON.stringify 进行转换,如下所示:\n\nexport default defineConfig({\n buildConfig: {\n define: {\n VERSION: JSON.stringify(require('./package.json').version || '0.0.0'),\n },\n },\n});\n\n\n不过要注意:如果项目是一个 TypeScript 项目,那么你可能需要在项目源代码目录下的 .d.ts 文件里增加以下内容:\n\n> 如果不存在 d.ts 文件,则可以手动创建。\n\ndeclare const YOUR_ADD_GLOBAL_VAR;\n\n\n我们也可以进行环境变量替换:\n\n\nexport default defineConfig({\n buildConfig: {\n define: {\n 'process.env.VERSION': JSON.stringify(process.env.VERSION || '0.0.0'),\n },\n },\n});\n\n\n通过上面的配置,我们就可以将下面这段代码:\n\n// 编译前代码\nconsole.log(process.env.VERSION);\n\n\n在执行 VERSION=1.0.0 modern build 的时候,转换为:\n\n// 编译后代码\nconsole.log('1.0.0');\n\n\nTIP\n\n为了防止全局替换替换过度,建议使用时遵循以下两个原则:\n\n * 全局常量使用大写\n * 自定义全局常量前缀后缀,确保独一无二\n\n\ndts#\n\n类型文件生成的相关配置,默认情况会生成。\n\n * 类型: false | object\n * 默认值:\n\n{\n abortOnError: true,\n distPath: './',\n only: false,\n}\n\n\n\ndts.abortOnError#\n\n用于控制在出现类型错误的时候,是否允许构建成功。\n\n * 类型:boolean\n * 默认值:true\n\n默认情况下,在出现类型错误的时候会导致构建失败。将 abortOnError 设置为 false 后,即使代码中出现了类型问题,构建依然会成功:\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n abortOnError: false,\n },\n },\n});\n\n\nWARNING\n\n当关闭该配置后,无法保证类型文件能正常生成,且不保证内容正确。在 buildType: 'bundle' 时,即打包模式下,类型文件一定不会生成。\n\n\ndts.distPath#\n\n类型文件的输出路径,基于 outDir 进行输出。\n\n * 类型: string\n * 默认值: ./\n\n比如输出到 outDir 下面的 types 目录:\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n distPath: './types',\n },\n },\n});\n\n\n\ndts.only#\n\n是否在构建时只生成类型文件,不生成 JavaScript 产物文件。\n\n * 类型: boolean\n * 默认值: false\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n only: true,\n },\n },\n});\n\n\n\ndts.respectExternal#\n\n当设为 false 时,不会打包任何三方包类型,设为 true 时,会根据 externals 来决定是否需要打包三方类型。\n\n在对类型文件进行打包时,构建工具还未对 export\n进行分析,因此当你引用的任何一个三方包出现类型错误时,都可能会中断当前的构建流程,这会导致构建流程不可控,因此我们可以通过这个配置来避免该问题。\n\n * 类型: boolean\n * 默认值: true\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n respectExternal: false,\n },\n },\n});\n\n\n\ndts.tsconfigPath#\n\n废弃,使用 tsconfig 配置替代。\n\n指定用于生成类型文件的 tsconfig 文件路径。\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n tsconfigPath: './other-tsconfig.json',\n },\n },\n});\n\n\n\nesbuildOptions#\n\n用于修改底层的 esbuild 配置。\n\n * 类型: Function\n * 默认值: c => c\n\n例如,我们需要修改生成文件的后缀:\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.outExtension = { '.js': '.mjs' };\n return options;\n },\n },\n});\n\n\n例如,注册一个 esbuild 插件:\n\n\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.plugins = [myEsbuildPlugin, ...options.plugins];\n return options;\n },\n },\n});\n\n\n在增加 esbuild 插件时,请注意你需要将插件加在 plugins 数组的头部,因为 Modern.js Module 内部也是通过一个 esbuild\n插件介入到整个构建流程中去的,因此需要将自定义插件优先注册。\n\nTIP\n\n我们在原本 esbuild 构建的基础上做了许多扩展,因此使用此配置需要注意以下几点:\n\n 1. 优先使用 Modern.js Module 提供的配置,例如 esbuild 并不支持 target: 'es5',但我们内部使用 SWC\n 支持了此场景,此时通过 esbuildOptions 设置target: 'es5'会报错。\n 2. 目前我们内部使用 enhanced-resolve 替代了 esbuild 的 resolve 解析算法,所以修改 esbuild resolve\n 相关配置无效,计划在未来会切换回来。\n\n\nexternalHelpers#\n\n默认情况下,输出的 JS 代码可能会依赖一些辅助函数来支持目标环境或者输出格式,这些辅助函数会被内联在需要它的文件中。\n\n使用此配置,将会使用 SWC 对代码进行转换,将内联的辅助函数转换为从外部模块 @swc/helpers 导入这些辅助函数。\n\n * 类型:boolean\n * 默认值:false\n\n下面是使用该配置前后的产物变化比较。\n\n开启前:\n\n// 辅助函数\nfunction asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {\n // ...\n}\n// 辅助函数\nfunction _async_to_generator(fn) {\n return function () {\n // use asyncGeneratorStep\n // ...\n };\n}\n\n// 你的代码\nexport var yourCode = function () {\n // use _async_to_generator\n};\n\n\n开启后:\n\n// 从 @swc/helpers 导入的辅助函数\n\n\n// 你的代码\nexport var yourCode = function () {\n // use _async_to_generator\n};\n\n\n\nexternals#\n\n用于在打包时排除一些外部依赖,避免将这些依赖打包到最终的 bundle 中。\n\n * 类型:\n\ntype Externals = (string | RegExp)[];\n\n\n * 默认值: []\n * 构建类型:仅支持 buildType: 'bundle'\n * 示例:\n\nexport default defineConfig({\n buildConfig: {\n // 避免打包 React\n externals: ['react'],\n },\n});\n\n\n\nfooter#\n\n同 banner 配置,用于在输出文件末尾添加注释。\n\n\nformat#\n\n用于设置 JavaScript 产物输出的格式,其中 iife 和 umd 只在 buildType 为 bundle 时生效。\n\n * 类型:'esm' | 'cjs' | 'iife' | 'umd'\n * 默认值:cjs\n\n\nformat: esm#\n\nesm 代表 \"ECMAScript 模块\",它需要运行环境支持 import 和 export 语法。\n\n * 示例:\n\nexport default defineConfig({\n buildConfig: {\n format: 'esm',\n },\n});\n\n\n\nformat: cjs#\n\ncjs 代表 \"CommonJS\",它需要运行环境支持 exports、require 和 module 语法,通常为 Node.js 环境。\n\n * 示例:\n\nexport default defineConfig({\n buildConfig: {\n format: 'cjs',\n },\n});\n\n\n\nformat: iife#\n\niife 代表 \"立即调用函数表达式\",它将代码包裹在函数表达式中,确保代码中的任何变量不会意外地与全局范围中的变量冲突,通常在浏览器环境中运行。\n\n * 示例:\n\nexport default defineConfig({\n buildConfig: {\n format: 'iife',\n },\n});\n\n\n\nformat: umd#\n\numd 代表 \"Universal Module Definition\",用于在不同环境(浏览器、Node.js 等)中运行。umd\n格式的模块可以在多种环境下使用,既可以作为全局变量访问,也可以通过模块加载器(如 RequireJS)进行模块化加载。\n\n * 示例:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n },\n});\n\n\n\nhooks#\n\n构建生命周期钩子,允许在构建流程的特定阶段注入自定义逻辑。\n\n * 类型:\n\ntype HookList = {\n name: string;\n apply: (compiler: ICompiler) => void;\n};\n\n\n * 默认值:[]\n\n我们可以在 apply 方法里拿到 compiler 实例,修改其属性,以及在不同阶段执行自定义逻辑,对于 Hook 的详细介绍, 参考使用 Hook\n介入构建流程。\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundle',\n hooks: [\n {\n name: 'renderChunk',\n apply: compiler => {\n // any logic for compiler\n compiler.hooks.renderChunk.tapPromise(\n { name: 'renderChunk' },\n async chunk => {\n return chunk;\n },\n );\n },\n },\n ],\n },\n});\n\n\n\ninput#\n\n指定构建的入口文件,数组形式可以指定目录。\n\n * 类型:\n\ntype Input =\n | string[];\n | {\n [name: string]: string;\n }\n\n\n * 默认值:bundle 模式下默认为 ['src/index.ts'],bundleless 模式下默认为 ['src']\n\n数组用法:\n\n在 bundle 模式下,下面的配置会以 src/index.ts 和 src/index2.ts 为入口分别进行构建。bundle 模式不支持配置 input\n为目录。\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundle',\n input: ['src/index.ts', 'src/index2.ts'],\n },\n});\n\n\n在 bundleless 模式下,下面的配置会同时处理 src/a 目录下的文件和 src/index.ts 文件。\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundleless',\n input: ['src/a', 'src/index.ts'],\n },\n});\n\n\n在 bundleless 模式下,数组模式还支持使用 ! 来过滤部分文件:\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundleless',\n input: ['src', '!src/*.spec.ts'],\n },\n});\n\n\n上面的配置将打包 src 目录下的文件,同时会过滤以 spec.ts 为后缀的文件。这在测试文件与源码文件在同一个根目录下的情况会很有用。\n\n对象用法:\n\n当在 bundle 模式下需要修改产物的输出文件名称的时候,可以使用对象形式进行配置。\n\n对象的 Key 是产物的文件名称,Value 是源码的文件路径。\n\nexport default defineConfig({\n buildConfig: {\n format: 'esm',\n input: {\n 'index.esm': './src/index.ts',\n },\n },\n});\n\n\n\njsx#\n\n指定 JSX 的编译方式,默认支持 React 17 及更高版本,自动注入 JSX 运行时代码。\n\n * 类型: automatic | transform | preserve\n * 默认值: automatic\n\n如果你需要支持 React 16,则可以设置 jsx 为 transform:\n\nexport default defineConfig({\n buildConfig: {\n jsx: 'transform',\n },\n});\n\n\nTIP\n\n如果你不需要转换 JSX ,可以设置 jsx 为 preserve, 但此时请不要使用 swc 做代码转换。 关于 JSX Transform\n的更多说明,可以参考以下链接:\n\n * React Blog - Introducing the New JSX Transform.\n * esbuild - JSX.\n\n\nmetafile#\n\n这个选项用于构建分析,开启该选项后,esbuild 会以 JSON 格式生成有关构建的一些元数据。\n\n * 类型:boolean\n * 默认值:false\n * 构建类型:仅支持 buildType: 'bundle'\n\n开启 metafile 生成:\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundle',\n metafile: true,\n },\n});\n\n\n在执行 build 构建后,产物目录下会生成 metafile-[xxx].json 文件,你可以通过 esbuild analyze 和\nbundle-buddy 等工具进行可视化分析。\n\n\nminify#\n\n使用 esbuild 或者 terser 压缩代码,也可以传入 terserOptions。\n\n * 类型: 'terser' | 'esbuild' | false | object\n * 默认值: false\n\nexport default defineConfig({\n buildConfig: {\n minify: {\n compress: {\n drop_console: true,\n },\n },\n },\n});\n\n\n\noutDir#\n\n指定构建的输出目录。\n\n * 类型: string\n * 默认值: ./dist\n\nexport default defineConfig({\n buildConfig: {\n outDir: './dist/esm',\n },\n});\n\n\n\nplatform#\n\n默认生成用于 Node.js 环境下的代码,你也可以指定为 browser,会生成用于浏览器环境的代码。\n\n * 类型: 'browser' | 'node'\n * 默认值: 'node'\n\nexport default defineConfig({\n buildConfig: {\n platform: 'browser',\n },\n});\n\n\n\nredirect#\n\n在 buildType: 'bundleless' 构建模式下,会对引用路径进行重定向,确保指向了正确的产物,例如:\n\n * import './index.less' 会被改写成 import './index.css'\n * 会被改写成 (依实际情况而定)\n\n在某些场景下,你可能不需要这些功能,那么可以通过此配置关闭它,关闭后,其引用路径将不会发生改变。\n\nexport default {\n buildConfig: {\n redirect: {\n alias: false, // 关闭对别名路径的修改\n style: false, // 关闭对样式文件路径的修改\n asset: false, // 关闭对资源文件路径的修改\n },\n },\n};\n\n\n\nresolve#\n\n自定义模块解析选项\n\n\nresolve.mainFields#\n\npackage.json 中,在解析包的入口点时尝试的字段列表。\n\n * 类型:string[]\n * 默认值:取决于platform\n * node: ['module', 'main']\n * browser: ['module', 'browser', 'main']\n * 版本:v2.36.0\n\n例如,我们想要先加载 js:source 字段:\n\nexport default defineConfig({\n buildConfig: {\n resolve: {\n mainFields: ['js:source', 'module', 'main'],\n },\n },\n});\n\n\nWARNING\n\nresolve.mainFields 比 package.json 中 exports 字段的优先级低,如果一个入口点从 exports\n成功解析,resolve.mainFields 将被忽略。\n\n\nresolve.jsExtentions#\n\n支持隐式文件扩展名\n\n * 类型: string[]\n * 默认值: ['.jsx', '.tsx', '.js', '.ts', '.json']\n * 版本:v2.36.0\n\n对于 css 文件,请不要使用隐式文件扩展名,目前 Module 仅支持 ['.less', '.css', '.sass', '.scss'] 后缀。\n\nNode 的解析算法不会将 .mjs 和 cjs 视为隐式文件扩展名,因此这里默认也不会,但是可以通过更改此配置来包含:\n\nexport default defineConfig({\n buildConfig: {\n resolve: {\n jsExtentions: ['.mts', 'ts'],\n },\n },\n});\n\n\n\nsideEffects#\n\n配置模块的副作用\n\n * 类型: RegExg[] | (filePath: string, isExternal: boolean) => boolean | boolean\n * 默认值: undefined\n\n通常情况下,我们通过 package.json 的 \"sideEffects\" 字段来配置模块的副作用,但是在某些情况下,三方包的 package.json\n是不可靠的。 例如我们引用了一个三方包的样式文件。\n\nimport 'other-package/dist/index.css';\n\n\n但是这个三方包的 package.json 里并没有将样式文件配置到 \"sideEffects\" 里。\n\n{\n \"sideEffects\": [\"dist/index.js\"]\n}\n\n\n同时你又设置了 style.inject 为 true,在控制台可以看到类似的警告信息:\n\n[LIBUILD:ESBUILD_WARN] Ignoring this import because \"other-package/dist/index.css\" was marked as having no side effects\n\n\n这时候就可以使用这个配置项,手动配置模块的\"sideEffects\",配置支持正则和函数形式。\n\nexport default defineConfig({\n buildConfig: {\n sideEffects: [/\\.css$/],\n // or\n // sideEffects: (filePath, isExternal) => /\\.css$/.test(filePath),\n },\n});\n\n\nTIP\n\n添加此配置后,打包时将不会再读取 package.json 里的 \"sideEffects\" 字段。\n\n\nsourceDir#\n\n指定构建的源码目录,默认为 src,用于在 bundleless 构建时基于源码目录结构生成对应的产物目录。\n\n * 类型: string\n * 默认值: src\n\n\nsourceMap#\n\n控制 sourceMap 如何生成。\n\n * 类型: boolean | 'inline' | 'external'\n * 默认值: false\n\n\nsourceType#\n\nWARNING\n\n已废弃,此配置不会产生任何影响。\n\n设置源码的格式。默认情况下,会将源码作为 EsModule 进行处理。当源码使用的是 CommonJS 的时候,需要设置 commonjs。\n\n * 类型:'commonjs' | 'module'\n * 默认值:'module'\n\n\nsplitting#\n\n是否开启代码分割。\n\n * 类型: boolean\n * 默认值: false\n\n\nstyle#\n\n配置样式相关的配置。\n\n\nstyle.less#\n\nless 相关配置。\n\n\nstyle.less.lessOptions#\n\n详细配置参考 less。\n\n * 类型: object\n * 默认值: { javascriptEnabled: true }\n\n\nstyle.less.additionalData#\n\n在入口文件起始添加 Less 代码。\n\n * 类型: string\n * 默认值: undefined\n\nexport default defineConfig({\n buildConfig: {\n style: {\n less: {\n additionalData: `@base-color: #c6538c;`,\n },\n },\n },\n});\n\n\n\nstyle.less.implementation#\n\n配置 Less 使用的实现库,在不指定的情况下,使用的内置版本是 4.1.3。\n\n * 类型: string | object\n * 默认值: undefined\n\n设置 object 类型时,可以指定 Less 的实现库。\n\nexport default defineConfig({\n buildConfig: {\n style: {\n less: {\n implementation: require('less'),\n },\n },\n },\n});\n\n\nstring 类型时,指定 Less 的实现库的路径\n\nexport default defineConfig({\n buildConfig: {\n style: {\n less: {\n implementation: require.resolve('less'),\n },\n },\n },\n});\n\n\n\nsass#\n\nSass 相关配置。\n\n\nstyle.sass.sassOptions#\n\n详细配置参考 node-sass\n\n * 类型: object\n * 默认值: {}\n\n\nstyle.sass.additionalData#\n\n在入口文件起始添加 Sass 代码。\n\n * 类型: string | Function\n * 默认值: undefined\n\nexport default defineConfig({\n buildConfig: {\n style: {\n sass: {\n additionalData: `$base-color: #c6538c;\n $border-dark: rgba($base-color, 0.88);`,\n },\n },\n },\n});\n\n\n\nstyle.sass.implementation#\n\n配置 Sass 使用的实现库,在不指定的情况下,使用的内置版本是 1.5.4。\n\n * 类型: string | object\n * 默认值: undefined\n\n设置为 object 类型时,可以指定 Sass 的实现库。\n\nexport default defineConfig({\n buildConfig: {\n style: {\n sass: {\n implementation: require('sass'),\n },\n },\n },\n});\n\n\nstring 类型时,指定 Sass 的实现库的路径\n\nexport default defineConfig({\n buildConfig: {\n style: {\n sass: {\n implementation: require.resolve('sass'),\n },\n },\n },\n});\n\n\n\nstyle.postcss#\n\n用于配置 PostCSS 的选项,传入的值会与默认配置通过 Object.assign 合并。注意 Object.assign 是浅拷贝,因此会完全覆盖内置的\nplugins 数组。\n\n详细配置请查看 PostCSS。\n\n * 类型:\n\ntype PostcssOptions = {\n processOptions?: ProcessOptions;\n plugins?: AcceptedPlugin[];\n};\n\n\n * 默认值:\n\nconst defaultConfig = {\n plugins: [\n // 以下插件默认启用\n require('postcss-flexbugs-fixes'),\n require('postcss-media-minmax'),\n require('postcss-nesting'),\n // 以下插件仅在 target 为 `es5` 时启用\n require('postcss-custom-properties'),\n require('postcss-initial'),\n require('postcss-page-break'),\n require('postcss-font-variant'),\n ],\n};\n\n\n * 示例:\n\nexport default defineConfig({\n buildConfig: {\n style: {\n postcss: {\n plugins: [yourPostCSSPlugin],\n },\n },\n },\n});\n\n\n\nstyle.inject#\n\n配置打包模式下是否将 CSS 样式插入到 JavaScript 代码中。\n\n * 类型: boolean\n * 默认值: false\n\n将 inject 设置为 true 来开启此功能:\n\nexport default defineConfig({\n buildConfig: {\n inject: true,\n },\n});\n\n\n开启后,你会看到源码中引用的 CSS 代码被包含在了打包后的 JS 产物中。\n\n例如,你在源码里写了 import './index.scss',那么在产物中你会看到以下代码:\n\n// node_modules/style-inject/dist/style-inject.es.js\nfunction styleInject(css, ref) {\n // ...\n}\nvar style_inject_es_default = styleInject;\n\n// src/index.scss\nvar css_248z = '.body {\\n color: black;\\n}';\nstyle_inject_es_default(css_248z);\n\n\nTIP\n\n开启 inject 后,你需要注意以下几点:\n\n * CSS 文件中的 @import 不会被处理。如果你的 CSS 文件中有 @import ,那么你需要在 JS 文件中手动引入 CSS\n 文件(less,scss 文件不需要,因为它们会有预处理)。\n * 需要考虑 sideEffects 的影响。默认情况下,我们的构建器会认为 CSS 是有副作用的,如果你的项目中或者三方包的 package.json\n 设置了 sideEffects 字段并且没有包含此 CSS 文件,那么你将会得到一个警告:\n\n[LIBUILD:ESBUILD_WARN] Ignoring this import because \"src/index.scss\" was marked as having no side effects by plugin \"libuild:adapter\"\n\n\n此时可以通过配置 sideEffects 来解决。\n\n\nstyle.autoModules#\n\n根据文件名自动启用 CSS Modules。\n\n * 类型: boolean | RegExp\n * 默认值: true\n\ntrue : 为以 .module.css .module.less .module.scss .module.sass 文件名结尾的样式文件启用 CSS\nModules。\n\nfalse : 禁用 CSS Modules.\n\nRegExp : 为匹配正则条件的所有文件启用 CSS Modules.\n\n\nstyle.modules#\n\nCSS Modules 配置。\n\n * 类型: object\n * 默认值: {}\n\n一个常用的配置是 localsConvention,它可以改变 CSS Modules 的类名生成规则。\n\nexport default defineConfig({\n buildConfig: {\n style: {\n modules: {\n localsConvention: 'camelCaseOnly',\n },\n },\n },\n});\n\n\n对于以下样式:\n\n.box-title {\n color: red;\n}\n\n\n你可以使用 styles.boxTitle 来访问。\n\n详细配置查看 postcss-modules\n\n\nstyle.tailwindcss#\n\n用于修改 Tailwind CSS 的配置项。\n\n * 类型: object | Function\n * 默认值:\n\nconst tailwind = {\n content: [\n './src/**/*.{js,jsx,ts,tsx}',\n './config/html/**/*.{html,ejs,hbs}',\n './storybook/**/*',\n ],\n};\n\n\n\n启用 Tailwind CSS#\n\n在使用 style.tailwindcss 之前,你需要启用 Modern.js Module 的 Tailwind CSS 插件。\n\n请阅读「使用 Tailwind CSS」 章节来了解开启方式。\n\n\n类型#\n\n值为 object 类型时,与默认配置通过 Object.assign 合并。\n\n值为 Function 类型时,函数返回的对象与默认配置通过 Object.assign 合并。\n\n其他的使用方式和 Tailwind CSS 一致: 快速传送门。\n\n\n注意事项#\n\n注意:\n\n * 如果你同时使用了 tailwind.config.{ts,js} 文件和 tools.tailwindcss 选项,那么\n tools.tailwindcss 定义的配置会优先生效,并覆盖 tailwind.config.{ts,js} 中定义的内容。\n * 如果你同时使用了 designSystem 配置项,那么 Tailwind CSS 的 theme 配置将会被 designSystem 的值所覆盖。\n\n其他配置的使用方式与 Tailwind CSS 官方用法一致,请参考 tailwindcss - Configuration。\n\n\ntarget#\n\ntarget 用于为生成的 JavaScript 代码设置目标环境。它让 Modern.js Module 将目标环境无法识别的 JavaScript\n语法转换为在这些环境中可用的低版本 JavaScript 语法。\n\n * 类型:\n\ntype Target =\n | 'es5'\n | 'es6'\n | 'es2015'\n | 'es2016'\n | 'es2017'\n | 'es2018'\n | 'es2019'\n | 'es2020'\n | 'es2021'\n | 'es2022'\n | 'esnext';\n\n\n * 默认值: 'es6'\n\n例如,将代码编译到 es5 语法:\n\nexport default defineConfig({\n buildConfig: {\n target: 'es5',\n },\n});\n\n\n\ntransformImport#\n\n提供与 babel-plugin-import 等价的能力和配置,基于 SWC 实现,使用此配置,将会使用 SWC 对代码进行转换。\n\n * 类型:object[]\n * 默认值:[]\n\n数组元素为一个 babel-plugin-import 的配置对象。配置对象可以参考 options。\n\n使用示例:\n\nexport default defineConfig({\n buildConfig: {\n transformImport: [\n // babel-plugin-import 的 options 配置\n {\n libraryName: 'foo',\n style: true,\n },\n ],\n },\n});\n\n\n参考「Import 插件——注意事项」\n\n\ntransformLodash#\n\n是否模块化 lodash 的导入,删除未使用的 lodash 模块,从而减少 lodash 代码体积。这项优化基于 babel-plugin-lodash 和\nswc-plugin-lodash 实现。 使用此配置,将会使用 SWC 对代码进行转换。\n\n * 类型:boolean\n * 默认值:false\n\n当开启此选项时,Modern.js Module 会自动将 lodash 的代码引用指向子路径。\n\n比如:\n\n\n\n\nconst addOne = add(1);\n_.map([1, 2, 3], addOne);\n\n\n转换后的代码:\n\n\n\n\nconst addOne = _add(1);\n_map([1, 2, 3], addOne);\n\n\n\ntsconfig#\n\nTypeScript 配置文件的路径。\n\n * 类型: string\n * 默认值: tsconfig.json\n * 版本: v2.36.0\n\nexport default defineConfig({\n buildConfig: {\n tsconfig: 'tsconfig.build.json',\n },\n});\n\n\n\numdGlobals#\n\n指定 UMD 产物外部导入的全局变量。\n\n * 类型: Record\n * 默认值: {}\n\nexport default defineConfig({\n buildConfig: {\n umdGlobals: {\n react: 'React',\n 'react-dom': 'ReactDOM',\n },\n },\n});\n\n\n此时,react 和 react-dom 会被看做是外部导入的全局变量,不会被打包进 UMD 产物中,而是通过 global.React 和\nglobal.ReactDOM 的方式进行访问。\n\n\numdModuleName#\n\n指定 UMD 产物的模块名。\n\n * 类型: string | Function\n * 默认值: name => name\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdModuleName: 'myLib',\n },\n});\n\n\n此时 UMD 产物会去挂载到 global.myLib 上。\n\nTIP\n * 需要遵守 UMD 规范,UMD 产物的模块名不能和全局变量名冲突。\n * 模块名会被转换为驼峰命名,如 my-lib 会被转换为 myLib,可参考toIdentifier。\n\n同时函数形式可以接收一个参数,为当前打包文件的输出路径\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdModuleName: path => {\n if (path.includes('index')) {\n return 'myLib';\n } else {\n return 'myLib2';\n }\n },\n },\n});\n","frontmatter":{"sidebar_position":1},"version":""},{"id":46,"title":"buildPreset","routePath":"/module-tools/api/config/build-preset","lang":"zh","toc":[{"text":"npm-library","id":"npm-library","depth":2,"charIndex":76},{"text":"npm-library-with-umd","id":"npm-library-with-umd","depth":2,"charIndex":655},{"text":"npm-component","id":"npm-component","depth":2,"charIndex":1376},{"text":"npm-component-with-umd","id":"npm-component-with-umd","depth":2,"charIndex":2027},{"text":"npm-library-{es5...esnext}","id":"npm-library-es5esnext","depth":2,"charIndex":2784},{"text":"string / function","id":"string--function","depth":2,"charIndex":3082}],"domain":"","content":"#\n\n构建的预设字符串或者预设函数。提供开箱即用的构建配置。\n\n * 类型:string | Function\n\n * 默认值: undefined\n\n\nnpm-library#\n\n在类 NPM 包管理器下使用的 Library 通用模式,包含 esm 和 cjs 两种 Bundle 产物,并且包含一份类型文件。\n\nINFO\n\n关于类 NPM 包管理器\n\n * npm\n * yarn\n * pnpm\n\n{\n \"main\": \"./dist/lib/index.js\",\n \"module\": \"./dist/es/index.js\",\n \"types\": \"./dist/types/index.d.ts\"\n}\n\n\n预设字符串对应的构建配置:\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/es',\n },\n {\n buildType: 'bundle',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-library-with-umd#\n\n在类 NPM 包管理器下使用,并且 Library 支持类似 unpkg 的模式。在预设 'npm-library' 的基础上,额外提供 umd 产物。\n\n{\n \"main\": \"./dist/lib/index.js\",\n \"module\": \"./dist/es/index.js\",\n \"types\": \"./dist/types/index.d.ts\",\n \"unpkg\": \"./dist/umd/index.js\",\n};\n\n\n预设字符串对应的构建配置:\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/es',\n },\n {\n format: 'umd',\n target: 'es6',\n platform: 'browser',\n buildType: 'bundle',\n outDir: './dist/umd',\n },\n {\n buildType: 'bundle',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-component#\n\n在类 NPM 包管理器下使用的 组件(库)通用模式。包含 esm 和 cjs 两种 Bundleless 产物(便于 Tree shaking\n优化),以及包含一份类型文件。\n\n对于源码中包含的样式文件,产物中提供样式的编译产物和样式的源文件。\n\n{\n \"main\": \"./dist/lib/index.js\", // bundleless type\n \"module\": \"./dist/es/index.js\", // bundleless type\n \"types\": \"./dist/types/index.d.ts\",\n};\n\n\n预设字符串对应的构建配置:\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/es',\n },\n {\n buildType: 'bundleless',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-component-with-umd#\n\n在类 NPM 包管理器下使用的组件(库),同时支持类 unpkg 的模式。 在预设 'npm-component' 的基础上,额外提供 umd 产物。\n\n{\n \"main\": \"./dist/lib/index.js\", // bundleless type\n \"module\": \"./dist/es/index.js\", // bundleless type\n \"types\": \"./dist/types/index.d.ts\",\n \"unpkg\": \"./dist/umd/index.js\",\n};\n\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/es',\n },\n {\n format: 'umd',\n target: 'es6',\n platform: 'browser',\n buildType: 'bundle',\n outDir: './dist/umd',\n },\n {\n buildType: 'bundleless',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-library-{es5...esnext}#\n\n当想要使用支持其他 ECMAScript 版本的 buildPreset 预设的时候,可以直接在\n'npm-library'、'npm-library-with-umd'、'npm-component'、'npm-component-with-umd'\n这些预设值后面增加想要支持的版本。\n\n例如希望 'npm-library' 预设支持 'es2017',则可以按照如下方式配置:\n\n\n\nexport default defineConfig({\n buildPreset: 'npm-library-es2017',\n});\n\n\n\nstring / function#\n\nbuildPreset 除了支持基本的字符串形式,还支持函数形式,可以通过 preset 或者 extendPreset\n参数获取我们提供的预设值,然后进行修改。\n\n以下是两个分别使用 preset 和 extendPreset 的例子:\n\n\n\nexport default defineConfig({\n buildPreset({ preset }) {\n const { NPM_LIBRARY } = preset;\n return NPM_LIBRARY.map(config => {\n config.define = {\n VERSION: '1.0.1',\n };\n return config;\n });\n },\n});\n\n\nextendPreset 里会使用 lodash.merge 进行配置合并\n\n\n\nexport default defineConfig({\n buildPreset({ extendPreset }) {\n return extendPreset('npm-library', {\n define: {\n VERSION: '1.0.1',\n },\n });\n },\n});\n","frontmatter":{"sidebar_position":2},"version":""},{"id":47,"title":"dev","routePath":"/module-tools/api/config/dev","lang":"zh","toc":[{"text":"storybook","id":"storybook","depth":2,"charIndex":132},{"text":"storybook.webpack","id":"storybookwebpack","depth":3,"charIndex":295},{"text":"配置 Manager App","id":"配置-manager-app","depth":4,"charIndex":605},{"text":"storybook.webpackChain","id":"storybookwebpackchain","depth":3,"charIndex":901}],"domain":"","content":"#\n\n本章节描述了 Modern.js Module 关于调试工具相关的所有配置。\n\nexport default {\n dev: {\n storybook: {\n /* Storybook Config */\n },\n },\n};\n\n\n\nstorybook#\n\n首先需要确保:\n\n * 开启 Storybook 调试功能或者安装 @modern-js/plugin-storybook 插件。\n * 注册 @modern-js/plugin-storybook 插件。\n\n> 关于如何开启 Storybook 调试功能,可以参考:「Storybook 调试」\n\n\nstorybook.webpack#\n\n * 类型:object | Function | undefined\n * 默认值:undefined\n\nexport default {\n dev: {\n storybook: {\n webpack(config) {\n return config;\n },\n },\n },\n};\n\n\n你可以通过 dev.storybook.webpack 来修改 Storybook Preview-iframe 的 webpack 配置。使用方式可以参考\nModern.js Builder 的 tools.webpack 配置。\n\n\n\n配置 Manager App#\n\n对于 Storybook Manager App 部分的 webpack 配置,可以通过增加 ./config/storybook/main.js\n文件进行配置。\n\n// ./config/storybook/main.js\n\nmodule.exports = {\n // it controls the Storybook manager app\n managerWebpack: async (config, options) => {\n // update config here\n return config;\n },\n};\n\n\n\nstorybook.webpackChain#\n\n * 类型:Function | undefined\n * 默认值:undefined\n\nexport default {\n dev: {\n storybook: {\n webpackChain(chain) {\n return chain;\n },\n },\n },\n};\n\n\n你可以通过 dev.storybook.webpackChain 来修改 Storybook Preview-iframe 的 webpack\n配置。使用方式可以参考 Modern.js Builder 的 tools.webpackChain 配置。","frontmatter":{"sidebar_position":3},"version":""},{"id":48,"title":"plugins","routePath":"/module-tools/api/config/plugins","lang":"zh","toc":[{"text":"插件执行顺序","id":"插件执行顺序","depth":2,"charIndex":79},{"text":"开发插件","id":"开发插件","depth":2,"charIndex":221},{"text":"示例","id":"示例","depth":2,"charIndex":253},{"text":"使用 npm 上的插件","id":"使用-npm-上的插件","depth":3,"charIndex":259},{"text":"使用本地插件","id":"使用本地插件","depth":4,"charIndex":377},{"text":"插件配置项","id":"插件配置项","depth":3,"charIndex":486}],"domain":"","content":"#\n\n本章介绍注册 Modern.js Module 插件的配置。\n\n * 类型:ModuleToolsPlugin[]\n * 默认值:undefined\n\n\n插件执行顺序#\n\n默认情况下,自定义插件会按照 plugins 数组的顺序依次执行,Modern.js Module 内置插件的执行时机早于自定义插件。\n\n当插件内部使用了控制顺序的相关字段,比如 pre、post 时,会基于声明的字段对执行顺序进行调整,详见 插件之间的关系。\n\n\n开发插件#\n\n关于如何编写插件,可以查看「插件编写指南」。\n\n\n示例#\n\n\n使用 npm 上的插件#\n\n使用 npm 上的插件,需要通过包管理器安装插件,并通过 import 引入。\n\n\n\nexport default defineConfig({\n plugins: [myPlugin()],\n});\n\n\n使用本地插件#\n\n使用本地代码仓库中的插件,直接通过相对路径 import 引入即可。\n\n\n\nexport default defineConfig({\n plugins: [myPlugin()],\n});\n\n\n\n插件配置项#\n\n如果插件提供了一些自定义的配置项,你可以通过插件函数的参数传入配置。\n\n\n\nexport default defineConfig({\n plugins: [\n myPlugin({\n foo: 1,\n bar: 2,\n }),\n ],\n});\n","frontmatter":{"sidebar_position":4},"version":""},{"id":49,"title":"testing","routePath":"/module-tools/api/config/testing","lang":"zh","toc":[{"text":"jest","id":"jest","depth":2,"charIndex":55},{"text":"transformer","id":"transformer","depth":2,"charIndex":457}],"domain":"","content":"#\n\n本章描述了测试相关的配置。\n\nTIP\n\n需要先通过 pnpm run new 启用 单元测试 功能。\n\n\njest#\n\n * 类型: object | Function\n * 默认值:{}\n\n对应 Jest 的配置,当为 object 类型时,可以配置 Jest 所支持的所有底层配置 。\n\n\n\nexport default defineConfig({\n testing: {\n jest: {\n testTimeout: 10000,\n },\n },\n});\n\n\n值为 Function 类型时,默认配置作为第一个参数传入,需要返回新的 Jest 配置对象。\n\n\n\nexport default defineConfig({\n testing: {\n jest: options => {\n return {\n ...options,\n testTimeout: 10000,\n };\n },\n },\n});\n\n\n\ntransformer#\n\n * 类型:'babel-jest' | 'ts-jest'\n * 默认值:'babel-jest'\n\n配置执行测试的时候对于源码的编译工具: babel-jest 或 ts-jest。默认使用 babel-jest。\n\nINFO\n\nbabel-jest 也可以编译 TS 文件,但不会类型报错,如果你需要跑测试的时候对 TS 类型进行校验,那么请使用 ts-jest。","frontmatter":{"sidebar_position":5},"version":""},{"id":50,"title":"概览","routePath":"/module-tools/api/","lang":"zh","toc":[],"domain":"","content":"#","frontmatter":{"overview":true,"sidebar_label":"概览","sidebar_position":1},"version":""},{"id":51,"title":"Plugin Hooks","routePath":"/module-tools/api/plugin-api/plugin-hooks","lang":"zh","toc":[{"text":"构建钩子","id":"构建钩子","depth":2,"charIndex":172},{"text":"beforeBuild","id":"beforebuild","depth":3,"charIndex":281},{"text":"beforeBuildTask","id":"beforebuildtask","depth":3,"charIndex":831},{"text":"afterBuildTask","id":"afterbuildtask","depth":3,"charIndex":1163},{"text":"afterBuild","id":"afterbuild","depth":3,"charIndex":1513},{"text":"buildPlatform 钩子","id":"buildplatform-钩子","depth":2,"charIndex":1905},{"text":"registerBuildPlatform","id":"registerbuildplatform","depth":3,"charIndex":2244},{"text":"beforeBuildPlatform","id":"beforebuildplatform","depth":3,"charIndex":2851},{"text":"buildPlatform","id":"buildplatform","depth":3,"charIndex":3432},{"text":"afterBuildPlatform","id":"afterbuildplatform","depth":3,"charIndex":3807},{"text":"调试钩子","id":"调试钩子","depth":2,"charIndex":4385},{"text":"registerDev","id":"registerdev","depth":3,"charIndex":4614},{"text":"beforeDev","id":"beforedev","depth":3,"charIndex":5460},{"text":"(before|after)DevMenu","id":"beforeafterdevmenu","depth":3,"charIndex":5972},{"text":"beforeDevTask","id":"beforedevtask","depth":3,"charIndex":7008},{"text":"afterDev","id":"afterdev","depth":3,"charIndex":7517}],"domain":"","content":"#\n\n本章介绍关于 Modern.js Module 支持的生命周期钩子。\n\n目前主要包含两类生命周期钩子:\n\n * 构建钩子:仅在执行 build 命令构建源码产物时触发。\n * buildPlatform 钩子:仅在执行 build --platform 命令生成其他构建产物时触发。\n * 调试钩子:运行 dev 命令时会触发的钩子。\n\n\n构建钩子#\n\n在执行 build 命令的时候,会按照顺序触发以下 Hooks:\n\n * beforeBuild\n * beforeBuildTask\n * afterBuildTask\n * afterBuild\n\n\nbeforeBuild#\n\n执行整体构建流程之前触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuild(options: Options): Return {\n return options.config;\n },\n };\n },\n});\n\n\n参数和返回值类型:\n\ntype Options = {\n options: { config: BuildConfig; cliOptions: BuildCommandOptions };\n};\n\nexport interface BuildCommandOptions {\n config: string;\n clear?: boolean;\n dts?: boolean;\n platform?: boolean | string[];\n tsconfig: string;\n watch?: boolean;\n}\n\ntype Return = BuildConfig;\n\n\n> BuildConfig 类型参考 API 配置\n\n\nbeforeBuildTask#\n\n根据构建配置,Modern.js Module 会将整体构建分成多个子构建任务。该 Hook 将会在每一个构建子任务之前触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuildTask(config: BaseBuildConfig): BaseBuildConfig {\n return config;\n },\n };\n },\n});\n\n\n参数和返回值类型:\n\nBaseBuildConfig 类型参考 API 配置。\n\n\nafterBuildTask#\n\n每一个构建子任务结束之后触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuildTask(options: BuildTaskResult): void {\n // ...\n },\n };\n },\n});\n\n\n参数和返回值类型:\n\nexport interface BuildTaskResult {\n status: 'success' | 'fail';\n message?: string;\n config: BaseBuildConfig;\n}\n\n\n\nafterBuild#\n\n整体构建流程结束之后触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuild(options: BuildResult): void {\n // ...\n },\n };\n },\n});\n\n\n参数和返回值类型:\n\nexport interface BuildResult {\n status: 'success' | 'fail';\n message?: string;\n config: BuildConfig;\n commandOptions: BuildCommandOptions;\n totalDuration: number;\n}\n\n\n\nbuildPlatform 钩子#\n\nmodule-tools 还提供了 build --platform 命令来执行特定的构建任务。\n\n例如在安装了 Storybook 插件后,就可以执行 build --platform 或者 build --platform storybook 来执行\nStorybook 的构建任务。因为 Storybook 插件基于 buildPlatform Hooks 实现了该功能。\n\n在执行 build --platform 后会按照以下顺序触发 Hooks:\n\n * registerBuildPlatform\n * beforeBuildPlatform\n * buildPlatform\n * afterBuildPlatform\n\n\nregisterBuildPlatform#\n\n获取在执行 build --platform 命令时候需要运行的任务信息。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n registerBuildPlatform(): RegisterBuildPlatformResult {\n // ...\n return {\n platform: 'stroybook',\n build() {\n // run storybook logic\n },\n };\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface RegisterBuildPlatformResult {\n platform: string | string[];\n build: (\n currentPlatform: string, // 当前运行的 platform 构建任务\n context: { isTsProject: boolean },\n ) => void | Promise;\n}\n\n\n\nbeforeBuildPlatform#\n\n当执行 build --platform 命令的时候,会触发所有已注册的构建任务。beforeBuildPlatform 会在执行整体的构建任务之前触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuildPlatform(platforms: RegisterBuildPlatformResult[]): void {\n console.info(`have ${platforms.length} platform tasks`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface RegisterBuildPlatformResult {\n platform: string | string[];\n build: (\n currentPlatform: string, // 当前运行的 platform 构建任务\n context: { isTsProject: boolean },\n ) => void | Promise;\n}\n\n\n\nbuildPlatform#\n\n当执行 build --platform 命令的时候,会触发所有已注册的构建任务。buildPlatform 会在每个构建任务执行之前触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n buildPlatform({ platform }: Options): void {\n console.info(`current task is ${platform}`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface Options {\n platform: string;\n}\n\n\n\nafterBuildPlatform#\n\n当执行 build --platform 命令的时候,会触发所有已注册的构建任务。afterBuildPlatform 会在整体 platform\n构建任务结束后触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuildPlatform(result: BuildPlatformResult): void {\n if (result.status === 'success') {\n console.info(`all platform build task success`);\n } else {\n console.error(result.message);\n }\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface BuildPlatformResult {\n status: 'success' | 'fail';\n message: string | Error | null;\n}\n\n\n\n调试钩子#\n\n在执行 dev 命令的时候,会按照顺序触发以下 Hooks:\n\n * registerDev: 在获取调试功能信息的时候触发。\n * beforeDev: 开始执行调试整体流程之前触发。\n * beforeDevMenu: 出现调试列表/菜单之前触发。\n * afterDevMenu: 选择调试列表/菜单选项后触发。\n * beforeDevTask: 执行调试任务之前触发。\n * afterDev: 执行 dev 整体流程最后触发。\n\n\nregisterDev#\n\n注册调试工具相关的数据。主要包含:\n\n * 调试工具的名称\n * 显示在菜单列表中的项目名称以及对应的值。\n * dev 子命令的定义。\n * 是否在运行调试任务之前执行源码构建\n * 执行调试任务的函数。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n registerDev() {\n return {\n // 调试工具名称\n name: 'storybook',\n // 菜单显示内容\n menuItem: {\n name: 'Storybook',\n value: 'storybook',\n },\n // 定义的 dev 子命令\n subCommands: ['storybook', 'story'],\n async action() {\n // dev logic\n },\n };\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\nbeforeDev#\n\n在收集完所有调试工具元数据后,执行 dev 任务之前触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDev(metas: DevToolData[]) {\n console.info(`have ${metas.length} dev tools`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\n(before|after)DevMenu#\n\nbeforeDevMenu 在出现调试列表/菜单之前触发。接收 inquirer question 作为参数。默认值为:\n\nconst question = [\n {\n name: 'choiceDevTool',\n message: '选择调试工具',\n type: 'list',\n // 注册的调试信息\n choices,\n },\n];\n\n\nafterDevMenu 选择调试列表/菜单选项后触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDevMenu(questions) {\n questions[0].message += '!';\n return questions; // required\n },\n afterDevMenu(options: Options) {\n console.info(`choise ${options.result.choiceDevTool} dev tools`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport type { QuestionCollection } from 'inquirer';\n\nexport interface Options {\n result: PromptResult;\n devTools: DevToolData[];\n}\n\nexport type PromptResult = { choiceDevTool: string };\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\nbeforeDevTask#\n\n执行调试任务之前触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDevTask(currentDevData: DevToolData) {\n console.info(`${currentDevData.name} running`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\nafterDev#\n\n在中断调试任务进程时触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterDev() {\n console.info(`exit!`);\n },\n };\n },\n});\n","frontmatter":{},"version":""},{"id":52,"title":"","routePath":"/module-tools/components/faq-build-exception","lang":"zh","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":53,"title":"","routePath":"/module-tools/components/faq-build-other","lang":"zh","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":54,"title":"","routePath":"/module-tools/components/faq-build-product","lang":"zh","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":55,"title":"","routePath":"/module-tools/components/faq-storybook","lang":"zh","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":56,"title":"","routePath":"/module-tools/components/faq-test","lang":"zh","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":57,"title":"","routePath":"/module-tools/components/register-esbuild-plugin","lang":"zh","toc":[],"domain":"","content":"\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.plugins = [myEsbuildPlugin, ...options.plugins];\n return options;\n },\n },\n});\n\n\n在增加 esbuild 插件时,请注意你需要将插件加在 plugins 数组的头部,因为 Modern.js Module 内部也是通过一个 esbuild\n插件介入到整个构建流程中去的,因此需要将自定义插件优先注册。","frontmatter":{},"version":""},{"id":58,"title":"处理静态资源","routePath":"/module-tools/guide/advance/asset","lang":"zh","toc":[{"text":"默认行为","id":"默认行为","depth":2,"charIndex":74},{"text":"示例","id":"示例","depth":2,"charIndex":355}],"domain":"","content":"#\n\nModern.js Module 会对代码中使用的静态资源进行处理。如果需要配置,则可以使用 buildConfig.asset API。\n\n\n默认行为#\n\n默认情况下,Modern.js Module 会处理以下静态资源:\n\n * '.svg'、'.png'、'.jpg'、'.jpeg'、'.gif'、'.webp'\n * '.ttf'、'.otf'、'.woff'、'.woff2'、'.eot'\n * '.mp3'、'.mp4'、'.webm'、'.ogg'、'.wav'、'.flac'、'.aac'、'.mov'\n\n对于静态文件的处理,Modern.js Module 目前默认支持的功能有:\n\n * 输出静态资源至 ./assets。\n * 对于不超过 10kb 的文件会内联到代码中。\n\n\n示例#\n\n让我们看下面的例子:\n\n * 项目源代码:\n\n\n\n\n * 如果 bg.png 的大小小于 10 kb,则此时产物目录结构和产物内容为:\n\n./dist\n└── asset.js\n\n\nvar img_default = 'data:image/png;base64,';\n\n\n * 如果 bg.png 的大小大于 10 kb,则此时产物目录结构和产物内容为:\n\n./dist\n├── asset.js\n└── assets\n └── bg.13e2aba2.png\n\n\n\n\n\n当你想要修改默认行为的时候,可以使用以下 API:\n\n * asset.path:修改静态资源文件输出路径。\n * asset.limit:修改内联静态资源文件的阈值。","frontmatter":{"sidebar_position":7},"version":""},{"id":59,"title":"构建 umd 产物","routePath":"/module-tools/guide/advance/build-umd","lang":"zh","toc":[{"text":"umd 产物的第三方依赖处理","id":"umd-产物的第三方依赖处理","depth":2,"charIndex":256},{"text":"示例","id":"示例","depth":3,"charIndex":377},{"text":"三方依赖的全局变量名称","id":"三方依赖的全局变量名称","depth":3,"charIndex":1563},{"text":"更改项目的全局变量名称","id":"更改项目的全局变量名称","depth":2,"charIndex":2612}],"domain":"","content":"#\n\numd 全称为 Universal Module Definition,这种格式的 JS 文件可以运行在多个运行环境:\n\n * 浏览器环境:基于 AMD 规范进行模块加载\n * Node.js 环境:基于 CommonJS 进行模块加载\n * 其他情况:将模块挂载在全局对象上。\n\n因此我们可以通过下面的方式,将项目的构建产物指定为 umd 产物:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n },\n});\n\n\n\numd 产物的第三方依赖处理#\n\n在 「如何处理第三方依赖」 章节中,我们知道可以通过 autoExternals 和 externals API 来控制项目是否对第三方依赖打包。 因此在构建\numd 产物的过程中,我们也可以这样使用:\n\n\n示例#\n\n * 如果项目依赖了 react:\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n * modern.config.ts 配置:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n autoExternal: false,\n externals: ['react'],\n },\n});\n\n\n * 当源码中使用了 react 依赖:\n\n\nconsole.info(React);\n\n\n * 此时产物中不会将 react 代码打包到产物中:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports, require('react'));\n else if (typeof define === 'function' && define.amd)\n define(['exports', 'react'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.index = {}), global.react);\n})(this, function (exports, _react) {\n 'use strict';\n Object.defineProperty(exports, '__esModule', {\n value: true,\n });\n _react = /*#__PURE__*/ _interopRequireDefault(_react);\n function _interopRequireDefault(obj) {\n return obj && obj.__esModule\n ? obj\n : {\n default: obj,\n };\n }\n console.info(_react.default);\n});\n\n\n通过上面的例子我们知道,当使用 autoExternal 和 externals API 后:\n\n * 在 Node.js 环境下,可以通过 require('react') 获取 react 依赖。\n * 在 浏览器环境下,可以通过 global.react 获取 react 依赖。\n\n\n三方依赖的全局变量名称#\n\n然而在浏览器环境下,获取第三方依赖的时候,全局变量名称不一定与依赖名称完全相同,此时就要使用 buildConfig.umdGlobals API。\n\n还是使用之前的例子,当 react 依赖以 windows.React 或者 global.React 全局变量的形式存在于浏览器环境下,那么此时:\n\n * modern.config.ts 配置:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdGlobals: {\n react: 'React',\n },\n },\n});\n\n\n * 当源码中使用了 react 依赖:\n\n\nconsole.info(React);\n\n\n * 此时我们会看到这样的产物代码:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory();\n else if (typeof define === 'function' && define.amd) define([], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory();\n})(this, function () {\n // ...\n // libuild:globals:react\n var require_react = __commonJS({\n 'libuild:globals:react'(exports, module1) {\n module1.exports = Function('return this')()['React'];\n },\n });\n // src/index.ts\n var import_react = __toESM(require_react());\n console.info(import_react.default);\n});\n\n\n此时项目就可以运行在浏览器中,并使用存在于全局对象上的 React 变量了。\n\n\n更改项目的全局变量名称#\n\n当我们将下面的代码打包成 umd 产物并运行在浏览器的时候,我们可以通过 window.index 来使用该模块。\n\nexport default () => {\n console.info('hello world');\n};\n\n\n默认情况下,以源码文件名称作为该模块在浏览器里全局变量的名称。对于上面的例子,其产物内容如下:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports);\n else if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.index = {}));\n})(this, function (exports) {\n //...\n});\n\n\n如果需要修改它,则需要使用 buildConfig.umdModuleName API。\n\n当使用该 API 后:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdModuleName: 'myLib',\n },\n});\n\n\n此时构建产物的内容为:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports);\n else if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.myLib = {}));\n})(this, function (exports) {\n //...\n});\n","frontmatter":{"sidebar_position":5},"version":""},{"id":60,"title":"使用 Copy 工具","routePath":"/module-tools/guide/advance/copy","lang":"zh","toc":[{"text":"了解 Copy API","id":"了解-copy-api","depth":2,"charIndex":72},{"text":"API 详解","id":"api-详解","depth":2,"charIndex":165},{"text":"不同场景使用示例","id":"不同场景使用示例","depth":2,"charIndex":1492},{"text":"将文件复制文件","id":"将文件复制文件","depth":3,"charIndex":1504},{"text":"将文件复制到目录","id":"将文件复制到目录","depth":3,"charIndex":1848},{"text":"从目录复制到目录","id":"从目录复制到目录","depth":3,"charIndex":2186},{"text":"从目录到文件","id":"从目录到文件","depth":3,"charIndex":2580},{"text":"使用 Glob","id":"使用-glob","depth":3,"charIndex":2985}],"domain":"","content":"#\n\nModern.js Module 提供了 Copy 工具用于将已经存在的单个文件或整个目录复制到产物目录中。接下来我们学习如何使用它。\n\n\n了解 Copy API#\n\n我们可以通过 buildConfig.copy API 来使用 Copy 工具,它包含以下两个主要配置:\n\n * patterns\n * options\n\n\nAPI 详解#\n\ncopy.patterns 用于寻找复制的文件以及配置输出的路径。\n\n其中 patterns.from 用于指定要复制的文件或者目录。它接收 Glob 形式字符串或具体路径。Glob 形式字符串是指 fast-glob\npattern-syntax。因此我们可以按照如下两种方式使用它:\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n { from: './index.html', to: '' },\n { from: './*.html', to: '' },\n ],\n },\n },\n});\n\n\npatterns.context 一般和 patterns.from 配合使用,默认情况下它的值与 buildConfig.sourceDir\n相同,因此我们可以按照如下方式指定 src/data.json 文件为要复制的文件:\n\n> 默认情况下,buildConfig.sourceDir 为 src\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n { from: './data.json' to: ''},\n ],\n },\n },\n});\n\n\n当指定的文件不在源码目录的时候,可以修改 context 配置。例如指定项目目录下的 temp/index.html 为要复制的文件:\n\n\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n {\n from: './index.html',\n context: path.join(__dirname, './temp')\n to: '',\n }\n ],\n },\n },\n});\n\n\npatterns.to 用于指定复制文件的输出路径,默认情况下它的值为 buildConfig.outDir对应的值。因此我们按照如下方式将\nsrc/index.html 复制到 dist 目录下:\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [{ from: './index.html' }],\n },\n },\n});\n\n\n当我们配置了 patterns.to 的时候:\n\n * 如果是相对路径,则该路径会相对于 buildConfig.outDir 计算出复制文件输出的绝对路径。\n * 如果是绝对路径,则会直接使用该值。\n\n最后 patterns.globOptions 用于配置寻找复制文件 globby 对象,其配置可参考:\n\n * globby.options\n\n\n不同场景使用示例#\n\n\n将文件复制文件#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy file to file\n */\n {\n from: './temp-1/a.png',\n context: __dirname,\n to: './temp-1/b.png',\n },\n ],\n },\n },\n ],\n});\n\n\n\n将文件复制到目录#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy file to dir\n */\n {\n from: './temp-2/a.png',\n context: __dirname,\n to: './temp-2',\n },\n ],\n },\n },\n ],\n});\n\n\n\n从目录复制到目录#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy dir to dir\n */\n {\n from: './temp-3/',\n to: './temp-3',\n context: __dirname,\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n\n\n\n从目录到文件#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy dir to file\n */\n {\n from: './temp-4/',\n context: __dirname,\n to: './temp-4/_index.html',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n\n\n\n使用 Glob#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy glob to dir\n */\n {\n from: './*.html',\n to: './temp-5',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n {\n copy: {\n patterns: [\n /**\n * copy glob to file\n */\n {\n from: './*.html',\n to: './temp-6/index.html',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n","frontmatter":{"sidebar_position":3},"version":""},{"id":61,"title":"处理三方依赖","routePath":"/module-tools/guide/advance/external-dependency","lang":"zh","toc":[{"text":"第三方依赖的默认处理","id":"第三方依赖的默认处理","depth":2,"charIndex":314},{"text":"示例","id":"示例","depth":3,"charIndex":571},{"text":"排除指定第三方依赖","id":"排除指定第三方依赖","depth":2,"charIndex":849}],"domain":"","content":"#\n\n一般来说,项目所需要的第三方依赖可以通过包管理器的 install 命令安装,在安装第三方依赖成功后,这些第三方依赖一般会出现在项目 package.json\n的 dependencies 和 devDependencies 下。\n\n{\n \"dependencies\": {},\n \"devDependencies\": {}\n}\n\n\n\"dependencies\" 下的依赖通常来说是这个包运行所需的依赖, \"devDependencies\" 则代表着开发依赖。\n\n除了 \"dependencies\" 以外,\"peerDependencies\" 也可以声明在生产环境下运行所需要的依赖,此时会和它的宿主共享一份依赖。\n\n\n第三方依赖的默认处理#\n\n在 Modern.js Module 里,默认情况下不会对 \"dependencies\" 以及 \"peerDependencies\"\n下的第三方依赖进行打包处理。\n\n这是因为在安装 npm 包时,其 \"dependencies\" 也会被安装。不打包 \"dependencies\",可以减小包产物的体积。\n\n如果需要打包某些依赖,建议将它们从 \"dependencies\" 挪到 \"devDependencies\" ,这相当于对依赖进行 prebundle\n,可以减小依赖安装的体积。\n\n\n示例#\n\n如果项目依赖了 react:\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n },\n // or\n \"peerDependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n当源码中使用了 react 依赖:\n\n\nconsole.info(React);\n\n\n此时产物中不会包含 react 的代码:\n\n\nconsole.info(React);\n\n\n如果想要修改默认的处理方式,可以通过下面的 API 进行修改:\n\n * buildConfig.autoExternal\n\n\n排除指定第三方依赖#\n\n在上面我们提到了 buildConfig.autoExternal API 的用途,同时 buildConfig.externals\n可以实现对三方依赖更细微的处理。\n\n例如当我们需要仅对某些依赖不进行打包处理的时候,可以按照如下方式进行配置:\n\n> 一般这种情况,可能是某些依赖不适合进行打包处理。如果遇到这种情况,则可以按照下面的方式进行处理。\n\nepxort default defineConfig({\n buildConfig: {\n autoExternal: false,\n externals: ['pkg-1', /pkg-2/],\n }\n});\n","frontmatter":{"sidebar_position":4},"version":""},{"id":62,"title":"深入理解构建","routePath":"/module-tools/guide/advance/in-depth-about-build","lang":"zh","toc":[{"text":"bundle / bundleless","id":"bundle--bundleless","depth":2,"charIndex":195},{"text":"input / sourceDir","id":"input--sourcedir","depth":2,"charIndex":715},{"text":"使用 swc","id":"使用-swc","depth":2,"charIndex":1372},{"text":"使用 Hook 介入构建流程","id":"使用-hook-介入构建流程","depth":2,"charIndex":1851},{"text":"Hook 类型","id":"hook-类型","depth":3,"charIndex":2025},{"text":"AsyncSeriesBailHook","id":"asyncseriesbailhook","depth":4,"charIndex":2035},{"text":"AsyncSeriesWaterFallHooks","id":"asyncserieswaterfallhooks","depth":4,"charIndex":2137},{"text":"Hook API","id":"hook-api","depth":3,"charIndex":2206},{"text":"load","id":"load","depth":4,"charIndex":2217},{"text":"transform","id":"transform","depth":4,"charIndex":2824},{"text":"renderChunk","id":"renderchunk","depth":4,"charIndex":3246},{"text":"类型文件生成","id":"类型文件生成","depth":2,"charIndex":4134},{"text":"关闭类型生成","id":"关闭类型生成","depth":3,"charIndex":4176},{"text":"打包类型文件","id":"打包类型文件","depth":3,"charIndex":4327},{"text":"别名转换","id":"别名转换","depth":3,"charIndex":4624},{"text":"一些示例","id":"一些示例","depth":3,"charIndex":4909},{"text":"构建过程","id":"构建过程","depth":2,"charIndex":5480},{"text":"构建报错","id":"构建报错","depth":2,"charIndex":5654},{"text":"调试模式","id":"调试模式","depth":2,"charIndex":6052}],"domain":"","content":"#\n\n在 \"基础使用\" 的部分,我们已经知道可以通过 buildConfig 配置对项目的输出产物进行修改。buildConfig\n不仅描述了产物的一些特性,同时还为构建产物提供了一些功能。\n\nTIP\n\n如果你还不了解 buildConfig 的作用,请先阅读 修改输出产物。\n\n而在本章里我们将要深入理解某些构建配置的作用以及了解执行 modern build 命令的时候发生了什么。\n\n\nbundle / bundleless#\n\n那么首先我们来了解一下 bundle 和 bundleless。\n\n所谓 bundle 是指对构建产物进行打包,构建产物可能是一个文件,也有可能是基于一定的代码拆分策略得到的多个文件。\n\n而 bundleless 则是指对每个源文件单独进行编译构建,但是并不将它们打包在一起。每一个产物文件都可以找到与之相对应的源码文件。bundleless\n构建的过程,也可以理解为仅对源文件进行代码转换的过程。\n\n它们有各自的好处:\n\n * bundle 可以减少构建产物的体积,也可以对依赖预打包,减小安装依赖的体积。提前对库进行打包,可以加快应用项目构建的速度。\n * bundleless 则是可以保持原有的文件结构,更有利于调试和 tree shaking。\n\nWARNING\n\nbundleless 是单文件编译模式,因此对于类型的引用和导出你需要加上 type 字段, 例如 import type { A } from\n'./types\n\n在 buildConfig 中可以通过 buildConfig.buildType 来指定当前构建任务是 bundle 还是 bundleless。\n\n\ninput / sourceDir#\n\nbuildConfig.input 用于指定读取源码的文件路径或者目录路径,其默认值在 bundle 和 bundleless 构建过程中有所不同:\n\n * 当 buildType: 'bundle' 的时候,input 默认值为 src/index.(j|t)sx?\n * 当 buildType: 'bundleless' 的时候,input 默认值为 ['src']\n\n从默认值上我们可以知道:使用 bundle 模式构建时一般指定一个或多个文件作为构建的入口,而使用 bundleless\n构建则是指定一个目录,将目录下所有文件作为入口。\n\nsourceDir 用于指定源码目录,它只与以下两个内容有关系:\n\n * 类型文件生成\n * 指定构建过程中的 outbase\n\n因此我们可以得到其最佳实践:\n\n * 在 bundle 构建过程中,只能指定 input 。\n * 一般情况下,bundleless 只需要指定 sourceDir(此时 input 会与 sourceDir 保持一致)。\n\n如果我们想要在 bundleless 里只对一部分文件进行转换,例如只需要转换 src/runtime 目录的文件,此时需要配置 input:\n\n\n\nexport default defineConfig({\n buildConfig: {\n input: ['src/runtime'],\n sourceDir: 'src',\n },\n});\n\n\n\n使用 swc#\n\n在部分场景下,esbuild 不足以满足我们的需求,此时我们会使用 swc 来做代码转换。\n\n从 2.36.0 版本开始,涉及到以下功能时,Modern.js Module 默认会使用 swc ,但不这意味着不使用 esbuild 了,其余功能还是使用\nesbuild:\n\n * transformImport\n * transformLodash\n * externalHelpers\n * format: umd\n * target: es5\n * emitDecoratorMetadata: true\n\n事实上,我们在 2.16.0 开始全量使用 swc 进行代码转换。不过 swc 同样也存在一些限制,为此我们添加了 sourceType 配置,当源码格式为\n'commonjs' 时关闭 swc, 但这种方式并不符合用户直觉,另外,swc 格式化输出的 cjs 模式没有给每个导出名称添加注释,这在 node\n中使用可能会带来一些问题。 因为我们废弃了此行为,回到了最初的设计 - 只在需要的场景下使用 swc 作为补充。\n\n\n使用 Hook 介入构建流程#\n\nModern.js Module 提供了 Hook 机制,允许我们在构建流程的不同阶段注入自定义逻辑。 Modern.js Module Hook 使用了\ntapable 实现,扩展了 esbuild 的插件机制,若 esbuild plugins 已经满足了你的需求,建议直接使用它。 下面展开说明其用法:\n\n\nHook 类型#\n\nAsyncSeriesBailHook#\n\n串行执行的 hooks,如果某个 tapped function 返回非 undefined 结果,则后续其他的 tapped function 停止执行。\n\nAsyncSeriesWaterFallHooks#\n\n串行执行的 hooks,其结果会传递给下一个 tapped function\n\n\nHook API#\n\nload#\n\n * AsyncSeriesBailHook\n * 在 esbuild onLoad callbacks 触发,根据模块路径来获取模块内容\n * 输入参数\n\ninterface LoadArgs {\n path: string;\n namespace: string;\n suffix: string;\n}\n\n\n * 返回参数\n\ntype LoadResult =\n | {\n contents: string; // 模块内容\n map?: SourceMap; // https://esbuild.github.io/api/#sourcemap\n loader?: Loader; // https://esbuild.github.io/api/#loader\n resolveDir?: string;\n }\n | undefined;\n\n\n * 例子\n\ncompiler.hooks.load.tapPromise('load content from memfs', async args => {\n const contents = memfs.readFileSync(args.path);\n return {\n contents: contents,\n loader: 'js',\n };\n});\n\n\ntransform#\n\n * AsyncSeriesWaterFallHooks\n * 在 esbuild onLoad callbacks 触发, 将 load 阶段获取的模块内容进行转换\n * 输入参数(返回参数)\n\nexport type Source = {\n code: string;\n map?: SourceMap;\n path: string;\n loader?: string;\n};\n\n\n * 例子\n\ncompiler.hooks.transform.tapPromise('6to5', async args => {\n const result = babelTransform(args.code, { presets: ['@babel/preset-env'] });\n return {\n code: result.code,\n map: result.map,\n };\n});\n\n\nrenderChunk#\n\n * AsyncSeriesWaterFallHooks\n * 在 esbuild onEnd callbacks 触发, 类似于 transform hook,但是作用在 esbuild 生成的产物\n * 输入参数(返回参数)\n\nexport type AssetChunk = {\n type: 'asset';\n contents: string | Buffer;\n entryPoint?: string;\n /**\n * absolute file path\n */\n fileName: string;\n originalFileName?: string;\n};\n\nexport type JsChunk = {\n type: 'chunk';\n contents: string;\n entryPoint?: string;\n /**\n * absolute file path\n */\n fileName: string;\n map?: SourceMap;\n modules?: Record;\n originalFileName?: string;\n};\n\nexport type Chunk = AssetChunk | JsChunk;\n\n\n * 例子\n\ncompiler.hooks.renderChunk.tapPromise('minify', async chunk => {\n if (chunk.type === 'chunk') {\n const code = chunk.contents.toString();\n const result = await minify.call(compiler, code);\n return {\n ...chunk,\n contents: result.code,\n map: result.map,\n };\n }\n return chunk;\n});\n\n\n\n类型文件生成#\n\nbuildConfig.dts 配置主要用于类型文件的生成。\n\n\n关闭类型生成#\n\n默认情况下类型生成功能是开启的,如果需要关闭的话,可以按照如下配置:\n\n\n\nexport default defineConfig({\n buildConfig: {\n dts: false,\n },\n});\n\n\nTIP\n\n关闭类型文件后,一般来说构建速度会有所提升。\n\n\n打包类型文件#\n\n在 buildType: 'bundleless' 的时候,类型文件的生成是使用项目的 tsc 命令来完成生产。\n\nModern.js Module 同时还支持对类型文件进行打包,不过使用该功能的时候需要注意:\n\n * 一些第三方依赖存在错误的语法会导致打包过程失败。因此对于这种情况,需要手动通过 buildConfig.externals 将这类第三方包排除。\n * 对于第三方依赖的类型文件指向的是一个 .ts 文件的情况,目前无法处理。比如第三方依赖的 package.json 中存在这样的内容: {\"types\":\n \"./src/index.ts\"}。\n\n\n别名转换#\n\n在 bundleless 构建过程中,如果源代码中出现了别名,例如:\n\n\n\n\n正常来说,使用 tsc 生成的产物类型文件也会包含这些别名。不过 Modern.js Module 会对 tsc 生成的类型文件里的别名进行转换处理:\n\n * 对于类似 `` 这样形式的代码可以进行别名转换。\n * 对于类似 export { utils } from '@common/utils' 这样形式的代码可以进行别名转换。\n\n然而也存在一些情况,目前还无法处理,例如 Promise 这样形式的输出类型目前无法进行转换。 对于这种情况的解决办法,可以参与讨论。\n\n\n一些示例#\n\n\n\nexport default defineConfig({\n // 此时打包的类型文件输出路径为 `./dist/types`,并且将会读取项目下的 other-tsconfig.json 文件\n buildConfig: {\n buildType: 'bundle',\n dts: {\n tsconfigPath: './other-tsconfig.json',\n distPath: './types',\n },\n outDir: './dist',\n },\n});\n\n\n\n\nexport default defineConfig({\n // 此时类型文件没有进行打包,输出路径为 `./dist/types`\n buildConfig: [\n {\n buildType: 'bundle',\n dts: false,\n outDir: './dist',\n },\n {\n buildType: 'bundleless',\n dts: {\n only: true,\n },\n outDir: './dist/types',\n },\n ],\n});\n\n\n\n构建过程#\n\n当执行 modern build 命令的时候,会发生\n\n * 根据 buildConfig.outDir 清理产物目录。\n * 编译 js/ts 源代码生成 bundle / bundleless 的 JS 构建产物。\n * 使用 tsc 生成 bundle / bundleless 的类型文件。\n * 处理 copy 任务。\n\n\n构建报错#\n\n当发生构建报错的时候,基于以上了解到的信息,可以很容易的明白在终端出现的报错内容:\n\njs 或者 ts 构建的报错:\n\nerror ModuleBuildError:\n\n╭───────────────────────╮\n│ bundle failed: │\n│ - format is \"cjs\" │\n│ - target is \"esnext\" │\n╰───────────────────────╯\n\nDetailed Information:\n\n\n类型文件生成过程的报错:\n\nerror ModuleBuildError:\n\nbundle DTS failed:\n\n\n对于 js/ts 构建错误,我们可以从报错信息中知道:\n\n * 报错的 buildType\n * 报错的 format\n * 报错的 target\n * 其他具体报错信息\n\n\n调试模式#\n\n从 2.36.0 版本开始,为了便于排查问题,Modern.js Module 提供了调试模式,你可以在执行构建时添加 DEBUG=module\n环境变量来开启调试模式。\n\nDEBUG=module modern build\n\n\n调试模式下,你会看到 Shell 中输出更详细的构建日志,这主要以流程日志为主:\n\nmodule run beforeBuildTask hooks +6ms\nmodule run beforeBuildTask hooks done +0ms\nmodule [DTS] Build Start +139ms\nmodule [CJS] Build Start +1ms\n\n\n另外,Module 还提供了调试内部工作流程的能力。你可以通过设置环境变量 DEBUG=module:* 来开启更详细的调试日志:\n\n目前只支持了 DEBUG=module:resolve,可以查看 Module 内部模块解析的详细日志:\n\n module:resolve onResolve args: {\n path: './src/hooks/misc.ts',\n importer: '',\n namespace: 'file',\n resolveDir: '/Users/bytedance/modern.js/packages/solutions/module-tools',\n kind: 'entry-point',\n pluginData: undefined\n} +0ms\n module:resolve onResolve result: {\n path: '/Users/bytedance/modern.js/packages/solutions/module-tools/src/hooks/misc.ts',\n external: false,\n namespace: 'file',\n sideEffects: undefined,\n suffix: ''\n} +0ms\n","frontmatter":{"sidebar_position":1},"version":""},{"id":63,"title":"深入理解 dev 命令","routePath":"/module-tools/guide/advance/in-depth-about-dev-command","lang":"zh","toc":[{"text":"命令运行的整体流程","id":"命令运行的整体流程","depth":2,"charIndex":42},{"text":"扩展 dev 命令","id":"扩展-dev-命令","depth":2,"charIndex":339}],"domain":"","content":"#\n\nModern.js Module 提供的 dev 命令主要用于代码的调试。\n\n\n命令运行的整体流程#\n\n 1. 当执行 dev 命令的时候,Modern.js Module 开始寻找是否存在可以执行的调试工具或者任务。调试工具或者任务就是类似 Storybook\n 这样的 Modern.js Module 调试工具插件。\n 2. 当发现存在一个调试工具的时候,则会立即执行它。\n 3. 当发现多个调试工具的时候,则显示调试工具列表菜单。可以通过选择某个调试工具对应的名称选项启动它。\n 4. 当没有发现调试工具的时候,则告诉用户没有可用的调试工具。\n\n我们除了可以执行 dev 命令以外,也可以通过 dev [调试工具名称] 的方式来直接启动调试工具或者任务。\n\n\n扩展 dev 命令#\n\n如果需要扩展 dev 命令或者说提供自己的 Modern.js Module 调试工具插件,那么你需要先了解以下内容:\n\n * 开发插件\n * 调试工具插件 API\n\n一般来说,实现一个什么都不做的调试工具,其实现代码以及相关配置如下:\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'do-nothing',\n setup() {\n return {\n registerDev() {\n return {\n // 调试工具名称\n name: 'do-nothing',\n // 菜单显示内容\n menuItem: {\n name: 'DoNothing',\n value: 'do-nothing',\n },\n // 定义的 dev 子命令\n subCommands: ['donothing', 'dn'],\n async action() {\n // dev logic\n console.info('Run build --watch, and do nothing.');\n },\n };\n },\n };\n },\n});\n\n\n如果需要使用该调试工具插件,则需要在配置文件中增加它:\n\n\n\nexport default defineConfig({\n plugins: [\n //..\n doNothingPlugin()\n ],\n});\n\n\n此时我们执行 dev 或者 dev do-nothing 命令的时候,就可以执行它了。在执行后,它会先执行监听模式的源码构建任务,并紧接着打印日志信息。\n\n对于目前官方支持的调试工具和第三方支持的调试工具,可以在插件列表中查看。","frontmatter":{"sidebar_position":2},"version":""},{"id":64,"title":"开始之前","routePath":"/module-tools/guide/basic/before-getting-started","lang":"zh","toc":[{"text":"环境准备","id":"环境准备","depth":2,"charIndex":3},{"text":"初识 npm","id":"初识-npm","depth":2,"charIndex":189},{"text":"npm 包类型项目","id":"npm-包类型项目","depth":2,"charIndex":392},{"text":"使用第三方 npm 包","id":"使用第三方-npm-包","depth":2,"charIndex":1023},{"text":"还需要了解的 npm 零碎知识","id":"还需要了解的-npm-零碎知识","depth":2,"charIndex":1990},{"text":"npm 包的程序入口","id":"npm-包的程序入口","depth":3,"charIndex":2009},{"text":"\\\"scripts\\\"","id":"scripts","depth":3,"charIndex":-1},{"text":"npm install","id":"npm-install","depth":4,"charIndex":2878},{"text":"npm publish","id":"npm-publish","depth":4,"charIndex":3142},{"text":"peerDependencies","id":"peerdependencies","depth":3,"charIndex":3302},{"text":"npm 包管理器","id":"npm-包管理器","depth":2,"charIndex":3616},{"text":"Modern.js Module 配置文件","id":"modernjs-module-配置文件","depth":2,"charIndex":3744}],"domain":"","content":"#\n\n\n环境准备#\n\n为了使用 Modern.js Module,首先需要 NodeJS,我们推荐最新的长期维护版本,并确保 Node 版本大于等于 14.18.0。因为非稳定的\nNodeJS 时常有一些 Bug,你可以使用 nvm-windows 和 nvm(Mac / Linux)安装,这样你就可以方便地切换到不同的 NodeJS\n版本,这些版本可能会用于不同的项目。\n\n\n初识 npm#\n\n当 NodeJS 被安装后,你不仅可以在命令行中访问 node 可执行程序,同时你也可以执行 npm 命令。\n\nnpm 是 NodeJS 的标准软件包管理器。它一开始的用途是用于下载和管理 NodeJS 包的依赖关系,但后来它逐渐变成为一个用于前端 JavaScript\n的工具。\n\n如果你已经对 npm 和 npm 包的使用方式有所了解,那么可以直接跳到「npm 包管理器」部分。\n\n\nnpm 包类型项目#\n\n那么什么是 npm 包类型的项目呢?当我们在一个空的项目目录下执行 npm init 命令的时候,它会在当前目录下面创建一个文件名为 package.json\n的 JSON 文件。在创建过程中,我们需要填写包括但不限于 npm 包的名称、版本号、描述等等内容,这些填写的内容都会在生成的 package.json\n文件中找到:\n\n{\n \"name\": \"npm-demo\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"index.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n },\n \"author\": \"\",\n \"license\": \"ISC\"\n}\n\n\n此时这个包含了初始化后的 package.json 文件的项目就是一个 npm 包类型的项目,你可以执行 npm publish 命令将这个项目发布到 npm\nRegistry。\n\nnpm Registry 是一个 npm 包存储的地方,开发者们不仅可以将他们自己的 npm 包发布到 npm Registry,还可以通过 npm\nRegistry 使用其他开发者发布的 npm 包。\n\n优质的 npm 包会有更多的人去使用,因为它不仅节省了很多代码实现的工作,同时也不容易让项目出现问题。\n\n\n使用第三方 npm 包#\n\n当要为初始化的项目增加第三方的 npm 包的时候,我们可以把这一过程叫做“为项目安装依赖”或是“为项目增加依赖”。在增加依赖之前,首先我们要特别了解一件事情\n—— npm 依赖的软件包类型:\n\n * \"dependencies\":一种是你的应用程序在生产环境中需要的软件包。\n * \"devDependencies\":另一种是仅在本地开发和测试中需要的软件包。\n \n > 软件包可以理解为是第三方的 npm 包。\n\n你可以通过执行 npm install npm-package-name 或者 npm add npm-package-name\n的方式来安装在生产环境中需要的软件包,或者也可以在 package.json 文件中手动的将需要安装的包和对应的语义化版本写在 \"dependencies\"\n里,并执行 npm install 命令:\n\n{\n \"name\": \"your-npm-project\",\n \"dependencies\": {\n \"npm-package-name\": \"0.1.0\"\n }\n}\n\n\n同理,你也可以执行 npm install npm-package-name --save-dev 或 npm add npm-package-name\n--save-dev 的方式来安装仅在本地开发和测试中需要的软件包,或者也可以在 package.json 文件中手动的将需要安装的包和对应的语义化版本写在\n\"devDependencies\" 里,并执行 npm install 命令:\n\n{\n \"name\": \"your-npm-project\",\n \"devDependencies\": {\n \"npm-package-name\": \"0.1.0\"\n }\n}\n\n\n在安装或者使用第三方 npm 包的时候一定要确定它们的用途,以及通过区分它们的类型确定好它们应该放在 \"dependencies\" 还是\n\"devDependencies\" 中。\n\nTIP\n\n一般来说,需要在源代码中使用到的包都属于 dependencies 依赖。除非你通过打包的方式将依赖的代码输出到本地,那么这种情况可以将它作为\ndevDependencies 依赖。\n\n\n还需要了解的 npm 零碎知识#\n\n\nnpm 包的程序入口#\n\n在 package.json 中存在一个 \"main\" 属性,它对应的值是一个模块 ID,或者更直观的说是一个 NodeJS 文件路径,它是你程序的主要入口。\n\n例如你的包名为 foo,并且用户安装了它,然后执行 require(\"foo\") 代码,那么 foo 这个 npm 包的 \"main\"\n字段对应的文件将会被导出。\n\n推荐在你的 npm 包里一定要设置 \"main\" 字段。如果没有设置 \"main\",则默认入口为包的根目录下的 index.js 文件。\n\n除了需要设置 \"main\" 属性以外,一般还会设置 \"module\" 属性。它与 \"main\" 属性的用途类似,它主要是用于在 webpack\n场景下使用。webpack 在大多数情况下,会以 \"module\" -> \"main\" 这个顺序读取 npm 包的入口(文件)。\n\n> 想要了解关于 webpack 如何做这件事,可以查看这个链接。\n\n\n\"scripts\"#\n\npackage.json 文件的 \"scripts\" 属性支持一些内置的脚本和 npm 预设的生命周期事件,以及任意的脚本。\n\n这些都可以通过运行 npm run-script 或简称 npm run 来执行。\n\n名称匹配的前置命令和后置命令也会被运行(例如 premyscript、myscript、postmyscript)。\n\n{\n \"scripts\": {\n \"premyscript\": \"\",\n \"myscript\": \"\",\n \"postmyscript\": \"\"\n }\n}\n\n\n当执行 npm run myscripts 的时候,premyscripts 对应的脚本会在它之前执行,postmyscripts 对应的脚本会在它之后执行。\n\n来自依赖的脚本命令可以用 npm explore -- npm run 运行。\n\n还有一些特殊的生命周期脚本(Life Scripts),只在某些情况下发生。这里介绍几个通常需要了解的情况。\n\nnpm install#\n\n当你运行 npm install -g 时,以下脚本会运行。\n\n * preinstall\n * install\n * postinstall\n * prepublish\n * preprepare\n * prepare\n * postprepare\n\n如果你的软件包根目录有一个 binding.gyp 文件,而你没有定义 install 或 preinstall 脚本,那么 npm 将以 node-gyp\nrebuild 作为默认的 install 命令,使用 node-gyp 进行编译。\n\nnpm publish#\n\n当发布项目的时候,执行该命令会触发以下脚本:\n\n * prepublishOnly\n * prepack\n * prepare\n * postpack\n * publish\n * postpublish\n\n当以 --dry-run 模式运行的时候,prepare 对应的脚本将不会执行。\n\n\npeerDependencies#\n\n在某些情况下,你的 npm 项目与它的宿主工具或者库之间存在某种兼容关系(例如一个 webpack 插件项目和 webpack),同时你的 npm\n项目不想将宿主作为必要的依赖,这个时候通常说明你的项目可能是这个宿主工具或者库的插件。你的 npm\n项目会对宿主包的版本有一定的要求,因为只有在特定的版本下才会暴露出 npm 项目所需要的 API。\n\n关于更多 peerDependencies 的解释,可以通过下面的链接了解 npm、pnpm、Yarn 对于它的不同处理方式:\n\n * npm 对 peerDependencies 的解释\n * pnpm vs npm VS Yarn\n\n\nnpm 包管理器#\n\n除了 npm 这种标准的包管理器以外,目前主流的还有 pnpm 和 Yarn,它们都是不错的 npm cli 替代品。\n\n推荐使用 pnpm 来管理项目依赖,可以通过下面的方式安装它:\n\nnpm install -g pnpm\n\n\n\nModern.js Module 配置文件#\n\n通过 @modern-js/create 创建的项目目录下提供了 Modern.js Module 的配置文件 ——\nmodern.config.(j|t)s。但 modern.config 配置文件不是必须存在的。\n\n默认情况下,生成的配置文件的内容如下:\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n});\n\n\n我们推荐使用 defineConfig 函数,不过并不强制使用它。因此你也可以在配置文件中直接返回一个对象:\n\n\n\nexport default {\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n};\n","frontmatter":{"sidebar_position":1},"version":""},{"id":65,"title":"CLI 命令","routePath":"/module-tools/guide/basic/command-preview","lang":"zh","toc":[{"text":"modern build","id":"modern-build","depth":2,"charIndex":39},{"text":"modern new","id":"modern-new","depth":2,"charIndex":1090},{"text":"modern dev","id":"modern-dev","depth":2,"charIndex":1549},{"text":"modern test","id":"modern-test","depth":2,"charIndex":1925},{"text":"modern lint","id":"modern-lint","depth":2,"charIndex":2129},{"text":"modern change","id":"modern-change","depth":2,"charIndex":2422},{"text":"modern pre","id":"modern-pre","depth":2,"charIndex":2662},{"text":"modern bump","id":"modern-bump","depth":2,"charIndex":2808},{"text":"modern release","id":"modern-release","depth":2,"charIndex":3151},{"text":"modern gen-release-note","id":"modern-gen-release-note","depth":2,"charIndex":3502},{"text":"modern upgrade","id":"modern-upgrade","depth":2,"charIndex":3832}],"domain":"","content":"#\n\nModern.js Module 项目可以使用的 CLI 命令如下:\n\n\nmodern build#\n\nUsage: modern build [options]\n\n构建生产环境产物\n\nOptions:\n -w, --watch 使用监听模式构建代码\n --tsconfig [tsconfig] 指定 tsconfig.json 文件的路径 (default:\n \"./tsconfig.json\")\n --platform [platform] 构建所有或者指定平台的产物\n --no-dts 关闭 DTS 类型文件生成和类型检查\n --no-clear 关闭自动清除产物输出目录的行为\n -h, --help 展示当前命令的信息\n\n\n当想要启动项目构建的时候,可以执行 modern build 命令。在使用这个命令的时候,我们可以:\n\n * 当想要以观察模式启动构建时,使用 --watch 选项。\n * 当想要指定项目编译读取的 TypeScript 配置文件的路径时,使用 build --tsconfig ./path/config.json\n 选项。使用该选项后,会覆盖所有 buildConfig 里 dts.tsconfigPath 配置。\n * 当需要关闭项目的 DTS 类型文件生成和类型检查行为时,可以使用 --no-dts\n 选项。注意:类型文件的生成依赖类型检查的结果。如果关闭了类型检查,那么类型文件也不会生成。\n * 当需要关闭自动清除产物输出目录的行为时,可以使用 --no-clear 选项。\n\n除了以上方式,Modern.js Module 还支持 platform 构建模式,可以用于执行其他工具的构建任务。例如,目前官方支持在安装了\n@modern-js/plugin-storybook 插件后,可以通过执行 modern build --platform 或者 modern build\n--platform storybook 命令启动 Storybook 构建任务生成 Storybook 产物。\n\nTIP\n\n在执行 Storybook 构建的时候,如果需要读取项目的构建产物。那么在执行 modern build --platform 命令启动 Storybook\n构建之前,不要忘记先执行 modern build 命令确保项目构建产物的存在。\n\n\nmodern new#\n\nUsage: modern new [options]\n\n启用可选功能\n\nOptions:\n -d, --debug 开启 Debug 模式,打印调试日志信息 (default: false)\n -c, --config 生成器运行默认配置(JSON 字符串)\n --dist-tag 生成器使用特殊的 npm Tag 版本\n --registry 生成器运行过程中定制 npm Registry\n -h, --help display help for command\n\n\nmodern new 命令用于启动微生成器功能,它可以为项目启用默认没有提供的功能。\n\n目前可以开启的功能有:\n\n * Test 测试\n * Storybook 调试\n * Tailwind CSS 支持\n * Modern.js Runtime API\n\n关于这些功能,可以通过「使用微生成器」 章节了解更多。\n\n\nmodern dev#\n\nUsage: modern dev [options]\n\n运行和调试模块\n\nOptions:\n -h, --help display help for command\n\nCommands:\n[dev-tools-subCommand]\n\n\nModern.js Module 提供了使用调试工具的能力,可以通过 modern dev\n命令来启动。不过要注意的是,默认情况下是没有提供调试相关的插件,因此此时执行 modern dev 会提示: \"No dev tools found\navailable\"。\n\n目前官方支持的调试工具有 Storybook,因此在你执行 modern new 命令开启它后,就可以执行 modern dev 或者 modern dev\nstorybook 执行它。\n\n\nmodern test#\n\nUsage: modern test [options]\n\nOptions:\n -h, --help display help for command\n\n\n需要先执行 modern new 开启测试功能,然后才可以执行 modern test 命令。 modern test 命令会自动将\ntests/*.test.(js|ts|jsx|tsx) 文件当做测试用例运行。\n\n\nmodern lint#\n\nUsage: modern lint [options] [...files]\n\nlint and fix source files\n\nOptions:\n --no-fix disable auto fix source file\n -h, --help display help for command\n\n\n运行 ESLint 检查代码语法情况。通常情况下,我们只需要在 git commit 阶段通过 lint-staged 检查本次提交修改的部分代码。\n\n * --no-fix 参数设置后可以关闭自动修复 lint 错误代码的能力。\n\n\nmodern change#\n\nUsage: modern change [options]\n\n创建变更集\n\nOptions:\n --empty 创建空变更集 (default: false)\n --open 使用编辑器中打开创建的变更集 (default: false)\n -h, --help display help for command\n\n\nmodern change 命令用于生成 changesets 需要的 Markdown 文件。\n\n\nmodern pre#\n\nUsage: modern pre [options] [tag]\n\n进入和退出预发布模式\n\nOptions:\n -h, --help display help for command\n\n\n可以使用 modern pre 命令在正式发布前预发布一个版本。\n\n\nmodern bump#\n\nUsage: modern bump [options]\n\n使用变更集自动更新发布版本和变更日志\n\nOptions:\n --canary 创建一个预发布版本进行测试 (default: false)\n --preid 在对预发布版本进行版本控制时指定标识符 (default: \"next\")\n --snapshot 创建一个特殊版本进行测试 (default: false)\n -h, --help display help for command\n\n\n按照 changesets 生成的变更记录的 Markdown 文件修改 package.json 中的版本号, 同时生成 CHANGELOG.md 文件。\n\n\nmodern release#\n\nUsage: modern release [options]\n\n发布 npm 包\n\nOptions:\n --tag 发布 npm 包使用特定的 tag (default: \"\")\n --ignore-scripts 发布时忽略 package.json 中的 scripts 命令,仅支持在 pnpm monorepo\n 中使用 (default: \"\")\n -h, --help display help for command\n\n\nmodern release 命令可以将模块发布到 npm Registry 上。\n\n * --tag 参数可以指定发布时具体的 dist tags。\n\n\nmodern gen-release-note#\n\nUsage: modern gen-release-note [options]\n\n根据当前仓库 changeset 信息生成 Release Note\n\nOptions:\n --repo 仓库名称,用于生成 Pull Request 链接, 例如: web-infra-dev/modern.js\n --custom 自定义 Release Note 生成函数\n -h, --help display help for command\n\n\n根据当前仓库的 changeset 信息自动生成 Release Note。\n\nTIP\n\n需要在 bump 命令之前执行。\n\n\nmodern upgrade#\n\nUsage: modern upgrade [options]\n\n升级 Modern.js 到最新版本\n\nOptions:\n --registry 定制 npm registry (default: \"\")\n -d,--debug 开启 Debug 模式,打印调试日志信息 (default: false)\n --cwd 项目路径 (default: \"\")\n -h, --help display help for command\n\n\nmodern upgrade 命令,用于升级项目 Modern.js 相关依赖至最新版本。\n\n在项目根目录下执行命令 npx modern upgrade,会默认将当前执行命令项目的 package.json 中的 Modern.js\n相关依赖更新至最新版本。","frontmatter":{"sidebar_position":2},"version":""},{"id":66,"title":"修改输出产物","routePath":"/module-tools/guide/basic/modify-output-product","lang":"zh","toc":[{"text":"默认输出产物","id":"默认输出产物","depth":2,"charIndex":3},{"text":"构建预设","id":"构建预设","depth":2,"charIndex":486},{"text":"构建配置","id":"构建配置","depth":2,"charIndex":804},{"text":"结合配置与预设","id":"结合配置与预设","depth":2,"charIndex":2092}],"domain":"","content":"#\n\n\n默认输出产物#\n\n当你在初始化的项目里使用 modern build 命令的时候,Modern.js Module 会根据当前配置内容,生成相应的构建产物。\n\n模板创建的默认配置内容如下:\n\n\n\nexport default defineConfig({\n // 注册 Modern.js Module 的 CLI 工具\n plugins: [moduleTools()],\n // 指定构建预设配置\n buildPreset: 'npm-library',\n});\n\n\n默认生成产物具有以下特点:\n\n * 会生成 CommonJS 和 ESM 两份产物。\n * 代码语法支持到 ES6 ,更高级的语法将会被转换。\n * 所有的代码经过打包变成了一个文件,即进行了 bundle 处理。\n * 产物输出根目录为项目下的 dist 目录,类型文件输出的目录为 dist/types。\n\n看到这里你可能会有以下疑问:\n\n 1. buildPreset 是什么?\n 2. 产物的这些特点是由什么决定的?\n\n接下来,我们首先来了解一下 buildPreset。\n\n\n构建预设#\n\nbuildPreset 代表着提前准备好的一组或者多组构建相关的配置,只需要使用 buildPreset\n对应的预设值,就可以省去麻烦且复杂的配置工作,得到符合预期的产物。\n\nModern.js Module 主要内置了两套构建预设,包括:\n\n * npm-component: 用于构建组件库。\n * npm-library: 用于打包其他库类型的项目,如工具库。\n\n同时,还提供一些变体,例如 npm-library-with-umd 和 npm-library-es5,顾名思义,分别对应带有 umd 产物和支持到 es5\n语法的库预设。 详细配置可以查看其API。\n\n除此之外,我们也可以完全自定义构建配置:\n\n\n构建配置#\n\nbuildConfig 是一个用来描述如何编译、生成构建产物的配置项。在最开始提到的关于“构建产物的特点”,其实都是 buildConfig\n所支持的属性。目前所支持的属性覆盖了大部分模块类型项目在构建产物时的需求,buildConfig\n不仅包含一些产物所具备的属性,也包含了构建产物所需要的一些特性功能。接下来从分类的角度简单罗列一下:\n\n构建产物的基本属性包括:\n\n * 产物是否被打包:对应的 API 是 buildConfig.buildType。\n * 产物对于语法的支持:对应的 API 是 buildConfig.target。\n * 产物格式:对应的 API 是 buildConfig.format。\n * 产物类型文件如何处理,对应的 API 是 buildConfig.dts。\n * 产物的 sourceMap 如何处理:对应的 API 是 buildConfig.sourceMap。\n * 产物对应的输入(或者是源文件):对应的 API 是 buildConfig.input。\n * 产物输出的目录:对应的 API 是 buildConfig.outDir。\n * 构建的源码目录:对应的 API 是 buildConfig.sourceDir。\n\n构建产物所需的常用功能包括:\n\n * 别名:对应的 API 是 buildConfig.alias。\n * 静态资源处理:对应的 API 是 buildConfig.asset。\n * 第三方依赖处理:对应的 API 有:\n * buildConfig.autoExternal。\n * buildConfig.externals。\n * 拷贝:对应的 API 是 buildConfig.copy。\n * 全局变量替换:对应的 API 是 buildConfig.define。\n * 指定 JSX 编译方式,对应的 API 是 buildConfig.jsx。\n\n一些高级属性或者使用频率不高的功能:\n\n * 产物代码压缩:对应的 API 是 buildConfig.minify。\n * 代码分割:buildConfig.spitting\n * 指定构建产物用于 NodeJS 环境还是浏览器环境:对应的 API 是 buildConfig.platform。\n * umd 产物相关:\n * 指定 umd 产物外部导入的全局变量:对应的 API 是 buildConfig.umdGlobals。\n * 指定 umd 产物的模块名:对应的 API 是 buildConfig.umdModuleName。\n\n除了以上分类以外,关于这些 API 的常见问题和最佳实践可以通过下面的链接来了解:\n\n * 关于 bundle 和 bundleless\n * 关于 input 和 sourceDir。\n * 关于类型描述文件。\n * 如何使用 define\n * 如何处理第三方依赖\n * 如何使用拷贝\n * 如何构建 umd 产物\n * 如何使用静态资源\n\n\n结合配置与预设#\n\n了解 buildPreset 和 buildConfig 之后,我们可以将二者进行结合使用。\n\n在实际项目中,我们可以先使用 buildPreset 来快速获取一套默认构建配置。如果需要自定义,可以使用 buildConfig 进行覆盖和扩展。\n\n扩展的逻辑如下:\n\n * 当 buildConfig 是数组时,会在原来的预设基础上添加新的配置项。\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n buildConfig: [\n {\n format: 'iife',\n target: 'es2020',\n outDir: './dist/global'\n }\n ]\n});\n\n\n这会在原本预设的基础上,额外生成一份 IIFE 格式、支持到 ES2020 语法的产物,输出目录为项目下的 dist/global 目录。\n\n * 当 buildConfig 是对象时,会将对象中的配置项覆盖到预设中。\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n buildConfig: {\n sourceMap: true,\n }\n});\n\n\n这会使得每一项构建任务都会生成 sourceMap 文件。","frontmatter":{"sidebar_position":3},"version":""},{"id":67,"title":"版本管理与发布","routePath":"/module-tools/guide/basic/publish-your-project","lang":"zh","toc":[{"text":"跟踪变更","id":"跟踪变更","depth":2,"charIndex":156},{"text":"版本更新","id":"版本更新","depth":2,"charIndex":1050},{"text":"发布","id":"发布","depth":2,"charIndex":1313},{"text":"预发布","id":"预发布","depth":2,"charIndex":1651}],"domain":"","content":"#\n\n一个 npm 类型的模块项目发布流程包含了两个阶段:\n\n * 第一阶段是在开发期间,开发者需要提供变更文件,该文件记录了在发布期间需要的变更内容;\n * 第二阶段是在发布期间,Modern.js Module 会收集所有的变更文件来更新版本、更新发布日志,并发布新的包到 npm Registry 上。\n\n\n跟踪变更#\n\n当项目发生变化的时候需要将变化的内容记录下来。项目发生的变化一般是指:\n\n * 新功能\n * 修复问题\n * 配置文件修改\n * ...\n\n当这些任务一旦开发完成后,需要通过以下命令来对当前的变化进行记录:\n\n * modern change\n\n执行 modern change 命令后会向开发者提出几个问题,并根据开发者的回答生成变更记录。变更记录文件包含了版本变化的类型和其描述,该文件会被提交到\ngit 仓库中。\n\n$ npx modern change\n🦋 What kind of change is this for module-example? (current version is 0.1.0) · patch\n🦋 Please enter a summary for this change (this will be in the changelogs). Submit empty line to open external editor\n🦋 Summary · publish test\n🦋 === Releasing the following packages ===\n🦋 [Patch]\n🦋 module\n🦋 Is this your desired changeset? (Y/n) · true\n🦋 Changeset added! - you can now commit it\n🦋\n🦋 If you want to modify or expand on the changeset summary, you can find it here\n🦋 info /xxxxxx/module/.changeset/brave-dryers-agree.md\n\n\n当执行成功后,生成的包含变更记录的 Markdown 文件会保存在项目的 .changeset 目录下面。其内容类似下面这样:\n\n---\n'module-example': patch\n---\n\npublish test\n\n\n\n版本更新#\n\n当需要更新项目版本的时候,执行以下命令:\n\n * modern bump\n\n执行 modern bump 将会基于 .changeset/ 目录下记录了变更的 Markdown 文件内容来修改 package.json\n中的版本号,同时生成 CHANGELOG.md 文件。而当版本更新完成后,这些记录变更的 Markdown 文件也会被删除,也可说这些 Markdown\n文件被“消耗”掉了。\n\n# module\n\n## 0.1.1\n\n### Patch Changes\n\n- publish test\n\n\n\n发布#\n\n发布项目可以执行以下命令:\n\n * modern release\n\nmodern release 命令可以将项目发布到 npm Registry。\n\n此时发布的是 latest 版本,也可以说是正式版本。如果想要修改 dist-tag,可以通过 modern release --tag 命令来指定。例如:\n\nmodern release --tag beta\n\n\n但是如果希望将当前项目的版本号也修改为预发布的版本号,则需要使用 modern pre 命令。\n\n> 所谓 dist-tag,可以理解:为当前发布的版本打标签。一般来说,默认发布的版本对应的 dist-tag 为 latest,因此可以把 latest\n> 认为是正式版本的 dist-tag。\n\n\n预发布#\n\n当需要在正式发布之前进行预发布,则需要执行以下命令:\n\n * modern pre\n\n首先 modern pre enter 进入预发布模式, 可以与发布项目的时候使用 modern release --tag 命令指定的 tag 一致。\n\n$ npx modern pre enter next\n🦋 success Entered pre mode with tag next\n🦋 info Run `changeset version` to version packages with prerelease versions\n✨ Done in 5.30s.\n\n\n接着可以使用 modern bump 命令更新具体的版本号,此时不会真正的“消耗”记录变更的 Markdown 文件:\n\n$ npx modern bump\n🦋 warn ===============================IMPORTANT!===============================\n🦋 warn You are in prerelease mode\n🦋 warn If you meant to do a normal release you should revert these changes and run `changeset pre exit`\n🦋 warn You can then run `changeset version` again to do a normal release\n🦋 warn ----------------------------------------------------------------------\n🦋 All files have been updated. Review them and commit at your leisure\n\n\n然后可以看到 package.json 中更新的版本号会类似这样:0.1.2-next.0。\n\n最后,如果不需要再进行预发布,则一定要执行 modern pre exit 命令,这样可以退出预发布状态,并且当再次执行 modern bump\n命令的时候,就可以发布正式的版本。","frontmatter":{"sidebar_position":7},"version":""},{"id":68,"title":"测试项目","routePath":"/module-tools/guide/basic/test-your-project","lang":"zh","toc":[{"text":"先决条件和约定","id":"先决条件和约定","depth":2,"charIndex":21},{"text":"运行测试","id":"运行测试","depth":2,"charIndex":417},{"text":"使用配置","id":"使用配置","depth":2,"charIndex":551},{"text":"测试示例","id":"测试示例","depth":2,"charIndex":633},{"text":"普通模块","id":"普通模块","depth":3,"charIndex":641},{"text":"组件","id":"组件","depth":3,"charIndex":1057}],"domain":"","content":"#\n\n本章将要介绍如何测试可复用模块。\n\n\n先决条件和约定#\n\n想要使用项目的测试功能,需要确保项目中包含依赖:\"@modern-js/plugin-testing\",以及按照类似下面的内容进行配置:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n testingPlugin(),\n ],\n});\n\n\n可以通过执行 modern new 命令来开启测试功能。\n\n在 Modern.js Module 中,对于测试用例或者说编写测试的文件有如下约定:\n\n * 项目目录下的 tests 目录为测试用例和测试文件的目录,不支持更改运行测试用例的目录。\n * 默认会自动将后缀为 .test.[tj]sx? 的文件识别为测试文件。\n * 其他的 .[tj]sx? 后缀的文件被识别为普通的文件,可以用于测试的 utils 文件或者其他用途。\n\n\n运行测试#\n\n当准备好了依赖、增加了相关配置以及了解了测试用例在哪里编写后,我们可以通过以下命令来执行测试:\n\nmodern test\n\n// 更新 snapshot\nmodern test --updateSnapshot\n\n\n执行之后,会看到测试的结果:\n\n\n\n\n使用配置#\n\nModern.js Module 对测试提供了以下配置:\n\n * testing\n\n可以在 modern.config.(j|t)s 中增加它。\n\n\n测试示例#\n\n\n普通模块#\n\n对于普通的模块,我们可以按照如下方式使用测试功能:\n\n * 首先是模块的代码:\n\nexport default function () {\n return 'hello world';\n}\n\n\n * 然后在测试文件中,我们可以按以下方式引用,其中 @ 指向了源码目录,在初始化项目的 tests/tsconfig.json 的 paths 中定义了。\n\n\n\ndescribe('默认值 cases', () => {\n test('Have returns', () => {\n const drink = jest.fn(main);\n drink();\n expect(drink).toHaveReturned();\n });\n});\n\n\n * 最后我们可以执行 modern test:\n\npnpm test\n## or\nyarn test\n## or\nnpm run test\n\n\n\n组件#\n\n对于组件,Modern.js 的 Runtime API 提供了用于测试 UI 组件的功能,其功能由 @modern-js/runtime/testing\n提供。\n\nTIP\n\n如果需要使用 Runtime API,那么可以通过 微生成器 开启。\n\n * 首先是组件的代码:\n\nexport const default () {\n return (\n \nThis is a UI Component\n );\n}\n\n\n * 然后在测试文件中,我们可以按以下方式引用,其中 @ 指向了源码目录,在初始化项目的 tests/tsconfig.json 的 paths 中定义了。\n\n\n\n\n\ndescribe('默认值 cases', () => {\n test('Rendered', () => {\n render();\n expect(screen.getByText('This is a UI Component')).toBeInTheDocument();\n });\n});\n\n\n * 最后我们可以执行 modern test。\n\npnpm test\n## or\nyarn test\n## or\nnpm run test\n","frontmatter":{"sidebar_position":6},"version":""},{"id":69,"title":"使用微生成器","routePath":"/module-tools/guide/basic/use-micro-generator","lang":"zh","toc":[{"text":"Test 测试","id":"test-测试","depth":2,"charIndex":166},{"text":"Storybook 调试","id":"storybook-调试","depth":2,"charIndex":407},{"text":"Tailwind CSS 支持","id":"tailwind-css-支持","depth":2,"charIndex":751},{"text":"Modern.js Runtime API 支持","id":"modernjs-runtime-api-支持","depth":2,"charIndex":899}],"domain":"","content":"#\n\nModern.js Module 提供了微生成器工具,它可以为当前项目:\n\n * 新增目录和文件\n * 修改 package.json\n * 执行命令\n\n因此通过这些能力,微生成器可以为项目开启额外的特性功能。\n\n可以通过 modern new 启动微生成器。目前 Modern.js Module 支持的微生成器功能有:\n\n\nTest 测试#\n\n当我们想要对一些模块进行测试的时候,可以启用测试功能。启动该功能后,会在项目目录下创建 tests 目录以及相关文件,在 package.json 中新增\n\"@modern-js/plugin-testing\" 依赖。\n\nTIP\n\n在成功开启后,会提示需要手动在配置中增加如下类似的代码。\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), testingPlugin()],\n});\n\n\n\nStorybook 调试#\n\n当我们想要对组件或者普通模块进行调试的时候,可以启用 Storybook 调试功能。启动该功能后,会在项目目录下创建 stories 目录以及相关文件,在\npackage.json 中新增 \"@modern-js/plugin-storybook\" 依赖。\n\nTIP\n\n在成功开启后,会提示需要手动在配置中增加如下类似的代码。\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), storybookPlugin()],\n});\n\n\n关于如何启动 Storybook 以及如何使用 Storybook,可以查看下面的链接:\n\n * modern dev\n * 使用 Storybook\n\n\nTailwind CSS 支持#\n\nTailwind CSS 是一个以 Utility Class 为基础的 CSS 框架和设计系统,可以快速地为组件添加常用样式,同时支持主题样式的灵活扩展。\n\n如果你想要在项目使用 Tailwind CSS,可以参考 「使用 Tailwind CSS」。\n\n\nModern.js Runtime API 支持#\n\nModern.js 提供了 Runtime API 能力,这些 API 只能在 Modern.js 的应用项目环境中使用。如果你需要开发一个 Modern.js\n应用环境中使用的组件,那么你可以开启该特性,微生成器会增加 \"@modern-js/runtime\"依赖。\n\n另外,Storybook 调试工具也会通过检测项目的依赖确定项目是否需要使用 Runtime API,并且提供与 Modern.js 应用项目一样的\nRuntime API 运行环境。\n\nTIP\n\n在成功开启后,会提示需要手动在配置中增加如下类似的代码。\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), runtime()],\n});\n","frontmatter":{"sidebar_position":4},"version":""},{"id":70,"title":"使用 Storybook","routePath":"/module-tools/guide/basic/using-storybook","lang":"zh","toc":[{"text":"调试代码","id":"调试代码","depth":2,"charIndex":292},{"text":"引用组件产物","id":"引用组件产物","depth":3,"charIndex":491},{"text":"引用组件源码","id":"引用组件源码","depth":3,"charIndex":1862},{"text":"配置 Storybook","id":"配置-storybook","depth":2,"charIndex":2277},{"text":"构建 Storybook 产物","id":"构建-storybook-产物","depth":2,"charIndex":2686},{"text":"结合 Tailwind CSS 使用","id":"结合-tailwind-css-使用","depth":2,"charIndex":2901}],"domain":"","content":"#\n\n首先如果没有看过以下内容的话,可以先花几分钟先了解一下:\n\n * 使用微生成器开启 Storybook 调试\n * modern dev\n\nStorybook 是一个专门用于组件调试的工具,它围绕着组件开发提供了:\n\n * 丰富多样的调试能力\n * 可与一些测试工具结合使用\n * 可重复使用的文档内容\n * 可分享能力\n * 工作流程自动化\n\n因此 Storybook 是一个复杂且功能强大的工具。\n\nModern.js Module 集成了 Storybook,因此你几乎可以按照 Storybook\n官方文档的内容进行使用。不过依然有一些地方需要注意,接下来讲解一下。\n\n\n调试代码#\n\n在调试代码过程中需要引入项目代码,目前可以通过两种方式引入项目代码:\n\n * 引用项目产物\n * 引用项目源码\n\n我们推荐使用第一种“引用项目产物”的方式。因为它更接近真实的使用场景,不仅可以对组件功能进行调试,同时也对构建产物的正确性进行了验证。不过我们也可以在测试项目功\n能的时候引用源码,在验证项目产物的时候引用项目的包名。\n\n接下来我们分别讲一下这两种方式具体如何使用。\n\n\n引用组件产物#\n\n假如存在 TypeScript 项目 foo,首先要确保 package.json 的 main 和 types 的值为正确的产物路径。\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/types/index.d.ts\"\n}\n\n\nfoo 项目的源码:\n\nexport const content = 'hello world';\n\n\n请确保在 stories/tsconfig.json 中设置了指向项目根目录的 paths 配置。paths 的 key\n与项目名称相同,这样在编译过程中以及在代码中不会出现问题。\n\n{\n \"extends\": \"../tsconfig.json\",\n \"compilerOptions\": {\n \"baseUrl\": \"../\",\n \"paths\": {\n \"foo\": [\".\"],\n \"foo/*\": [\"./*\"]\n }\n },\n \"include\": [\"**/*\"]\n}\n\n\n在 Story 代码中直接以项目名称的方式引用:\n\n\n\nconst Component = () => \nthis is a Story Component {content};\n\nexport const YourStory = () => ;\n\nexport default {\n title: 'Your Stories',\n};\n\n\n最后在执行命令的时候,先启动监听模式的源码构建,然后启动 Storybook 调试即可:\n\n## 源码构建\nmodern build --watch\n\n\n## Storybook 调试\nmodern dev storybook\n\n\nINFO\n\n在开发过程中,可能会遇到无法实时获得类型定义的情况。因为只有当保存代码后,产物目录下的类型文件才会更新。此时:\n\n对于 pnpm 的项目,可以按照下面的内容对 package.json 进行修改:\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./src/index.ts\",\n \"publishConfig\": {\n \"types\": \"./dist/index.d.ts\",\n }\n}\n\n\n> 关于 pnpm 的 publishConfig 的使用,可以阅读下面这个链接。\n\n而对于 npm 和 Yarn 的项目,则只能通过手动的方式在开发阶段和发布阶段对 package.json 的 types 的值进行修改。\n\n那么为什么可以直接引用产物呢?\n\n 1. 在执行 modern dev storybook 命令之前,执行 modern build --watch 命令,保证项目构建产物的存在。\n 2. 在 Storybook 内部增加了根据 tsconfig.json 文件的 compilerOptions.paths 配置或者(在 JS\n 项目中)直接以项目名称作为别名的处理逻辑,保证能够根据 package.json 解析出项目的产物路径。\n\n\n引用组件源码#\n\n引用组件的源码可以通过相对路径的方式:\n\n\n\nconst Component = () => \nthis is a Story Component {content};\n\nexport const YourStory = () => ;\n\nexport default {\n title: 'Your Stories',\n};\n\n\n为什么不推荐使用源码的方式?\n\n不仅仅是因为使用组件源码无法验证组件产物是否正确,同时 Modern.js Module 对于构建产物支持的一些配置无法完全转换为 Storybook\n内部的配置。如果某些配置无法进行相互转换的话,就会在 Storybook 调试过程中出现不符合预期的结果。\n\nModern.js Module 是基于 esbuild 实现的,而 Storybook 是基于 Webpack 实现的。esbuild 的配置无法与\nWebpack 完全兼容。\n\n\n配置 Storybook#\n\nStorybook 官方通过一个名为 .storybook 的文件夹来进行项目配置,其中包含各种配置文件。在 Modern.js Module 中,可以在项目的\nconfig/storybook 目录下增加 Storybook 配置文件。\n\n关于 Storybook 各种配置文件的使用方式,可以查看下面的链接:\n\n * Configure Storybook\n\n不过在模块项目里进行 Storybook 存在一些限制:\n\n * 目前不能修改 Story 文件存放的位置,即无法在 main.js 文件里修改 stories 配置。\n * 目前不能修改 Webpack 和 Babel 相关的配置,即无法在 main.js 文件里修改 webpackFinal 和 babel 配置。\n\n在未来我们会考虑这些配置是否可以允许修改,不过目前为了减少不可预知的问题暂时限制使用这些配置。\n\n\n构建 Storybook 产物#\n\n除了可以对组件或者普通的模块进行 Storybook 调试,还可以通过下面的命令来执行 Storybook 的构建任务。\n\nmodern build --platform storybook\n\n\n关于 modern build --platform 命令可以查看:\n\n * modern build\n\n构建完成后,可以在 dist/storybook-static 目录看到构建产物文件。\n\n\n结合 Tailwind CSS 使用#\n\n如果你需要在 stories 目录下使用 Tailwind CSS,请确保当前项目的 Tailwind CSS 配置中包含了 stories 目录。\n\n以 tailwind.config.ts 文件为例,你需要配置以下内容:\n\nexport default {\n content: [\n './src/**/*.{js,jsx,ts,tsx}',\n+ './stories/**/*.{js,jsx,ts,tsx}',\n ],\n};\n","frontmatter":{"sidebar_position":5},"version":""},{"id":71,"title":"开发组件","routePath":"/module-tools/guide/best-practices/components","lang":"zh","toc":[{"text":"初始化项目","id":"初始化项目","depth":2,"charIndex":40},{"text":"使用 Storybook 调试代码","id":"使用-storybook-调试代码","depth":2,"charIndex":513},{"text":"开发样式","id":"开发样式","depth":2,"charIndex":574},{"text":"CSS/PostCSS","id":"csspostcss","depth":3,"charIndex":682},{"text":"Less","id":"less","depth":3,"charIndex":1192},{"text":"Sass/Scss","id":"sassscss","depth":3,"charIndex":1445},{"text":"Tailwind CSS","id":"tailwind-css","depth":3,"charIndex":1728},{"text":"CSS Modules","id":"css-modules","depth":3,"charIndex":1776},{"text":"配置构建产物","id":"配置构建产物","depth":2,"charIndex":2090},{"text":"测试组件","id":"测试组件","depth":2,"charIndex":2571},{"text":"发布组件","id":"发布组件","depth":2,"charIndex":2605}],"domain":"","content":"#\n\n本章将要介绍如何使用 Modern.js Module 开发组件项目。\n\n\n初始化项目#\n\n 1. 推荐使用 @modern-js/create 命令来初始化一个 npm 项目。\n\nnpx @modern-js/create@latest components-project\n\n? 请选择你想创建的工程类型:Npm 模块\n? 请填写项目名称:components-demo\n? 请选择开发语言:TS\n? 请选择包管理工具:pnpm\n\n\n 2. 初始化的目录结构如下:\n\n.\n├── README.md\n├── node_modules/\n├── dist/\n├── modern.config.ts\n├── package.json\n├── pnpm-lock.yaml\n├── src\n│ ├── index.ts\n│ └── modern-app-env.d.ts\n└── tsconfig.json\n\n\n 3. 最后修改 ./src/index.ts 文件后缀和内容如下,就完成了组件项目的初始化。\n\nexport default () => {\n return \nhello world;\n};\n\n\n\n使用 Storybook 调试代码#\n\n请参考 「使用 Storybook」 来使用 Storybook 调试代码。\n\n\n开发样式#\n\n接下来我们可以给组件添加样式。\n\n目前支持开发样式的能力有:\n\n * CSS/PostCSS\n * Less\n * Scss/Sass\n * Tailwind CSS\n * CSS Modules\n\n\nCSS/PostCSS#\n\nModern.js Module 支持 PostCSS,并且内置了以下 PostCSS 插件:\n\n * flexbugs-fixes\n * custom-properties\n * initial\n * page-break\n * font-variant\n * media-minmax\n * nesting\n\n因此我们可以在项目中创建 .css 文件,并且可以直接在 css 文件中使用这些插件提供的语法支持和能力。\n\n * 源代码:\n\na,\nb {\n color: red;\n\n /* \"&\" comes first */\n & c,\n & d {\n color: white;\n }\n\n /* \"&\" comes later, requiring \"@nest\" */\n @nest e & {\n color: yellow;\n }\n}\n\n\n * CSS 产物:\n\na,\nb {\n color: red;\n}\na c,\nb c,\na d,\nb d {\n color: white;\n}\ne a,\ne b {\n color: yellow;\n}\n\n\n\nLess#\n\nModern.js Module 支持使用 Less 开发样式。\n\n> 目前内置的 Less 版本为 v4.1.3\n\n * 源代码:\n\n@bg: black;\n@bg-light: boolean(luma(@bg) > 50%);\n\ndiv {\n background: @bg;\n color: if(@bg-light, black, white);\n}\n\n\n * Less 产物:\n\ndiv {\n background: black;\n color: white;\n}\n\n\n\nSass/Scss#\n\nModern.js Module 支持使用 Scss/Sass 开发样式。\n\n> 目前内置的 Sass 版本为 v1.54.4\n\n * 源代码:\n\n$font-stack: Helvetica, sans-serif;\n$primary-color: #333;\n\nbody {\n font: 100% $font-stack;\n color: $primary-color;\n}\n\n\n * Sass 产物:\n\nbody {\n font: 100% Helvetica, sans-serif;\n color: #333;\n}\n\n\n\nTailwind CSS#\n\n请参考 「使用 Tailwind CSS」 来了解相关用法。\n\n\nCSS Modules#\n\nModern.js Module 支持使用 CSS Module 开发样式。默认情况下会将以下文件识别为 CSS Module 文件:\n\n * .module.css\n * .module.less\n * .module.scss\n * .module.sass\n\n如果需要对 CSS Modules 进行配置,可以查看以下 API:\n\n * style.autoModules\n * style.modules\n\n下面是一个代码示例:\n\n\n\nexport default () => {\n return \nhello world;\n};\n\n\n.btn {\n color: blue;\n}\n\n\n\n配置构建产物#\n\n根据组件项目使用的多数场景,推荐使用 npm-component 构建预设。该预设得到的产物目录结构为:\n\n.\n├── dist\n│ ├── es\n│ ├── lib\n│ └── types\n\n\n * ./dist/es: 包含了支持 es6 语法的 ES modules 格式的 bundleless 产物。\n * ./dist/lib: 包含了支持 es6 语法的 CommonJS 格式的 bundleless 产物。\n * ./dist/types: 包含了类型文件。\n\n如果对使用语法支持有要求,可以手动配置 buildPreset,并且支持在 npm-component 基础上增加后缀的方式修改支持的语法:\n\nexport default defineConfig({\n buildPreset: 'npm-component-es2019',\n});\n\n\n如果对构建产物目录结构有特殊需求,则可以使用 buildConfig API,可以通过以下文档来了解使用方式:\n\n * 修改输出产物\n * 深入理解构建\n\n\n测试组件#\n\n关于如何对组件进行测试,可以参考 「测试项目」。\n\n\n发布组件#\n\n推荐使用 Modern.js Module 提供的版本发布功能,可以参考 「版本管理与发布」。","frontmatter":{"sidebar_position":1},"version":""},{"id":72,"title":"使用 Tailwind CSS","routePath":"/module-tools/guide/best-practices/use-tailwindcss","lang":"zh","toc":[{"text":"启用 Tailwind CSS","id":"启用-tailwind-css","depth":2,"charIndex":127},{"text":"配置 Tailwind CSS","id":"配置-tailwind-css","depth":2,"charIndex":962},{"text":"Tailwind CSS 自动补全","id":"tailwind-css-自动补全","depth":2,"charIndex":1608},{"text":"构建模式","id":"构建模式","depth":2,"charIndex":1921},{"text":"Bundle 模式","id":"bundle-模式","depth":3,"charIndex":2038},{"text":"Bundleless 模式","id":"bundleless-模式","depth":3,"charIndex":2627},{"text":"类名前缀","id":"类名前缀","depth":2,"charIndex":2837},{"text":"用法介绍","id":"用法介绍","depth":2,"charIndex":3222},{"text":"HTML 类名","id":"html-类名","depth":3,"charIndex":3257},{"text":"@apply","id":"apply","depth":3,"charIndex":3568},{"text":"Sass","id":"sass","depth":4,"charIndex":3756},{"text":"Less","id":"less","depth":4,"charIndex":3953},{"text":"关于 designSystem 配置","id":"关于-designsystem-配置","depth":2,"charIndex":4467}],"domain":"","content":"#\n\nTailwind CSS 是一个以 Utility Class 为基础的 CSS 框架和设计系统,可以快速地为组件添加常用样式,同时支持主题样式的灵活扩展。\n\nModern.js Module 支持使用 Tailwind CSS 开发组件样式。\n\n\n启用 Tailwind CSS#\n\n在 Modern.js Module 中使用 Tailwind CSS,你只需要按照以下步骤操作:\n\n 1. 在项目根目录下执行 pnpm run new,按照如下进行选择:\n\n? 请选择你想要的操作 启用可选功能\n? 请选择功能名称 启用 「Tailwind CSS」 支持\n\n\n成功开启后,会看到 package.json 中新增了依赖:\n\n{\n \"dependencies\": {\n \"tailwindcss\": \"^3.0.0\"\n },\n \"devDependencies\": {\n \"@modern-js/plugin-tailwindcss\": \"^2.0.0\"\n }\n}\n\n\n 2. 在 modern.config.ts 中注册 Tailwind 插件:\n\n\n\nexport default defineConfig({\n plugins: [..., tailwindcssPlugin()],\n});\n\n\n 3. 创建 index.css 文件,添加以下代码:\n\n/* base 和 components 是可选的,请酌情添加 */\n@tailwind base;\n@tailwind components;\n@tailwind utilities;\n\n\nINFO\n\n根据需求不同,你可以选择性地导入 Tailwind CSS 提供的 CSS 样式。请参考 @tailwind 文档 来了解 @tailwind 指令的详细用法。\n\n 4. 引用 index.css 文件,比如在入口的 src/index.jsx 文件添加如下代码:\n\nimport './index.css';\n\n\n 5. 然后即可在各个组件中使用 Tailwind CSS 提供的 Utility Class 了:\n\nconst Hello = () => (\n \n\n \n\nhello world\n \n);\n\n\n\n配置 Tailwind CSS#\n\n在 Modern.js Module 中,你有两种方式来配置 Tailwind CSS:\n\n 1. 使用 tailwind.config.{ts,js} 文件,该用法与 Tailwind CSS 的官方用法一致,请参考 \"Tailwind CSS -\n Configuration\" 来了解更多用法。\n\n\n\nexport default {\n content: ['./src/**/*.{js,jsx,ts,tsx}'],\n} as Config;\n\n\nTIP\n\n请升级 Modern.js Module 到 >= 2.33.0 版本,以支持自动读取 tailwind.config.{ts,js} 文件。\n\n 2. 使用 style.tailwindcss 配置项,这是旧版本的用法,我们更推荐使用 tailwind.config.{ts,js} 文件进行配置。\n\nexport default {\n style: {\n tailwindcss: {\n content: ['./src/**/*.{js,jsx,ts,tsx}'],\n },\n },\n};\n\n\n如果你同时使用了 tailwind.config.{ts,js} 文件和 style.tailwindcss 选项,那么 style.tailwindcss\n定义的配置会优先生效,并覆盖 tailwind.config.{ts,js} 中定义的内容。\n\n\nTailwind CSS 自动补全#\n\nTailwind CSS 官方提供了 Tailwind CSS IntelliSense 插件,用于在 VS Code 中自动补全 Tailwind CSS 的\nclass names、CSS functions 和 directives。\n\n你可以参考以下步骤来启动自动补全功能:\n\n 1. 在 VS Code 中安装 Tailwind CSS IntelliSense 插件。\n 2. 如果项目的根目录没有 tailwind.config.{ts,js} 文件,那么你需要创建该文件,并写入当前项目的 Tailwind CSS 配置,否则\n IDE 插件将无法正确生效。\n\n\n构建模式#\n\n在使用 Tailwind CSS 时,请注意构建产物在 bundle 和 bundleless 两种模式下会有很大区别。\n\nTIP\n\n关于 bundle 和 bundleless 的定义,可以查看 「深入理解构建」\n\n\nBundle 模式#\n\n在 Bundle 模式下,会生成一份单独的产物 CSS 文件,并且 JS 产物不会自动引用产物 CSS 文件。\n\n * 源代码:\n\nimport './index.css';\n\nexport default () => {\n return \nhello world;\n};\n\n\n * 产物代码:\n\n// src/index.tsx\n\nvar src_default = () => {\n return /* @__PURE__ */ jsx('div', {\n className: 'bg-black',\n children: 'hello world',\n });\n};\nexport { src_default as default };\n\n\n.bg-black {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity));\n}\n/** some more... */\n\n\n如果你需要将样式注入 JS 产物中,可以开启 style.inject 选项。\n\n如果你没有开启 style.inject,那么也可以让用户手动引用产物 CSS 文件:\n\nimport 'your-package/dist/es/index.css';\n\n\n\nBundleless 模式#\n\n在 Bundleless 模式下,默认会引用产物 CSS 文件,无须进行额外处理。\n\n * 产物代码:\n\n\nimport './index.css';\nexport default () =>\n /* @__PURE__ */ _jsx('div', {\n className: 'bg-black',\n children: 'hello world',\n });\n\n\n\n类名前缀#\n\n你可以通过 Tailwind CSS 提供的 prefix 选项来添加类名前缀,这样可以避免潜在的类名冲突问题(比如 App 和 Module 使用了不同版本的\nTailwind CSS)。\n\n例如,通过 prefix 选项添加 foo- 前缀:\n\nmodule.exports = {\n prefix: 'foo-',\n};\n\n\n * 源代码:\n\nimport './index.css';\n\nexport default () => {\n return \nhello world;\n};\n\n\n * 产物代码:\n\n.foo-bg-black {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity));\n}\n/** some more... */\n\n\n\n用法介绍#\n\n下面是一些 Tailwind CSS 的用法示例。\n\n\nHTML 类名#\n\nTailwind CSS 支持在 HTML 标签上通过类名的方式增加样式。当使用 HTML 类名的时候,请注意必须要提前导入 Tailwind CSS 相应的\nCSS 样式。\n\nimport './index.css';\n\nexport default () => {\n return \nhello world;\n};\n\n\n样式产物(此时是 bundle 构建):\n\n.bg-black {\n --tw-bg-opacity: 1;\n background-color: rgba(0, 0, 0, var(--tw-bg-opacity));\n}\n/** some more... */\n\n\n\n@apply#\n\nTailwind CSS 提供了 @apply 指令,可以通过它将 Tailwind CSS 提供的样式内联到我们编写的样式中。\n\n@apply 可以用于 CSS、Less、Sass 中。\n\n.btn {\n @apply font-bold py-2 px-4 rounded;\n}\n\n\n但是使用过程中,对于 Less 和 Sass 有些情况需要注意:\n\nSass#\n\n当将 Tailwind 与 Sass 一起使用时,@apply 后面存在 !important 的时候,需要使用插值来让 Sass 正确编译。\n\n * 不能正常工作:\n\n.alert {\n @apply bg-red-500 !important;\n}\n\n\n * 能够正常工作:\n\n.alert {\n @apply bg-red-500 #{!important};\n}\n\n\nLess#\n\n在与 Less 一起使用 Tailwind 时,你不能嵌套 Tailwind 的 @screen 指令。\n\n * 不能正常工作:\n\n.card {\n @apply rounded-none;\n\n @screen sm {\n @apply rounded-lg;\n }\n}\n\n\n * 相反,使用常规的媒体查询和 theme() 函数来引用你的屏幕尺寸,或者干脆不要嵌套你的 @screen 指令。\n\n// Use a regular media query and theme()\n.card {\n @apply rounded-none;\n\n @media (min-width: theme('screens.sm')) {\n @apply rounded-lg;\n }\n}\n\n\n// Use the @screen directive at the top-level\n.card {\n @apply rounded-none;\n\n @media (min-width: theme('screens.sm')) {\n @apply rounded-lg;\n }\n}\n\n\n\n关于 designSystem 配置#\n\ndesignSystem 是 Modern.js Module 中废弃的配置项。\n\n从 Modern.js Module v2.33.0 版本开始,你可以使用 Tailwind CSS 的 theme 配置项来代替\ndesignSystem,不再需要将 theme 配置拆分并设置到 designSystem 上。\n\n * 旧版本用法:\n\nconst { theme, ...rest } = tailwindConfig;\n\nexport default {\n style: {\n tailwindcss: rest,\n },\n designSystem: theme,\n};\n\n\n * 当前版本用法:\n\nexport default {\n style: {\n tailwindcss: tailwindConfig,\n },\n};\n","frontmatter":{"sidebar_position":2},"version":""},{"id":73,"title":"构建相关问题","routePath":"/module-tools/guide/faq/build","lang":"zh","toc":[{"text":"产物问题","id":"产物问题","depth":2,"charIndex":3},{"text":"Class Fields 的初始化处理","id":"class-fields-的初始化处理","depth":3,"charIndex":11},{"text":"babel-plugin-lodash 将引入的 lodash 处理成 undefined","id":"babel-plugin-lodash-将引入的-lodash-处理成-undefined","depth":3,"charIndex":1315},{"text":"异常类问题","id":"异常类问题","depth":2,"charIndex":1722},{"text":"Dynamic require of \\\"react\\\" is not supported","id":"dynamic-require-of-react-is-not-supported","depth":3,"charIndex":-1},{"text":"问题描述","id":"问题描述","depth":4,"charIndex":1777},{"text":"解决办法","id":"解决办法","depth":4,"charIndex":1952},{"text":"参考链接","id":"参考链接","depth":4,"charIndex":2246},{"text":"编译过程中,因为某个组件库的 less 文件报错:\\'Operation on an invalid type\\'","id":"编译过程中因为某个组件库的-less-文件报错operation-on-an-invalid-type","depth":3,"charIndex":-1},{"text":"Bundle DTS failed","id":"bundle-dts-failed","depth":3,"charIndex":3439},{"text":"defineConfig 函数类型报错:如果没有引用 \\\"...\\\",则无法命名 \\\"default\\\" 的推断类型","id":"defineconfig-函数类型报错如果没有引用-则无法命名-default-的推断类型","depth":3,"charIndex":-1},{"text":"其他","id":"其他","depth":2,"charIndex":3873},{"text":"增加额外的编译能力","id":"增加额外的编译能力","depth":3,"charIndex":3879},{"text":"支持生成 CSS Modules 的 TypeScript 声明文件","id":"支持生成-css-modules-的-typescript-声明文件","depth":3,"charIndex":4370}],"domain":"","content":"#\n\n\n产物问题#\n\n\nClass Fields 的初始化处理#\n\nTypeSript 提供了 useDefineForClassFields 配置用于控制对于 public class fields 的转换处理。\n\n如果有一段代码:\n\nclass C {\n foo = 100;\n bar: string;\n}\n\n\n当 useDefineForClassFields 为 false 的时候,则编译后的代码会变为:\n\nclass C {\n constructor() {\n this.foo = 100;\n }\n}\n\n\n当 useDefineForClassFields 为 true 的时候,则编译后的代码会变为:\n\nclass C {\n constructor() {\n Object.defineProperty(this, 'foo', {\n enumerable: true,\n configurable: true,\n writable: true,\n value: 100,\n });\n Object.defineProperty(this, 'bar', {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0,\n });\n }\n}\n\n\n同时该配置的默认值会根据 tsconfig.json 的 target 配置而变化:当 target 是 ES2022 或者更高的时候,则\nuseDefineForClassFields 默认配置为 true,否则就是默认为 false。\n\n关于 TypeScript 这个配置的更多信息,可以参考下面的链接:\n\n * The useDefineForClassFields Flag and The declare Property Modifier\n\nModern.js Module 目前会根据下面的逻辑进行处理:\n\n 1. 首先根据当前项目的 tsconfig.json 的 useDefineForClassFields 配置确定在 Modern.js Module\n 内部如何处理。目前只会读取当前项目路径下的 tsconfig.json 文件的内容,暂时不支持根据 extends 配置来获取最终的 tsconfig\n 配置。\n 2. 如果没有检测 tsconfig.json 的 useDefineForClassFields 配置,则会根据 tsconfig.json 的\n target 配置来确定默认值。如果 target 大于 ES2022(包含 EsNext),则useDefineForClassFields默认为\n true,否则为 false。\n 3. 如果没有检测到 tsconfig.json 的 target,则按照 useDefineForClassFields的值 为 true 进行处理。\n\n\nbabel-plugin-lodash 将引入的 lodash 处理成 undefined#\n\n当使用类似下面的方式的时候,会出现这个问题:\n\n\n\nexport const libs = {\n _: Lodash,\n};\n\n\n目前在 babel-plugin-lodash Github 上的相关 Issue:\n\n * #235\n\n这个问题的解决办法是移除 babel-plugin-lodash,因为此时不需要该插件进行按需引用,使用该插件会产生副作用。\n\n类似的情况在 babel-plugin-import 上也可能会出现。比如有类似如下的代码:\n\n\n\nexport const libs = {\n comps: Comps,\n};\n\n\n此时 babel-plugin-import 也可能会导致 Comps 变为 undefined。因此也需要移除对应的 babel-plugin-import。\n\n\n异常类问题#\n\n\nDynamic require of \"react\" is not supported#\n\n问题描述#\n\n当构建的产物配置中产物格式为 ES modules 的时候:\n\nexport default defineConfig({\n buildConfig: {\n format: 'esm',\n },\n});\n\n\n如果导入了的第三方 npm 包的 cjs 产物,那么生成的产物可能会在 webpack 下有可能无法正常运行。\n\n\n\n解决办法#\n\n 1. 首先需要找到是哪个第三方包引起的问题。例如报错信息中指向了 react 这个包,那么就要寻找在哪个第三方包里存在 require('react')\n 这样的代码。比如 react-draggable ,这个包仅包含 cjs 产物,那么问题定位到 react-draggable 这个包。\n 2. 然后我们需要将这个包通过下面的配置进行排除,即不打包存在问题的第三方包。\n\nexport default defineConfig({\n buildConfig: {\n externals: ['react-draggable'],\n },\n});\n\n\n参考链接#\n\n * When using esbuild with external react I get Dynamic require of \"react\" is\n not supported\n\n\n编译过程中,因为某个组件库的 less 文件报错:'Operation on an invalid type'#\n\n可能是因为该组件库依赖的 Less 版本是 v3,而 Modern.js Module 默认是 v4。v3 与 v4 在 math 配置上存在有 Break\nChange,可以查看这个链接 了解详情。\n\n因此,如果是在源码中使用了类似这样的组件库:\n\n在构建配置中使用了 buildPreset 的情况下,按照下面进行修改:\n\nmodule.exports = {\n buildPreset({ extendPreset }) {\n return extendPreset('your-build-preset', {\n style: {\n less: {\n lessOptions: {\n math: 'always',\n },\n },\n },\n });\n },\n};\n\n\n或者使用了自定义的 buildConfig 的情况下,按照下面进行修改:\n\nmodule.exports = {\n buildConfig: {\n style: {\n less: {\n lessOptions: {\n math: 'always',\n },\n },\n },\n },\n};\n\n\n如果是在 Storybook 中使用了类似这样的组件,则需要修改 Storybook 的调试配置:\n\nmodule.exports = {\n dev: {\n storybook: {\n webpackChain(chain, { CHAIN_ID }) {\n chain.module\n .rule(CHAIN_ID.RULE.LESS)\n .use(CHAIN_ID.USE.LESS)\n .tap(options => {\n options.lessOptions = {\n ...options.lessOptions,\n math: 'always',\n };\n return options;\n });\n },\n },\n },\n};\n\n\n\nBundle DTS failed#\n\n正常情况下,使用 tsc Modern.js Module\n不仅支持输出松散的类型文件产物,同时也支持打包类型文件,可以将这些松散的类型文件以及第三方依赖的类型文件打包成一个文件。\n\n不过,打包第三方依赖的类型文件是存在风险的,因为存在第三方依赖的类型文件无法打包的情况。\n\n因此当遇到 Modern.js Module 构建过程中出现 Bundle DTS failed\n的错误信息标题的时候,可以观察报错信息是来自某个第三方依赖。尝试设置 dts.respectExternal 为 false\n来关闭打包第三方依赖的类型文件的行为。\n\n\ndefineConfig 函数类型报错:如果没有引用 \"...\",则无法命名 \"default\" 的推断类型#\n\n检查项目的 tsconfig.json 文件中是否存在 include 配置,如果没有,则尝试增加下面的内容:\n\n{\n \"include\": [\"src\"]\n}\n\n\n\n其他#\n\n\n增加额外的编译能力#\n\nModern.js Module 基于 esbuild 实现,因此如果有特殊需求或者想要增加额外的编译能力,可以通过实现 esbuild 插件来解决。\n\nModern.js Module 提供了 esbuildOptions 配置允许修改 Modern.js Module 内部的 esbuild\n配置,因此可以通过该配置来增加自定义的 esbuild 插件:\n\n\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.plugins = [myEsbuildPlugin, ...options.plugins];\n return options;\n },\n },\n});\n\n\n在增加 esbuild 插件时,请注意你需要将插件加在 plugins 数组的头部,因为 Modern.js Module 内部也是通过一个 esbuild\n插件介入到整个构建流程中去的,因此需要将自定义插件优先注册。\n\n\n支持生成 CSS Modules 的 TypeScript 声明文件#\n\n * 方案一:typed-css-modules\n * 方案二:postcss-modules-dts\n\n\n\nexport default defineConfig(async () => {\n const { dts } = await import(\"@guanghechen/postcss-modules-dts\");\n return {\n buildConfig: {\n style: {\n modules: { ...dts },\n },\n },\n // 你的自定义配置\n }\n});\n","frontmatter":{},"version":""},{"id":74,"title":"常见问题","routePath":"/module-tools/guide/faq/","lang":"zh","toc":[],"domain":"","content":"#\n\n这里是 Modern.js Module 常见问题分类列表:\n\n * 代码构建相关的问题\n * 测试相关的问题\n * Storybook 相关的问题","frontmatter":{},"version":""},{"id":75,"title":"Storybook 相关问题","routePath":"/module-tools/guide/faq/storybook","lang":"zh","toc":[{"text":"支持 Storybook v7","id":"支持-storybook-v7","depth":2,"charIndex":3},{"text":"使用 Storybook Addon 或者其他配置不生效","id":"使用-storybook-addon-或者其他配置不生效","depth":2,"charIndex":102},{"text":"Cannot find module \\'react-dom/package.json","id":"cannot-find-module-react-dompackagejson","depth":2,"charIndex":-1},{"text":"报错后,看不到具体报错信息","id":"报错后看不到具体报错信息","depth":2,"charIndex":534},{"text":"Couldn\\'t find any stories is your Storybook","id":"couldnt-find-any-stories-is-your-storybook","depth":2,"charIndex":-1},{"text":"Storybook 添加 Proxy 功能","id":"storybook-添加-proxy-功能","depth":2,"charIndex":1411},{"text":"修改存在 Story 文件的目录","id":"修改存在-story-文件的目录","depth":2,"charIndex":2095}],"domain":"","content":"#\n\n\n支持 Storybook v7#\n\nStorybook v7 目前还没支持,目前计划在 Storybook v7 中支持 Rspack 构建,因此进度会慢一些。 相关 Issue:#3376。\n\n\n使用 Storybook Addon 或者其他配置不生效#\n\nModern.js Module 目前使用的 Storybook 版本是 v6,如果使用了 v7 版本的 Addon 可能会出现插件不生效的情况。\n\n除了 Addon 以外,其他配置也可能会有区别。比如修改 preview.js 配置文件的话,Storybook v6 与 v7 的写法也不相同:\n\n * v6:文档链接\n * v7:文档链接\n\n\nCannot find module 'react-dom/package.json#\n\n在执行 Storybook 调试的时候,出现下面的报错提示:\n\nERR! Error: Cannot find module 'react-dom/package.json'\n\n\n解决办法:在项目中安装 react-dom 依赖。\n\n{\n \"devDependencies\": {\n \"react-dom\": \"^17\"\n }\n}\n\n\n\n报错后,看不到具体报错信息#\n\n解决办法:\n\n 1. 找到 @storybook/core-server/dist/cjs/dev-server.js\n 2. 找到 var _await$Promise$all = await Promise.all([preview, manager 这附近的代码。\n 3. 修改成:\n\nvar _await$Promise$all = await Promise.all([\n preview.catch(e => console.info(e)),\n manager // TODO #13083 Restore this when compiling the preview is fast enough\n // .then((result) => {\n // if (!options.ci && !options.smokeTest) openInBrowser(address);\n // return result;\n // })\n .catch(previewBuilder.bail)]),\n _await$Promise$all2 = _slicedToArray(_await$Promise$all, 2),\n previewResult = _await$Promise$all2[0],\n managerResult = _await$Promise$all2[1]; // TODO #13083 Remove this when compiling the preview is fast enough\n\n\n\nCouldn't find any stories is your Storybook#\n\n\n\n当在预览区域看到类似这样的报错提示的时候,首先可以打开一下浏览器的控制台,应该会有些报错信息。可以先根据报错信息来推断是不是编写代码里出现的问题导致\nStorybook 无法正常运行。修复后,再次刷新查看是否正常。\n\n\nStorybook 添加 Proxy 功能#\n\nStorybook 没有提供相关方案,不过 Storybook Issue 中有找到相关的解决办法。在 Modern.js Module 中,你可以:\n\n 1. 添加 config/storybook/middleware.js 文件,并初始化下面的内容:\n\n/* eslint-disable filenames/match-exported */\nmodule.exports = function expressMiddleware(router) {\n // router is express router\n // \n // router = new Router();\n};\n\n\n 2. 添加 http-proxy-middleware 依赖\n 3. 添加代理路由相关配置\n\n/* eslint-disable filenames/match-exported */\nconst { createProxyMiddleware } = require(\"http-proxy-middleware\");\n\nmodule.exports = function expressMiddleware (router) {\n router.use('/api', createProxyMiddleware({\n target: \"http://localhost:8000\",\n changeOrigin: true\n }))\n}\n\n\n相关 issue 链接:#11551。\n\n\n修改存在 Story 文件的目录#\n\n目前暂时无法修改存放 Story 文件的目录,仅对 your-project/stories 目录下的\n*.stories.(t|j)s(x)、*.stories.md(x) 文件识别为 Story 文件。","frontmatter":{},"version":""},{"id":76,"title":"测试相关问题","routePath":"/module-tools/guide/faq/test","lang":"zh","toc":[{"text":"执行 test 命令报错 TypeError: Cannot read property \\'testEnvironmentOptions\\' of undefined","id":"执行-test-命令报错-typeerror-cannot-read-property-testenvironmentoptions-of-undefined","depth":2,"charIndex":-1}],"domain":"","content":"#\n\n\n执行 test 命令报错 TypeError: Cannot read property 'testEnvironmentOptions' of\nundefined#\n\n\n\n问题原因多是存在多个版本的 jest-environment-jsdom 依赖,可以检查 Monorepo 中其他项目是否有\njest-environment-jsdom 依赖,并通过 Monorepo 提供的 overrides 能力统一依赖版本。","frontmatter":{},"version":""},{"id":77,"title":"快速开始","routePath":"/module-tools/guide/intro/getting-started","lang":"zh","toc":[{"text":"三分钟快速上手","id":"三分钟快速上手","depth":2,"charIndex":3},{"text":"创建新项目","id":"创建新项目","depth":3,"charIndex":111},{"text":"接入已有项目","id":"接入已有项目","depth":3,"charIndex":516},{"text":"核心 npm 包","id":"核心-npm-包","depth":3,"charIndex":1013},{"text":"查看官方示例","id":"查看官方示例","depth":3,"charIndex":1411},{"text":"让我们开始吧","id":"让我们开始吧","depth":2,"charIndex":1669}],"domain":"","content":"#\n\n\n三分钟快速上手#\n\n想要实际体验 Modern.js Module?首先你需要安装 Node.js LTS,并确保 Node 版本大于等于 14.18.0。我们推荐使用\nNode.js 18 的 LTS 版本。\n\n\n创建新项目#\n\n如果你想要创建一个完整的 Modern.js Module 项目,可以执行以下命令:\n\nnpx @modern-js/create your-project-dir-name\n\n\nINFO\n\n执行 npx @modern-js/create -h 查看更多命令行参数\n\n接着在问题交互中,按照如下选择:\n\n? 请选择你想创建的工程类型:Npm 模块\n? 请填写项目名称:library\n? 请选择开发语言:TS\n? 请选择包管理工具:pnpm\n\n\n> 项目名称为 package.json 中的 \"name\" 字段值。\n\n接着就会开始初始化项目的流程。在项目目录和文件生成以及依赖安装完毕后,此时就创建了一个完整的 Modern.js Module 项目。\n\n我们可以直接执行 pnpm build 命令启动项目的构建,执行 pnpm build --watch 命令开启构建的观察模式。\n\n\n接入已有项目#\n\n在你的项目里安装以下依赖:\n\n * \"@modern-js/module-tools\"\n\n * \"typescript\"(如果不是 TypeScript 项目,则省略)\n\n> 对于使用 pnpm 或者 Yarn 包管理器的项目,只需要替换 npm 就可以了。推荐使用 pnpm。\n\n接着在项目的根目录下创建 modern.config.(t|j)s 文件:\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n});\n\n\n最后在项目的 package.json 文件里增加命令 \"build\": \"modern build\":\n\n{\n \"scripts\": {\n \"build\": \"modern build\"\n }\n}\n\n\n如果你的项目存在 src/index.(js|jsx) 文件或者同时存在 src/index.(ts|tsx) 和 tsconfig.json\n文件,那么恭喜你可以运行直接运行 npm run build 来使用 Modern.js Module 构建你的项目了。\n\n\n核心 npm 包#\n\n@modern-js/module-tools 是 Modern.js Module 的核心 npm 包,主要提供以下能力:\n\n * 提供 modern dev, modern build 等常用的 CLI 命令。\n * 集成 Modern.js Core,提供配置解析、插件加载等能力。\n * 集成 esbuild 和 SWC,提供构建能力。\n * 集成一些最为常用的插件,比如 plugin-lint、plugin-changeset 等。\n\n@modern-js/module-tools 是基于 Modern.js 的插件体系实现的,本质上是一个插件,因此你需要在配置文件的 plugins\n字段中注册 moduleTools:\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n});\n\n\n\n查看官方示例#\n\n如果你想要看看使用了 Modern.js Module 的完整项目,可以执行以下命令:\n\ngit clone https://github.com/web-infra-dev/module-tools-examples\ncd module-tools-example/base\n\n## 执行构建:\npnpm build\n\n## 监听模式执行构建:\npnpm build --watch\n\n## 启动 Storybook\npnpm dev storybook\n\n## 测试\npnpm test\n\n\n\n让我们开始吧#\n\n选择适合你的教程:\n\n * 我是初学者,需要学习 Modern.js Module 的基础使用。\n * 我已经初步掌握了 Modern.js Module 的使用,可以学习 Modern.js Module 的进阶指南。\n * 我需要扩展项目能力,需要学习如何开发 Modern.js Module 的插件。","frontmatter":{"sidebar_position":3},"version":""},{"id":78,"title":"欢迎使用","routePath":"/module-tools/guide/intro/welcome","lang":"zh","toc":[],"domain":"","content":"#\n\nModern.js Module 是 Modern.js\n的模块工程解决方案,同时也是核心依赖。它可以让开发者更轻松地构建、调试、发布模块类型的项目。模块类型的项目大多数情况可以认为是 npm\n包类型的项目,它可能是一个组件、组件库或者工具库项目。\n\n如果你正打算开发一个 npm 包类型的项目,那么你就来对地方了!Modern.js 提供了专业的模块工程解决方案。它带来了:\n\n * 简单的项目初始化:仅需执行 npx @modern-js/create project-dir\n 命令,然后进行几个交互问题,就可以创建一个完整的模块类型项目。创建的项目还支持选择 pnpm、Yarn 两种包管理器。\n * 代码格式化:在模块工程项目中,你可以执行 modern lint 来对代码进行格式化。同时初始化的模块工程项目里包含了 Modern.js 的\n ESLint 规则集,可以满足大部分场景下的需求。\n * 全面的构建能力和更快的构建速度:Modern.js Module 基于 esbuild 和 SWC\n 提供了高性能的构建能力,并且为不同构建模块的场景提供了丰富的配置。\n * Storybook 调试工具:Modern.js Module 为调试模块项目提供了 Storybook 调试工具。在安装了 Modern.js\n Module 的 Storybook 插件后,你可以使用 modern dev storybook 命令来启动它。你不仅可以使用 Storybook\n 对组件进行调试,也可以使用在其他类型的模块上。\n * 集成 Jest 的测试能力:在需要对模块测试的时候,可以使用 Modern.js Module 的 modern test 命令。Modern.js\n Module 不仅集成了 Jest,同时也提供了配置 Jest 的 API。\n * 基于 Changesets 实现的版本管理:当需要对项目记录变更内容的时候,可以使用 modern change 命令生成包含变更内容的 Markdown\n 文件;当需要对项目进行版本升级的时候,可以使用 modern bump 命令通过 Markdown 文件分析并升级版本;当需要发布项目的时候,可以使用\n modern release 命令对项目进行发布。Modern.js Module 基于 Changesets 实现了这些命令。\n * 可扩展性的插件机制:想要为项目集成其他的调试工具?又或者是想要在构建过程中做一些额外处理?Modern.js Module\n 提供了插件机制和插件钩子,插件钩子覆盖了 dev 命令和 build 命令两个流程。你可以通过它们为项目进行能力的扩展。\n * 还有更多:Modern.js Module\n 在未来还会不断地在构建、调试功能上进行优化。如果在模块项目构建上存在需要解决的重要问题,又或者是某个主流的模块项目调试工具、模式出现的时候,那么它们很可能\n 成为 Modern.js Module 将要支持功能。","frontmatter":{"sidebar_position":1},"version":""},{"id":79,"title":"为什么需要 Modern.js Module","routePath":"/module-tools/guide/intro/why-module-engineering-solution","lang":"zh","toc":[],"domain":"","content":"#\n\n大家可能都经历过:从零开始开发一个组件库或者工具库的过程中,我们不仅要考虑项目本身的代码逻辑如何编写,还要考虑项目的构建、调试、测试、代码格式化等等和代码逻辑无\n关的事情。\n\n比如说,当我们考虑构建模块项目的代码是使用什么构建工具的时候,在之前我们可能会考虑使用 webpack 还是 Rollup,然而现在的话,也许还会考虑是使用\nesbuild 还是 SWC。\n\n无论选择哪个构建工具,这对于没有熟练掌握这些构建工具使用方式的开发者来说,是需要一定的成本去学习的。即使想要快速使用,也会需要花费大量的时间和精力。\n\n而除了构建这件事情以外,像为项目提供调试工具、支持测试能力、增加代码格式校验等等,对于一个新手来说都有可能需要花费很长的时间和精力了解或者掌握它们,并且真正的服\n务于当前的项目中。\n\n而为了保证代码质量以及项目的完整性,我们往往是需要做这些与代码逻辑实现无关的事情。然而这些事情很有可能会影响整体的项目开发进度,降低开发者的开发体验,会让开发者\n感觉模块项目的开发门槛很高。\n\n如果说每次开发一个模块类型的项目都需要经历一遍这些工作准备的话,那么基本上刚开始开发的时间会大部分花费在这些与代码实现无关的事情上。如果能够提供一个模块工程解决\n方案,它能够帮助开发者解决项目工程上的事情,让开发者可以更专注于代码的实现上,那么这将会大大提升模块类型项目的开发体验。\n\n\n\nModern.js 为了让开发模块类型的项目更简单、解决上述提到的问题,提供了模块工程解决方案,并且通过 Modern.js Module\n提供了主要的功能。Modern.js Module 可以理解为是一个专门用于模块类型项目开发的工具。","frontmatter":{"sidebar_position":2},"version":""},{"id":81,"title":"快速开始","routePath":"/module-tools/plugins/guide/getting-started","lang":"zh","toc":[],"domain":"","content":"#\n\nModern.js Module 不仅提供了丰富的功能,同时也支持通过插件的方式为当前项目扩展能力。\n\n我们可以通过下面的例子来快速了解如何编写一个 Modern.js Module 插件:\n\n 1. 首先我们在初始化的项目下创建 ./plugins/example.ts 文件。\n\n./\n├── plugins\n│ └── example.ts\n├── src/\n└── modern.config.ts\n\n\n 2. 接着在 example.ts 文件中增加插件的代码。\n\n\n\nexport const ExamplePlugin = (): CliPlugin => {\n return {\n name: 'example',\n setup() {\n console.info('this is example plugin');\n return {\n // use hooks\n afterBuild() {\n console.info('build over');\n },\n };\n },\n };\n};\n\n\n 3. 然后我们通过 plugins API,将刚刚写好的插件进行注册。\n\n\nexport default defineConfig({\n plugins: [examplePlugin()],\n});\n\n\n 4. 最后运行 modern build,就可以看到:\n\nthis is example plugin\nBuild succeed: 510.684ms\nbuild over\n\n\n通过上面这个例子,我们了解到了下面几件事:\n\n * 推荐的插件目录结构\n * 插件的初始化代码\n * 插件的注册\n\n除了以上内容以外,我们还需要了解:\n\n * 插件对象、类型定义与推荐配置项\n * setup 函数、api 对象参数、生命周期钩子","frontmatter":{"sidebar_position":1},"version":""},{"id":82,"title":"插件对象","routePath":"/module-tools/plugins/guide/plugin-object","lang":"zh","toc":[{"text":"插件类型定义","id":"插件类型定义","depth":2,"charIndex":480},{"text":"插件配置项","id":"插件配置项","depth":2,"charIndex":745}],"domain":"","content":"#\n\nModern.js Module 的插件是一个对象,对象包含以下属性:\n\n * name:插件的名称,唯一标识符。\n * setup:插件初始化函数,只会执行一次。setup 函数可以返回一个 Hooks 对象,Modern.js Module 会在特定的时机执行 Hooks\n 对象上定义的 Hook 对应的函数。\n\n例如在下面的插件代码示例中,在项目开始执行构建任务之前会触发 beforeBuild 函数的执行,并打印 build start 的 log 内容。\n\n\n\nconst myPlugin: CliPlugin = {\n name: 'my-plugin',\n\n setup() {\n return {\n // this is hook\n beforeBuild: () => {\n console.info('build start');\n },\n };\n },\n};\n\n\n\nexport default {\n plugins: [myPlugin()],\n};\n\n\n\n插件类型定义#\n\n使用 TypeScript 时,可以引入内置的 CliPlugin 和 ModuleTools 类型,为插件提供正确的类型推导:\n\n\n\nconst myPlugin: CliPlugin = {\n name: 'my-plugin',\n\n setup() {\n const foo = '1';\n\n return {\n // this is hook\n afterBuild: () => {\n //...\n },\n };\n },\n};\n\n\n\n插件配置项#\n\n建议将插件写成函数的形式,使插件能通过函数入参来接收配置项:\n\n\n\ntype MyPluginOptions = {\n foo: string;\n};\n\nconst myPlugin = (options: MyPluginOptions): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n console.log(options.foo);\n },\n});\n","frontmatter":{"sidebar_position":2},"version":""},{"id":83,"title":"Setup 函数","routePath":"/module-tools/plugins/guide/setup-function","lang":"zh","toc":[{"text":"插件 API 对象","id":"插件-api-对象","depth":2,"charIndex":77},{"text":"api.useAppContext","id":"apiuseappcontext","depth":3,"charIndex":441},{"text":"api.useResolvedConfigContext","id":"apiuseresolvedconfigcontext","depth":3,"charIndex":823},{"text":"api.useHookRunners","id":"apiusehookrunners","depth":3,"charIndex":1198},{"text":"异步 setup","id":"异步-setup","depth":2,"charIndex":1461},{"text":"生命周期钩子","id":"生命周期钩子","depth":2,"charIndex":1731}],"domain":"","content":"#\n\n在「插件对象」 部分我们知道插件对象包含了一个 setup 函数,该函数不仅包含了一个 api 对象参数,同时还可以返回一个 Hooks 对象。\n\n\n插件 API 对象#\n\n插件的 setup 函数会提供一个 api 对象参数,你可以调用该对象上提供的一些方法来获取到配置、项目上下文等信息。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup(api) {\n // 获取应用原始配置\n const config = api.useConfigContext();\n // 获取应用运行上下文\n const appContext = api.useAppContext();\n // 获取解析之后的最终配置\n const resolvedConfig = api.useResolvedConfigContext();\n },\n});\n\n\n\napi.useAppContext#\n\n用于获取项目上下文信息。\n\nconst useAppContext: () => IAppContext;\n\ninterface IAppContext {\n appDirectory: string;\n configFile: string | false;\n packageName: string;\n nodeModulesDirectory: string;\n internalDirectory: string;\n plugins: {\n cli?: any;\n server?: any;\n }[];\n}\n\n\nINFO\n\n通过实际的类型文件,我们可以看到还存在一些其他字段,不过目前对于 Modern.js Module 有意义的字段只有以上内容,api 对象其他的方法也是如此。\n\n\napi.useResolvedConfigContext#\n\n用于获取解析之后的最终配置。\n\nINFO\n\n如果需要获取构建相关的最终配置,需要使用 beforeBuild Hook。\n\nconst useResolvedConfigContext: () => NormalizedConfig;\n\ninterface NormalizedConfig {\n buildConfig: PartialBuildConfig;\n buildPreset: BuildPreset;\n dev: Dev;\n plugins: PluginConfig;\n runtime: RuntimeConfig;\n runtimeByEntries?: RuntimeByEntriesConfig;\n _raw: UserConfig;\n}\n\n\n\napi.useHookRunners#\n\n用于获取 Hooks 的执行器,并触发特定的 Hook 执行。\n\n\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n async setup(api) {\n const hookRunners = api.useHookRunners();\n // 触发 afterBuild Hook\n await hookRunners.afterBuild();\n },\n});\n\n\n\n异步 setup#\n\nCLI 插件的 setup 可以是一个异步函数,在初始化过程中执行异步逻辑。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n async setup(api) {\n await doSomething();\n },\n});\n\n\n注意,只有当前插件的 setup 异步函数执行完毕,才会继续执行下一个插件的 setup 函数。因此,你需要避免在 setup\n函数中进行耗时过长的异步操作,防止影响 CLI 启动性能。\n\n\n生命周期钩子#\n\n我们知道 setup 函数会返回一个 Hooks 对象,所谓 Hooks 对象也可以理解是具有 Modern.js Module 生命周期钩子的对象。\n\n目前主要包含两类钩子:\n\n * 构建钩子:仅在执行 build 命令构建源码产物时触发。\n * buildPlatform 钩子:仅在执行 build --platform 命令生成其他构建产物时触发。\n * 调试钩子:运行 dev 命令时会触发的钩子。\n\n关于生命周期钩子的完整列表参考 API 文档。","frontmatter":{"sidebar_position":3},"version":""},{"id":84,"title":"总览","routePath":"/module-tools/plugins/official-list/overview","lang":"zh","toc":[{"text":"官方插件","id":"官方插件","depth":2,"charIndex":3}],"domain":"","content":"#\n\n\n官方插件#\n\n * @modern-js/plugin-module-import:使用 SWC 提供与 babel-plugin-import 一样的能力。\n * @modern-js/plugin-module-banner:为每个 JS 和 CSS 文件的顶部和底部添加自定义内容,例如版权信息。\n * @modern-js/plugin-module-node-polyfill:会自动注入 Node 核心模块在浏览器端的 polyfills。\n * @modern-js/plugin-module-polyfill:为你的代码中使用到的不支持的功能注入 polyfill。\n * @modern-js/plugin-module-babel:使用 Babel 转换你的代码。","frontmatter":{},"version":""},{"id":85,"title":"Babel 插件","routePath":"/module-tools/plugins/official-list/plugin-babel","lang":"zh","toc":[{"text":"快速开始","id":"快速开始","depth":2,"charIndex":50},{"text":"安装","id":"安装","depth":3,"charIndex":58},{"text":"注册插件","id":"注册插件","depth":3,"charIndex":64},{"text":"配置","id":"配置","depth":2,"charIndex":197}],"domain":"","content":"#\n\nTIP\n\n通常情况下,我们无需使用 Babel 转换我们的代码,此插件仅作为一种降级方式。\n\n\n快速开始#\n\n\n安装#\n\n\n注册插件#\n\n在 Modern.js Module 中,你可以按照如下方式注册插件:\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginBabel()],\n});\n\n\n\n配置#\n\nSee Babel options\n\n下面是一个配置了@babel/preset-env的例子:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBabel({\n presets: [['@babel/preset-env']],\n }),\n ],\n});\n","frontmatter":{},"version":""},{"id":86,"title":"Banner 插件","routePath":"/module-tools/plugins/official-list/plugin-banner","lang":"zh","toc":[{"text":"快速开始","id":"快速开始","depth":2,"charIndex":133},{"text":"安装","id":"安装","depth":3,"charIndex":141},{"text":"注册插件","id":"注册插件","depth":3,"charIndex":147},{"text":"示例","id":"示例","depth":2,"charIndex":426},{"text":"在 JS 文件顶部增加版权信息","id":"在-js-文件顶部增加版权信息","depth":3,"charIndex":432},{"text":"配置","id":"配置","depth":2,"charIndex":898},{"text":"banner","id":"banner","depth":3,"charIndex":1045},{"text":"footer","id":"footer","depth":3,"charIndex":1124}],"domain":"","content":"#\n\n提供为每个 JS 和 CSS 文件的顶部和底部注入内容的能力。\n\nTIP\n\n从 @modern-js/module-tools v2.36.0 版本开始,该插件功能内置在 Modern.js Module 中,由 banner 和\nfooter 配置提供。\n\n\n快速开始#\n\n\n安装#\n\n\n注册插件#\n\n在 Modern.js Module 中,你可以按照如下方式注册插件:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBanner({\n banner: {\n js: '//comment',\n css: '/*comment*/',\n },\n }),\n ],\n});\n\n\nTIP\n\n注意:CSS 的注释不支持 //comment 这样的写法。详见「CSS 注释」\n\n\n示例#\n\n\n在 JS 文件顶部增加版权信息#\n\n\n\n\nconst copyRight = `/*\n © Copyright 2020 xxx.com or one of its affiliates.\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n*/`;\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBanner({\n banner: {\n js: copyRight,\n },\n }),\n ],\n});\n\n\n\n配置#\n\n * 类型:\n\ntype BannerOptions = {\n banner: {\n js?: string;\n css?: string;\n };\n footer?: {\n js?: string;\n css?: string;\n };\n};\n\n\n\nbanner#\n\n在顶部增加内容。\n\n * banner.js:在 JS 文件顶部增加内容。\n * banner.css:在 CSS 文件顶部增加内容。\n\n\nfooter#\n\n在底部增加内容。\n\n * footer.js:在 JS 文件底部增加内容。\n * footer.css:在 CSS 文件底部增加内容。","frontmatter":{},"version":""},{"id":87,"title":"Import 插件","routePath":"/module-tools/plugins/official-list/plugin-import","lang":"zh","toc":[{"text":"快速开始","id":"快速开始","depth":2,"charIndex":145},{"text":"安装","id":"安装","depth":3,"charIndex":153},{"text":"注册插件","id":"注册插件","depth":3,"charIndex":159},{"text":"配置","id":"配置","depth":2,"charIndex":459},{"text":"pluginImport","id":"pluginimport","depth":3,"charIndex":526},{"text":"注意事项","id":"注意事项","depth":2,"charIndex":878}],"domain":"","content":"#\n\n提供与 babel-plugin-import 等价的能力和配置,基于 SWC 实现。\n\nTIP\n\n从 @modern-js/module-tools v2.16.0 版本开始,该插件功能内置在 Modern.js Module 中,由\ntransformImport 配置提供。\n\n\n快速开始#\n\n\n安装#\n\n\n注册插件#\n\n在 Modern.js Module 中,你可以按照如下方式注册插件:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginImport({\n pluginImport: [\n {\n libraryName: 'antd',\n style: true,\n },\n ],\n }),\n ],\n});\n\n\n这样我们就可以在 Modern.js Module 中使用自动导入的能力了。\n\n\n配置#\n\n * 类型:\n\ntype Options = {\n pluginImport?: ImportItem[];\n};\n\n\n\npluginImport#\n\n * 类型:object[]\n\n其中数组元素为一个 babel-plugin-import 的配置对象。配置对象可以参考 options。\n\n使用示例:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginImport({\n pluginImport: [\n // babel-plugin-import 的 options 配置\n {\n libraryName: 'foo',\n style: true,\n },\n ],\n }),\n ],\n});\n\n\n\n注意事项#\n\nSWC (Speedy Web Compiler) 是基于 Rust 语言编写的,而该插件是基于 SWC,移植自\nbabel-plugin-import,配置选项保持了一致。\n\n一些配置可以传入函数,例如 customName,customStyleName 等,这些 JavaScript 函数会由 Rust 通过 Node-API\n调用,这种调用会造成一些性能劣化。\n\n简单的函数逻辑其实可以通过模版语言来代替,因此 customName,customStyleName\n等这些配置除了可以传入函数,也可以传入字符串作为模版来代替函数,提高性能。\n\n我们以这段代码作为示例:\n\n\n\n\n添加以下配置:\n\nmodulePluginImport({\n pluginImport: [\n {\n libraryName: 'foo',\n customName: 'foo/es/{{ member }}',\n },\n ],\n});\n\n\n其中的 {{ member }} 会被替换为相应的引入成员,转换后:\n\n\n\n\n可以看出配置 customName: \"foo/es/{{ member }}\" 的效果等同于配置 customName: (member) =>\n`foo/es/${member}` ,但是不会有 Node-API 的调用开销。\n\n这里使用到的模版是 handlebars,模版配置中还内置了一些有用的辅助工具,还是以上面的导入语句为例,配置成:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginImport({\n pluginImport: [\n {\n libraryName: 'foo',\n customName: 'foo/es/{{ kebabCase member }}',\n },\n ],\n }),\n ],\n});\n\n\n会转换成下面的结果:\n\n\n\n\n除了 kebabCase 以外还有 camelCase,snakeCase,upperCase,lowerCase 可以使用。","frontmatter":{},"version":""},{"id":88,"title":"Node Polyfill 插件","routePath":"/module-tools/plugins/official-list/plugin-node-polyfill","lang":"zh","toc":[{"text":"快速开始","id":"快速开始","depth":2,"charIndex":213},{"text":"安装","id":"安装","depth":3,"charIndex":221},{"text":"注册插件","id":"注册插件","depth":3,"charIndex":227},{"text":"配置","id":"配置","depth":2,"charIndex":367},{"text":"exclude","id":"exclude","depth":3,"charIndex":459},{"text":"overrides","id":"overrides","depth":3,"charIndex":636},{"text":"Node Polyfills","id":"node-polyfills","depth":2,"charIndex":866},{"text":"Globals","id":"globals","depth":3,"charIndex":884},{"text":"Modules","id":"modules","depth":3,"charIndex":1007},{"text":"Fallbacks","id":"fallbacks","depth":3,"charIndex":1445}],"domain":"","content":"#\n\nNode Polyfill 介绍\n\n通常情况下,我们不会在浏览器端使用 Node 模块。但在当前代码需要同时在 Node 端和浏览器端运行时,用到一些 Node 模块是有可能的。Node\nPolyfill 为这些 Node 模块提供了浏览器版本的 polyfills。\n\n通过使用 Node Polyfill 插件,会自动注入 Node 核心模块在浏览器端的 polyfills,让你可以在浏览器端放心使用这些模块。\n\n\n快速开始#\n\n\n安装#\n\n\n注册插件#\n\n在 Modern.js Module 中,你可以按照如下方式注册插件:\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginNodePolyfill()],\n});\n\n\n\n配置#\n\n * 类型:\n\ntype NodePolyfillOptions = {\n exclude?: string[];\n overrides?: Record;\n};\n\n\n\nexclude#\n\n排除要注入的 Node Polyfill。\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginNodePolyfill({\n exclude: ['console'],\n }),\n ],\n});\n\n\n\noverrides#\n\n覆盖内置的 Node Polyfill。\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginNodePolyfill({\n overrides: {\n fs: path.join(__dirname, './custom-fs.js'),\n },\n }),\n ],\n});\n\n\n\nNode Polyfills#\n\n\nGlobals#\n\n * Buffer\n * process\n * console\n\n当你在代码中使用以上全局变量时,对应 polyfill 会被自动注入。\n\nconst bufferData = Buffer.from('xxxx');\n\n\n\nModules#\n\n * assert\n * buffer\n * console\n * constants\n * crypto\n * domain\n * events\n * http\n * https\n * os\n * path\n * punycode\n * process\n * querystring\n * stream\n * _stream_duplex\n * _stream_passthrough\n * _stream_readable\n * _stream_transform\n * _stream_writable\n * string_decoder\n * sys\n * timers\n * tty\n * url\n * util\n * vm\n * zlib\n\n当你通过 require 或 import 等语法在代码中引用以上模块时,对应 polyfill 会被注入。\n\n\n\nconst bufferData = Buffer.from('xxxx');\n\n\n\nFallbacks#\n\n * child_process\n * cluster\n * dgram\n * dns\n * fs\n * module\n * net\n * readline\n * repl\n * tls\n\n目前浏览器端没有以上模块的 polyfill,因此当你引用以上模块时,会自动 fallback 为一个空对象。\n\n\n\nconsole.log(fs); // -> {}\n","frontmatter":{},"version":""},{"id":89,"title":"Polyfill 插件","routePath":"/module-tools/plugins/official-list/plugin-polyfill","lang":"zh","toc":[{"text":"快速开始","id":"快速开始","depth":2,"charIndex":197},{"text":"安装","id":"安装","depth":3,"charIndex":205},{"text":"注册插件","id":"注册插件","depth":3,"charIndex":211},{"text":"配置","id":"配置","depth":2,"charIndex":347},{"text":"targets","id":"targets","depth":3,"charIndex":412}],"domain":"","content":"#\n\nTIP\n\n通常情况下,我们不需要为 npm 包注入 polyfill,这一步应该在 Web\n应用的框架侧完成,但是在某些场景,为了让我们的库能够直接运行在低版本浏览器里,我们需要注入 polyfill。\n\n请注意,此插件并不会转化你的代码语法,只会为你的代码中使用到的不支持的功能注入 polyfill,把它们作为普通函数导入而不是污染全局。你需要安装\ncore-js-pure 依赖\n\n\n快速开始#\n\n\n安装#\n\n\n注册插件#\n\n在 Modern.js Module 中,你可以按照如下方式注册插件:\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginPolyfill()],\n});\n\n\n\n配置#\n\n * 类型:\n\ntype options = {\n targets?: Record | string;\n};\n\n\n\ntargets#\n\n参考 Babel target.\n\n下面是一个例子:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginPolyfill({\n targets: '> 0.25%, not dead',\n }),\n ],\n});\n","frontmatter":{},"version":""}] \ No newline at end of file +[{"id":45,"title":"buildConfig","routePath":"/module-tools/api/config/build-config","lang":"zh","toc":[{"text":"alias","id":"alias","depth":2,"charIndex":141},{"text":"asset","id":"asset","depth":2,"charIndex":862},{"text":"asset.path","id":"assetpath","depth":2,"charIndex":885},{"text":"asset.limit","id":"assetlimit","depth":2,"charIndex":956},{"text":"asset.publicPath","id":"assetpublicpath","depth":2,"charIndex":1276},{"text":"asset.svgr","id":"assetsvgr","depth":2,"charIndex":1493},{"text":"asset.svgr.include","id":"assetsvgrinclude","depth":2,"charIndex":1889},{"text":"asset.svgr.exclude","id":"assetsvgrexclude","depth":2,"charIndex":1988},{"text":"autoExternal","id":"autoexternal","depth":2,"charIndex":2089},{"text":"autoExternal.dependencies","id":"autoexternaldependencies","depth":2,"charIndex":2588},{"text":"autoExternal.peerDependencies","id":"autoexternalpeerdependencies","depth":2,"charIndex":2676},{"text":"banner","id":"banner","depth":2,"charIndex":2772},{"text":"buildType","id":"buildtype","depth":2,"charIndex":3278},{"text":"copy","id":"copy","depth":2,"charIndex":3381},{"text":"copy.patterns","id":"copypatterns","depth":2,"charIndex":3549},{"text":"copy.options","id":"copyoptions","depth":2,"charIndex":3716},{"text":"define","id":"define","depth":2,"charIndex":3949},{"text":"dts","id":"dts","depth":2,"charIndex":4761},{"text":"dts.abortOnError","id":"dtsabortonerror","depth":2,"charIndex":4882},{"text":"dts.distPath","id":"dtsdistpath","depth":2,"charIndex":5216},{"text":"dts.only","id":"dtsonly","depth":2,"charIndex":5416},{"text":"dts.respectExternal","id":"dtsrespectexternal","depth":2,"charIndex":5588},{"text":"dts.tsconfigPath","id":"dtstsconfigpath","depth":2,"charIndex":5911},{"text":"esbuildOptions","id":"esbuildoptions","depth":2,"charIndex":6102},{"text":"externalHelpers","id":"externalhelpers","depth":2,"charIndex":6954},{"text":"externals","id":"externals","depth":2,"charIndex":7553},{"text":"footer","id":"footer","depth":2,"charIndex":7807},{"text":"format","id":"format","depth":2,"charIndex":7845},{"text":"format: esm","id":"format-esm","depth":3,"charIndex":7970},{"text":"format: cjs","id":"format-cjs","depth":3,"charIndex":8124},{"text":"format: iife","id":"format-iife","depth":3,"charIndex":8297},{"text":"format: umd","id":"format-umd","depth":3,"charIndex":8474},{"text":"hooks","id":"hooks","depth":2,"charIndex":8702},{"text":"input","id":"input","depth":2,"charIndex":9321},{"text":"jsx","id":"jsx","depth":2,"charIndex":10360},{"text":"metafile","id":"metafile","depth":2,"charIndex":10761},{"text":"minify","id":"minify","depth":2,"charIndex":11100},{"text":"outDir","id":"outdir","depth":2,"charIndex":11352},{"text":"platform","id":"platform","depth":2,"charIndex":11488},{"text":"redirect","id":"redirect","depth":2,"charIndex":11679},{"text":"resolve","id":"resolve","depth":2,"charIndex":12046},{"text":"resolve.mainFields","id":"resolvemainfields","depth":3,"charIndex":12068},{"text":"resolve.jsExtentions","id":"resolvejsextentions","depth":3,"charIndex":12513},{"text":"sideEffects","id":"sideeffects","depth":2,"charIndex":12883},{"text":"sourceDir","id":"sourcedir","depth":2,"charIndex":13689},{"text":"sourceMap","id":"sourcemap","depth":2,"charIndex":13785},{"text":"sourceType","id":"sourcetype","depth":2,"charIndex":13872},{"text":"splitting","id":"splitting","depth":2,"charIndex":14030},{"text":"style","id":"style","depth":2,"charIndex":14084},{"text":"style.less","id":"styleless","depth":2,"charIndex":14105},{"text":"style.less.lessOptions","id":"stylelesslessoptions","depth":2,"charIndex":14131},{"text":"style.less.additionalData","id":"stylelessadditionaldata","depth":2,"charIndex":14222},{"text":"style.less.implementation","id":"stylelessimplementation","depth":2,"charIndex":14454},{"text":"sass","id":"sass","depth":2,"charIndex":14917},{"text":"style.sass.sassOptions","id":"stylesasssassoptions","depth":2,"charIndex":14937},{"text":"style.sass.additionalData","id":"stylesassadditionaldata","depth":2,"charIndex":15007},{"text":"style.sass.implementation","id":"stylesassimplementation","depth":2,"charIndex":15299},{"text":"style.postcss","id":"stylepostcss","depth":2,"charIndex":15763},{"text":"style.inject","id":"styleinject","depth":2,"charIndex":16502},{"text":"style.autoModules","id":"styleautomodules","depth":2,"charIndex":17446},{"text":"style.modules","id":"stylemodules","depth":2,"charIndex":17680},{"text":"style.tailwindcss","id":"styletailwindcss","depth":2,"charIndex":18033},{"text":"启用 Tailwind CSS","id":"启用-tailwind-css","depth":3,"charIndex":18254},{"text":"类型","id":"类型","depth":3,"charIndex":18374},{"text":"注意事项","id":"注意事项","depth":3,"charIndex":18505},{"text":"target","id":"target","depth":2,"charIndex":18795},{"text":"transformImport","id":"transformimport","depth":2,"charIndex":19188},{"text":"transformLodash","id":"transformlodash","depth":2,"charIndex":19578},{"text":"tsconfig","id":"tsconfig","depth":2,"charIndex":19924},{"text":"umdGlobals","id":"umdglobals","depth":2,"charIndex":20104},{"text":"umdModuleName","id":"umdmodulename","depth":2,"charIndex":20398}],"domain":"","content":"#\n\nbuildConfig 是一个用来描述如何编译、生成构建产物的配置项,它包含了构建的所有配置。\n\n * 类型:object | object[]\n\nTIP\n\n在开始使用 buildConfig 之前,请先阅读以下文档来了解其作用:\n\n * 修改输出产物\n * 深入理解构建\n\n\nalias#\n\n * 类型:Record | Function\n * 默认值:{'@': 'src',}\n\nTIP\n\n对于 TypeScript 项目,只需要在 tsconfig.json 中配置 compilerOptions.paths, Modern.js Module\n会自动识别 tsconfig.json 里的别名,因此不需要额外配置 alias 字段。\n\nexport default defineConfig({\n buildConfig: {\n alias: {\n '@common': './src/common',\n },\n },\n});\n\n\n以上配置完成后,如果在代码中引用 @common/Foo.tsx, 则会映射到 /src/common/Foo.tsx 路径上。\n\nalias 的值定义为函数时,可以接受预设的 alias 对象,并对其进行修改。\n\nexport default defineConfig({\n buildConfig: {\n alias: alias => {\n alias['@common'] = './src/common';\n },\n },\n});\n\n\n也可以在函数中返回一个新对象作为最终结果,新对象会覆盖预设的 alias 对象。\n\nexport default defineConfig({\n buildConfig: {\n alias: alias => {\n return {\n '@common': './src/common',\n };\n },\n },\n});\n\n\n\nasset#\n\n包含静态资源相关的配置。\n\n\nasset.path#\n\n静态资源输出路径,会基于 outDir 进行输出。\n\n * 类型: string\n * 默认值: assets\n\n\nasset.limit#\n\n用于设置静态资源被自动内联为 base64 的体积阈值。\n\nModern.js Module 在进行打包时,默认会内联体积小于 10KB 的图片、字体、媒体等资源,将它们通过 Base64\n编码,并内联到产物中,不再会发送独立的 HTTP 请求。\n\n你可以通过修改 limit 参数来调整这个阈值。\n\n * 类型: number\n * 默认值: 10 * 1024\n\n例如,将 limit 设置为 0 来避免资源内联:\n\nexport default defineConfig({\n buildConfig: {\n asset: {\n limit: 0,\n },\n },\n});\n\n\n\nasset.publicPath#\n\n打包时给未内联资源的 CDN 前缀。\n\n * 类型: string\n * 默认值: undefined\n\nexport default defineConfig({\n buildConfig: {\n asset: {\n publicPath: 'https://xxx/',\n },\n },\n});\n\n\n此时,所有静态资源都会添加 https://xxx/ 前缀。\n\n\nasset.svgr#\n\n打包时将 SVG 作为一个 React 组件处理,options 参考 svgr,另外还支持了 include 和 exclude\n两个配置项,用于匹配需要处理的 SVG 文件。\n\n * 类型: boolean | object\n * 默认值: false\n\n开启 svgr 功能后,可以使用默认导出的方式将 SVG 当做组件使用。\n\n// true\n\n\nexport default () => ;\n\n\nWARNING\n\n目前不支持下面的用法:\n\n\n\n\n当开启功能后,可以通过在 modern-app-env.d.ts 文件中增加类型定义,修改使用 SVG 的类型:\n\ndeclare module '*.svg' {\n const src: React.FunctionComponent>;\n export default src;\n}\n\n/// \n\n\n\nasset.svgr.include#\n\n设定匹配的 SVG 文件\n\n * 类型: string | RegExp | (string | RegExp)[]\n * 默认值: /\\.svg$/\n\n\nasset.svgr.exclude#\n\n设定不匹配的 SVG 文件\n\n * 类型: string | RegExp | (string | RegExp)[]\n * 默认值: undefined\n\n\nautoExternal#\n\n自动外置项目的 \"dependencies\" 和 \"peerDependencies\",不会将其打包到最终的 bundle 产物中。\n\n * 类型: boolean | object\n * 默认值: true\n\n当我们希望关闭对于第三方依赖的默认处理行为时候,可以通过以下方式来实现:\n\nexport default defineConfig({\n buildConfig: {\n autoExternal: false,\n },\n});\n\n\n这样对于 \"dependencies\" 和 \"peerDependencies\" 下面的依赖都会进行打包处理。如果只想要关闭其中某个下面的依赖处理,则可以使用\nbuildConfig.autoExternal 的对象形式:\n\nexport default defineConfig({\n buildConfig: {\n autoExternal: {\n dependencies: false,\n peerDependencies: false,\n },\n },\n});\n\n\n\nautoExternal.dependencies#\n\n是否需要外置项目的 \"dependencies\" 依赖。\n\n * 类型: boolean\n * 默认值: true\n\n\nautoExternal.peerDependencies#\n\n是否需要外置项目的 \"peerDependencies\" 依赖。\n\n * 类型: boolean\n * 默认值: true\n\n\nbanner#\n\n提供为每个 JS , CSS 和 DTS 文件的顶部和底部注入内容的能力。\n\ninterface BannerAndFooter {\n js?: string;\n css?: string;\n dts?: string;\n}\n\n\n * 类型: BannerAndFooter\n * 默认值: {}\n * 版本: v2.36.0\n\n例如你想为 JS 和 CSS 文件添加版权信息:\n\n\n\nconst copyRight = `/*\n © Copyright 2020 xxx.com or one of its affiliates.\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n*/`;\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildConfig: {\n banner: {\n js: copyRight,\n css: copyRight,\n },\n },\n});\n\n\n\nbuildType#\n\n构建类型,bundle 会打包你的代码,bundleless 只做代码的转换。\n\n * 类型: 'bundle' | 'bundleless'\n * 默认值: 'bundle'\n\n\ncopy#\n\n将文件或目录拷贝到指定位置。\n\n * 类型: object\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [{ from: './src/assets', to: '' }],\n },\n },\n});\n\n\n\ncopy.patterns#\n\n * 类型: CopyPattern[]\n * 默认值: []\n\ninterface CopyPattern {\n from: string;\n to?: string;\n context?: string;\n globOptions?: globby.GlobbyOptions;\n}\n\n\n\ncopy.options#\n\n * 类型:\n\ntype Options = {\n concurrency?: number;\n enableCopySync?: boolean;\n};\n\n\n * 默认值: { concurrency: 100, enableCopySync: false }\n\n * concurrency: 指定并行执行多少个复制任务。\n\n * enableCopySync: 使用 fs.copySync,默认情况下 fs.copy。\n\n\ndefine#\n\n定义全局变量,注入到代码中\n\n * 类型: Record\n * 默认值: {}\n\n由于 define 功能是由全局文本替换实现的,所以需要保证全局变量值为字符串,更为安全的做法是将每个全局变量的值转化为字符串,使用\nJSON.stringify 进行转换,如下所示:\n\nexport default defineConfig({\n buildConfig: {\n define: {\n VERSION: JSON.stringify(require('./package.json').version || '0.0.0'),\n },\n },\n});\n\n\n不过要注意:如果项目是一个 TypeScript 项目,那么你可能需要在项目源代码目录下的 .d.ts 文件里增加以下内容:\n\n> 如果不存在 d.ts 文件,则可以手动创建。\n\ndeclare const YOUR_ADD_GLOBAL_VAR;\n\n\n我们也可以进行环境变量替换:\n\n\nexport default defineConfig({\n buildConfig: {\n define: {\n 'process.env.VERSION': JSON.stringify(process.env.VERSION || '0.0.0'),\n },\n },\n});\n\n\n通过上面的配置,我们就可以将下面这段代码:\n\n// 编译前代码\nconsole.log(process.env.VERSION);\n\n\n在执行 VERSION=1.0.0 modern build 的时候,转换为:\n\n// 编译后代码\nconsole.log('1.0.0');\n\n\nTIP\n\n为了防止全局替换替换过度,建议使用时遵循以下两个原则:\n\n * 全局常量使用大写\n * 自定义全局常量前缀后缀,确保独一无二\n\n\ndts#\n\n类型文件生成的相关配置,默认情况会生成。\n\n * 类型: false | object\n * 默认值:\n\n{\n abortOnError: true,\n distPath: './',\n only: false,\n}\n\n\n\ndts.abortOnError#\n\n用于控制在出现类型错误的时候,是否允许构建成功。\n\n * 类型:boolean\n * 默认值:true\n\n默认情况下,在出现类型错误的时候会导致构建失败。将 abortOnError 设置为 false 后,即使代码中出现了类型问题,构建依然会成功:\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n abortOnError: false,\n },\n },\n});\n\n\nWARNING\n\n当关闭该配置后,无法保证类型文件能正常生成,且不保证内容正确。在 buildType: 'bundle' 时,即打包模式下,类型文件一定不会生成。\n\n\ndts.distPath#\n\n类型文件的输出路径,基于 outDir 进行输出。\n\n * 类型: string\n * 默认值: ./\n\n比如输出到 outDir 下面的 types 目录:\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n distPath: './types',\n },\n },\n});\n\n\n\ndts.only#\n\n是否在构建时只生成类型文件,不生成 JavaScript 产物文件。\n\n * 类型: boolean\n * 默认值: false\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n only: true,\n },\n },\n});\n\n\n\ndts.respectExternal#\n\n当设为 false 时,不会打包任何三方包类型,设为 true 时,会根据 externals 来决定是否需要打包三方类型。\n\n在对类型文件进行打包时,构建工具还未对 export\n进行分析,因此当你引用的任何一个三方包出现类型错误时,都可能会中断当前的构建流程,这会导致构建流程不可控,因此我们可以通过这个配置来避免该问题。\n\n * 类型: boolean\n * 默认值: true\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n respectExternal: false,\n },\n },\n});\n\n\n\ndts.tsconfigPath#\n\n废弃,使用 tsconfig 配置替代。\n\n指定用于生成类型文件的 tsconfig 文件路径。\n\nexport default defineConfig({\n buildConfig: {\n dts: {\n tsconfigPath: './other-tsconfig.json',\n },\n },\n});\n\n\n\nesbuildOptions#\n\n用于修改底层的 esbuild 配置。\n\n * 类型: Function\n * 默认值: c => c\n\n例如,我们需要修改生成文件的后缀:\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.outExtension = { '.js': '.mjs' };\n return options;\n },\n },\n});\n\n\n例如,注册一个 esbuild 插件:\n\n\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.plugins = [myEsbuildPlugin, ...options.plugins];\n return options;\n },\n },\n});\n\n\n在增加 esbuild 插件时,请注意你需要将插件加在 plugins 数组的头部,因为 Modern.js Module 内部也是通过一个 esbuild\n插件介入到整个构建流程中去的,因此需要将自定义插件优先注册。\n\nTIP\n\n我们在原本 esbuild 构建的基础上做了许多扩展,因此使用此配置需要注意以下几点:\n\n 1. 优先使用 Modern.js Module 提供的配置,例如 esbuild 并不支持 target: 'es5',但我们内部使用 SWC\n 支持了此场景,此时通过 esbuildOptions 设置target: 'es5'会报错。\n 2. 目前我们内部使用 enhanced-resolve 替代了 esbuild 的 resolve 解析算法,所以修改 esbuild resolve\n 相关配置无效,计划在未来会切换回来。\n\n\nexternalHelpers#\n\n默认情况下,输出的 JS 代码可能会依赖一些辅助函数来支持目标环境或者输出格式,这些辅助函数会被内联在需要它的文件中。\n\n使用此配置,将会使用 SWC 对代码进行转换,将内联的辅助函数转换为从外部模块 @swc/helpers 导入这些辅助函数。\n\n * 类型:boolean\n * 默认值:false\n\n下面是使用该配置前后的产物变化比较。\n\n开启前:\n\n// 辅助函数\nfunction asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {\n // ...\n}\n// 辅助函数\nfunction _async_to_generator(fn) {\n return function () {\n // use asyncGeneratorStep\n // ...\n };\n}\n\n// 你的代码\nexport var yourCode = function () {\n // use _async_to_generator\n};\n\n\n开启后:\n\n// 从 @swc/helpers 导入的辅助函数\n\n\n// 你的代码\nexport var yourCode = function () {\n // use _async_to_generator\n};\n\n\n\nexternals#\n\n用于在打包时排除一些外部依赖,避免将这些依赖打包到最终的 bundle 中。\n\n * 类型:\n\ntype Externals = (string | RegExp)[];\n\n\n * 默认值: []\n * 构建类型:仅支持 buildType: 'bundle'\n * 示例:\n\nexport default defineConfig({\n buildConfig: {\n // 避免打包 React\n externals: ['react'],\n },\n});\n\n\n\nfooter#\n\n同 banner 配置,用于在输出文件末尾添加注释。\n\n\nformat#\n\n用于设置 JavaScript 产物输出的格式,其中 iife 和 umd 只在 buildType 为 bundle 时生效。\n\n * 类型:'esm' | 'cjs' | 'iife' | 'umd'\n * 默认值:cjs\n\n\nformat: esm#\n\nesm 代表 \"ECMAScript 模块\",它需要运行环境支持 import 和 export 语法。\n\n * 示例:\n\nexport default defineConfig({\n buildConfig: {\n format: 'esm',\n },\n});\n\n\n\nformat: cjs#\n\ncjs 代表 \"CommonJS\",它需要运行环境支持 exports、require 和 module 语法,通常为 Node.js 环境。\n\n * 示例:\n\nexport default defineConfig({\n buildConfig: {\n format: 'cjs',\n },\n});\n\n\n\nformat: iife#\n\niife 代表 \"立即调用函数表达式\",它将代码包裹在函数表达式中,确保代码中的任何变量不会意外地与全局范围中的变量冲突,通常在浏览器环境中运行。\n\n * 示例:\n\nexport default defineConfig({\n buildConfig: {\n format: 'iife',\n },\n});\n\n\n\nformat: umd#\n\numd 代表 \"Universal Module Definition\",用于在不同环境(浏览器、Node.js 等)中运行。umd\n格式的模块可以在多种环境下使用,既可以作为全局变量访问,也可以通过模块加载器(如 RequireJS)进行模块化加载。\n\n * 示例:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n },\n});\n\n\n\nhooks#\n\n构建生命周期钩子,允许在构建流程的特定阶段注入自定义逻辑。\n\n * 类型:\n\ntype HookList = {\n name: string;\n apply: (compiler: ICompiler) => void;\n};\n\n\n * 默认值:[]\n\n我们可以在 apply 方法里拿到 compiler 实例,修改其属性,以及在不同阶段执行自定义逻辑,对于 Hook 的详细介绍, 参考使用 Hook\n介入构建流程。\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundle',\n hooks: [\n {\n name: 'renderChunk',\n apply: compiler => {\n // any logic for compiler\n compiler.hooks.renderChunk.tapPromise(\n { name: 'renderChunk' },\n async chunk => {\n return chunk;\n },\n );\n },\n },\n ],\n },\n});\n\n\n\ninput#\n\n指定构建的入口文件,数组形式可以指定目录。\n\n * 类型:\n\ntype Input =\n | string[];\n | {\n [name: string]: string;\n }\n\n\n * 默认值:bundle 模式下默认为 ['src/index.ts'],bundleless 模式下默认为 ['src']\n\n数组用法:\n\n在 bundle 模式下,下面的配置会以 src/index.ts 和 src/index2.ts 为入口分别进行构建。bundle 模式不支持配置 input\n为目录。\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundle',\n input: ['src/index.ts', 'src/index2.ts'],\n },\n});\n\n\n在 bundleless 模式下,下面的配置会同时处理 src/a 目录下的文件和 src/index.ts 文件。\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundleless',\n input: ['src/a', 'src/index.ts'],\n },\n});\n\n\n在 bundleless 模式下,数组模式还支持使用 ! 来过滤部分文件:\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundleless',\n input: ['src', '!src/*.spec.ts'],\n },\n});\n\n\n上面的配置将打包 src 目录下的文件,同时会过滤以 spec.ts 为后缀的文件。这在测试文件与源码文件在同一个根目录下的情况会很有用。\n\n对象用法:\n\n当在 bundle 模式下需要修改产物的输出文件名称的时候,可以使用对象形式进行配置。\n\n对象的 Key 是产物的文件名称,Value 是源码的文件路径。\n\nexport default defineConfig({\n buildConfig: {\n format: 'esm',\n input: {\n 'index.esm': './src/index.ts',\n },\n },\n});\n\n\n\njsx#\n\n指定 JSX 的编译方式,默认支持 React 17 及更高版本,自动注入 JSX 运行时代码。\n\n * 类型: automatic | transform | preserve\n * 默认值: automatic\n\n如果你需要支持 React 16,则可以设置 jsx 为 transform:\n\nexport default defineConfig({\n buildConfig: {\n jsx: 'transform',\n },\n});\n\n\nTIP\n\n如果你不需要转换 JSX ,可以设置 jsx 为 preserve, 但此时请不要使用 swc 做代码转换。 关于 JSX Transform\n的更多说明,可以参考以下链接:\n\n * React Blog - Introducing the New JSX Transform.\n * esbuild - JSX.\n\n\nmetafile#\n\n这个选项用于构建分析,开启该选项后,esbuild 会以 JSON 格式生成有关构建的一些元数据。\n\n * 类型:boolean\n * 默认值:false\n * 构建类型:仅支持 buildType: 'bundle'\n\n开启 metafile 生成:\n\nexport default defineConfig({\n buildConfig: {\n buildType: 'bundle',\n metafile: true,\n },\n});\n\n\n在执行 build 构建后,产物目录下会生成 metafile-[xxx].json 文件,你可以通过 esbuild analyze 和\nbundle-buddy 等工具进行可视化分析。\n\n\nminify#\n\n使用 esbuild 或者 terser 压缩代码,也可以传入 terserOptions。\n\n * 类型: 'terser' | 'esbuild' | false | object\n * 默认值: false\n\nexport default defineConfig({\n buildConfig: {\n minify: {\n compress: {\n drop_console: true,\n },\n },\n },\n});\n\n\n\noutDir#\n\n指定构建的输出目录。\n\n * 类型: string\n * 默认值: ./dist\n\nexport default defineConfig({\n buildConfig: {\n outDir: './dist/esm',\n },\n});\n\n\n\nplatform#\n\n默认生成用于 Node.js 环境下的代码,你也可以指定为 browser,会生成用于浏览器环境的代码。\n\n * 类型: 'browser' | 'node'\n * 默认值: 'node'\n\nexport default defineConfig({\n buildConfig: {\n platform: 'browser',\n },\n});\n\n\n\nredirect#\n\n在 buildType: 'bundleless' 构建模式下,会对引用路径进行重定向,确保指向了正确的产物,例如:\n\n * import './index.less' 会被改写成 import './index.css'\n * 会被改写成 (依实际情况而定)\n\n在某些场景下,你可能不需要这些功能,那么可以通过此配置关闭它,关闭后,其引用路径将不会发生改变。\n\nexport default {\n buildConfig: {\n redirect: {\n alias: false, // 关闭对别名路径的修改\n style: false, // 关闭对样式文件路径的修改\n asset: false, // 关闭对资源文件路径的修改\n },\n },\n};\n\n\n\nresolve#\n\n自定义模块解析选项\n\n\nresolve.mainFields#\n\npackage.json 中,在解析包的入口点时尝试的字段列表。\n\n * 类型:string[]\n * 默认值:取决于platform\n * node: ['module', 'main']\n * browser: ['module', 'browser', 'main']\n * 版本:v2.36.0\n\n例如,我们想要先加载 js:source 字段:\n\nexport default defineConfig({\n buildConfig: {\n resolve: {\n mainFields: ['js:source', 'module', 'main'],\n },\n },\n});\n\n\nWARNING\n\nresolve.mainFields 比 package.json 中 exports 字段的优先级低,如果一个入口点从 exports\n成功解析,resolve.mainFields 将被忽略。\n\n\nresolve.jsExtentions#\n\n支持隐式文件扩展名\n\n * 类型: string[]\n * 默认值: ['.jsx', '.tsx', '.js', '.ts', '.json']\n * 版本:v2.36.0\n\n对于 css 文件,请不要使用隐式文件扩展名,目前 Module 仅支持 ['.less', '.css', '.sass', '.scss'] 后缀。\n\nNode 的解析算法不会将 .mjs 和 cjs 视为隐式文件扩展名,因此这里默认也不会,但是可以通过更改此配置来包含:\n\nexport default defineConfig({\n buildConfig: {\n resolve: {\n jsExtentions: ['.mts', 'ts'],\n },\n },\n});\n\n\n\nsideEffects#\n\n配置模块的副作用\n\n * 类型: RegExg[] | (filePath: string, isExternal: boolean) => boolean | boolean\n * 默认值: undefined\n\n通常情况下,我们通过 package.json 的 \"sideEffects\" 字段来配置模块的副作用,但是在某些情况下,三方包的 package.json\n是不可靠的。 例如我们引用了一个三方包的样式文件。\n\nimport 'other-package/dist/index.css';\n\n\n但是这个三方包的 package.json 里并没有将样式文件配置到 \"sideEffects\" 里。\n\n{\n \"sideEffects\": [\"dist/index.js\"]\n}\n\n\n同时你又设置了 style.inject 为 true,在控制台可以看到类似的警告信息:\n\n[LIBUILD:ESBUILD_WARN] Ignoring this import because \"other-package/dist/index.css\" was marked as having no side effects\n\n\n这时候就可以使用这个配置项,手动配置模块的\"sideEffects\",配置支持正则和函数形式。\n\nexport default defineConfig({\n buildConfig: {\n sideEffects: [/\\.css$/],\n // or\n // sideEffects: (filePath, isExternal) => /\\.css$/.test(filePath),\n },\n});\n\n\nTIP\n\n添加此配置后,打包时将不会再读取 package.json 里的 \"sideEffects\" 字段。\n\n\nsourceDir#\n\n指定构建的源码目录,默认为 src,用于在 bundleless 构建时基于源码目录结构生成对应的产物目录。\n\n * 类型: string\n * 默认值: src\n\n\nsourceMap#\n\n控制 sourceMap 如何生成。\n\n * 类型: boolean | 'inline' | 'external'\n * 默认值: false\n\n\nsourceType#\n\nWARNING\n\n已废弃,此配置不会产生任何影响。\n\n设置源码的格式。默认情况下,会将源码作为 EsModule 进行处理。当源码使用的是 CommonJS 的时候,需要设置 commonjs。\n\n * 类型:'commonjs' | 'module'\n * 默认值:'module'\n\n\nsplitting#\n\n是否开启代码分割。\n\n * 类型: boolean\n * 默认值: false\n\n\nstyle#\n\n配置样式相关的配置。\n\n\nstyle.less#\n\nless 相关配置。\n\n\nstyle.less.lessOptions#\n\n详细配置参考 less。\n\n * 类型: object\n * 默认值: { javascriptEnabled: true }\n\n\nstyle.less.additionalData#\n\n在入口文件起始添加 Less 代码。\n\n * 类型: string\n * 默认值: undefined\n\nexport default defineConfig({\n buildConfig: {\n style: {\n less: {\n additionalData: `@base-color: #c6538c;`,\n },\n },\n },\n});\n\n\n\nstyle.less.implementation#\n\n配置 Less 使用的实现库,在不指定的情况下,使用的内置版本是 4.1.3。\n\n * 类型: string | object\n * 默认值: undefined\n\n设置 object 类型时,可以指定 Less 的实现库。\n\nexport default defineConfig({\n buildConfig: {\n style: {\n less: {\n implementation: require('less'),\n },\n },\n },\n});\n\n\nstring 类型时,指定 Less 的实现库的路径\n\nexport default defineConfig({\n buildConfig: {\n style: {\n less: {\n implementation: require.resolve('less'),\n },\n },\n },\n});\n\n\n\nsass#\n\nSass 相关配置。\n\n\nstyle.sass.sassOptions#\n\n详细配置参考 node-sass\n\n * 类型: object\n * 默认值: {}\n\n\nstyle.sass.additionalData#\n\n在入口文件起始添加 Sass 代码。\n\n * 类型: string | Function\n * 默认值: undefined\n\nexport default defineConfig({\n buildConfig: {\n style: {\n sass: {\n additionalData: `$base-color: #c6538c;\n $border-dark: rgba($base-color, 0.88);`,\n },\n },\n },\n});\n\n\n\nstyle.sass.implementation#\n\n配置 Sass 使用的实现库,在不指定的情况下,使用的内置版本是 1.5.4。\n\n * 类型: string | object\n * 默认值: undefined\n\n设置为 object 类型时,可以指定 Sass 的实现库。\n\nexport default defineConfig({\n buildConfig: {\n style: {\n sass: {\n implementation: require('sass'),\n },\n },\n },\n});\n\n\nstring 类型时,指定 Sass 的实现库的路径\n\nexport default defineConfig({\n buildConfig: {\n style: {\n sass: {\n implementation: require.resolve('sass'),\n },\n },\n },\n});\n\n\n\nstyle.postcss#\n\n用于配置 PostCSS 的选项,传入的值会与默认配置通过 Object.assign 合并。注意 Object.assign 是浅拷贝,因此会完全覆盖内置的\nplugins 数组。\n\n详细配置请查看 PostCSS。\n\n * 类型:\n\ntype PostcssOptions = {\n processOptions?: ProcessOptions;\n plugins?: AcceptedPlugin[];\n};\n\n\n * 默认值:\n\nconst defaultConfig = {\n plugins: [\n // 以下插件默认启用\n require('postcss-flexbugs-fixes'),\n require('postcss-media-minmax'),\n require('postcss-nesting'),\n // 以下插件仅在 target 为 `es5` 时启用\n require('postcss-custom-properties'),\n require('postcss-initial'),\n require('postcss-page-break'),\n require('postcss-font-variant'),\n ],\n};\n\n\n * 示例:\n\nexport default defineConfig({\n buildConfig: {\n style: {\n postcss: {\n plugins: [yourPostCSSPlugin],\n },\n },\n },\n});\n\n\n\nstyle.inject#\n\n配置打包模式下是否将 CSS 样式插入到 JavaScript 代码中。\n\n * 类型: boolean\n * 默认值: false\n\n将 inject 设置为 true 来开启此功能:\n\nexport default defineConfig({\n buildConfig: {\n inject: true,\n },\n});\n\n\n开启后,你会看到源码中引用的 CSS 代码被包含在了打包后的 JS 产物中。\n\n例如,你在源码里写了 import './index.scss',那么在产物中你会看到以下代码:\n\n// node_modules/style-inject/dist/style-inject.es.js\nfunction styleInject(css, ref) {\n // ...\n}\nvar style_inject_es_default = styleInject;\n\n// src/index.scss\nvar css_248z = '.body {\\n color: black;\\n}';\nstyle_inject_es_default(css_248z);\n\n\nTIP\n\n开启 inject 后,你需要注意以下几点:\n\n * CSS 文件中的 @import 不会被处理。如果你的 CSS 文件中有 @import ,那么你需要在 JS 文件中手动引入 CSS\n 文件(less,scss 文件不需要,因为它们会有预处理)。\n * 需要考虑 sideEffects 的影响。默认情况下,我们的构建器会认为 CSS 是有副作用的,如果你的项目中或者三方包的 package.json\n 设置了 sideEffects 字段并且没有包含此 CSS 文件,那么你将会得到一个警告:\n\n[LIBUILD:ESBUILD_WARN] Ignoring this import because \"src/index.scss\" was marked as having no side effects by plugin \"libuild:adapter\"\n\n\n此时可以通过配置 sideEffects 来解决。\n\n\nstyle.autoModules#\n\n根据文件名自动启用 CSS Modules。\n\n * 类型: boolean | RegExp\n * 默认值: true\n\ntrue : 为以 .module.css .module.less .module.scss .module.sass 文件名结尾的样式文件启用 CSS\nModules。\n\nfalse : 禁用 CSS Modules.\n\nRegExp : 为匹配正则条件的所有文件启用 CSS Modules.\n\n\nstyle.modules#\n\nCSS Modules 配置。\n\n * 类型: object\n * 默认值: {}\n\n一个常用的配置是 localsConvention,它可以改变 CSS Modules 的类名生成规则。\n\nexport default defineConfig({\n buildConfig: {\n style: {\n modules: {\n localsConvention: 'camelCaseOnly',\n },\n },\n },\n});\n\n\n对于以下样式:\n\n.box-title {\n color: red;\n}\n\n\n你可以使用 styles.boxTitle 来访问。\n\n详细配置查看 postcss-modules\n\n\nstyle.tailwindcss#\n\n用于修改 Tailwind CSS 的配置项。\n\n * 类型: object | Function\n * 默认值:\n\nconst tailwind = {\n content: [\n './src/**/*.{js,jsx,ts,tsx}',\n './config/html/**/*.{html,ejs,hbs}',\n './storybook/**/*',\n ],\n};\n\n\n\n启用 Tailwind CSS#\n\n在使用 style.tailwindcss 之前,你需要启用 Modern.js Module 的 Tailwind CSS 插件。\n\n请阅读「使用 Tailwind CSS」 章节来了解开启方式。\n\n\n类型#\n\n值为 object 类型时,与默认配置通过 Object.assign 合并。\n\n值为 Function 类型时,函数返回的对象与默认配置通过 Object.assign 合并。\n\n其他的使用方式和 Tailwind CSS 一致: 快速传送门。\n\n\n注意事项#\n\n注意:\n\n * 如果你同时使用了 tailwind.config.{ts,js} 文件和 tools.tailwindcss 选项,那么\n tools.tailwindcss 定义的配置会优先生效,并覆盖 tailwind.config.{ts,js} 中定义的内容。\n * 如果你同时使用了 designSystem 配置项,那么 Tailwind CSS 的 theme 配置将会被 designSystem 的值所覆盖。\n\n其他配置的使用方式与 Tailwind CSS 官方用法一致,请参考 tailwindcss - Configuration。\n\n\ntarget#\n\ntarget 用于为生成的 JavaScript 代码设置目标环境。它让 Modern.js Module 将目标环境无法识别的 JavaScript\n语法转换为在这些环境中可用的低版本 JavaScript 语法。\n\n * 类型:\n\ntype Target =\n | 'es5'\n | 'es6'\n | 'es2015'\n | 'es2016'\n | 'es2017'\n | 'es2018'\n | 'es2019'\n | 'es2020'\n | 'es2021'\n | 'es2022'\n | 'esnext';\n\n\n * 默认值: 'es6'\n\n例如,将代码编译到 es5 语法:\n\nexport default defineConfig({\n buildConfig: {\n target: 'es5',\n },\n});\n\n\n\ntransformImport#\n\n提供与 babel-plugin-import 等价的能力和配置,基于 SWC 实现,使用此配置,将会使用 SWC 对代码进行转换。\n\n * 类型:object[]\n * 默认值:[]\n\n数组元素为一个 babel-plugin-import 的配置对象。配置对象可以参考 options。\n\n使用示例:\n\nexport default defineConfig({\n buildConfig: {\n transformImport: [\n // babel-plugin-import 的 options 配置\n {\n libraryName: 'foo',\n style: true,\n },\n ],\n },\n});\n\n\n参考「Import 插件——注意事项」\n\n\ntransformLodash#\n\n是否模块化 lodash 的导入,删除未使用的 lodash 模块,从而减少 lodash 代码体积。这项优化基于 babel-plugin-lodash 和\nswc-plugin-lodash 实现。 使用此配置,将会使用 SWC 对代码进行转换。\n\n * 类型:boolean\n * 默认值:false\n\n当开启此选项时,Modern.js Module 会自动将 lodash 的代码引用指向子路径。\n\n比如:\n\n\n\n\nconst addOne = add(1);\n_.map([1, 2, 3], addOne);\n\n\n转换后的代码:\n\n\n\n\nconst addOne = _add(1);\n_map([1, 2, 3], addOne);\n\n\n\ntsconfig#\n\nTypeScript 配置文件的路径。\n\n * 类型: string\n * 默认值: tsconfig.json\n * 版本: v2.36.0\n\nexport default defineConfig({\n buildConfig: {\n tsconfig: 'tsconfig.build.json',\n },\n});\n\n\n\numdGlobals#\n\n指定 UMD 产物外部导入的全局变量。\n\n * 类型: Record\n * 默认值: {}\n\nexport default defineConfig({\n buildConfig: {\n umdGlobals: {\n react: 'React',\n 'react-dom': 'ReactDOM',\n },\n },\n});\n\n\n此时,react 和 react-dom 会被看做是外部导入的全局变量,不会被打包进 UMD 产物中,而是通过 global.React 和\nglobal.ReactDOM 的方式进行访问。\n\n\numdModuleName#\n\n指定 UMD 产物的模块名。\n\n * 类型: string | Function\n * 默认值: name => name\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdModuleName: 'myLib',\n },\n});\n\n\n此时 UMD 产物会去挂载到 global.myLib 上。\n\nTIP\n * 需要遵守 UMD 规范,UMD 产物的模块名不能和全局变量名冲突。\n * 模块名会被转换为驼峰命名,如 my-lib 会被转换为 myLib,可参考toIdentifier。\n\n同时函数形式可以接收一个参数,为当前打包文件的输出路径\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdModuleName: path => {\n if (path.includes('index')) {\n return 'myLib';\n } else {\n return 'myLib2';\n }\n },\n },\n});\n","frontmatter":{"sidebar_position":1},"version":""},{"id":46,"title":"buildPreset","routePath":"/module-tools/api/config/build-preset","lang":"zh","toc":[{"text":"npm-library","id":"npm-library","depth":2,"charIndex":76},{"text":"npm-library-with-umd","id":"npm-library-with-umd","depth":2,"charIndex":655},{"text":"npm-component","id":"npm-component","depth":2,"charIndex":1376},{"text":"npm-component-with-umd","id":"npm-component-with-umd","depth":2,"charIndex":2027},{"text":"npm-library-{es5...esnext}","id":"npm-library-es5esnext","depth":2,"charIndex":2784},{"text":"string / function","id":"string--function","depth":2,"charIndex":3082}],"domain":"","content":"#\n\n构建的预设字符串或者预设函数。提供开箱即用的构建配置。\n\n * 类型:string | Function\n\n * 默认值: undefined\n\n\nnpm-library#\n\n在类 NPM 包管理器下使用的 Library 通用模式,包含 esm 和 cjs 两种 Bundle 产物,并且包含一份类型文件。\n\nINFO\n\n关于类 NPM 包管理器\n\n * npm\n * yarn\n * pnpm\n\n{\n \"main\": \"./dist/lib/index.js\",\n \"module\": \"./dist/es/index.js\",\n \"types\": \"./dist/types/index.d.ts\"\n}\n\n\n预设字符串对应的构建配置:\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/es',\n },\n {\n buildType: 'bundle',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-library-with-umd#\n\n在类 NPM 包管理器下使用,并且 Library 支持类似 unpkg 的模式。在预设 'npm-library' 的基础上,额外提供 umd 产物。\n\n{\n \"main\": \"./dist/lib/index.js\",\n \"module\": \"./dist/es/index.js\",\n \"types\": \"./dist/types/index.d.ts\",\n \"unpkg\": \"./dist/umd/index.js\",\n};\n\n\n预设字符串对应的构建配置:\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundle',\n outDir: './dist/es',\n },\n {\n format: 'umd',\n target: 'es6',\n platform: 'browser',\n buildType: 'bundle',\n outDir: './dist/umd',\n },\n {\n buildType: 'bundle',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-component#\n\n在类 NPM 包管理器下使用的 组件(库)通用模式。包含 esm 和 cjs 两种 Bundleless 产物(便于 Tree shaking\n优化),以及包含一份类型文件。\n\n对于源码中包含的样式文件,产物中提供样式的编译产物和样式的源文件。\n\n{\n \"main\": \"./dist/lib/index.js\", // bundleless type\n \"module\": \"./dist/es/index.js\", // bundleless type\n \"types\": \"./dist/types/index.d.ts\",\n};\n\n\n预设字符串对应的构建配置:\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/es',\n },\n {\n buildType: 'bundleless',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-component-with-umd#\n\n在类 NPM 包管理器下使用的组件(库),同时支持类 unpkg 的模式。 在预设 'npm-component' 的基础上,额外提供 umd 产物。\n\n{\n \"main\": \"./dist/lib/index.js\", // bundleless type\n \"module\": \"./dist/es/index.js\", // bundleless type\n \"types\": \"./dist/types/index.d.ts\",\n \"unpkg\": \"./dist/umd/index.js\",\n};\n\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './dist/es',\n },\n {\n format: 'umd',\n target: 'es6',\n platform: 'browser',\n buildType: 'bundle',\n outDir: './dist/umd',\n },\n {\n buildType: 'bundleless',\n outDir: './dist/types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nnpm-library-{es5...esnext}#\n\n当想要使用支持其他 ECMAScript 版本的 buildPreset 预设的时候,可以直接在\n'npm-library'、'npm-library-with-umd'、'npm-component'、'npm-component-with-umd'\n这些预设值后面增加想要支持的版本。\n\n例如希望 'npm-library' 预设支持 'es2017',则可以按照如下方式配置:\n\n\n\nexport default defineConfig({\n buildPreset: 'npm-library-es2017',\n});\n\n\n\nstring / function#\n\nbuildPreset 除了支持基本的字符串形式,还支持函数形式,可以通过 preset 或者 extendPreset\n参数获取我们提供的预设值,然后进行修改。\n\n以下是两个分别使用 preset 和 extendPreset 的例子:\n\n\n\nexport default defineConfig({\n buildPreset({ preset }) {\n const { NPM_LIBRARY } = preset;\n return NPM_LIBRARY.map(config => {\n config.define = {\n VERSION: '1.0.1',\n };\n return config;\n });\n },\n});\n\n\nextendPreset 里会使用 lodash.merge 进行配置合并\n\n\n\nexport default defineConfig({\n buildPreset({ extendPreset }) {\n return extendPreset('npm-library', {\n define: {\n VERSION: '1.0.1',\n },\n });\n },\n});\n","frontmatter":{"sidebar_position":2},"version":""},{"id":47,"title":"dev","routePath":"/module-tools/api/config/dev","lang":"zh","toc":[{"text":"storybook","id":"storybook","depth":2,"charIndex":132},{"text":"storybook.webpack","id":"storybookwebpack","depth":3,"charIndex":295},{"text":"配置 Manager App","id":"配置-manager-app","depth":4,"charIndex":605},{"text":"storybook.webpackChain","id":"storybookwebpackchain","depth":3,"charIndex":901}],"domain":"","content":"#\n\n本章节描述了 Modern.js Module 关于调试工具相关的所有配置。\n\nexport default {\n dev: {\n storybook: {\n /* Storybook Config */\n },\n },\n};\n\n\n\nstorybook#\n\n首先需要确保:\n\n * 开启 Storybook 调试功能或者安装 @modern-js/plugin-storybook 插件。\n * 注册 @modern-js/plugin-storybook 插件。\n\n> 关于如何开启 Storybook 调试功能,可以参考:「Storybook 调试」\n\n\nstorybook.webpack#\n\n * 类型:object | Function | undefined\n * 默认值:undefined\n\nexport default {\n dev: {\n storybook: {\n webpack(config) {\n return config;\n },\n },\n },\n};\n\n\n你可以通过 dev.storybook.webpack 来修改 Storybook Preview-iframe 的 webpack 配置。使用方式可以参考\nModern.js Builder 的 tools.webpack 配置。\n\n\n\n配置 Manager App#\n\n对于 Storybook Manager App 部分的 webpack 配置,可以通过增加 ./config/storybook/main.js\n文件进行配置。\n\n// ./config/storybook/main.js\n\nmodule.exports = {\n // it controls the Storybook manager app\n managerWebpack: async (config, options) => {\n // update config here\n return config;\n },\n};\n\n\n\nstorybook.webpackChain#\n\n * 类型:Function | undefined\n * 默认值:undefined\n\nexport default {\n dev: {\n storybook: {\n webpackChain(chain) {\n return chain;\n },\n },\n },\n};\n\n\n你可以通过 dev.storybook.webpackChain 来修改 Storybook Preview-iframe 的 webpack\n配置。使用方式可以参考 Modern.js Builder 的 tools.webpackChain 配置。","frontmatter":{"sidebar_position":3},"version":""},{"id":48,"title":"plugins","routePath":"/module-tools/api/config/plugins","lang":"zh","toc":[{"text":"插件执行顺序","id":"插件执行顺序","depth":2,"charIndex":79},{"text":"开发插件","id":"开发插件","depth":2,"charIndex":221},{"text":"示例","id":"示例","depth":2,"charIndex":253},{"text":"使用 npm 上的插件","id":"使用-npm-上的插件","depth":3,"charIndex":259},{"text":"使用本地插件","id":"使用本地插件","depth":4,"charIndex":377},{"text":"插件配置项","id":"插件配置项","depth":3,"charIndex":486}],"domain":"","content":"#\n\n本章介绍注册 Modern.js Module 插件的配置。\n\n * 类型:ModuleToolsPlugin[]\n * 默认值:undefined\n\n\n插件执行顺序#\n\n默认情况下,自定义插件会按照 plugins 数组的顺序依次执行,Modern.js Module 内置插件的执行时机早于自定义插件。\n\n当插件内部使用了控制顺序的相关字段,比如 pre、post 时,会基于声明的字段对执行顺序进行调整,详见 插件之间的关系。\n\n\n开发插件#\n\n关于如何编写插件,可以查看「插件编写指南」。\n\n\n示例#\n\n\n使用 npm 上的插件#\n\n使用 npm 上的插件,需要通过包管理器安装插件,并通过 import 引入。\n\n\n\nexport default defineConfig({\n plugins: [myPlugin()],\n});\n\n\n使用本地插件#\n\n使用本地代码仓库中的插件,直接通过相对路径 import 引入即可。\n\n\n\nexport default defineConfig({\n plugins: [myPlugin()],\n});\n\n\n\n插件配置项#\n\n如果插件提供了一些自定义的配置项,你可以通过插件函数的参数传入配置。\n\n\n\nexport default defineConfig({\n plugins: [\n myPlugin({\n foo: 1,\n bar: 2,\n }),\n ],\n});\n","frontmatter":{"sidebar_position":4},"version":""},{"id":49,"title":"testing","routePath":"/module-tools/api/config/testing","lang":"zh","toc":[{"text":"jest","id":"jest","depth":2,"charIndex":55},{"text":"transformer","id":"transformer","depth":2,"charIndex":457}],"domain":"","content":"#\n\n本章描述了测试相关的配置。\n\nTIP\n\n需要先通过 pnpm run new 启用 单元测试 功能。\n\n\njest#\n\n * 类型: object | Function\n * 默认值:{}\n\n对应 Jest 的配置,当为 object 类型时,可以配置 Jest 所支持的所有底层配置 。\n\n\n\nexport default defineConfig({\n testing: {\n jest: {\n testTimeout: 10000,\n },\n },\n});\n\n\n值为 Function 类型时,默认配置作为第一个参数传入,需要返回新的 Jest 配置对象。\n\n\n\nexport default defineConfig({\n testing: {\n jest: options => {\n return {\n ...options,\n testTimeout: 10000,\n };\n },\n },\n});\n\n\n\ntransformer#\n\n * 类型:'babel-jest' | 'ts-jest'\n * 默认值:'babel-jest'\n\n配置执行测试的时候对于源码的编译工具: babel-jest 或 ts-jest。默认使用 babel-jest。\n\nINFO\n\nbabel-jest 也可以编译 TS 文件,但不会类型报错,如果你需要跑测试的时候对 TS 类型进行校验,那么请使用 ts-jest。","frontmatter":{"sidebar_position":5},"version":""},{"id":50,"title":"概览","routePath":"/module-tools/api/","lang":"zh","toc":[],"domain":"","content":"#","frontmatter":{"overview":true,"sidebar_label":"概览","sidebar_position":1},"version":""},{"id":51,"title":"Plugin Hooks","routePath":"/module-tools/api/plugin-api/plugin-hooks","lang":"zh","toc":[{"text":"构建钩子","id":"构建钩子","depth":2,"charIndex":172},{"text":"beforeBuild","id":"beforebuild","depth":3,"charIndex":281},{"text":"beforeBuildTask","id":"beforebuildtask","depth":3,"charIndex":831},{"text":"afterBuildTask","id":"afterbuildtask","depth":3,"charIndex":1163},{"text":"afterBuild","id":"afterbuild","depth":3,"charIndex":1513},{"text":"buildPlatform 钩子","id":"buildplatform-钩子","depth":2,"charIndex":1905},{"text":"registerBuildPlatform","id":"registerbuildplatform","depth":3,"charIndex":2244},{"text":"beforeBuildPlatform","id":"beforebuildplatform","depth":3,"charIndex":2851},{"text":"buildPlatform","id":"buildplatform","depth":3,"charIndex":3432},{"text":"afterBuildPlatform","id":"afterbuildplatform","depth":3,"charIndex":3807},{"text":"调试钩子","id":"调试钩子","depth":2,"charIndex":4385},{"text":"registerDev","id":"registerdev","depth":3,"charIndex":4614},{"text":"beforeDev","id":"beforedev","depth":3,"charIndex":5460},{"text":"(before|after)DevMenu","id":"beforeafterdevmenu","depth":3,"charIndex":5972},{"text":"beforeDevTask","id":"beforedevtask","depth":3,"charIndex":7008},{"text":"afterDev","id":"afterdev","depth":3,"charIndex":7517}],"domain":"","content":"#\n\n本章介绍关于 Modern.js Module 支持的生命周期钩子。\n\n目前主要包含两类生命周期钩子:\n\n * 构建钩子:仅在执行 build 命令构建源码产物时触发。\n * buildPlatform 钩子:仅在执行 build --platform 命令生成其他构建产物时触发。\n * 调试钩子:运行 dev 命令时会触发的钩子。\n\n\n构建钩子#\n\n在执行 build 命令的时候,会按照顺序触发以下 Hooks:\n\n * beforeBuild\n * beforeBuildTask\n * afterBuildTask\n * afterBuild\n\n\nbeforeBuild#\n\n执行整体构建流程之前触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuild(options: Options): Return {\n return options.config;\n },\n };\n },\n});\n\n\n参数和返回值类型:\n\ntype Options = {\n options: { config: BuildConfig; cliOptions: BuildCommandOptions };\n};\n\nexport interface BuildCommandOptions {\n config: string;\n clear?: boolean;\n dts?: boolean;\n platform?: boolean | string[];\n tsconfig: string;\n watch?: boolean;\n}\n\ntype Return = BuildConfig;\n\n\n> BuildConfig 类型参考 API 配置\n\n\nbeforeBuildTask#\n\n根据构建配置,Modern.js Module 会将整体构建分成多个子构建任务。该 Hook 将会在每一个构建子任务之前触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuildTask(config: BaseBuildConfig): BaseBuildConfig {\n return config;\n },\n };\n },\n});\n\n\n参数和返回值类型:\n\nBaseBuildConfig 类型参考 API 配置。\n\n\nafterBuildTask#\n\n每一个构建子任务结束之后触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuildTask(options: BuildTaskResult): void {\n // ...\n },\n };\n },\n});\n\n\n参数和返回值类型:\n\nexport interface BuildTaskResult {\n status: 'success' | 'fail';\n message?: string;\n config: BaseBuildConfig;\n}\n\n\n\nafterBuild#\n\n整体构建流程结束之后触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuild(options: BuildResult): void {\n // ...\n },\n };\n },\n});\n\n\n参数和返回值类型:\n\nexport interface BuildResult {\n status: 'success' | 'fail';\n message?: string;\n config: BuildConfig;\n commandOptions: BuildCommandOptions;\n totalDuration: number;\n}\n\n\n\nbuildPlatform 钩子#\n\nmodule-tools 还提供了 build --platform 命令来执行特定的构建任务。\n\n例如在安装了 Storybook 插件后,就可以执行 build --platform 或者 build --platform storybook 来执行\nStorybook 的构建任务。因为 Storybook 插件基于 buildPlatform Hooks 实现了该功能。\n\n在执行 build --platform 后会按照以下顺序触发 Hooks:\n\n * registerBuildPlatform\n * beforeBuildPlatform\n * buildPlatform\n * afterBuildPlatform\n\n\nregisterBuildPlatform#\n\n获取在执行 build --platform 命令时候需要运行的任务信息。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n registerBuildPlatform(): RegisterBuildPlatformResult {\n // ...\n return {\n platform: 'stroybook',\n build() {\n // run storybook logic\n },\n };\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface RegisterBuildPlatformResult {\n platform: string | string[];\n build: (\n currentPlatform: string, // 当前运行的 platform 构建任务\n context: { isTsProject: boolean },\n ) => void | Promise;\n}\n\n\n\nbeforeBuildPlatform#\n\n当执行 build --platform 命令的时候,会触发所有已注册的构建任务。beforeBuildPlatform 会在执行整体的构建任务之前触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuildPlatform(platforms: RegisterBuildPlatformResult[]): void {\n console.info(`have ${platforms.length} platform tasks`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface RegisterBuildPlatformResult {\n platform: string | string[];\n build: (\n currentPlatform: string, // 当前运行的 platform 构建任务\n context: { isTsProject: boolean },\n ) => void | Promise;\n}\n\n\n\nbuildPlatform#\n\n当执行 build --platform 命令的时候,会触发所有已注册的构建任务。buildPlatform 会在每个构建任务执行之前触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n buildPlatform({ platform }: Options): void {\n console.info(`current task is ${platform}`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface Options {\n platform: string;\n}\n\n\n\nafterBuildPlatform#\n\n当执行 build --platform 命令的时候,会触发所有已注册的构建任务。afterBuildPlatform 会在整体 platform\n构建任务结束后触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuildPlatform(result: BuildPlatformResult): void {\n if (result.status === 'success') {\n console.info(`all platform build task success`);\n } else {\n console.error(result.message);\n }\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface BuildPlatformResult {\n status: 'success' | 'fail';\n message: string | Error | null;\n}\n\n\n\n调试钩子#\n\n在执行 dev 命令的时候,会按照顺序触发以下 Hooks:\n\n * registerDev: 在获取调试功能信息的时候触发。\n * beforeDev: 开始执行调试整体流程之前触发。\n * beforeDevMenu: 出现调试列表/菜单之前触发。\n * afterDevMenu: 选择调试列表/菜单选项后触发。\n * beforeDevTask: 执行调试任务之前触发。\n * afterDev: 执行 dev 整体流程最后触发。\n\n\nregisterDev#\n\n注册调试工具相关的数据。主要包含:\n\n * 调试工具的名称\n * 显示在菜单列表中的项目名称以及对应的值。\n * dev 子命令的定义。\n * 是否在运行调试任务之前执行源码构建\n * 执行调试任务的函数。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n registerDev() {\n return {\n // 调试工具名称\n name: 'storybook',\n // 菜单显示内容\n menuItem: {\n name: 'Storybook',\n value: 'storybook',\n },\n // 定义的 dev 子命令\n subCommands: ['storybook', 'story'],\n async action() {\n // dev logic\n },\n };\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\nbeforeDev#\n\n在收集完所有调试工具元数据后,执行 dev 任务之前触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDev(metas: DevToolData[]) {\n console.info(`have ${metas.length} dev tools`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\n(before|after)DevMenu#\n\nbeforeDevMenu 在出现调试列表/菜单之前触发。接收 inquirer question 作为参数。默认值为:\n\nconst question = [\n {\n name: 'choiceDevTool',\n message: '选择调试工具',\n type: 'list',\n // 注册的调试信息\n choices,\n },\n];\n\n\nafterDevMenu 选择调试列表/菜单选项后触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDevMenu(questions) {\n questions[0].message += '!';\n return questions; // required\n },\n afterDevMenu(options: Options) {\n console.info(`choise ${options.result.choiceDevTool} dev tools`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport type { QuestionCollection } from 'inquirer';\n\nexport interface Options {\n result: PromptResult;\n devTools: DevToolData[];\n}\n\nexport type PromptResult = { choiceDevTool: string };\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\nbeforeDevTask#\n\n执行调试任务之前触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDevTask(currentDevData: DevToolData) {\n console.info(`${currentDevData.name} running`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise;\n}\n\n\n\nafterDev#\n\n在中断调试任务进程时触发。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterDev() {\n console.info(`exit!`);\n },\n };\n },\n});\n","frontmatter":{},"version":""},{"id":52,"title":"","routePath":"/module-tools/components/faq-build-exception","lang":"zh","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":53,"title":"","routePath":"/module-tools/components/faq-build-other","lang":"zh","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":54,"title":"","routePath":"/module-tools/components/faq-build-product","lang":"zh","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":55,"title":"","routePath":"/module-tools/components/faq-storybook","lang":"zh","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":56,"title":"","routePath":"/module-tools/components/faq-test","lang":"zh","toc":[],"domain":"","content":"","frontmatter":{},"version":""},{"id":57,"title":"","routePath":"/module-tools/components/register-esbuild-plugin","lang":"zh","toc":[],"domain":"","content":"\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.plugins = [myEsbuildPlugin, ...options.plugins];\n return options;\n },\n },\n});\n\n\n在增加 esbuild 插件时,请注意你需要将插件加在 plugins 数组的头部,因为 Modern.js Module 内部也是通过一个 esbuild\n插件介入到整个构建流程中去的,因此需要将自定义插件优先注册。","frontmatter":{},"version":""},{"id":58,"title":"处理静态资源","routePath":"/module-tools/guide/advance/asset","lang":"zh","toc":[{"text":"默认行为","id":"默认行为","depth":2,"charIndex":74},{"text":"示例","id":"示例","depth":2,"charIndex":355}],"domain":"","content":"#\n\nModern.js Module 会对代码中使用的静态资源进行处理。如果需要配置,则可以使用 buildConfig.asset API。\n\n\n默认行为#\n\n默认情况下,Modern.js Module 会处理以下静态资源:\n\n * '.svg'、'.png'、'.jpg'、'.jpeg'、'.gif'、'.webp'\n * '.ttf'、'.otf'、'.woff'、'.woff2'、'.eot'\n * '.mp3'、'.mp4'、'.webm'、'.ogg'、'.wav'、'.flac'、'.aac'、'.mov'\n\n对于静态文件的处理,Modern.js Module 目前默认支持的功能有:\n\n * 输出静态资源至 ./assets。\n * 对于不超过 10kb 的文件会内联到代码中。\n\n\n示例#\n\n让我们看下面的例子:\n\n * 项目源代码:\n\n\n\n\n * 如果 bg.png 的大小小于 10 kb,则此时产物目录结构和产物内容为:\n\n./dist\n└── asset.js\n\n\nvar img_default = 'data:image/png;base64,';\n\n\n * 如果 bg.png 的大小大于 10 kb,则此时产物目录结构和产物内容为:\n\n./dist\n├── asset.js\n└── assets\n └── bg.13e2aba2.png\n\n\n\n\n\n当你想要修改默认行为的时候,可以使用以下 API:\n\n * asset.path:修改静态资源文件输出路径。\n * asset.limit:修改内联静态资源文件的阈值。","frontmatter":{"sidebar_position":7},"version":""},{"id":59,"title":"构建 umd 产物","routePath":"/module-tools/guide/advance/build-umd","lang":"zh","toc":[{"text":"umd 产物的第三方依赖处理","id":"umd-产物的第三方依赖处理","depth":2,"charIndex":256},{"text":"示例","id":"示例","depth":3,"charIndex":377},{"text":"三方依赖的全局变量名称","id":"三方依赖的全局变量名称","depth":3,"charIndex":1563},{"text":"更改项目的全局变量名称","id":"更改项目的全局变量名称","depth":2,"charIndex":2612}],"domain":"","content":"#\n\numd 全称为 Universal Module Definition,这种格式的 JS 文件可以运行在多个运行环境:\n\n * 浏览器环境:基于 AMD 规范进行模块加载\n * Node.js 环境:基于 CommonJS 进行模块加载\n * 其他情况:将模块挂载在全局对象上。\n\n因此我们可以通过下面的方式,将项目的构建产物指定为 umd 产物:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n },\n});\n\n\n\numd 产物的第三方依赖处理#\n\n在 「如何处理第三方依赖」 章节中,我们知道可以通过 autoExternals 和 externals API 来控制项目是否对第三方依赖打包。 因此在构建\numd 产物的过程中,我们也可以这样使用:\n\n\n示例#\n\n * 如果项目依赖了 react:\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n * modern.config.ts 配置:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n autoExternal: false,\n externals: ['react'],\n },\n});\n\n\n * 当源码中使用了 react 依赖:\n\n\nconsole.info(React);\n\n\n * 此时产物中不会将 react 代码打包到产物中:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports, require('react'));\n else if (typeof define === 'function' && define.amd)\n define(['exports', 'react'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.index = {}), global.react);\n})(this, function (exports, _react) {\n 'use strict';\n Object.defineProperty(exports, '__esModule', {\n value: true,\n });\n _react = /*#__PURE__*/ _interopRequireDefault(_react);\n function _interopRequireDefault(obj) {\n return obj && obj.__esModule\n ? obj\n : {\n default: obj,\n };\n }\n console.info(_react.default);\n});\n\n\n通过上面的例子我们知道,当使用 autoExternal 和 externals API 后:\n\n * 在 Node.js 环境下,可以通过 require('react') 获取 react 依赖。\n * 在 浏览器环境下,可以通过 global.react 获取 react 依赖。\n\n\n三方依赖的全局变量名称#\n\n然而在浏览器环境下,获取第三方依赖的时候,全局变量名称不一定与依赖名称完全相同,此时就要使用 buildConfig.umdGlobals API。\n\n还是使用之前的例子,当 react 依赖以 windows.React 或者 global.React 全局变量的形式存在于浏览器环境下,那么此时:\n\n * modern.config.ts 配置:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdGlobals: {\n react: 'React',\n },\n },\n});\n\n\n * 当源码中使用了 react 依赖:\n\n\nconsole.info(React);\n\n\n * 此时我们会看到这样的产物代码:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory();\n else if (typeof define === 'function' && define.amd) define([], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory();\n})(this, function () {\n // ...\n // libuild:globals:react\n var require_react = __commonJS({\n 'libuild:globals:react'(exports, module1) {\n module1.exports = Function('return this')()['React'];\n },\n });\n // src/index.ts\n var import_react = __toESM(require_react());\n console.info(import_react.default);\n});\n\n\n此时项目就可以运行在浏览器中,并使用存在于全局对象上的 React 变量了。\n\n\n更改项目的全局变量名称#\n\n当我们将下面的代码打包成 umd 产物并运行在浏览器的时候,我们可以通过 window.index 来使用该模块。\n\nexport default () => {\n console.info('hello world');\n};\n\n\n默认情况下,以源码文件名称作为该模块在浏览器里全局变量的名称。对于上面的例子,其产物内容如下:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports);\n else if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.index = {}));\n})(this, function (exports) {\n //...\n});\n\n\n如果需要修改它,则需要使用 buildConfig.umdModuleName API。\n\n当使用该 API 后:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdModuleName: 'myLib',\n },\n});\n\n\n此时构建产物的内容为:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports);\n else if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.myLib = {}));\n})(this, function (exports) {\n //...\n});\n","frontmatter":{"sidebar_position":5},"version":""},{"id":60,"title":"使用 Copy 工具","routePath":"/module-tools/guide/advance/copy","lang":"zh","toc":[{"text":"了解 Copy API","id":"了解-copy-api","depth":2,"charIndex":72},{"text":"API 详解","id":"api-详解","depth":2,"charIndex":165},{"text":"不同场景使用示例","id":"不同场景使用示例","depth":2,"charIndex":1492},{"text":"将文件复制文件","id":"将文件复制文件","depth":3,"charIndex":1504},{"text":"将文件复制到目录","id":"将文件复制到目录","depth":3,"charIndex":1848},{"text":"从目录复制到目录","id":"从目录复制到目录","depth":3,"charIndex":2186},{"text":"从目录到文件","id":"从目录到文件","depth":3,"charIndex":2580},{"text":"使用 Glob","id":"使用-glob","depth":3,"charIndex":2985}],"domain":"","content":"#\n\nModern.js Module 提供了 Copy 工具用于将已经存在的单个文件或整个目录复制到产物目录中。接下来我们学习如何使用它。\n\n\n了解 Copy API#\n\n我们可以通过 buildConfig.copy API 来使用 Copy 工具,它包含以下两个主要配置:\n\n * patterns\n * options\n\n\nAPI 详解#\n\ncopy.patterns 用于寻找复制的文件以及配置输出的路径。\n\n其中 patterns.from 用于指定要复制的文件或者目录。它接收 Glob 形式字符串或具体路径。Glob 形式字符串是指 fast-glob\npattern-syntax。因此我们可以按照如下两种方式使用它:\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n { from: './index.html', to: '' },\n { from: './*.html', to: '' },\n ],\n },\n },\n});\n\n\npatterns.context 一般和 patterns.from 配合使用,默认情况下它的值与 buildConfig.sourceDir\n相同,因此我们可以按照如下方式指定 src/data.json 文件为要复制的文件:\n\n> 默认情况下,buildConfig.sourceDir 为 src\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n { from: './data.json' to: ''},\n ],\n },\n },\n});\n\n\n当指定的文件不在源码目录的时候,可以修改 context 配置。例如指定项目目录下的 temp/index.html 为要复制的文件:\n\n\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n {\n from: './index.html',\n context: path.join(__dirname, './temp')\n to: '',\n }\n ],\n },\n },\n});\n\n\npatterns.to 用于指定复制文件的输出路径,默认情况下它的值为 buildConfig.outDir对应的值。因此我们按照如下方式将\nsrc/index.html 复制到 dist 目录下:\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [{ from: './index.html' }],\n },\n },\n});\n\n\n当我们配置了 patterns.to 的时候:\n\n * 如果是相对路径,则该路径会相对于 buildConfig.outDir 计算出复制文件输出的绝对路径。\n * 如果是绝对路径,则会直接使用该值。\n\n最后 patterns.globOptions 用于配置寻找复制文件 globby 对象,其配置可参考:\n\n * globby.options\n\n\n不同场景使用示例#\n\n\n将文件复制文件#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy file to file\n */\n {\n from: './temp-1/a.png',\n context: __dirname,\n to: './temp-1/b.png',\n },\n ],\n },\n },\n ],\n});\n\n\n\n将文件复制到目录#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy file to dir\n */\n {\n from: './temp-2/a.png',\n context: __dirname,\n to: './temp-2',\n },\n ],\n },\n },\n ],\n});\n\n\n\n从目录复制到目录#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy dir to dir\n */\n {\n from: './temp-3/',\n to: './temp-3',\n context: __dirname,\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n\n\n\n从目录到文件#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy dir to file\n */\n {\n from: './temp-4/',\n context: __dirname,\n to: './temp-4/_index.html',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n\n\n\n使用 Glob#\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy glob to dir\n */\n {\n from: './*.html',\n to: './temp-5',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n {\n copy: {\n patterns: [\n /**\n * copy glob to file\n */\n {\n from: './*.html',\n to: './temp-6/index.html',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n","frontmatter":{"sidebar_position":3},"version":""},{"id":61,"title":"处理三方依赖","routePath":"/module-tools/guide/advance/external-dependency","lang":"zh","toc":[{"text":"第三方依赖的默认处理","id":"第三方依赖的默认处理","depth":2,"charIndex":314},{"text":"示例","id":"示例","depth":3,"charIndex":571},{"text":"排除指定第三方依赖","id":"排除指定第三方依赖","depth":2,"charIndex":849}],"domain":"","content":"#\n\n一般来说,项目所需要的第三方依赖可以通过包管理器的 install 命令安装,在安装第三方依赖成功后,这些第三方依赖一般会出现在项目 package.json\n的 dependencies 和 devDependencies 下。\n\n{\n \"dependencies\": {},\n \"devDependencies\": {}\n}\n\n\n\"dependencies\" 下的依赖通常来说是这个包运行所需的依赖, \"devDependencies\" 则代表着开发依赖。\n\n除了 \"dependencies\" 以外,\"peerDependencies\" 也可以声明在生产环境下运行所需要的依赖,此时会和它的宿主共享一份依赖。\n\n\n第三方依赖的默认处理#\n\n在 Modern.js Module 里,默认情况下不会对 \"dependencies\" 以及 \"peerDependencies\"\n下的第三方依赖进行打包处理。\n\n这是因为在安装 npm 包时,其 \"dependencies\" 也会被安装。不打包 \"dependencies\",可以减小包产物的体积。\n\n如果需要打包某些依赖,建议将它们从 \"dependencies\" 挪到 \"devDependencies\" ,这相当于对依赖进行 prebundle\n,可以减小依赖安装的体积。\n\n\n示例#\n\n如果项目依赖了 react:\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n },\n // or\n \"peerDependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n当源码中使用了 react 依赖:\n\n\nconsole.info(React);\n\n\n此时产物中不会包含 react 的代码:\n\n\nconsole.info(React);\n\n\n如果想要修改默认的处理方式,可以通过下面的 API 进行修改:\n\n * buildConfig.autoExternal\n\n\n排除指定第三方依赖#\n\n在上面我们提到了 buildConfig.autoExternal API 的用途,同时 buildConfig.externals\n可以实现对三方依赖更细微的处理。\n\n例如当我们需要仅对某些依赖不进行打包处理的时候,可以按照如下方式进行配置:\n\n> 一般这种情况,可能是某些依赖不适合进行打包处理。如果遇到这种情况,则可以按照下面的方式进行处理。\n\nepxort default defineConfig({\n buildConfig: {\n autoExternal: false,\n externals: ['pkg-1', /pkg-2/],\n }\n});\n","frontmatter":{"sidebar_position":4},"version":""},{"id":62,"title":"深入理解构建","routePath":"/module-tools/guide/advance/in-depth-about-build","lang":"zh","toc":[{"text":"bundle / bundleless","id":"bundle--bundleless","depth":2,"charIndex":195},{"text":"input / sourceDir","id":"input--sourcedir","depth":2,"charIndex":715},{"text":"使用 swc","id":"使用-swc","depth":2,"charIndex":1372},{"text":"使用 Hook 介入构建流程","id":"使用-hook-介入构建流程","depth":2,"charIndex":1851},{"text":"Hook 类型","id":"hook-类型","depth":3,"charIndex":2025},{"text":"AsyncSeriesBailHook","id":"asyncseriesbailhook","depth":4,"charIndex":2035},{"text":"AsyncSeriesWaterFallHooks","id":"asyncserieswaterfallhooks","depth":4,"charIndex":2137},{"text":"Hook API","id":"hook-api","depth":3,"charIndex":2206},{"text":"load","id":"load","depth":4,"charIndex":2217},{"text":"transform","id":"transform","depth":4,"charIndex":2824},{"text":"renderChunk","id":"renderchunk","depth":4,"charIndex":3246},{"text":"类型文件生成","id":"类型文件生成","depth":2,"charIndex":4134},{"text":"关闭类型生成","id":"关闭类型生成","depth":3,"charIndex":4176},{"text":"打包类型文件","id":"打包类型文件","depth":3,"charIndex":4327},{"text":"别名转换","id":"别名转换","depth":3,"charIndex":4624},{"text":"一些示例","id":"一些示例","depth":3,"charIndex":4909},{"text":"构建过程","id":"构建过程","depth":2,"charIndex":5480},{"text":"构建报错","id":"构建报错","depth":2,"charIndex":5654},{"text":"调试模式","id":"调试模式","depth":2,"charIndex":6052}],"domain":"","content":"#\n\n在 \"基础使用\" 的部分,我们已经知道可以通过 buildConfig 配置对项目的输出产物进行修改。buildConfig\n不仅描述了产物的一些特性,同时还为构建产物提供了一些功能。\n\nTIP\n\n如果你还不了解 buildConfig 的作用,请先阅读 修改输出产物。\n\n而在本章里我们将要深入理解某些构建配置的作用以及了解执行 modern build 命令的时候发生了什么。\n\n\nbundle / bundleless#\n\n那么首先我们来了解一下 bundle 和 bundleless。\n\n所谓 bundle 是指对构建产物进行打包,构建产物可能是一个文件,也有可能是基于一定的代码拆分策略得到的多个文件。\n\n而 bundleless 则是指对每个源文件单独进行编译构建,但是并不将它们打包在一起。每一个产物文件都可以找到与之相对应的源码文件。bundleless\n构建的过程,也可以理解为仅对源文件进行代码转换的过程。\n\n它们有各自的好处:\n\n * bundle 可以减少构建产物的体积,也可以对依赖预打包,减小安装依赖的体积。提前对库进行打包,可以加快应用项目构建的速度。\n * bundleless 则是可以保持原有的文件结构,更有利于调试和 tree shaking。\n\nWARNING\n\nbundleless 是单文件编译模式,因此对于类型的引用和导出你需要加上 type 字段, 例如 import type { A } from\n'./types\n\n在 buildConfig 中可以通过 buildConfig.buildType 来指定当前构建任务是 bundle 还是 bundleless。\n\n\ninput / sourceDir#\n\nbuildConfig.input 用于指定读取源码的文件路径或者目录路径,其默认值在 bundle 和 bundleless 构建过程中有所不同:\n\n * 当 buildType: 'bundle' 的时候,input 默认值为 src/index.(j|t)sx?\n * 当 buildType: 'bundleless' 的时候,input 默认值为 ['src']\n\n从默认值上我们可以知道:使用 bundle 模式构建时一般指定一个或多个文件作为构建的入口,而使用 bundleless\n构建则是指定一个目录,将目录下所有文件作为入口。\n\nsourceDir 用于指定源码目录,它只与以下两个内容有关系:\n\n * 类型文件生成\n * 指定构建过程中的 outbase\n\n因此我们可以得到其最佳实践:\n\n * 在 bundle 构建过程中,只能指定 input 。\n * 一般情况下,bundleless 只需要指定 sourceDir(此时 input 会与 sourceDir 保持一致)。\n\n如果我们想要在 bundleless 里只对一部分文件进行转换,例如只需要转换 src/runtime 目录的文件,此时需要配置 input:\n\n\n\nexport default defineConfig({\n buildConfig: {\n input: ['src/runtime'],\n sourceDir: 'src',\n },\n});\n\n\n\n使用 swc#\n\n在部分场景下,esbuild 不足以满足我们的需求,此时我们会使用 swc 来做代码转换。\n\n从 2.36.0 版本开始,涉及到以下功能时,Modern.js Module 默认会使用 swc ,但不这意味着不使用 esbuild 了,其余功能还是使用\nesbuild:\n\n * transformImport\n * transformLodash\n * externalHelpers\n * format: umd\n * target: es5\n * emitDecoratorMetadata: true\n\n事实上,我们在 2.16.0 开始全量使用 swc 进行代码转换。不过 swc 同样也存在一些限制,为此我们添加了 sourceType 配置,当源码格式为\n'commonjs' 时关闭 swc, 但这种方式并不符合用户直觉,另外,swc 格式化输出的 cjs 模式没有给每个导出名称添加注释,这在 node\n中使用可能会带来一些问题。 因为我们废弃了此行为,回到了最初的设计 - 只在需要的场景下使用 swc 作为补充。\n\n\n使用 Hook 介入构建流程#\n\nModern.js Module 提供了 Hook 机制,允许我们在构建流程的不同阶段注入自定义逻辑。 Modern.js Module Hook 使用了\ntapable 实现,扩展了 esbuild 的插件机制,若 esbuild plugins 已经满足了你的需求,建议直接使用它。 下面展开说明其用法:\n\n\nHook 类型#\n\nAsyncSeriesBailHook#\n\n串行执行的 hooks,如果某个 tapped function 返回非 undefined 结果,则后续其他的 tapped function 停止执行。\n\nAsyncSeriesWaterFallHooks#\n\n串行执行的 hooks,其结果会传递给下一个 tapped function\n\n\nHook API#\n\nload#\n\n * AsyncSeriesBailHook\n * 在 esbuild onLoad callbacks 触发,根据模块路径来获取模块内容\n * 输入参数\n\ninterface LoadArgs {\n path: string;\n namespace: string;\n suffix: string;\n}\n\n\n * 返回参数\n\ntype LoadResult =\n | {\n contents: string; // 模块内容\n map?: SourceMap; // https://esbuild.github.io/api/#sourcemap\n loader?: Loader; // https://esbuild.github.io/api/#loader\n resolveDir?: string;\n }\n | undefined;\n\n\n * 例子\n\ncompiler.hooks.load.tapPromise('load content from memfs', async args => {\n const contents = memfs.readFileSync(args.path);\n return {\n contents: contents,\n loader: 'js',\n };\n});\n\n\ntransform#\n\n * AsyncSeriesWaterFallHooks\n * 在 esbuild onLoad callbacks 触发, 将 load 阶段获取的模块内容进行转换\n * 输入参数(返回参数)\n\nexport type Source = {\n code: string;\n map?: SourceMap;\n path: string;\n loader?: string;\n};\n\n\n * 例子\n\ncompiler.hooks.transform.tapPromise('6to5', async args => {\n const result = babelTransform(args.code, { presets: ['@babel/preset-env'] });\n return {\n code: result.code,\n map: result.map,\n };\n});\n\n\nrenderChunk#\n\n * AsyncSeriesWaterFallHooks\n * 在 esbuild onEnd callbacks 触发, 类似于 transform hook,但是作用在 esbuild 生成的产物\n * 输入参数(返回参数)\n\nexport type AssetChunk = {\n type: 'asset';\n contents: string | Buffer;\n entryPoint?: string;\n /**\n * absolute file path\n */\n fileName: string;\n originalFileName?: string;\n};\n\nexport type JsChunk = {\n type: 'chunk';\n contents: string;\n entryPoint?: string;\n /**\n * absolute file path\n */\n fileName: string;\n map?: SourceMap;\n modules?: Record;\n originalFileName?: string;\n};\n\nexport type Chunk = AssetChunk | JsChunk;\n\n\n * 例子\n\ncompiler.hooks.renderChunk.tapPromise('minify', async chunk => {\n if (chunk.type === 'chunk') {\n const code = chunk.contents.toString();\n const result = await minify.call(compiler, code);\n return {\n ...chunk,\n contents: result.code,\n map: result.map,\n };\n }\n return chunk;\n});\n\n\n\n类型文件生成#\n\nbuildConfig.dts 配置主要用于类型文件的生成。\n\n\n关闭类型生成#\n\n默认情况下类型生成功能是开启的,如果需要关闭的话,可以按照如下配置:\n\n\n\nexport default defineConfig({\n buildConfig: {\n dts: false,\n },\n});\n\n\nTIP\n\n关闭类型文件后,一般来说构建速度会有所提升。\n\n\n打包类型文件#\n\n在 buildType: 'bundleless' 的时候,类型文件的生成是使用项目的 tsc 命令来完成生产。\n\nModern.js Module 同时还支持对类型文件进行打包,不过使用该功能的时候需要注意:\n\n * 一些第三方依赖存在错误的语法会导致打包过程失败。因此对于这种情况,需要手动通过 buildConfig.externals 将这类第三方包排除。\n * 对于第三方依赖的类型文件指向的是一个 .ts 文件的情况,目前无法处理。比如第三方依赖的 package.json 中存在这样的内容: {\"types\":\n \"./src/index.ts\"}。\n\n\n别名转换#\n\n在 bundleless 构建过程中,如果源代码中出现了别名,例如:\n\n\n\n\n正常来说,使用 tsc 生成的产物类型文件也会包含这些别名。不过 Modern.js Module 会对 tsc 生成的类型文件里的别名进行转换处理:\n\n * 对于类似 `` 这样形式的代码可以进行别名转换。\n * 对于类似 export { utils } from '@common/utils' 这样形式的代码可以进行别名转换。\n\n然而也存在一些情况,目前还无法处理,例如 Promise 这样形式的输出类型目前无法进行转换。 对于这种情况的解决办法,可以参与讨论。\n\n\n一些示例#\n\n\n\nexport default defineConfig({\n // 此时打包的类型文件输出路径为 `./dist/types`,并且将会读取项目下的 other-tsconfig.json 文件\n buildConfig: {\n buildType: 'bundle',\n dts: {\n tsconfigPath: './other-tsconfig.json',\n distPath: './types',\n },\n outDir: './dist',\n },\n});\n\n\n\n\nexport default defineConfig({\n // 此时类型文件没有进行打包,输出路径为 `./dist/types`\n buildConfig: [\n {\n buildType: 'bundle',\n dts: false,\n outDir: './dist',\n },\n {\n buildType: 'bundleless',\n dts: {\n only: true,\n },\n outDir: './dist/types',\n },\n ],\n});\n\n\n\n构建过程#\n\n当执行 modern build 命令的时候,会发生\n\n * 根据 buildConfig.outDir 清理产物目录。\n * 编译 js/ts 源代码生成 bundle / bundleless 的 JS 构建产物。\n * 使用 tsc 生成 bundle / bundleless 的类型文件。\n * 处理 copy 任务。\n\n\n构建报错#\n\n当发生构建报错的时候,基于以上了解到的信息,可以很容易的明白在终端出现的报错内容:\n\njs 或者 ts 构建的报错:\n\nerror ModuleBuildError:\n\n╭───────────────────────╮\n│ bundle failed: │\n│ - format is \"cjs\" │\n│ - target is \"esnext\" │\n╰───────────────────────╯\n\nDetailed Information:\n\n\n类型文件生成过程的报错:\n\nerror ModuleBuildError:\n\nbundle DTS failed:\n\n\n对于 js/ts 构建错误,我们可以从报错信息中知道:\n\n * 报错的 buildType\n * 报错的 format\n * 报错的 target\n * 其他具体报错信息\n\n\n调试模式#\n\n从 2.36.0 版本开始,为了便于排查问题,Modern.js Module 提供了调试模式,你可以在执行构建时添加 DEBUG=module\n环境变量来开启调试模式。\n\nDEBUG=module modern build\n\n\n调试模式下,你会看到 Shell 中输出更详细的构建日志,这主要以流程日志为主:\n\nmodule run beforeBuildTask hooks +6ms\nmodule run beforeBuildTask hooks done +0ms\nmodule [DTS] Build Start +139ms\nmodule [CJS] Build Start +1ms\n\n\n另外,Module 还提供了调试内部工作流程的能力。你可以通过设置环境变量 DEBUG=module:* 来开启更详细的调试日志:\n\n目前只支持了 DEBUG=module:resolve,可以查看 Module 内部模块解析的详细日志:\n\n module:resolve onResolve args: {\n path: './src/hooks/misc.ts',\n importer: '',\n namespace: 'file',\n resolveDir: '/Users/bytedance/modern.js/packages/solutions/module-tools',\n kind: 'entry-point',\n pluginData: undefined\n} +0ms\n module:resolve onResolve result: {\n path: '/Users/bytedance/modern.js/packages/solutions/module-tools/src/hooks/misc.ts',\n external: false,\n namespace: 'file',\n sideEffects: undefined,\n suffix: ''\n} +0ms\n","frontmatter":{"sidebar_position":1},"version":""},{"id":63,"title":"深入理解 dev 命令","routePath":"/module-tools/guide/advance/in-depth-about-dev-command","lang":"zh","toc":[{"text":"命令运行的整体流程","id":"命令运行的整体流程","depth":2,"charIndex":42},{"text":"扩展 dev 命令","id":"扩展-dev-命令","depth":2,"charIndex":339}],"domain":"","content":"#\n\nModern.js Module 提供的 dev 命令主要用于代码的调试。\n\n\n命令运行的整体流程#\n\n 1. 当执行 dev 命令的时候,Modern.js Module 开始寻找是否存在可以执行的调试工具或者任务。调试工具或者任务就是类似 Storybook\n 这样的 Modern.js Module 调试工具插件。\n 2. 当发现存在一个调试工具的时候,则会立即执行它。\n 3. 当发现多个调试工具的时候,则显示调试工具列表菜单。可以通过选择某个调试工具对应的名称选项启动它。\n 4. 当没有发现调试工具的时候,则告诉用户没有可用的调试工具。\n\n我们除了可以执行 dev 命令以外,也可以通过 dev [调试工具名称] 的方式来直接启动调试工具或者任务。\n\n\n扩展 dev 命令#\n\n如果需要扩展 dev 命令或者说提供自己的 Modern.js Module 调试工具插件,那么你需要先了解以下内容:\n\n * 开发插件\n * 调试工具插件 API\n\n一般来说,实现一个什么都不做的调试工具,其实现代码以及相关配置如下:\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'do-nothing',\n setup() {\n return {\n registerDev() {\n return {\n // 调试工具名称\n name: 'do-nothing',\n // 菜单显示内容\n menuItem: {\n name: 'DoNothing',\n value: 'do-nothing',\n },\n // 定义的 dev 子命令\n subCommands: ['donothing', 'dn'],\n async action() {\n // dev logic\n console.info('Run build --watch, and do nothing.');\n },\n };\n },\n };\n },\n});\n\n\n如果需要使用该调试工具插件,则需要在配置文件中增加它:\n\n\n\nexport default defineConfig({\n plugins: [\n //..\n doNothingPlugin()\n ],\n});\n\n\n此时我们执行 dev 或者 dev do-nothing 命令的时候,就可以执行它了。在执行后,它会先执行监听模式的源码构建任务,并紧接着打印日志信息。\n\n对于目前官方支持的调试工具和第三方支持的调试工具,可以在插件列表中查看。","frontmatter":{"sidebar_position":2},"version":""},{"id":64,"title":"开始之前","routePath":"/module-tools/guide/basic/before-getting-started","lang":"zh","toc":[{"text":"环境准备","id":"环境准备","depth":2,"charIndex":3},{"text":"初识 npm","id":"初识-npm","depth":2,"charIndex":189},{"text":"npm 包类型项目","id":"npm-包类型项目","depth":2,"charIndex":392},{"text":"使用第三方 npm 包","id":"使用第三方-npm-包","depth":2,"charIndex":1023},{"text":"还需要了解的 npm 零碎知识","id":"还需要了解的-npm-零碎知识","depth":2,"charIndex":1990},{"text":"npm 包的程序入口","id":"npm-包的程序入口","depth":3,"charIndex":2009},{"text":"\\\"scripts\\\"","id":"scripts","depth":3,"charIndex":-1},{"text":"npm install","id":"npm-install","depth":4,"charIndex":2878},{"text":"npm publish","id":"npm-publish","depth":4,"charIndex":3142},{"text":"peerDependencies","id":"peerdependencies","depth":3,"charIndex":3302},{"text":"npm 包管理器","id":"npm-包管理器","depth":2,"charIndex":3616},{"text":"Modern.js Module 配置文件","id":"modernjs-module-配置文件","depth":2,"charIndex":3744}],"domain":"","content":"#\n\n\n环境准备#\n\n为了使用 Modern.js Module,首先需要 NodeJS,我们推荐最新的长期维护版本,并确保 Node 版本大于等于 14.18.0。因为非稳定的\nNodeJS 时常有一些 Bug,你可以使用 nvm-windows 和 nvm(Mac / Linux)安装,这样你就可以方便地切换到不同的 NodeJS\n版本,这些版本可能会用于不同的项目。\n\n\n初识 npm#\n\n当 NodeJS 被安装后,你不仅可以在命令行中访问 node 可执行程序,同时你也可以执行 npm 命令。\n\nnpm 是 NodeJS 的标准软件包管理器。它一开始的用途是用于下载和管理 NodeJS 包的依赖关系,但后来它逐渐变成为一个用于前端 JavaScript\n的工具。\n\n如果你已经对 npm 和 npm 包的使用方式有所了解,那么可以直接跳到「npm 包管理器」部分。\n\n\nnpm 包类型项目#\n\n那么什么是 npm 包类型的项目呢?当我们在一个空的项目目录下执行 npm init 命令的时候,它会在当前目录下面创建一个文件名为 package.json\n的 JSON 文件。在创建过程中,我们需要填写包括但不限于 npm 包的名称、版本号、描述等等内容,这些填写的内容都会在生成的 package.json\n文件中找到:\n\n{\n \"name\": \"npm-demo\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"index.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n },\n \"author\": \"\",\n \"license\": \"ISC\"\n}\n\n\n此时这个包含了初始化后的 package.json 文件的项目就是一个 npm 包类型的项目,你可以执行 npm publish 命令将这个项目发布到 npm\nRegistry。\n\nnpm Registry 是一个 npm 包存储的地方,开发者们不仅可以将他们自己的 npm 包发布到 npm Registry,还可以通过 npm\nRegistry 使用其他开发者发布的 npm 包。\n\n优质的 npm 包会有更多的人去使用,因为它不仅节省了很多代码实现的工作,同时也不容易让项目出现问题。\n\n\n使用第三方 npm 包#\n\n当要为初始化的项目增加第三方的 npm 包的时候,我们可以把这一过程叫做“为项目安装依赖”或是“为项目增加依赖”。在增加依赖之前,首先我们要特别了解一件事情\n—— npm 依赖的软件包类型:\n\n * \"dependencies\":一种是你的应用程序在生产环境中需要的软件包。\n * \"devDependencies\":另一种是仅在本地开发和测试中需要的软件包。\n \n > 软件包可以理解为是第三方的 npm 包。\n\n你可以通过执行 npm install npm-package-name 或者 npm add npm-package-name\n的方式来安装在生产环境中需要的软件包,或者也可以在 package.json 文件中手动的将需要安装的包和对应的语义化版本写在 \"dependencies\"\n里,并执行 npm install 命令:\n\n{\n \"name\": \"your-npm-project\",\n \"dependencies\": {\n \"npm-package-name\": \"0.1.0\"\n }\n}\n\n\n同理,你也可以执行 npm install npm-package-name --save-dev 或 npm add npm-package-name\n--save-dev 的方式来安装仅在本地开发和测试中需要的软件包,或者也可以在 package.json 文件中手动的将需要安装的包和对应的语义化版本写在\n\"devDependencies\" 里,并执行 npm install 命令:\n\n{\n \"name\": \"your-npm-project\",\n \"devDependencies\": {\n \"npm-package-name\": \"0.1.0\"\n }\n}\n\n\n在安装或者使用第三方 npm 包的时候一定要确定它们的用途,以及通过区分它们的类型确定好它们应该放在 \"dependencies\" 还是\n\"devDependencies\" 中。\n\nTIP\n\n一般来说,需要在源代码中使用到的包都属于 dependencies 依赖。除非你通过打包的方式将依赖的代码输出到本地,那么这种情况可以将它作为\ndevDependencies 依赖。\n\n\n还需要了解的 npm 零碎知识#\n\n\nnpm 包的程序入口#\n\n在 package.json 中存在一个 \"main\" 属性,它对应的值是一个模块 ID,或者更直观的说是一个 NodeJS 文件路径,它是你程序的主要入口。\n\n例如你的包名为 foo,并且用户安装了它,然后执行 require(\"foo\") 代码,那么 foo 这个 npm 包的 \"main\"\n字段对应的文件将会被导出。\n\n推荐在你的 npm 包里一定要设置 \"main\" 字段。如果没有设置 \"main\",则默认入口为包的根目录下的 index.js 文件。\n\n除了需要设置 \"main\" 属性以外,一般还会设置 \"module\" 属性。它与 \"main\" 属性的用途类似,它主要是用于在 webpack\n场景下使用。webpack 在大多数情况下,会以 \"module\" -> \"main\" 这个顺序读取 npm 包的入口(文件)。\n\n> 想要了解关于 webpack 如何做这件事,可以查看这个链接。\n\n\n\"scripts\"#\n\npackage.json 文件的 \"scripts\" 属性支持一些内置的脚本和 npm 预设的生命周期事件,以及任意的脚本。\n\n这些都可以通过运行 npm run-script 或简称 npm run 来执行。\n\n名称匹配的前置命令和后置命令也会被运行(例如 premyscript、myscript、postmyscript)。\n\n{\n \"scripts\": {\n \"premyscript\": \"\",\n \"myscript\": \"\",\n \"postmyscript\": \"\"\n }\n}\n\n\n当执行 npm run myscripts 的时候,premyscripts 对应的脚本会在它之前执行,postmyscripts 对应的脚本会在它之后执行。\n\n来自依赖的脚本命令可以用 npm explore -- npm run 运行。\n\n还有一些特殊的生命周期脚本(Life Scripts),只在某些情况下发生。这里介绍几个通常需要了解的情况。\n\nnpm install#\n\n当你运行 npm install -g 时,以下脚本会运行。\n\n * preinstall\n * install\n * postinstall\n * prepublish\n * preprepare\n * prepare\n * postprepare\n\n如果你的软件包根目录有一个 binding.gyp 文件,而你没有定义 install 或 preinstall 脚本,那么 npm 将以 node-gyp\nrebuild 作为默认的 install 命令,使用 node-gyp 进行编译。\n\nnpm publish#\n\n当发布项目的时候,执行该命令会触发以下脚本:\n\n * prepublishOnly\n * prepack\n * prepare\n * postpack\n * publish\n * postpublish\n\n当以 --dry-run 模式运行的时候,prepare 对应的脚本将不会执行。\n\n\npeerDependencies#\n\n在某些情况下,你的 npm 项目与它的宿主工具或者库之间存在某种兼容关系(例如一个 webpack 插件项目和 webpack),同时你的 npm\n项目不想将宿主作为必要的依赖,这个时候通常说明你的项目可能是这个宿主工具或者库的插件。你的 npm\n项目会对宿主包的版本有一定的要求,因为只有在特定的版本下才会暴露出 npm 项目所需要的 API。\n\n关于更多 peerDependencies 的解释,可以通过下面的链接了解 npm、pnpm、Yarn 对于它的不同处理方式:\n\n * npm 对 peerDependencies 的解释\n * pnpm vs npm VS Yarn\n\n\nnpm 包管理器#\n\n除了 npm 这种标准的包管理器以外,目前主流的还有 pnpm 和 Yarn,它们都是不错的 npm cli 替代品。\n\n推荐使用 pnpm 来管理项目依赖,可以通过下面的方式安装它:\n\nnpm install -g pnpm\n\n\n\nModern.js Module 配置文件#\n\n通过 @modern-js/create 创建的项目目录下提供了 Modern.js Module 的配置文件 ——\nmodern.config.(j|t)s。但 modern.config 配置文件不是必须存在的。\n\n默认情况下,生成的配置文件的内容如下:\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n});\n\n\n我们推荐使用 defineConfig 函数,不过并不强制使用它。因此你也可以在配置文件中直接返回一个对象:\n\n\n\nexport default {\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n};\n","frontmatter":{"sidebar_position":1},"version":""},{"id":65,"title":"CLI 命令","routePath":"/module-tools/guide/basic/command-preview","lang":"zh","toc":[{"text":"modern build","id":"modern-build","depth":2,"charIndex":39},{"text":"modern new","id":"modern-new","depth":2,"charIndex":1090},{"text":"modern dev","id":"modern-dev","depth":2,"charIndex":1549},{"text":"modern test","id":"modern-test","depth":2,"charIndex":1925},{"text":"modern lint","id":"modern-lint","depth":2,"charIndex":2129},{"text":"modern change","id":"modern-change","depth":2,"charIndex":2422},{"text":"modern pre","id":"modern-pre","depth":2,"charIndex":2662},{"text":"modern bump","id":"modern-bump","depth":2,"charIndex":2808},{"text":"modern release","id":"modern-release","depth":2,"charIndex":3151},{"text":"modern gen-release-note","id":"modern-gen-release-note","depth":2,"charIndex":3502},{"text":"modern upgrade","id":"modern-upgrade","depth":2,"charIndex":3832}],"domain":"","content":"#\n\nModern.js Module 项目可以使用的 CLI 命令如下:\n\n\nmodern build#\n\nUsage: modern build [options]\n\n构建生产环境产物\n\nOptions:\n -w, --watch 使用监听模式构建代码\n --tsconfig [tsconfig] 指定 tsconfig.json 文件的路径 (default:\n \"./tsconfig.json\")\n --platform [platform] 构建所有或者指定平台的产物\n --no-dts 关闭 DTS 类型文件生成和类型检查\n --no-clear 关闭自动清除产物输出目录的行为\n -h, --help 展示当前命令的信息\n\n\n当想要启动项目构建的时候,可以执行 modern build 命令。在使用这个命令的时候,我们可以:\n\n * 当想要以观察模式启动构建时,使用 --watch 选项。\n * 当想要指定项目编译读取的 TypeScript 配置文件的路径时,使用 build --tsconfig ./path/config.json\n 选项。使用该选项后,会覆盖所有 buildConfig 里 dts.tsconfigPath 配置。\n * 当需要关闭项目的 DTS 类型文件生成和类型检查行为时,可以使用 --no-dts\n 选项。注意:类型文件的生成依赖类型检查的结果。如果关闭了类型检查,那么类型文件也不会生成。\n * 当需要关闭自动清除产物输出目录的行为时,可以使用 --no-clear 选项。\n\n除了以上方式,Modern.js Module 还支持 platform 构建模式,可以用于执行其他工具的构建任务。例如,目前官方支持在安装了\n@modern-js/plugin-storybook 插件后,可以通过执行 modern build --platform 或者 modern build\n--platform storybook 命令启动 Storybook 构建任务生成 Storybook 产物。\n\nTIP\n\n在执行 Storybook 构建的时候,如果需要读取项目的构建产物。那么在执行 modern build --platform 命令启动 Storybook\n构建之前,不要忘记先执行 modern build 命令确保项目构建产物的存在。\n\n\nmodern new#\n\nUsage: modern new [options]\n\n启用可选功能\n\nOptions:\n -d, --debug 开启 Debug 模式,打印调试日志信息 (default: false)\n -c, --config 生成器运行默认配置(JSON 字符串)\n --dist-tag 生成器使用特殊的 npm Tag 版本\n --registry 生成器运行过程中定制 npm Registry\n -h, --help display help for command\n\n\nmodern new 命令用于启动微生成器功能,它可以为项目启用默认没有提供的功能。\n\n目前可以开启的功能有:\n\n * Test 测试\n * Storybook 调试\n * Tailwind CSS 支持\n * Modern.js Runtime API\n\n关于这些功能,可以通过「使用微生成器」 章节了解更多。\n\n\nmodern dev#\n\nUsage: modern dev [options]\n\n运行和调试模块\n\nOptions:\n -h, --help display help for command\n\nCommands:\n[dev-tools-subCommand]\n\n\nModern.js Module 提供了使用调试工具的能力,可以通过 modern dev\n命令来启动。不过要注意的是,默认情况下是没有提供调试相关的插件,因此此时执行 modern dev 会提示: \"No dev tools found\navailable\"。\n\n目前官方支持的调试工具有 Storybook,因此在你执行 modern new 命令开启它后,就可以执行 modern dev 或者 modern dev\nstorybook 执行它。\n\n\nmodern test#\n\nUsage: modern test [options]\n\nOptions:\n -h, --help display help for command\n\n\n需要先执行 modern new 开启测试功能,然后才可以执行 modern test 命令。 modern test 命令会自动将\ntests/*.test.(js|ts|jsx|tsx) 文件当做测试用例运行。\n\n\nmodern lint#\n\nUsage: modern lint [options] [...files]\n\nlint and fix source files\n\nOptions:\n --no-fix disable auto fix source file\n -h, --help display help for command\n\n\n运行 ESLint 检查代码语法情况。通常情况下,我们只需要在 git commit 阶段通过 lint-staged 检查本次提交修改的部分代码。\n\n * --no-fix 参数设置后可以关闭自动修复 lint 错误代码的能力。\n\n\nmodern change#\n\nUsage: modern change [options]\n\n创建变更集\n\nOptions:\n --empty 创建空变更集 (default: false)\n --open 使用编辑器中打开创建的变更集 (default: false)\n -h, --help display help for command\n\n\nmodern change 命令用于生成 changesets 需要的 Markdown 文件。\n\n\nmodern pre#\n\nUsage: modern pre [options] [tag]\n\n进入和退出预发布模式\n\nOptions:\n -h, --help display help for command\n\n\n可以使用 modern pre 命令在正式发布前预发布一个版本。\n\n\nmodern bump#\n\nUsage: modern bump [options]\n\n使用变更集自动更新发布版本和变更日志\n\nOptions:\n --canary 创建一个预发布版本进行测试 (default: false)\n --preid 在对预发布版本进行版本控制时指定标识符 (default: \"next\")\n --snapshot 创建一个特殊版本进行测试 (default: false)\n -h, --help display help for command\n\n\n按照 changesets 生成的变更记录的 Markdown 文件修改 package.json 中的版本号, 同时生成 CHANGELOG.md 文件。\n\n\nmodern release#\n\nUsage: modern release [options]\n\n发布 npm 包\n\nOptions:\n --tag 发布 npm 包使用特定的 tag (default: \"\")\n --ignore-scripts 发布时忽略 package.json 中的 scripts 命令,仅支持在 pnpm monorepo\n 中使用 (default: \"\")\n -h, --help display help for command\n\n\nmodern release 命令可以将模块发布到 npm Registry 上。\n\n * --tag 参数可以指定发布时具体的 dist tags。\n\n\nmodern gen-release-note#\n\nUsage: modern gen-release-note [options]\n\n根据当前仓库 changeset 信息生成 Release Note\n\nOptions:\n --repo 仓库名称,用于生成 Pull Request 链接, 例如: web-infra-dev/modern.js\n --custom 自定义 Release Note 生成函数\n -h, --help display help for command\n\n\n根据当前仓库的 changeset 信息自动生成 Release Note。\n\nTIP\n\n需要在 bump 命令之前执行。\n\n\nmodern upgrade#\n\nUsage: modern upgrade [options]\n\n升级 Modern.js 到最新版本\n\nOptions:\n --registry 定制 npm registry (default: \"\")\n -d,--debug 开启 Debug 模式,打印调试日志信息 (default: false)\n --cwd 项目路径 (default: \"\")\n -h, --help display help for command\n\n\nmodern upgrade 命令,用于升级项目 Modern.js 相关依赖至最新版本。\n\n在项目根目录下执行命令 npx modern upgrade,会默认将当前执行命令项目的 package.json 中的 Modern.js\n相关依赖更新至最新版本。","frontmatter":{"sidebar_position":2},"version":""},{"id":66,"title":"修改输出产物","routePath":"/module-tools/guide/basic/modify-output-product","lang":"zh","toc":[{"text":"默认输出产物","id":"默认输出产物","depth":2,"charIndex":3},{"text":"构建预设","id":"构建预设","depth":2,"charIndex":486},{"text":"构建配置","id":"构建配置","depth":2,"charIndex":804},{"text":"结合配置与预设","id":"结合配置与预设","depth":2,"charIndex":2092}],"domain":"","content":"#\n\n\n默认输出产物#\n\n当你在初始化的项目里使用 modern build 命令的时候,Modern.js Module 会根据当前配置内容,生成相应的构建产物。\n\n模板创建的默认配置内容如下:\n\n\n\nexport default defineConfig({\n // 注册 Modern.js Module 的 CLI 工具\n plugins: [moduleTools()],\n // 指定构建预设配置\n buildPreset: 'npm-library',\n});\n\n\n默认生成产物具有以下特点:\n\n * 会生成 CommonJS 和 ESM 两份产物。\n * 代码语法支持到 ES6 ,更高级的语法将会被转换。\n * 所有的代码经过打包变成了一个文件,即进行了 bundle 处理。\n * 产物输出根目录为项目下的 dist 目录,类型文件输出的目录为 dist/types。\n\n看到这里你可能会有以下疑问:\n\n 1. buildPreset 是什么?\n 2. 产物的这些特点是由什么决定的?\n\n接下来,我们首先来了解一下 buildPreset。\n\n\n构建预设#\n\nbuildPreset 代表着提前准备好的一组或者多组构建相关的配置,只需要使用 buildPreset\n对应的预设值,就可以省去麻烦且复杂的配置工作,得到符合预期的产物。\n\nModern.js Module 主要内置了两套构建预设,包括:\n\n * npm-component: 用于构建组件库。\n * npm-library: 用于打包其他库类型的项目,如工具库。\n\n同时,还提供一些变体,例如 npm-library-with-umd 和 npm-library-es5,顾名思义,分别对应带有 umd 产物和支持到 es5\n语法的库预设。 详细配置可以查看其API。\n\n除此之外,我们也可以完全自定义构建配置:\n\n\n构建配置#\n\nbuildConfig 是一个用来描述如何编译、生成构建产物的配置项。在最开始提到的关于“构建产物的特点”,其实都是 buildConfig\n所支持的属性。目前所支持的属性覆盖了大部分模块类型项目在构建产物时的需求,buildConfig\n不仅包含一些产物所具备的属性,也包含了构建产物所需要的一些特性功能。接下来从分类的角度简单罗列一下:\n\n构建产物的基本属性包括:\n\n * 产物是否被打包:对应的 API 是 buildConfig.buildType。\n * 产物对于语法的支持:对应的 API 是 buildConfig.target。\n * 产物格式:对应的 API 是 buildConfig.format。\n * 产物类型文件如何处理,对应的 API 是 buildConfig.dts。\n * 产物的 sourceMap 如何处理:对应的 API 是 buildConfig.sourceMap。\n * 产物对应的输入(或者是源文件):对应的 API 是 buildConfig.input。\n * 产物输出的目录:对应的 API 是 buildConfig.outDir。\n * 构建的源码目录:对应的 API 是 buildConfig.sourceDir。\n\n构建产物所需的常用功能包括:\n\n * 别名:对应的 API 是 buildConfig.alias。\n * 静态资源处理:对应的 API 是 buildConfig.asset。\n * 第三方依赖处理:对应的 API 有:\n * buildConfig.autoExternal。\n * buildConfig.externals。\n * 拷贝:对应的 API 是 buildConfig.copy。\n * 全局变量替换:对应的 API 是 buildConfig.define。\n * 指定 JSX 编译方式,对应的 API 是 buildConfig.jsx。\n\n一些高级属性或者使用频率不高的功能:\n\n * 产物代码压缩:对应的 API 是 buildConfig.minify。\n * 代码分割:buildConfig.spitting\n * 指定构建产物用于 NodeJS 环境还是浏览器环境:对应的 API 是 buildConfig.platform。\n * umd 产物相关:\n * 指定 umd 产物外部导入的全局变量:对应的 API 是 buildConfig.umdGlobals。\n * 指定 umd 产物的模块名:对应的 API 是 buildConfig.umdModuleName。\n\n除了以上分类以外,关于这些 API 的常见问题和最佳实践可以通过下面的链接来了解:\n\n * 关于 bundle 和 bundleless\n * 关于 input 和 sourceDir。\n * 关于类型描述文件。\n * 如何使用 define\n * 如何处理第三方依赖\n * 如何使用拷贝\n * 如何构建 umd 产物\n * 如何使用静态资源\n\n\n结合配置与预设#\n\n了解 buildPreset 和 buildConfig 之后,我们可以将二者进行结合使用。\n\n在实际项目中,我们可以先使用 buildPreset 来快速获取一套默认构建配置。如果需要自定义,可以使用 buildConfig 进行覆盖和扩展。\n\n扩展的逻辑如下:\n\n * 当 buildConfig 是数组时,会在原来的预设基础上添加新的配置项。\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n buildConfig: [\n {\n format: 'iife',\n target: 'es2020',\n outDir: './dist/global'\n }\n ]\n});\n\n\n这会在原本预设的基础上,额外生成一份 IIFE 格式、支持到 ES2020 语法的产物,输出目录为项目下的 dist/global 目录。\n\n * 当 buildConfig 是对象时,会将对象中的配置项覆盖到预设中。\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n buildConfig: {\n sourceMap: true,\n }\n});\n\n\n这会使得每一项构建任务都会生成 sourceMap 文件。","frontmatter":{"sidebar_position":3},"version":""},{"id":67,"title":"版本管理与发布","routePath":"/module-tools/guide/basic/publish-your-project","lang":"zh","toc":[{"text":"跟踪变更","id":"跟踪变更","depth":2,"charIndex":156},{"text":"版本更新","id":"版本更新","depth":2,"charIndex":1050},{"text":"发布","id":"发布","depth":2,"charIndex":1313},{"text":"预发布","id":"预发布","depth":2,"charIndex":1651}],"domain":"","content":"#\n\n一个 npm 类型的模块项目发布流程包含了两个阶段:\n\n * 第一阶段是在开发期间,开发者需要提供变更文件,该文件记录了在发布期间需要的变更内容;\n * 第二阶段是在发布期间,Modern.js Module 会收集所有的变更文件来更新版本、更新发布日志,并发布新的包到 npm Registry 上。\n\n\n跟踪变更#\n\n当项目发生变化的时候需要将变化的内容记录下来。项目发生的变化一般是指:\n\n * 新功能\n * 修复问题\n * 配置文件修改\n * ...\n\n当这些任务一旦开发完成后,需要通过以下命令来对当前的变化进行记录:\n\n * modern change\n\n执行 modern change 命令后会向开发者提出几个问题,并根据开发者的回答生成变更记录。变更记录文件包含了版本变化的类型和其描述,该文件会被提交到\ngit 仓库中。\n\n$ npx modern change\n🦋 What kind of change is this for module-example? (current version is 0.1.0) · patch\n🦋 Please enter a summary for this change (this will be in the changelogs). Submit empty line to open external editor\n🦋 Summary · publish test\n🦋 === Releasing the following packages ===\n🦋 [Patch]\n🦋 module\n🦋 Is this your desired changeset? (Y/n) · true\n🦋 Changeset added! - you can now commit it\n🦋\n🦋 If you want to modify or expand on the changeset summary, you can find it here\n🦋 info /xxxxxx/module/.changeset/brave-dryers-agree.md\n\n\n当执行成功后,生成的包含变更记录的 Markdown 文件会保存在项目的 .changeset 目录下面。其内容类似下面这样:\n\n---\n'module-example': patch\n---\n\npublish test\n\n\n\n版本更新#\n\n当需要更新项目版本的时候,执行以下命令:\n\n * modern bump\n\n执行 modern bump 将会基于 .changeset/ 目录下记录了变更的 Markdown 文件内容来修改 package.json\n中的版本号,同时生成 CHANGELOG.md 文件。而当版本更新完成后,这些记录变更的 Markdown 文件也会被删除,也可说这些 Markdown\n文件被“消耗”掉了。\n\n# module\n\n## 0.1.1\n\n### Patch Changes\n\n- publish test\n\n\n\n发布#\n\n发布项目可以执行以下命令:\n\n * modern release\n\nmodern release 命令可以将项目发布到 npm Registry。\n\n此时发布的是 latest 版本,也可以说是正式版本。如果想要修改 dist-tag,可以通过 modern release --tag 命令来指定。例如:\n\nmodern release --tag beta\n\n\n但是如果希望将当前项目的版本号也修改为预发布的版本号,则需要使用 modern pre 命令。\n\n> 所谓 dist-tag,可以理解:为当前发布的版本打标签。一般来说,默认发布的版本对应的 dist-tag 为 latest,因此可以把 latest\n> 认为是正式版本的 dist-tag。\n\n\n预发布#\n\n当需要在正式发布之前进行预发布,则需要执行以下命令:\n\n * modern pre\n\n首先 modern pre enter 进入预发布模式, 可以与发布项目的时候使用 modern release --tag 命令指定的 tag 一致。\n\n$ npx modern pre enter next\n🦋 success Entered pre mode with tag next\n🦋 info Run `changeset version` to version packages with prerelease versions\n✨ Done in 5.30s.\n\n\n接着可以使用 modern bump 命令更新具体的版本号,此时不会真正的“消耗”记录变更的 Markdown 文件:\n\n$ npx modern bump\n🦋 warn ===============================IMPORTANT!===============================\n🦋 warn You are in prerelease mode\n🦋 warn If you meant to do a normal release you should revert these changes and run `changeset pre exit`\n🦋 warn You can then run `changeset version` again to do a normal release\n🦋 warn ----------------------------------------------------------------------\n🦋 All files have been updated. Review them and commit at your leisure\n\n\n然后可以看到 package.json 中更新的版本号会类似这样:0.1.2-next.0。\n\n最后,如果不需要再进行预发布,则一定要执行 modern pre exit 命令,这样可以退出预发布状态,并且当再次执行 modern bump\n命令的时候,就可以发布正式的版本。","frontmatter":{"sidebar_position":7},"version":""},{"id":68,"title":"测试项目","routePath":"/module-tools/guide/basic/test-your-project","lang":"zh","toc":[{"text":"先决条件和约定","id":"先决条件和约定","depth":2,"charIndex":21},{"text":"运行测试","id":"运行测试","depth":2,"charIndex":417},{"text":"使用配置","id":"使用配置","depth":2,"charIndex":551},{"text":"测试示例","id":"测试示例","depth":2,"charIndex":633},{"text":"普通模块","id":"普通模块","depth":3,"charIndex":641},{"text":"组件","id":"组件","depth":3,"charIndex":1057}],"domain":"","content":"#\n\n本章将要介绍如何测试可复用模块。\n\n\n先决条件和约定#\n\n想要使用项目的测试功能,需要确保项目中包含依赖:\"@modern-js/plugin-testing\",以及按照类似下面的内容进行配置:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n testingPlugin(),\n ],\n});\n\n\n可以通过执行 modern new 命令来开启测试功能。\n\n在 Modern.js Module 中,对于测试用例或者说编写测试的文件有如下约定:\n\n * 项目目录下的 tests 目录为测试用例和测试文件的目录,不支持更改运行测试用例的目录。\n * 默认会自动将后缀为 .test.[tj]sx? 的文件识别为测试文件。\n * 其他的 .[tj]sx? 后缀的文件被识别为普通的文件,可以用于测试的 utils 文件或者其他用途。\n\n\n运行测试#\n\n当准备好了依赖、增加了相关配置以及了解了测试用例在哪里编写后,我们可以通过以下命令来执行测试:\n\nmodern test\n\n// 更新 snapshot\nmodern test --updateSnapshot\n\n\n执行之后,会看到测试的结果:\n\n\n\n\n使用配置#\n\nModern.js Module 对测试提供了以下配置:\n\n * testing\n\n可以在 modern.config.(j|t)s 中增加它。\n\n\n测试示例#\n\n\n普通模块#\n\n对于普通的模块,我们可以按照如下方式使用测试功能:\n\n * 首先是模块的代码:\n\nexport default function () {\n return 'hello world';\n}\n\n\n * 然后在测试文件中,我们可以按以下方式引用,其中 @ 指向了源码目录,在初始化项目的 tests/tsconfig.json 的 paths 中定义了。\n\n\n\ndescribe('默认值 cases', () => {\n test('Have returns', () => {\n const drink = jest.fn(main);\n drink();\n expect(drink).toHaveReturned();\n });\n});\n\n\n * 最后我们可以执行 modern test:\n\npnpm test\n## or\nyarn test\n## or\nnpm run test\n\n\n\n组件#\n\n对于组件,Modern.js 的 Runtime API 提供了用于测试 UI 组件的功能,其功能由 @modern-js/runtime/testing\n提供。\n\nTIP\n\n如果需要使用 Runtime API,那么可以通过 微生成器 开启。\n\n * 首先是组件的代码:\n\nexport const default () {\n return (\n \nThis is a UI Component\n );\n}\n\n\n * 然后在测试文件中,我们可以按以下方式引用,其中 @ 指向了源码目录,在初始化项目的 tests/tsconfig.json 的 paths 中定义了。\n\n\n\n\n\ndescribe('默认值 cases', () => {\n test('Rendered', () => {\n render();\n expect(screen.getByText('This is a UI Component')).toBeInTheDocument();\n });\n});\n\n\n * 最后我们可以执行 modern test。\n\npnpm test\n## or\nyarn test\n## or\nnpm run test\n","frontmatter":{"sidebar_position":6},"version":""},{"id":69,"title":"使用微生成器","routePath":"/module-tools/guide/basic/use-micro-generator","lang":"zh","toc":[{"text":"Test 测试","id":"test-测试","depth":2,"charIndex":166},{"text":"Storybook 调试","id":"storybook-调试","depth":2,"charIndex":407},{"text":"Tailwind CSS 支持","id":"tailwind-css-支持","depth":2,"charIndex":751},{"text":"Modern.js Runtime API 支持","id":"modernjs-runtime-api-支持","depth":2,"charIndex":899}],"domain":"","content":"#\n\nModern.js Module 提供了微生成器工具,它可以为当前项目:\n\n * 新增目录和文件\n * 修改 package.json\n * 执行命令\n\n因此通过这些能力,微生成器可以为项目开启额外的特性功能。\n\n可以通过 modern new 启动微生成器。目前 Modern.js Module 支持的微生成器功能有:\n\n\nTest 测试#\n\n当我们想要对一些模块进行测试的时候,可以启用测试功能。启动该功能后,会在项目目录下创建 tests 目录以及相关文件,在 package.json 中新增\n\"@modern-js/plugin-testing\" 依赖。\n\nTIP\n\n在成功开启后,会提示需要手动在配置中增加如下类似的代码。\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), testingPlugin()],\n});\n\n\n\nStorybook 调试#\n\n当我们想要对组件或者普通模块进行调试的时候,可以启用 Storybook 调试功能。启动该功能后,会在项目目录下创建 stories 目录以及相关文件,在\npackage.json 中新增 \"@modern-js/plugin-storybook\" 依赖。\n\nTIP\n\n在成功开启后,会提示需要手动在配置中增加如下类似的代码。\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), storybookPlugin()],\n});\n\n\n关于如何启动 Storybook 以及如何使用 Storybook,可以查看下面的链接:\n\n * modern dev\n * 使用 Storybook\n\n\nTailwind CSS 支持#\n\nTailwind CSS 是一个以 Utility Class 为基础的 CSS 框架和设计系统,可以快速地为组件添加常用样式,同时支持主题样式的灵活扩展。\n\n如果你想要在项目使用 Tailwind CSS,可以参考 「使用 Tailwind CSS」。\n\n\nModern.js Runtime API 支持#\n\nModern.js 提供了 Runtime API 能力,这些 API 只能在 Modern.js 的应用项目环境中使用。如果你需要开发一个 Modern.js\n应用环境中使用的组件,那么你可以开启该特性,微生成器会增加 \"@modern-js/runtime\"依赖。\n\n另外,Storybook 调试工具也会通过检测项目的依赖确定项目是否需要使用 Runtime API,并且提供与 Modern.js 应用项目一样的\nRuntime API 运行环境。\n\nTIP\n\n在成功开启后,会提示需要手动在配置中增加如下类似的代码。\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), runtime()],\n});\n","frontmatter":{"sidebar_position":4},"version":""},{"id":70,"title":"使用 Storybook","routePath":"/module-tools/guide/basic/using-storybook","lang":"zh","toc":[{"text":"调试代码","id":"调试代码","depth":2,"charIndex":292},{"text":"引用组件产物","id":"引用组件产物","depth":3,"charIndex":491},{"text":"引用组件源码","id":"引用组件源码","depth":3,"charIndex":1862},{"text":"配置 Storybook","id":"配置-storybook","depth":2,"charIndex":2277},{"text":"构建 Storybook 产物","id":"构建-storybook-产物","depth":2,"charIndex":2686},{"text":"结合 Tailwind CSS 使用","id":"结合-tailwind-css-使用","depth":2,"charIndex":2901}],"domain":"","content":"#\n\n首先如果没有看过以下内容的话,可以先花几分钟先了解一下:\n\n * 使用微生成器开启 Storybook 调试\n * modern dev\n\nStorybook 是一个专门用于组件调试的工具,它围绕着组件开发提供了:\n\n * 丰富多样的调试能力\n * 可与一些测试工具结合使用\n * 可重复使用的文档内容\n * 可分享能力\n * 工作流程自动化\n\n因此 Storybook 是一个复杂且功能强大的工具。\n\nModern.js Module 集成了 Storybook,因此你几乎可以按照 Storybook\n官方文档的内容进行使用。不过依然有一些地方需要注意,接下来讲解一下。\n\n\n调试代码#\n\n在调试代码过程中需要引入项目代码,目前可以通过两种方式引入项目代码:\n\n * 引用项目产物\n * 引用项目源码\n\n我们推荐使用第一种“引用项目产物”的方式。因为它更接近真实的使用场景,不仅可以对组件功能进行调试,同时也对构建产物的正确性进行了验证。不过我们也可以在测试项目功\n能的时候引用源码,在验证项目产物的时候引用项目的包名。\n\n接下来我们分别讲一下这两种方式具体如何使用。\n\n\n引用组件产物#\n\n假如存在 TypeScript 项目 foo,首先要确保 package.json 的 main 和 types 的值为正确的产物路径。\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/types/index.d.ts\"\n}\n\n\nfoo 项目的源码:\n\nexport const content = 'hello world';\n\n\n请确保在 stories/tsconfig.json 中设置了指向项目根目录的 paths 配置。paths 的 key\n与项目名称相同,这样在编译过程中以及在代码中不会出现问题。\n\n{\n \"extends\": \"../tsconfig.json\",\n \"compilerOptions\": {\n \"baseUrl\": \"../\",\n \"paths\": {\n \"foo\": [\".\"],\n \"foo/*\": [\"./*\"]\n }\n },\n \"include\": [\"**/*\"]\n}\n\n\n在 Story 代码中直接以项目名称的方式引用:\n\n\n\nconst Component = () => \nthis is a Story Component {content};\n\nexport const YourStory = () => ;\n\nexport default {\n title: 'Your Stories',\n};\n\n\n最后在执行命令的时候,先启动监听模式的源码构建,然后启动 Storybook 调试即可:\n\n## 源码构建\nmodern build --watch\n\n\n## Storybook 调试\nmodern dev storybook\n\n\nINFO\n\n在开发过程中,可能会遇到无法实时获得类型定义的情况。因为只有当保存代码后,产物目录下的类型文件才会更新。此时:\n\n对于 pnpm 的项目,可以按照下面的内容对 package.json 进行修改:\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./src/index.ts\",\n \"publishConfig\": {\n \"types\": \"./dist/index.d.ts\",\n }\n}\n\n\n> 关于 pnpm 的 publishConfig 的使用,可以阅读下面这个链接。\n\n而对于 npm 和 Yarn 的项目,则只能通过手动的方式在开发阶段和发布阶段对 package.json 的 types 的值进行修改。\n\n那么为什么可以直接引用产物呢?\n\n 1. 在执行 modern dev storybook 命令之前,执行 modern build --watch 命令,保证项目构建产物的存在。\n 2. 在 Storybook 内部增加了根据 tsconfig.json 文件的 compilerOptions.paths 配置或者(在 JS\n 项目中)直接以项目名称作为别名的处理逻辑,保证能够根据 package.json 解析出项目的产物路径。\n\n\n引用组件源码#\n\n引用组件的源码可以通过相对路径的方式:\n\n\n\nconst Component = () => \nthis is a Story Component {content};\n\nexport const YourStory = () => ;\n\nexport default {\n title: 'Your Stories',\n};\n\n\n为什么不推荐使用源码的方式?\n\n不仅仅是因为使用组件源码无法验证组件产物是否正确,同时 Modern.js Module 对于构建产物支持的一些配置无法完全转换为 Storybook\n内部的配置。如果某些配置无法进行相互转换的话,就会在 Storybook 调试过程中出现不符合预期的结果。\n\nModern.js Module 是基于 esbuild 实现的,而 Storybook 是基于 Webpack 实现的。esbuild 的配置无法与\nWebpack 完全兼容。\n\n\n配置 Storybook#\n\nStorybook 官方通过一个名为 .storybook 的文件夹来进行项目配置,其中包含各种配置文件。在 Modern.js Module 中,可以在项目的\nconfig/storybook 目录下增加 Storybook 配置文件。\n\n关于 Storybook 各种配置文件的使用方式,可以查看下面的链接:\n\n * Configure Storybook\n\n不过在模块项目里进行 Storybook 存在一些限制:\n\n * 目前不能修改 Story 文件存放的位置,即无法在 main.js 文件里修改 stories 配置。\n * 目前不能修改 Webpack 和 Babel 相关的配置,即无法在 main.js 文件里修改 webpackFinal 和 babel 配置。\n\n在未来我们会考虑这些配置是否可以允许修改,不过目前为了减少不可预知的问题暂时限制使用这些配置。\n\n\n构建 Storybook 产物#\n\n除了可以对组件或者普通的模块进行 Storybook 调试,还可以通过下面的命令来执行 Storybook 的构建任务。\n\nmodern build --platform storybook\n\n\n关于 modern build --platform 命令可以查看:\n\n * modern build\n\n构建完成后,可以在 dist/storybook-static 目录看到构建产物文件。\n\n\n结合 Tailwind CSS 使用#\n\n如果你需要在 stories 目录下使用 Tailwind CSS,请确保当前项目的 Tailwind CSS 配置中包含了 stories 目录。\n\n以 tailwind.config.ts 文件为例,你需要配置以下内容:\n\nexport default {\n content: [\n './src/**/*.{js,jsx,ts,tsx}',\n+ './stories/**/*.{js,jsx,ts,tsx}',\n ],\n};\n","frontmatter":{"sidebar_position":5},"version":""},{"id":71,"title":"开发组件","routePath":"/module-tools/guide/best-practices/components","lang":"zh","toc":[{"text":"初始化项目","id":"初始化项目","depth":2,"charIndex":40},{"text":"使用 Storybook 调试代码","id":"使用-storybook-调试代码","depth":2,"charIndex":513},{"text":"开发样式","id":"开发样式","depth":2,"charIndex":574},{"text":"CSS/PostCSS","id":"csspostcss","depth":3,"charIndex":682},{"text":"Less","id":"less","depth":3,"charIndex":1192},{"text":"Sass/Scss","id":"sassscss","depth":3,"charIndex":1445},{"text":"Tailwind CSS","id":"tailwind-css","depth":3,"charIndex":1728},{"text":"CSS Modules","id":"css-modules","depth":3,"charIndex":1776},{"text":"配置构建产物","id":"配置构建产物","depth":2,"charIndex":2090},{"text":"测试组件","id":"测试组件","depth":2,"charIndex":2571},{"text":"发布组件","id":"发布组件","depth":2,"charIndex":2605}],"domain":"","content":"#\n\n本章将要介绍如何使用 Modern.js Module 开发组件项目。\n\n\n初始化项目#\n\n 1. 推荐使用 @modern-js/create 命令来初始化一个 npm 项目。\n\nnpx @modern-js/create@latest components-project\n\n? 请选择你想创建的工程类型:Npm 模块\n? 请填写项目名称:components-demo\n? 请选择开发语言:TS\n? 请选择包管理工具:pnpm\n\n\n 2. 初始化的目录结构如下:\n\n.\n├── README.md\n├── node_modules/\n├── dist/\n├── modern.config.ts\n├── package.json\n├── pnpm-lock.yaml\n├── src\n│ ├── index.ts\n│ └── modern-app-env.d.ts\n└── tsconfig.json\n\n\n 3. 最后修改 ./src/index.ts 文件后缀和内容如下,就完成了组件项目的初始化。\n\nexport default () => {\n return \nhello world;\n};\n\n\n\n使用 Storybook 调试代码#\n\n请参考 「使用 Storybook」 来使用 Storybook 调试代码。\n\n\n开发样式#\n\n接下来我们可以给组件添加样式。\n\n目前支持开发样式的能力有:\n\n * CSS/PostCSS\n * Less\n * Scss/Sass\n * Tailwind CSS\n * CSS Modules\n\n\nCSS/PostCSS#\n\nModern.js Module 支持 PostCSS,并且内置了以下 PostCSS 插件:\n\n * flexbugs-fixes\n * custom-properties\n * initial\n * page-break\n * font-variant\n * media-minmax\n * nesting\n\n因此我们可以在项目中创建 .css 文件,并且可以直接在 css 文件中使用这些插件提供的语法支持和能力。\n\n * 源代码:\n\na,\nb {\n color: red;\n\n /* \"&\" comes first */\n & c,\n & d {\n color: white;\n }\n\n /* \"&\" comes later, requiring \"@nest\" */\n @nest e & {\n color: yellow;\n }\n}\n\n\n * CSS 产物:\n\na,\nb {\n color: red;\n}\na c,\nb c,\na d,\nb d {\n color: white;\n}\ne a,\ne b {\n color: yellow;\n}\n\n\n\nLess#\n\nModern.js Module 支持使用 Less 开发样式。\n\n> 目前内置的 Less 版本为 v4.1.3\n\n * 源代码:\n\n@bg: black;\n@bg-light: boolean(luma(@bg) > 50%);\n\ndiv {\n background: @bg;\n color: if(@bg-light, black, white);\n}\n\n\n * Less 产物:\n\ndiv {\n background: black;\n color: white;\n}\n\n\n\nSass/Scss#\n\nModern.js Module 支持使用 Scss/Sass 开发样式。\n\n> 目前内置的 Sass 版本为 v1.54.4\n\n * 源代码:\n\n$font-stack: Helvetica, sans-serif;\n$primary-color: #333;\n\nbody {\n font: 100% $font-stack;\n color: $primary-color;\n}\n\n\n * Sass 产物:\n\nbody {\n font: 100% Helvetica, sans-serif;\n color: #333;\n}\n\n\n\nTailwind CSS#\n\n请参考 「使用 Tailwind CSS」 来了解相关用法。\n\n\nCSS Modules#\n\nModern.js Module 支持使用 CSS Module 开发样式。默认情况下会将以下文件识别为 CSS Module 文件:\n\n * .module.css\n * .module.less\n * .module.scss\n * .module.sass\n\n如果需要对 CSS Modules 进行配置,可以查看以下 API:\n\n * style.autoModules\n * style.modules\n\n下面是一个代码示例:\n\n\n\nexport default () => {\n return \nhello world;\n};\n\n\n.btn {\n color: blue;\n}\n\n\n\n配置构建产物#\n\n根据组件项目使用的多数场景,推荐使用 npm-component 构建预设。该预设得到的产物目录结构为:\n\n.\n├── dist\n│ ├── es\n│ ├── lib\n│ └── types\n\n\n * ./dist/es: 包含了支持 es6 语法的 ES modules 格式的 bundleless 产物。\n * ./dist/lib: 包含了支持 es6 语法的 CommonJS 格式的 bundleless 产物。\n * ./dist/types: 包含了类型文件。\n\n如果对使用语法支持有要求,可以手动配置 buildPreset,并且支持在 npm-component 基础上增加后缀的方式修改支持的语法:\n\nexport default defineConfig({\n buildPreset: 'npm-component-es2019',\n});\n\n\n如果对构建产物目录结构有特殊需求,则可以使用 buildConfig API,可以通过以下文档来了解使用方式:\n\n * 修改输出产物\n * 深入理解构建\n\n\n测试组件#\n\n关于如何对组件进行测试,可以参考 「测试项目」。\n\n\n发布组件#\n\n推荐使用 Modern.js Module 提供的版本发布功能,可以参考 「版本管理与发布」。","frontmatter":{"sidebar_position":1},"version":""},{"id":72,"title":"使用 Tailwind CSS","routePath":"/module-tools/guide/best-practices/use-tailwindcss","lang":"zh","toc":[{"text":"启用 Tailwind CSS","id":"启用-tailwind-css","depth":2,"charIndex":127},{"text":"配置 Tailwind CSS","id":"配置-tailwind-css","depth":2,"charIndex":962},{"text":"Tailwind CSS 自动补全","id":"tailwind-css-自动补全","depth":2,"charIndex":1608},{"text":"构建模式","id":"构建模式","depth":2,"charIndex":1921},{"text":"Bundle 模式","id":"bundle-模式","depth":3,"charIndex":2038},{"text":"Bundleless 模式","id":"bundleless-模式","depth":3,"charIndex":2627},{"text":"类名前缀","id":"类名前缀","depth":2,"charIndex":2837},{"text":"用法介绍","id":"用法介绍","depth":2,"charIndex":3222},{"text":"HTML 类名","id":"html-类名","depth":3,"charIndex":3257},{"text":"@apply","id":"apply","depth":3,"charIndex":3568},{"text":"Sass","id":"sass","depth":4,"charIndex":3756},{"text":"Less","id":"less","depth":4,"charIndex":3953},{"text":"关于 designSystem 配置","id":"关于-designsystem-配置","depth":2,"charIndex":4467}],"domain":"","content":"#\n\nTailwind CSS 是一个以 Utility Class 为基础的 CSS 框架和设计系统,可以快速地为组件添加常用样式,同时支持主题样式的灵活扩展。\n\nModern.js Module 支持使用 Tailwind CSS 开发组件样式。\n\n\n启用 Tailwind CSS#\n\n在 Modern.js Module 中使用 Tailwind CSS,你只需要按照以下步骤操作:\n\n 1. 在项目根目录下执行 pnpm run new,按照如下进行选择:\n\n? 请选择你想要的操作 启用可选功能\n? 请选择功能名称 启用 「Tailwind CSS」 支持\n\n\n成功开启后,会看到 package.json 中新增了依赖:\n\n{\n \"dependencies\": {\n \"tailwindcss\": \"^3.0.0\"\n },\n \"devDependencies\": {\n \"@modern-js/plugin-tailwindcss\": \"^2.0.0\"\n }\n}\n\n\n 2. 在 modern.config.ts 中注册 Tailwind 插件:\n\n\n\nexport default defineConfig({\n plugins: [..., tailwindcssPlugin()],\n});\n\n\n 3. 创建 index.css 文件,添加以下代码:\n\n/* base 和 components 是可选的,请酌情添加 */\n@tailwind base;\n@tailwind components;\n@tailwind utilities;\n\n\nINFO\n\n根据需求不同,你可以选择性地导入 Tailwind CSS 提供的 CSS 样式。请参考 @tailwind 文档 来了解 @tailwind 指令的详细用法。\n\n 4. 引用 index.css 文件,比如在入口的 src/index.jsx 文件添加如下代码:\n\nimport './index.css';\n\n\n 5. 然后即可在各个组件中使用 Tailwind CSS 提供的 Utility Class 了:\n\nconst Hello = () => (\n \n\n \n\nhello world\n \n);\n\n\n\n配置 Tailwind CSS#\n\n在 Modern.js Module 中,你有两种方式来配置 Tailwind CSS:\n\n 1. 使用 tailwind.config.{ts,js} 文件,该用法与 Tailwind CSS 的官方用法一致,请参考 \"Tailwind CSS -\n Configuration\" 来了解更多用法。\n\n\n\nexport default {\n content: ['./src/**/*.{js,jsx,ts,tsx}'],\n} as Config;\n\n\nTIP\n\n请升级 Modern.js Module 到 >= 2.33.0 版本,以支持自动读取 tailwind.config.{ts,js} 文件。\n\n 2. 使用 style.tailwindcss 配置项,这是旧版本的用法,我们更推荐使用 tailwind.config.{ts,js} 文件进行配置。\n\nexport default {\n style: {\n tailwindcss: {\n content: ['./src/**/*.{js,jsx,ts,tsx}'],\n },\n },\n};\n\n\n如果你同时使用了 tailwind.config.{ts,js} 文件和 style.tailwindcss 选项,那么 style.tailwindcss\n定义的配置会优先生效,并覆盖 tailwind.config.{ts,js} 中定义的内容。\n\n\nTailwind CSS 自动补全#\n\nTailwind CSS 官方提供了 Tailwind CSS IntelliSense 插件,用于在 VS Code 中自动补全 Tailwind CSS 的\nclass names、CSS functions 和 directives。\n\n你可以参考以下步骤来启动自动补全功能:\n\n 1. 在 VS Code 中安装 Tailwind CSS IntelliSense 插件。\n 2. 如果项目的根目录没有 tailwind.config.{ts,js} 文件,那么你需要创建该文件,并写入当前项目的 Tailwind CSS 配置,否则\n IDE 插件将无法正确生效。\n\n\n构建模式#\n\n在使用 Tailwind CSS 时,请注意构建产物在 bundle 和 bundleless 两种模式下会有很大区别。\n\nTIP\n\n关于 bundle 和 bundleless 的定义,可以查看 「深入理解构建」\n\n\nBundle 模式#\n\n在 Bundle 模式下,会生成一份单独的产物 CSS 文件,并且 JS 产物不会自动引用产物 CSS 文件。\n\n * 源代码:\n\nimport './index.css';\n\nexport default () => {\n return \nhello world;\n};\n\n\n * 产物代码:\n\n// src/index.tsx\n\nvar src_default = () => {\n return /* @__PURE__ */ jsx('div', {\n className: 'bg-black',\n children: 'hello world',\n });\n};\nexport { src_default as default };\n\n\n.bg-black {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity));\n}\n/** some more... */\n\n\n如果你需要将样式注入 JS 产物中,可以开启 style.inject 选项。\n\n如果你没有开启 style.inject,那么也可以让用户手动引用产物 CSS 文件:\n\nimport 'your-package/dist/es/index.css';\n\n\n\nBundleless 模式#\n\n在 Bundleless 模式下,默认会引用产物 CSS 文件,无须进行额外处理。\n\n * 产物代码:\n\n\nimport './index.css';\nexport default () =>\n /* @__PURE__ */ _jsx('div', {\n className: 'bg-black',\n children: 'hello world',\n });\n\n\n\n类名前缀#\n\n你可以通过 Tailwind CSS 提供的 prefix 选项来添加类名前缀,这样可以避免潜在的类名冲突问题(比如 App 和 Module 使用了不同版本的\nTailwind CSS)。\n\n例如,通过 prefix 选项添加 foo- 前缀:\n\nmodule.exports = {\n prefix: 'foo-',\n};\n\n\n * 源代码:\n\nimport './index.css';\n\nexport default () => {\n return \nhello world;\n};\n\n\n * 产物代码:\n\n.foo-bg-black {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity));\n}\n/** some more... */\n\n\n\n用法介绍#\n\n下面是一些 Tailwind CSS 的用法示例。\n\n\nHTML 类名#\n\nTailwind CSS 支持在 HTML 标签上通过类名的方式增加样式。当使用 HTML 类名的时候,请注意必须要提前导入 Tailwind CSS 相应的\nCSS 样式。\n\nimport './index.css';\n\nexport default () => {\n return \nhello world;\n};\n\n\n样式产物(此时是 bundle 构建):\n\n.bg-black {\n --tw-bg-opacity: 1;\n background-color: rgba(0, 0, 0, var(--tw-bg-opacity));\n}\n/** some more... */\n\n\n\n@apply#\n\nTailwind CSS 提供了 @apply 指令,可以通过它将 Tailwind CSS 提供的样式内联到我们编写的样式中。\n\n@apply 可以用于 CSS、Less、Sass 中。\n\n.btn {\n @apply font-bold py-2 px-4 rounded;\n}\n\n\n但是使用过程中,对于 Less 和 Sass 有些情况需要注意:\n\nSass#\n\n当将 Tailwind 与 Sass 一起使用时,@apply 后面存在 !important 的时候,需要使用插值来让 Sass 正确编译。\n\n * 不能正常工作:\n\n.alert {\n @apply bg-red-500 !important;\n}\n\n\n * 能够正常工作:\n\n.alert {\n @apply bg-red-500 #{!important};\n}\n\n\nLess#\n\n在与 Less 一起使用 Tailwind 时,你不能嵌套 Tailwind 的 @screen 指令。\n\n * 不能正常工作:\n\n.card {\n @apply rounded-none;\n\n @screen sm {\n @apply rounded-lg;\n }\n}\n\n\n * 相反,使用常规的媒体查询和 theme() 函数来引用你的屏幕尺寸,或者干脆不要嵌套你的 @screen 指令。\n\n// Use a regular media query and theme()\n.card {\n @apply rounded-none;\n\n @media (min-width: theme('screens.sm')) {\n @apply rounded-lg;\n }\n}\n\n\n// Use the @screen directive at the top-level\n.card {\n @apply rounded-none;\n\n @media (min-width: theme('screens.sm')) {\n @apply rounded-lg;\n }\n}\n\n\n\n关于 designSystem 配置#\n\ndesignSystem 是 Modern.js Module 中废弃的配置项。\n\n从 Modern.js Module v2.33.0 版本开始,你可以使用 Tailwind CSS 的 theme 配置项来代替\ndesignSystem,不再需要将 theme 配置拆分并设置到 designSystem 上。\n\n * 旧版本用法:\n\nconst { theme, ...rest } = tailwindConfig;\n\nexport default {\n style: {\n tailwindcss: rest,\n },\n designSystem: theme,\n};\n\n\n * 当前版本用法:\n\nexport default {\n style: {\n tailwindcss: tailwindConfig,\n },\n};\n","frontmatter":{"sidebar_position":2},"version":""},{"id":73,"title":"构建相关问题","routePath":"/module-tools/guide/faq/build","lang":"zh","toc":[{"text":"产物问题","id":"产物问题","depth":2,"charIndex":3},{"text":"Class Fields 的初始化处理","id":"class-fields-的初始化处理","depth":3,"charIndex":11},{"text":"babel-plugin-lodash 将引入的 lodash 处理成 undefined","id":"babel-plugin-lodash-将引入的-lodash-处理成-undefined","depth":3,"charIndex":1315},{"text":"异常类问题","id":"异常类问题","depth":2,"charIndex":1722},{"text":"Dynamic require of \\\"react\\\" is not supported","id":"dynamic-require-of-react-is-not-supported","depth":3,"charIndex":-1},{"text":"问题描述","id":"问题描述","depth":4,"charIndex":1777},{"text":"解决办法","id":"解决办法","depth":4,"charIndex":1952},{"text":"参考链接","id":"参考链接","depth":4,"charIndex":2246},{"text":"编译过程中,因为某个组件库的 less 文件报错:\\'Operation on an invalid type\\'","id":"编译过程中因为某个组件库的-less-文件报错operation-on-an-invalid-type","depth":3,"charIndex":-1},{"text":"Bundle DTS failed","id":"bundle-dts-failed","depth":3,"charIndex":3439},{"text":"defineConfig 函数类型报错:如果没有引用 \\\"...\\\",则无法命名 \\\"default\\\" 的推断类型","id":"defineconfig-函数类型报错如果没有引用-则无法命名-default-的推断类型","depth":3,"charIndex":-1},{"text":"其他","id":"其他","depth":2,"charIndex":3873},{"text":"增加额外的编译能力","id":"增加额外的编译能力","depth":3,"charIndex":3879},{"text":"支持生成 CSS Modules 的 TypeScript 声明文件","id":"支持生成-css-modules-的-typescript-声明文件","depth":3,"charIndex":4370}],"domain":"","content":"#\n\n\n产物问题#\n\n\nClass Fields 的初始化处理#\n\nTypeSript 提供了 useDefineForClassFields 配置用于控制对于 public class fields 的转换处理。\n\n如果有一段代码:\n\nclass C {\n foo = 100;\n bar: string;\n}\n\n\n当 useDefineForClassFields 为 false 的时候,则编译后的代码会变为:\n\nclass C {\n constructor() {\n this.foo = 100;\n }\n}\n\n\n当 useDefineForClassFields 为 true 的时候,则编译后的代码会变为:\n\nclass C {\n constructor() {\n Object.defineProperty(this, 'foo', {\n enumerable: true,\n configurable: true,\n writable: true,\n value: 100,\n });\n Object.defineProperty(this, 'bar', {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0,\n });\n }\n}\n\n\n同时该配置的默认值会根据 tsconfig.json 的 target 配置而变化:当 target 是 ES2022 或者更高的时候,则\nuseDefineForClassFields 默认配置为 true,否则就是默认为 false。\n\n关于 TypeScript 这个配置的更多信息,可以参考下面的链接:\n\n * The useDefineForClassFields Flag and The declare Property Modifier\n\nModern.js Module 目前会根据下面的逻辑进行处理:\n\n 1. 首先根据当前项目的 tsconfig.json 的 useDefineForClassFields 配置确定在 Modern.js Module\n 内部如何处理。目前只会读取当前项目路径下的 tsconfig.json 文件的内容,暂时不支持根据 extends 配置来获取最终的 tsconfig\n 配置。\n 2. 如果没有检测 tsconfig.json 的 useDefineForClassFields 配置,则会根据 tsconfig.json 的\n target 配置来确定默认值。如果 target 大于 ES2022(包含 EsNext),则useDefineForClassFields默认为\n true,否则为 false。\n 3. 如果没有检测到 tsconfig.json 的 target,则按照 useDefineForClassFields的值 为 true 进行处理。\n\n\nbabel-plugin-lodash 将引入的 lodash 处理成 undefined#\n\n当使用类似下面的方式的时候,会出现这个问题:\n\n\n\nexport const libs = {\n _: Lodash,\n};\n\n\n目前在 babel-plugin-lodash Github 上的相关 Issue:\n\n * #235\n\n这个问题的解决办法是移除 babel-plugin-lodash,因为此时不需要该插件进行按需引用,使用该插件会产生副作用。\n\n类似的情况在 babel-plugin-import 上也可能会出现。比如有类似如下的代码:\n\n\n\nexport const libs = {\n comps: Comps,\n};\n\n\n此时 babel-plugin-import 也可能会导致 Comps 变为 undefined。因此也需要移除对应的 babel-plugin-import。\n\n\n异常类问题#\n\n\nDynamic require of \"react\" is not supported#\n\n问题描述#\n\n当构建的产物配置中产物格式为 ES modules 的时候:\n\nexport default defineConfig({\n buildConfig: {\n format: 'esm',\n },\n});\n\n\n如果导入了的第三方 npm 包的 cjs 产物,那么生成的产物可能会在 webpack 下有可能无法正常运行。\n\n\n\n解决办法#\n\n 1. 首先需要找到是哪个第三方包引起的问题。例如报错信息中指向了 react 这个包,那么就要寻找在哪个第三方包里存在 require('react')\n 这样的代码。比如 react-draggable ,这个包仅包含 cjs 产物,那么问题定位到 react-draggable 这个包。\n 2. 然后我们需要将这个包通过下面的配置进行排除,即不打包存在问题的第三方包。\n\nexport default defineConfig({\n buildConfig: {\n externals: ['react-draggable'],\n },\n});\n\n\n参考链接#\n\n * When using esbuild with external react I get Dynamic require of \"react\" is\n not supported\n\n\n编译过程中,因为某个组件库的 less 文件报错:'Operation on an invalid type'#\n\n可能是因为该组件库依赖的 Less 版本是 v3,而 Modern.js Module 默认是 v4。v3 与 v4 在 math 配置上存在有 Break\nChange,可以查看这个链接 了解详情。\n\n因此,如果是在源码中使用了类似这样的组件库:\n\n在构建配置中使用了 buildPreset 的情况下,按照下面进行修改:\n\nmodule.exports = {\n buildPreset({ extendPreset }) {\n return extendPreset('your-build-preset', {\n style: {\n less: {\n lessOptions: {\n math: 'always',\n },\n },\n },\n });\n },\n};\n\n\n或者使用了自定义的 buildConfig 的情况下,按照下面进行修改:\n\nmodule.exports = {\n buildConfig: {\n style: {\n less: {\n lessOptions: {\n math: 'always',\n },\n },\n },\n },\n};\n\n\n如果是在 Storybook 中使用了类似这样的组件,则需要修改 Storybook 的调试配置:\n\nmodule.exports = {\n dev: {\n storybook: {\n webpackChain(chain, { CHAIN_ID }) {\n chain.module\n .rule(CHAIN_ID.RULE.LESS)\n .use(CHAIN_ID.USE.LESS)\n .tap(options => {\n options.lessOptions = {\n ...options.lessOptions,\n math: 'always',\n };\n return options;\n });\n },\n },\n },\n};\n\n\n\nBundle DTS failed#\n\n正常情况下,使用 tsc Modern.js Module\n不仅支持输出松散的类型文件产物,同时也支持打包类型文件,可以将这些松散的类型文件以及第三方依赖的类型文件打包成一个文件。\n\n不过,打包第三方依赖的类型文件是存在风险的,因为存在第三方依赖的类型文件无法打包的情况。\n\n因此当遇到 Modern.js Module 构建过程中出现 Bundle DTS failed\n的错误信息标题的时候,可以观察报错信息是来自某个第三方依赖。尝试设置 dts.respectExternal 为 false\n来关闭打包第三方依赖的类型文件的行为。\n\n\ndefineConfig 函数类型报错:如果没有引用 \"...\",则无法命名 \"default\" 的推断类型#\n\n检查项目的 tsconfig.json 文件中是否存在 include 配置,如果没有,则尝试增加下面的内容:\n\n{\n \"include\": [\"src\"]\n}\n\n\n\n其他#\n\n\n增加额外的编译能力#\n\nModern.js Module 基于 esbuild 实现,因此如果有特殊需求或者想要增加额外的编译能力,可以通过实现 esbuild 插件来解决。\n\nModern.js Module 提供了 esbuildOptions 配置允许修改 Modern.js Module 内部的 esbuild\n配置,因此可以通过该配置来增加自定义的 esbuild 插件:\n\n\n\nexport default defineConfig({\n buildConfig: {\n esbuildOptions: options => {\n options.plugins = [myEsbuildPlugin, ...options.plugins];\n return options;\n },\n },\n});\n\n\n在增加 esbuild 插件时,请注意你需要将插件加在 plugins 数组的头部,因为 Modern.js Module 内部也是通过一个 esbuild\n插件介入到整个构建流程中去的,因此需要将自定义插件优先注册。\n\n\n支持生成 CSS Modules 的 TypeScript 声明文件#\n\n * 方案一:typed-css-modules\n * 方案二:postcss-modules-dts\n\n\n\nexport default defineConfig(async () => {\n const { dts } = await import(\"@guanghechen/postcss-modules-dts\");\n return {\n buildConfig: {\n style: {\n modules: { ...dts },\n },\n },\n // 你的自定义配置\n }\n});\n","frontmatter":{},"version":""},{"id":74,"title":"常见问题","routePath":"/module-tools/guide/faq/","lang":"zh","toc":[],"domain":"","content":"#\n\n这里是 Modern.js Module 常见问题分类列表:\n\n * 代码构建相关的问题\n * 测试相关的问题\n * Storybook 相关的问题","frontmatter":{},"version":""},{"id":75,"title":"Storybook 相关问题","routePath":"/module-tools/guide/faq/storybook","lang":"zh","toc":[{"text":"支持 Storybook v7","id":"支持-storybook-v7","depth":2,"charIndex":3},{"text":"使用 Storybook Addon 或者其他配置不生效","id":"使用-storybook-addon-或者其他配置不生效","depth":2,"charIndex":102},{"text":"Cannot find module \\'react-dom/package.json","id":"cannot-find-module-react-dompackagejson","depth":2,"charIndex":-1},{"text":"报错后,看不到具体报错信息","id":"报错后看不到具体报错信息","depth":2,"charIndex":534},{"text":"Couldn\\'t find any stories is your Storybook","id":"couldnt-find-any-stories-is-your-storybook","depth":2,"charIndex":-1},{"text":"Storybook 添加 Proxy 功能","id":"storybook-添加-proxy-功能","depth":2,"charIndex":1411},{"text":"修改存在 Story 文件的目录","id":"修改存在-story-文件的目录","depth":2,"charIndex":2095}],"domain":"","content":"#\n\n\n支持 Storybook v7#\n\nStorybook v7 目前还没支持,目前计划在 Storybook v7 中支持 Rspack 构建,因此进度会慢一些。 相关 Issue:#3376。\n\n\n使用 Storybook Addon 或者其他配置不生效#\n\nModern.js Module 目前使用的 Storybook 版本是 v6,如果使用了 v7 版本的 Addon 可能会出现插件不生效的情况。\n\n除了 Addon 以外,其他配置也可能会有区别。比如修改 preview.js 配置文件的话,Storybook v6 与 v7 的写法也不相同:\n\n * v6:文档链接\n * v7:文档链接\n\n\nCannot find module 'react-dom/package.json#\n\n在执行 Storybook 调试的时候,出现下面的报错提示:\n\nERR! Error: Cannot find module 'react-dom/package.json'\n\n\n解决办法:在项目中安装 react-dom 依赖。\n\n{\n \"devDependencies\": {\n \"react-dom\": \"^17\"\n }\n}\n\n\n\n报错后,看不到具体报错信息#\n\n解决办法:\n\n 1. 找到 @storybook/core-server/dist/cjs/dev-server.js\n 2. 找到 var _await$Promise$all = await Promise.all([preview, manager 这附近的代码。\n 3. 修改成:\n\nvar _await$Promise$all = await Promise.all([\n preview.catch(e => console.info(e)),\n manager // TODO #13083 Restore this when compiling the preview is fast enough\n // .then((result) => {\n // if (!options.ci && !options.smokeTest) openInBrowser(address);\n // return result;\n // })\n .catch(previewBuilder.bail)]),\n _await$Promise$all2 = _slicedToArray(_await$Promise$all, 2),\n previewResult = _await$Promise$all2[0],\n managerResult = _await$Promise$all2[1]; // TODO #13083 Remove this when compiling the preview is fast enough\n\n\n\nCouldn't find any stories is your Storybook#\n\n\n\n当在预览区域看到类似这样的报错提示的时候,首先可以打开一下浏览器的控制台,应该会有些报错信息。可以先根据报错信息来推断是不是编写代码里出现的问题导致\nStorybook 无法正常运行。修复后,再次刷新查看是否正常。\n\n\nStorybook 添加 Proxy 功能#\n\nStorybook 没有提供相关方案,不过 Storybook Issue 中有找到相关的解决办法。在 Modern.js Module 中,你可以:\n\n 1. 添加 config/storybook/middleware.js 文件,并初始化下面的内容:\n\n/* eslint-disable filenames/match-exported */\nmodule.exports = function expressMiddleware(router) {\n // router is express router\n // \n // router = new Router();\n};\n\n\n 2. 添加 http-proxy-middleware 依赖\n 3. 添加代理路由相关配置\n\n/* eslint-disable filenames/match-exported */\nconst { createProxyMiddleware } = require(\"http-proxy-middleware\");\n\nmodule.exports = function expressMiddleware (router) {\n router.use('/api', createProxyMiddleware({\n target: \"http://localhost:8000\",\n changeOrigin: true\n }))\n}\n\n\n相关 issue 链接:#11551。\n\n\n修改存在 Story 文件的目录#\n\n目前暂时无法修改存放 Story 文件的目录,仅对 your-project/stories 目录下的\n*.stories.(t|j)s(x)、*.stories.md(x) 文件识别为 Story 文件。","frontmatter":{},"version":""},{"id":76,"title":"测试相关问题","routePath":"/module-tools/guide/faq/test","lang":"zh","toc":[{"text":"执行 test 命令报错 TypeError: Cannot read property \\'testEnvironmentOptions\\' of undefined","id":"执行-test-命令报错-typeerror-cannot-read-property-testenvironmentoptions-of-undefined","depth":2,"charIndex":-1}],"domain":"","content":"#\n\n\n执行 test 命令报错 TypeError: Cannot read property 'testEnvironmentOptions' of\nundefined#\n\n\n\n问题原因多是存在多个版本的 jest-environment-jsdom 依赖,可以检查 Monorepo 中其他项目是否有\njest-environment-jsdom 依赖,并通过 Monorepo 提供的 overrides 能力统一依赖版本。","frontmatter":{},"version":""},{"id":77,"title":"快速开始","routePath":"/module-tools/guide/intro/getting-started","lang":"zh","toc":[{"text":"三分钟快速上手","id":"三分钟快速上手","depth":2,"charIndex":3},{"text":"创建新项目","id":"创建新项目","depth":3,"charIndex":111},{"text":"接入已有项目","id":"接入已有项目","depth":3,"charIndex":516},{"text":"核心 npm 包","id":"核心-npm-包","depth":3,"charIndex":1013},{"text":"查看官方示例","id":"查看官方示例","depth":3,"charIndex":1411},{"text":"让我们开始吧","id":"让我们开始吧","depth":2,"charIndex":1669}],"domain":"","content":"#\n\n\n三分钟快速上手#\n\n想要实际体验 Modern.js Module?首先你需要安装 Node.js LTS,并确保 Node 版本大于等于 14.18.0。我们推荐使用\nNode.js 18 的 LTS 版本。\n\n\n创建新项目#\n\n如果你想要创建一个完整的 Modern.js Module 项目,可以执行以下命令:\n\nnpx @modern-js/create your-project-dir-name\n\n\nINFO\n\n执行 npx @modern-js/create -h 查看更多命令行参数\n\n接着在问题交互中,按照如下选择:\n\n? 请选择你想创建的工程类型:Npm 模块\n? 请填写项目名称:library\n? 请选择开发语言:TS\n? 请选择包管理工具:pnpm\n\n\n> 项目名称为 package.json 中的 \"name\" 字段值。\n\n接着就会开始初始化项目的流程。在项目目录和文件生成以及依赖安装完毕后,此时就创建了一个完整的 Modern.js Module 项目。\n\n我们可以直接执行 pnpm build 命令启动项目的构建,执行 pnpm build --watch 命令开启构建的观察模式。\n\n\n接入已有项目#\n\n在你的项目里安装以下依赖:\n\n * \"@modern-js/module-tools\"\n\n * \"typescript\"(如果不是 TypeScript 项目,则省略)\n\n> 对于使用 pnpm 或者 Yarn 包管理器的项目,只需要替换 npm 就可以了。推荐使用 pnpm。\n\n接着在项目的根目录下创建 modern.config.(t|j)s 文件:\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n});\n\n\n最后在项目的 package.json 文件里增加命令 \"build\": \"modern build\":\n\n{\n \"scripts\": {\n \"build\": \"modern build\"\n }\n}\n\n\n如果你的项目存在 src/index.(js|jsx) 文件或者同时存在 src/index.(ts|tsx) 和 tsconfig.json\n文件,那么恭喜你可以运行直接运行 npm run build 来使用 Modern.js Module 构建你的项目了。\n\n\n核心 npm 包#\n\n@modern-js/module-tools 是 Modern.js Module 的核心 npm 包,主要提供以下能力:\n\n * 提供 modern dev, modern build 等常用的 CLI 命令。\n * 集成 Modern.js Core,提供配置解析、插件加载等能力。\n * 集成 esbuild 和 SWC,提供构建能力。\n * 集成一些最为常用的插件,比如 plugin-lint、plugin-changeset 等。\n\n@modern-js/module-tools 是基于 Modern.js 的插件体系实现的,本质上是一个插件,因此你需要在配置文件的 plugins\n字段中注册 moduleTools:\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n});\n\n\n\n查看官方示例#\n\n如果你想要看看使用了 Modern.js Module 的完整项目,可以执行以下命令:\n\ngit clone https://github.com/web-infra-dev/module-tools-examples\ncd module-tools-example/base\n\n## 执行构建:\npnpm build\n\n## 监听模式执行构建:\npnpm build --watch\n\n## 启动 Storybook\npnpm dev storybook\n\n## 测试\npnpm test\n\n\n\n让我们开始吧#\n\n选择适合你的教程:\n\n * 我是初学者,需要学习 Modern.js Module 的基础使用。\n * 我已经初步掌握了 Modern.js Module 的使用,可以学习 Modern.js Module 的进阶指南。\n * 我需要扩展项目能力,需要学习如何开发 Modern.js Module 的插件。","frontmatter":{"sidebar_position":3},"version":""},{"id":78,"title":"欢迎使用","routePath":"/module-tools/guide/intro/welcome","lang":"zh","toc":[],"domain":"","content":"#\n\nModern.js Module 是 Modern.js\n的模块工程解决方案,同时也是核心依赖。它可以让开发者更轻松地构建、调试、发布模块类型的项目。模块类型的项目大多数情况可以认为是 npm\n包类型的项目,它可能是一个组件、组件库或者工具库项目。\n\n如果你正打算开发一个 npm 包类型的项目,那么你就来对地方了!Modern.js 提供了专业的模块工程解决方案。它带来了:\n\n * 简单的项目初始化:仅需执行 npx @modern-js/create project-dir\n 命令,然后进行几个交互问题,就可以创建一个完整的模块类型项目。创建的项目还支持选择 pnpm、Yarn 两种包管理器。\n * 代码格式化:在模块工程项目中,你可以执行 modern lint 来对代码进行格式化。同时初始化的模块工程项目里包含了 Modern.js 的\n ESLint 规则集,可以满足大部分场景下的需求。\n * 全面的构建能力和更快的构建速度:Modern.js Module 基于 esbuild 和 SWC\n 提供了高性能的构建能力,并且为不同构建模块的场景提供了丰富的配置。\n * Storybook 调试工具:Modern.js Module 为调试模块项目提供了 Storybook 调试工具。在安装了 Modern.js\n Module 的 Storybook 插件后,你可以使用 modern dev storybook 命令来启动它。你不仅可以使用 Storybook\n 对组件进行调试,也可以使用在其他类型的模块上。\n * 集成 Jest 的测试能力:在需要对模块测试的时候,可以使用 Modern.js Module 的 modern test 命令。Modern.js\n Module 不仅集成了 Jest,同时也提供了配置 Jest 的 API。\n * 基于 Changesets 实现的版本管理:当需要对项目记录变更内容的时候,可以使用 modern change 命令生成包含变更内容的 Markdown\n 文件;当需要对项目进行版本升级的时候,可以使用 modern bump 命令通过 Markdown 文件分析并升级版本;当需要发布项目的时候,可以使用\n modern release 命令对项目进行发布。Modern.js Module 基于 Changesets 实现了这些命令。\n * 可扩展性的插件机制:想要为项目集成其他的调试工具?又或者是想要在构建过程中做一些额外处理?Modern.js Module\n 提供了插件机制和插件钩子,插件钩子覆盖了 dev 命令和 build 命令两个流程。你可以通过它们为项目进行能力的扩展。\n * 还有更多:Modern.js Module\n 在未来还会不断地在构建、调试功能上进行优化。如果在模块项目构建上存在需要解决的重要问题,又或者是某个主流的模块项目调试工具、模式出现的时候,那么它们很可能\n 成为 Modern.js Module 将要支持功能。","frontmatter":{"sidebar_position":1},"version":""},{"id":79,"title":"为什么需要 Modern.js Module","routePath":"/module-tools/guide/intro/why-module-engineering-solution","lang":"zh","toc":[],"domain":"","content":"#\n\n大家可能都经历过:从零开始开发一个组件库或者工具库的过程中,我们不仅要考虑项目本身的代码逻辑如何编写,还要考虑项目的构建、调试、测试、代码格式化等等和代码逻辑无\n关的事情。\n\n比如说,当我们考虑构建模块项目的代码是使用什么构建工具的时候,在之前我们可能会考虑使用 webpack 还是 Rollup,然而现在的话,也许还会考虑是使用\nesbuild 还是 SWC。\n\n无论选择哪个构建工具,这对于没有熟练掌握这些构建工具使用方式的开发者来说,是需要一定的成本去学习的。即使想要快速使用,也会需要花费大量的时间和精力。\n\n而除了构建这件事情以外,像为项目提供调试工具、支持测试能力、增加代码格式校验等等,对于一个新手来说都有可能需要花费很长的时间和精力了解或者掌握它们,并且真正的服\n务于当前的项目中。\n\n而为了保证代码质量以及项目的完整性,我们往往是需要做这些与代码逻辑实现无关的事情。然而这些事情很有可能会影响整体的项目开发进度,降低开发者的开发体验,会让开发者\n感觉模块项目的开发门槛很高。\n\n如果说每次开发一个模块类型的项目都需要经历一遍这些工作准备的话,那么基本上刚开始开发的时间会大部分花费在这些与代码实现无关的事情上。如果能够提供一个模块工程解决\n方案,它能够帮助开发者解决项目工程上的事情,让开发者可以更专注于代码的实现上,那么这将会大大提升模块类型项目的开发体验。\n\n\n\nModern.js 为了让开发模块类型的项目更简单、解决上述提到的问题,提供了模块工程解决方案,并且通过 Modern.js Module\n提供了主要的功能。Modern.js Module 可以理解为是一个专门用于模块类型项目开发的工具。","frontmatter":{"sidebar_position":2},"version":""},{"id":81,"title":"快速开始","routePath":"/module-tools/plugins/guide/getting-started","lang":"zh","toc":[],"domain":"","content":"#\n\nModern.js Module 不仅提供了丰富的功能,同时也支持通过插件的方式为当前项目扩展能力。\n\n我们可以通过下面的例子来快速了解如何编写一个 Modern.js Module 插件:\n\n 1. 首先我们在初始化的项目下创建 ./plugins/example.ts 文件。\n\n./\n├── plugins\n│ └── example.ts\n├── src/\n└── modern.config.ts\n\n\n 2. 接着在 example.ts 文件中增加插件的代码。\n\n\n\nexport const ExamplePlugin = (): CliPlugin => {\n return {\n name: 'example',\n setup() {\n console.info('this is example plugin');\n return {\n // use hooks\n afterBuild() {\n console.info('build over');\n },\n };\n },\n };\n};\n\n\n 3. 然后我们通过 plugins API,将刚刚写好的插件进行注册。\n\n\nexport default defineConfig({\n plugins: [examplePlugin()],\n});\n\n\n 4. 最后运行 modern build,就可以看到:\n\nthis is example plugin\nBuild succeed: 510.684ms\nbuild over\n\n\n通过上面这个例子,我们了解到了下面几件事:\n\n * 推荐的插件目录结构\n * 插件的初始化代码\n * 插件的注册\n\n除了以上内容以外,我们还需要了解:\n\n * 插件对象、类型定义与推荐配置项\n * setup 函数、api 对象参数、生命周期钩子","frontmatter":{"sidebar_position":1},"version":""},{"id":82,"title":"插件对象","routePath":"/module-tools/plugins/guide/plugin-object","lang":"zh","toc":[{"text":"插件类型定义","id":"插件类型定义","depth":2,"charIndex":480},{"text":"插件配置项","id":"插件配置项","depth":2,"charIndex":745}],"domain":"","content":"#\n\nModern.js Module 的插件是一个对象,对象包含以下属性:\n\n * name:插件的名称,唯一标识符。\n * setup:插件初始化函数,只会执行一次。setup 函数可以返回一个 Hooks 对象,Modern.js Module 会在特定的时机执行 Hooks\n 对象上定义的 Hook 对应的函数。\n\n例如在下面的插件代码示例中,在项目开始执行构建任务之前会触发 beforeBuild 函数的执行,并打印 build start 的 log 内容。\n\n\n\nconst myPlugin: CliPlugin = {\n name: 'my-plugin',\n\n setup() {\n return {\n // this is hook\n beforeBuild: () => {\n console.info('build start');\n },\n };\n },\n};\n\n\n\nexport default {\n plugins: [myPlugin()],\n};\n\n\n\n插件类型定义#\n\n使用 TypeScript 时,可以引入内置的 CliPlugin 和 ModuleTools 类型,为插件提供正确的类型推导:\n\n\n\nconst myPlugin: CliPlugin = {\n name: 'my-plugin',\n\n setup() {\n const foo = '1';\n\n return {\n // this is hook\n afterBuild: () => {\n //...\n },\n };\n },\n};\n\n\n\n插件配置项#\n\n建议将插件写成函数的形式,使插件能通过函数入参来接收配置项:\n\n\n\ntype MyPluginOptions = {\n foo: string;\n};\n\nconst myPlugin = (options: MyPluginOptions): CliPlugin => ({\n name: 'my-plugin',\n\n setup() {\n console.log(options.foo);\n },\n});\n","frontmatter":{"sidebar_position":2},"version":""},{"id":83,"title":"Setup 函数","routePath":"/module-tools/plugins/guide/setup-function","lang":"zh","toc":[{"text":"插件 API 对象","id":"插件-api-对象","depth":2,"charIndex":77},{"text":"api.useAppContext","id":"apiuseappcontext","depth":3,"charIndex":441},{"text":"api.useResolvedConfigContext","id":"apiuseresolvedconfigcontext","depth":3,"charIndex":823},{"text":"api.useHookRunners","id":"apiusehookrunners","depth":3,"charIndex":1198},{"text":"异步 setup","id":"异步-setup","depth":2,"charIndex":1461},{"text":"生命周期钩子","id":"生命周期钩子","depth":2,"charIndex":1731}],"domain":"","content":"#\n\n在「插件对象」 部分我们知道插件对象包含了一个 setup 函数,该函数不仅包含了一个 api 对象参数,同时还可以返回一个 Hooks 对象。\n\n\n插件 API 对象#\n\n插件的 setup 函数会提供一个 api 对象参数,你可以调用该对象上提供的一些方法来获取到配置、项目上下文等信息。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n setup(api) {\n // 获取应用原始配置\n const config = api.useConfigContext();\n // 获取应用运行上下文\n const appContext = api.useAppContext();\n // 获取解析之后的最终配置\n const resolvedConfig = api.useResolvedConfigContext();\n },\n});\n\n\n\napi.useAppContext#\n\n用于获取项目上下文信息。\n\nconst useAppContext: () => IAppContext;\n\ninterface IAppContext {\n appDirectory: string;\n configFile: string | false;\n packageName: string;\n nodeModulesDirectory: string;\n internalDirectory: string;\n plugins: {\n cli?: any;\n server?: any;\n }[];\n}\n\n\nINFO\n\n通过实际的类型文件,我们可以看到还存在一些其他字段,不过目前对于 Modern.js Module 有意义的字段只有以上内容,api 对象其他的方法也是如此。\n\n\napi.useResolvedConfigContext#\n\n用于获取解析之后的最终配置。\n\nINFO\n\n如果需要获取构建相关的最终配置,需要使用 beforeBuild Hook。\n\nconst useResolvedConfigContext: () => NormalizedConfig;\n\ninterface NormalizedConfig {\n buildConfig: PartialBuildConfig;\n buildPreset: BuildPreset;\n dev: Dev;\n plugins: PluginConfig;\n runtime: RuntimeConfig;\n runtimeByEntries?: RuntimeByEntriesConfig;\n _raw: UserConfig;\n}\n\n\n\napi.useHookRunners#\n\n用于获取 Hooks 的执行器,并触发特定的 Hook 执行。\n\n\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n async setup(api) {\n const hookRunners = api.useHookRunners();\n // 触发 afterBuild Hook\n await hookRunners.afterBuild();\n },\n});\n\n\n\n异步 setup#\n\nCLI 插件的 setup 可以是一个异步函数,在初始化过程中执行异步逻辑。\n\nexport const myPlugin = (): CliPlugin => ({\n name: 'my-plugin',\n\n async setup(api) {\n await doSomething();\n },\n});\n\n\n注意,只有当前插件的 setup 异步函数执行完毕,才会继续执行下一个插件的 setup 函数。因此,你需要避免在 setup\n函数中进行耗时过长的异步操作,防止影响 CLI 启动性能。\n\n\n生命周期钩子#\n\n我们知道 setup 函数会返回一个 Hooks 对象,所谓 Hooks 对象也可以理解是具有 Modern.js Module 生命周期钩子的对象。\n\n目前主要包含两类钩子:\n\n * 构建钩子:仅在执行 build 命令构建源码产物时触发。\n * buildPlatform 钩子:仅在执行 build --platform 命令生成其他构建产物时触发。\n * 调试钩子:运行 dev 命令时会触发的钩子。\n\n关于生命周期钩子的完整列表参考 API 文档。","frontmatter":{"sidebar_position":3},"version":""},{"id":84,"title":"总览","routePath":"/module-tools/plugins/official-list/overview","lang":"zh","toc":[{"text":"官方插件","id":"官方插件","depth":2,"charIndex":3}],"domain":"","content":"#\n\n\n官方插件#\n\n * @modern-js/plugin-module-import:使用 SWC 提供与 babel-plugin-import 一样的能力。\n * @modern-js/plugin-module-banner:为每个 JS 和 CSS 文件的顶部和底部添加自定义内容,例如版权信息。\n * @modern-js/plugin-module-node-polyfill:会自动注入 Node 核心模块在浏览器端的 polyfills。\n * @modern-js/plugin-module-polyfill:为你的代码中使用到的不支持的功能注入 polyfill。\n * @modern-js/plugin-module-babel:使用 Babel 转换你的代码。","frontmatter":{},"version":""},{"id":85,"title":"Babel 插件","routePath":"/module-tools/plugins/official-list/plugin-babel","lang":"zh","toc":[{"text":"快速开始","id":"快速开始","depth":2,"charIndex":50},{"text":"安装","id":"安装","depth":3,"charIndex":58},{"text":"注册插件","id":"注册插件","depth":3,"charIndex":64},{"text":"配置","id":"配置","depth":2,"charIndex":508}],"domain":"","content":"#\n\nTIP\n\n通常情况下,我们无需使用 Babel 转换我们的代码,此插件仅作为一种降级方式。\n\n\n快速开始#\n\n\n安装#\n\n\n注册插件#\n\n在 Modern.js Module 中,你可以按照如下方式注册插件:\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginBabel()],\n});\n\n\n你也可以通过 hooks 配置注册,例如你同时需要打包 A,B 两个文件,并只需要在打包 A 时使用 babel:\n\n\n\n\nconst babelHook = getBabelHook({\n // babel options\n});\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildConfig: [\n {\n hooks: [babelHook],\n input: ['src/a.ts'],\n },\n {\n input: ['src/b.ts'],\n },\n ],\n});\n\n\n\n配置#\n\nSee Babel options\n\n下面是一个配置了@babel/preset-env的例子:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBabel({\n presets: [['@babel/preset-env']],\n }),\n ],\n});\n","frontmatter":{},"version":""},{"id":86,"title":"Banner 插件","routePath":"/module-tools/plugins/official-list/plugin-banner","lang":"zh","toc":[{"text":"快速开始","id":"快速开始","depth":2,"charIndex":133},{"text":"安装","id":"安装","depth":3,"charIndex":141},{"text":"注册插件","id":"注册插件","depth":3,"charIndex":147},{"text":"示例","id":"示例","depth":2,"charIndex":426},{"text":"在 JS 文件顶部增加版权信息","id":"在-js-文件顶部增加版权信息","depth":3,"charIndex":432},{"text":"配置","id":"配置","depth":2,"charIndex":898},{"text":"banner","id":"banner","depth":3,"charIndex":1045},{"text":"footer","id":"footer","depth":3,"charIndex":1124}],"domain":"","content":"#\n\n提供为每个 JS 和 CSS 文件的顶部和底部注入内容的能力。\n\nTIP\n\n从 @modern-js/module-tools v2.36.0 版本开始,该插件功能内置在 Modern.js Module 中,由 banner 和\nfooter 配置提供。\n\n\n快速开始#\n\n\n安装#\n\n\n注册插件#\n\n在 Modern.js Module 中,你可以按照如下方式注册插件:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBanner({\n banner: {\n js: '//comment',\n css: '/*comment*/',\n },\n }),\n ],\n});\n\n\nTIP\n\n注意:CSS 的注释不支持 //comment 这样的写法。详见「CSS 注释」\n\n\n示例#\n\n\n在 JS 文件顶部增加版权信息#\n\n\n\n\nconst copyRight = `/*\n © Copyright 2020 xxx.com or one of its affiliates.\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n * Some Sample Copyright Text Line\n*/`;\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginBanner({\n banner: {\n js: copyRight,\n },\n }),\n ],\n});\n\n\n\n配置#\n\n * 类型:\n\ntype BannerOptions = {\n banner: {\n js?: string;\n css?: string;\n };\n footer?: {\n js?: string;\n css?: string;\n };\n};\n\n\n\nbanner#\n\n在顶部增加内容。\n\n * banner.js:在 JS 文件顶部增加内容。\n * banner.css:在 CSS 文件顶部增加内容。\n\n\nfooter#\n\n在底部增加内容。\n\n * footer.js:在 JS 文件底部增加内容。\n * footer.css:在 CSS 文件底部增加内容。","frontmatter":{},"version":""},{"id":87,"title":"Import 插件","routePath":"/module-tools/plugins/official-list/plugin-import","lang":"zh","toc":[{"text":"快速开始","id":"快速开始","depth":2,"charIndex":145},{"text":"安装","id":"安装","depth":3,"charIndex":153},{"text":"注册插件","id":"注册插件","depth":3,"charIndex":159},{"text":"配置","id":"配置","depth":2,"charIndex":459},{"text":"pluginImport","id":"pluginimport","depth":3,"charIndex":526},{"text":"注意事项","id":"注意事项","depth":2,"charIndex":878}],"domain":"","content":"#\n\n提供与 babel-plugin-import 等价的能力和配置,基于 SWC 实现。\n\nTIP\n\n从 @modern-js/module-tools v2.16.0 版本开始,该插件功能内置在 Modern.js Module 中,由\ntransformImport 配置提供。\n\n\n快速开始#\n\n\n安装#\n\n\n注册插件#\n\n在 Modern.js Module 中,你可以按照如下方式注册插件:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginImport({\n pluginImport: [\n {\n libraryName: 'antd',\n style: true,\n },\n ],\n }),\n ],\n});\n\n\n这样我们就可以在 Modern.js Module 中使用自动导入的能力了。\n\n\n配置#\n\n * 类型:\n\ntype Options = {\n pluginImport?: ImportItem[];\n};\n\n\n\npluginImport#\n\n * 类型:object[]\n\n其中数组元素为一个 babel-plugin-import 的配置对象。配置对象可以参考 options。\n\n使用示例:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginImport({\n pluginImport: [\n // babel-plugin-import 的 options 配置\n {\n libraryName: 'foo',\n style: true,\n },\n ],\n }),\n ],\n});\n\n\n\n注意事项#\n\nSWC (Speedy Web Compiler) 是基于 Rust 语言编写的,而该插件是基于 SWC,移植自\nbabel-plugin-import,配置选项保持了一致。\n\n一些配置可以传入函数,例如 customName,customStyleName 等,这些 JavaScript 函数会由 Rust 通过 Node-API\n调用,这种调用会造成一些性能劣化。\n\n简单的函数逻辑其实可以通过模版语言来代替,因此 customName,customStyleName\n等这些配置除了可以传入函数,也可以传入字符串作为模版来代替函数,提高性能。\n\n我们以这段代码作为示例:\n\n\n\n\n添加以下配置:\n\nmodulePluginImport({\n pluginImport: [\n {\n libraryName: 'foo',\n customName: 'foo/es/{{ member }}',\n },\n ],\n});\n\n\n其中的 {{ member }} 会被替换为相应的引入成员,转换后:\n\n\n\n\n可以看出配置 customName: \"foo/es/{{ member }}\" 的效果等同于配置 customName: (member) =>\n`foo/es/${member}` ,但是不会有 Node-API 的调用开销。\n\n这里使用到的模版是 handlebars,模版配置中还内置了一些有用的辅助工具,还是以上面的导入语句为例,配置成:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginImport({\n pluginImport: [\n {\n libraryName: 'foo',\n customName: 'foo/es/{{ kebabCase member }}',\n },\n ],\n }),\n ],\n});\n\n\n会转换成下面的结果:\n\n\n\n\n除了 kebabCase 以外还有 camelCase,snakeCase,upperCase,lowerCase 可以使用。","frontmatter":{},"version":""},{"id":88,"title":"Node Polyfill 插件","routePath":"/module-tools/plugins/official-list/plugin-node-polyfill","lang":"zh","toc":[{"text":"快速开始","id":"快速开始","depth":2,"charIndex":213},{"text":"安装","id":"安装","depth":3,"charIndex":221},{"text":"注册插件","id":"注册插件","depth":3,"charIndex":227},{"text":"配置","id":"配置","depth":2,"charIndex":367},{"text":"exclude","id":"exclude","depth":3,"charIndex":459},{"text":"overrides","id":"overrides","depth":3,"charIndex":636},{"text":"Node Polyfills","id":"node-polyfills","depth":2,"charIndex":866},{"text":"Globals","id":"globals","depth":3,"charIndex":884},{"text":"Modules","id":"modules","depth":3,"charIndex":1007},{"text":"Fallbacks","id":"fallbacks","depth":3,"charIndex":1445}],"domain":"","content":"#\n\nNode Polyfill 介绍\n\n通常情况下,我们不会在浏览器端使用 Node 模块。但在当前代码需要同时在 Node 端和浏览器端运行时,用到一些 Node 模块是有可能的。Node\nPolyfill 为这些 Node 模块提供了浏览器版本的 polyfills。\n\n通过使用 Node Polyfill 插件,会自动注入 Node 核心模块在浏览器端的 polyfills,让你可以在浏览器端放心使用这些模块。\n\n\n快速开始#\n\n\n安装#\n\n\n注册插件#\n\n在 Modern.js Module 中,你可以按照如下方式注册插件:\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginNodePolyfill()],\n});\n\n\n\n配置#\n\n * 类型:\n\ntype NodePolyfillOptions = {\n exclude?: string[];\n overrides?: Record;\n};\n\n\n\nexclude#\n\n排除要注入的 Node Polyfill。\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginNodePolyfill({\n exclude: ['console'],\n }),\n ],\n});\n\n\n\noverrides#\n\n覆盖内置的 Node Polyfill。\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginNodePolyfill({\n overrides: {\n fs: path.join(__dirname, './custom-fs.js'),\n },\n }),\n ],\n});\n\n\n\nNode Polyfills#\n\n\nGlobals#\n\n * Buffer\n * process\n * console\n\n当你在代码中使用以上全局变量时,对应 polyfill 会被自动注入。\n\nconst bufferData = Buffer.from('xxxx');\n\n\n\nModules#\n\n * assert\n * buffer\n * console\n * constants\n * crypto\n * domain\n * events\n * http\n * https\n * os\n * path\n * punycode\n * process\n * querystring\n * stream\n * _stream_duplex\n * _stream_passthrough\n * _stream_readable\n * _stream_transform\n * _stream_writable\n * string_decoder\n * sys\n * timers\n * tty\n * url\n * util\n * vm\n * zlib\n\n当你通过 require 或 import 等语法在代码中引用以上模块时,对应 polyfill 会被注入。\n\n\n\nconst bufferData = Buffer.from('xxxx');\n\n\n\nFallbacks#\n\n * child_process\n * cluster\n * dgram\n * dns\n * fs\n * module\n * net\n * readline\n * repl\n * tls\n\n目前浏览器端没有以上模块的 polyfill,因此当你引用以上模块时,会自动 fallback 为一个空对象。\n\n\n\nconsole.log(fs); // -> {}\n","frontmatter":{},"version":""},{"id":89,"title":"Polyfill 插件","routePath":"/module-tools/plugins/official-list/plugin-polyfill","lang":"zh","toc":[{"text":"快速开始","id":"快速开始","depth":2,"charIndex":197},{"text":"安装","id":"安装","depth":3,"charIndex":205},{"text":"注册插件","id":"注册插件","depth":3,"charIndex":211},{"text":"配置","id":"配置","depth":2,"charIndex":652},{"text":"targets","id":"targets","depth":3,"charIndex":717}],"domain":"","content":"#\n\nTIP\n\n通常情况下,我们不需要为 npm 包注入 polyfill,这一步应该在 Web\n应用的框架侧完成,但是在某些场景,为了让我们的库能够直接运行在低版本浏览器里,我们需要注入 polyfill。\n\n请注意,此插件并不会转化你的代码语法,只会为你的代码中使用到的不支持的功能注入 polyfill,把它们作为普通函数导入而不是污染全局。你需要安装\ncore-js-pure 依赖\n\n\n快速开始#\n\n\n安装#\n\n\n注册插件#\n\n在 Modern.js Module 中,你可以按照如下方式注册插件:\n\n\n\n\nexport default defineConfig({\n plugins: [moduleTools(), modulePluginPolyfill()],\n});\n\n\n你也可以通过 hooks 配置注册,例如你同时具有多份构建配置,并只需要在 bundle 构建时注入 polyfill:\n\n\n\n\nconst polyfillHook = getPolyfillHook();\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildConfig: [\n {\n buildType: 'bundle',\n hooks: [polyfillHook],\n },\n {\n buildType: 'bundleless',\n },\n ],\n});\n\n\n\n配置#\n\n * 类型:\n\ntype options = {\n targets?: Record | string;\n};\n\n\n\ntargets#\n\n参考 Babel target.\n\n下面是一个例子:\n\n\n\n\nexport default defineConfig({\n plugins: [\n moduleTools(),\n modulePluginPolyfill({\n targets: '> 0.25%, not dead',\n }),\n ],\n});\n","frontmatter":{},"version":""}] \ No newline at end of file