index
int64
0
0
repo_id
stringlengths
16
181
file_path
stringlengths
28
270
content
stringlengths
1
11.6M
__index_level_0__
int64
0
10k
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api/config/build-config.mdx
--- sidebar_position: 1 --- # 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[]` :::tip Before start using `buildConfig`, please read the following documentat...
7,900
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api/config/build-preset.mdx
--- sidebar_position: 2 --- # buildPreset A build preset string or preset function. Provides out-of-the-box build configuration - **Type**: `string | Function` ### `npm-library` Library generic schema used under class [NPM](https://www.npmjs.com/) package manager, contains `esm` and `cjs` bundle artifacts, and inc...
7,901
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api/config/dev.md
--- sidebar_position: 3 --- # dev This section describes all configuration of Modern.js Module related to debugging tools. ## storybook :::warning **Deprecated**: This configuration is deprecated and only applicable to Storybook V6. Please see [使用Storybook](/guide/basic/using-storybook) to get more info. ::: ### s...
7,902
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api/config/plugins.md
--- sidebar_position: 4 --- # plugins This chapter describes the configuration of the registered Modern.js Module plugin. - **Type**: `ModuleToolsPlugin[]` - **Default**: `undefined` ## Plugin Execution Order By default, custom plugins are executed in the order specified in the `plugins` array. The execution of bu...
7,903
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api/config/testing.md
--- sidebar_position: 5 --- # testing This chapter describes the test-related configuration :::tip You need to enable the unit testing feature with `pnpm run new` first. ::: ## jest - Type: `object | Function` - Default: `{}` The configuration corresponding to [Jest](https://jestjs.io/docs/configuration), when of...
7,904
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api/plugin-api/_category_.json
{ "label": "Plugin API", "collapsed": false }
7,905
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/api/plugin-api/plugin-hooks.md
# Plugin Hooks This chapter describes the lifecycle hooks supported by module-tools. Currently there are following main types of lifecycle hooks. - Config hooks: change user config. - Build hooks: triggered only when the `build` command is executed to build the source code product. - `buildPlatform` hook: triggered ...
7,906
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/components/faq-build-exception.mdx
7,907
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/components/faq-test.mdx
7,908
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/components/register-esbuild-plugin.mdx
```js title="modern.config.ts" import { myEsbuildPlugin } from './myEsbuildPlugin'; export default defineConfig({ buildConfig: { esbuildOptions: options => { options.plugins = [myEsbuildPlugin, ...options.plugins]; return options; }, }, }); ``` When adding an esbuild plugin, please note that y...
7,909
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/advance/_category_.json
{ "label": "Advanced Guide", "sidebar_position": 3 }
7,910
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/advance/asset.mdx
--- sidebar_position: 6 --- # Handle static assets Modern.js Module will handle static assets used in the code. If configuration is required, then the [`buildConfig.asset`](/en/api/config/build-config#asset) API can be used. ## Default behavior By default, Modern.js Module handles the following static assets: - `'...
7,911
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/advance/build-umd.mdx
--- sidebar_position: 5 --- # 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 - Node.js environment: module loading based on CommonJS - Other cases: ...
7,912
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/advance/copy.md
--- sidebar_position: 3 --- # 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`](/en/api/config/b...
7,913
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/advance/external-dependency.mdx
--- sidebar_position: 4 --- # 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...
7,914
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/advance/in-depth-about-build.md
--- sidebar_position: 1 --- # 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...
7,915
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/advance/in-depth-about-dev-command.md
--- sidebar_position: 2 --- # 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 1. When the `dev` command is executed, Modern.js Module starts looking for debugging tools or tasks that can be exe...
7,916
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/basic/_category_.json
{ "label": "Basic Guide", "sidebar_position": 2 }
7,917
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/basic/before-getting-started.md
--- sidebar_position: 1 --- # Before you start ## Environment preparation In order to use the Modern.js Module, you first need [NodeJS](https://nodejs.org/zh/) engine, we recommend the latest [LTS version](https://github.com/nodejs/Release), and make sure the Node version is **>=14.18.0**. because non-stable NodeJS ...
7,918
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/basic/command-preview.md
--- sidebar_position: 2 --- # CLI Commands CLI Commands available for Modern.js Module projects are as follows: ## `modern build` ```bash Usage: modern build [options] Build module command Options: -w, --watch Build code in listening mode --tsconfig [tsconfig] Specify the path to the tsconfig.json file (defau...
7,919
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/basic/modify-output-product.md
--- sidebar_position: 3 --- # Modify the output ## Default output artifacts 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: ```ts title="modern.config.ts" imp...
7,920
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/basic/publish-your-project.md
--- sidebar_position: 7 --- # 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. - The second phase is during release, where Modern.js Modu...
7,921
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/basic/test-your-project.mdx
--- sidebar_position: 6 --- # 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](/guide/basic...
7,922
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/basic/use-micro-generator.md
--- sidebar_position: 4 --- # Using the Microgenerator Modern.js Module provides the Microgenerator tool, which allows for the current project to. - add new directories and files - Modify the contents of the `package.json` file - Execute commands Thus with these capabilities, **Microgenerator can enable additional ...
7,923
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/basic/use-module-doc.mdx
--- sidebar_position: 5 --- # Developing Module documentation This chapter describes how to quickly build a static documentation site for a module project. ## Before we start ### Why we need to build a documentation site for a module 1. a documentation site can help us to better organize the structure of the docum...
7,924
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/basic/using-storybook.mdx
--- sidebar_position: 5 --- # Using Storybook [Storybook](https://storybook.js.org/) is a tool dedicated to component debugging, providing around component development. - Develop UIs that are more durable - Test UIs with less effort and no flakes - Document UI for your team to reuse - Share how the UI actually works...
7,925
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/best-practices/_category_.json
{ "label": "Best practices", "sidebar_position": 4 }
7,926
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/best-practices/components.mdx
--- sidebar_position: 1 --- # Developing Components This chapter will describe how to develop component projects using the Modern.js Module. ## Initialize the project 1. It is recommended to use the `@modern-js/create` command to initialize an npm project. ```text title="Interactive questions" npx @modern-js/creat...
7,927
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/best-practices/use-tailwindcss.mdx
--- sidebar_position: 2 --- # Using Tailwind CSS [Tailwind CSS](https://tailwindcss.com/) 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 Tailwin...
7,928
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/faq/_category_.json
{ "label": "FAQ", "sidebar_position": 5 }
7,929
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/faq/build.mdx
# Build FAQ ## Product FAQ import BuildProductFAQ from '@site-docs-en/components/faq-build-product'; <BuildProductFAQ /> ### Initialization of Class Fields TypeSript provides the `useDefineForClassFields` configuration to control the conversion handling for `public class fields`. If we have a piece of code: ```t...
7,930
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/faq/index.md
# FAQ Here is a list of all frequently asked questions about Modern.js Module. - [Build FAQ](./build.mdx) - [Test FAQ](./test.mdx) - [Storybook FAQ](./storybook.mdx)
7,931
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/faq/storybook.mdx
# Storybook FAQ import BuildStorybookFAQ from '@site-docs-en/components/faq-storybook'; <BuildStorybookFAQ /> ## Storybook v7 Support Storybook v7 is now fully supported and has become our recommended version. ## Using Storybook Addon or other configurations does not work Modern.js Module is currently using Story...
7,932
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/faq/test.mdx
# Test FAQ import TestFAQ from '@site-docs-en/components/faq-test'; <TestFAQ /> ### Execute `test` command with an error `TypeError: Cannot read property 'testEnvironmentOptions' of undefined` ![jest-error](https://lf3-static.bytednsdoc.com/obj/eden-cn/shylnyhaeh7uldvivhn/jest-error-testEnvironmentOptions-of-undefi...
7,933
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/intro/_category_.json
{ "label": "Introduction", "sidebar_position": 1 }
7,934
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/intro/getting-started.mdx
--- sidebar_position: 3 --- # Quick Start ## 3 minute demo Want to experience Modern.js Module in action? The only prerequisite you need is [Node.js LTS](https://github.com/nodejs/Release) and make sure your Node version is **>= 14.18.0**.We recommend using the LTS version of Node.js 18. ### Create new project **I...
7,935
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/intro/welcome.md
--- sidebar_position: 1 --- # 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, wh...
7,936
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/guide/intro/why-module-engineering-solution.md
--- sidebar_position: 2 --- # 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 h...
7,937
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins/guide/_category_.json
{ "label": "Guide", "sidebar_position": 1 }
7,938
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins/guide/getting-started.mdx
--- sidebar_position: 1 --- # 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. 1. First we create `. /plugins/example...
7,939
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins/guide/plugin-object.mdx
--- sidebar_position: 2 --- # 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. - `setup`: plugin initialization function, which will be executed only once. setup function can return a Hooks object, and Mod...
7,940
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins/guide/setup-function.mdx
--- sidebar_position: 3 --- # Setup function In the ["Plugin object"](/plugins/guide/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 prov...
7,941
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins/official-list/_category_.json
{ "label": "Plugins List", "sidebar_position": 2 }
7,942
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins/official-list/overview.md
# Overview ## Official Plugin * [@modern-js/plugin-module-import](./plugin-import.md):Use SWC to provide the same ability as [`babel-plugin-import`](https://github.com/umijs/babel-plugin-import). * [@modern-js/plugin-module-banner](./plugin-banner.md):Add custom content, such as copyright information, to the top and ...
7,943
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins/official-list/plugin-babel.mdx
# 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 import { PackageManagerTabs } from '@theme'; <PackageManagerTabs command="add @modern-js/plugin-module-babel -D" /> ### Register You can install the plugin wit...
7,944
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins/official-list/plugin-banner.mdx
# Banner Plugin Provide the ability to inject content at the top and bottom of each JS and CSS file. ## Quick Start ### Install import { PackageManagerTabs } from '@theme'; <PackageManagerTabs command="add @modern-js/plugin-module-banner -D" /> ### Register You can install the plugin with the following command: ...
7,945
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins/official-list/plugin-import.mdx
# Import Plugin Using [SWC](https://swc.rs/) provides the same ability and configuration as [`babel-plugin-import`](https://github.com/umijs/babel-plugin-import). :::tip Since `@modern-js/module-tools` version >= MAJOR_VERSION.16.0, this plugin functionality is built into Modern.js Module and is provided by [`transfo...
7,946
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins/official-list/plugin-node-polyfill.mdx
# Node Polyfill Plugin :::tip 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 th...
7,947
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins/official-list/plugin-polyfill.mdx
# 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 s...
7,948
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/en/plugins/official-list/plugin-vue.mdx
# Vue Plugin The Vue plugin provides support for building Vue 3 components. The plugin internally integrates [esbuild-plugin-vue3](https://github.com/pipe01/esbuild-plugin-vue3) and [@vue/babel-plugin-jsx](https://github.com/vuejs/babel-plugin-jsx)。 :::warning Notice that we have some limitation: 1. The current impl...
7,949
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/index.md
--- pageType: home hero: name: Modern.js Module text: 模块工程解决方案 tagline: 简单、强大、高性能的现代化 npm 包开发方案 actions: - theme: brand text: 欢迎使用 link: /guide/intro/welcome - theme: alt text: 快速上手 link: /guide/intro/getting-started features: - title: 'esbuild: 高性能的 JS Bundler' details: ...
7,950
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api/index.md
--- overview: true sidebar_label: 概览 sidebar_position: 1 --- # 概览
7,951
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api/config/_category_.json
{ "label": "配置项", "sidebar_position": 2 }
7,952
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api/config/build-config.mdx
--- sidebar_position: 1 --- # buildConfig `buildConfig` 是一个用来描述如何编译、生成构建产物的配置项,它包含了构建的所有配置。 - 类型:`object | object[]` :::tip 在开始使用 `buildConfig` 之前,请先阅读以下文档来了解其作用: - [修改输出产物](/guide/basic/modify-output-product.html) - [深入理解构建](/guide/advance/in-depth-about-build.html) ::: ## alias - 类型:`Record<string, string> | ...
7,953
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api/config/build-preset.mdx
--- sidebar_position: 2 --- # buildPreset 构建的预设字符串或者预设函数。提供开箱即用的构建配置。 - 类型:`string | Function` - 默认值: `undefined` ## `npm-library` 在类 [NPM](https://www.npmjs.com/) 包管理器下使用的 Library 通用模式,包含 `esm` 和 `cjs` 两种 Bundle 产物,并且包含一份类型文件。 :::info 关于类 [NPM](https://www.npmjs.com/) 包管理器 - [npm](https://www.npmjs.com) - [yar...
7,954
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api/config/dev.md
--- sidebar_position: 3 --- # dev 本章节描述了 Modern.js Module 关于调试工具相关的所有配置。 ## storybook :::warning **Deprecated**:该配置已过时,只适用于 StorybookV6,详情请看[使用Storybook](/guide/basic/using-storybook)。 ::: ### storybook.webpack - 类型:`object | Function | undefined` - 默认值:`undefined` ```ts export default { dev: { storybook: ...
7,955
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api/config/plugins.md
--- sidebar_position: 4 --- # plugins 本章介绍注册 Modern.js Module 插件的配置。 - 类型:`ModuleToolsPlugin[]` - 默认值:`undefined` ## 插件执行顺序 默认情况下,自定义插件会按照 `plugins` 数组的顺序依次执行,Modern.js Module 内置插件的执行时机早于自定义插件。 当插件内部使用了控制顺序的相关字段,比如 `pre`、`post` 时,会基于声明的字段对执行顺序进行调整,详见 [插件之间的关系](https://modernjs.dev/guides/topic-detail/framework-pl...
7,956
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api/config/testing.md
--- sidebar_position: 5 --- # testing 本章描述了测试相关的配置。 :::tip 需要先通过 `pnpm run new` 启用 单元测试 功能。 ::: ## jest - 类型: `object | Function` - 默认值:`{}` 对应 [Jest](https://jestjs.io/docs/configuration) 的配置,当为 `object` 类型时,可以配置 Jest 所支持的所有底层配置 。 ```js title="modern.config.ts" import { defineConfig } from '@modern-js/module-to...
7,957
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api/plugin-api/_category_.json
{ "label": "Plugin API", "sidebar_position": 3 }
7,958
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/api/plugin-api/plugin-hooks.md
# Plugin Hooks 本章介绍关于 Modern.js Module 支持的生命周期钩子。 目前主要包含以下几类生命周期钩子: - 配置钩子:用于处理用户配置。 - 构建钩子:仅在执行 `build` 命令构建源码产物时触发。 - `buildPlatform` 钩子:仅在执行 `build --platform` 命令生成其他构建产物时触发。 - 调试钩子:运行 `dev` 命令时会触发的钩子。 这里详细解释了 [Hook 模型](https://modernjs.dev/guides/topic-detail/framework-plugin/hook.html) ## 配置钩子 ### `resolveMo...
7,959
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/components/faq-build-exception.mdx
7,960
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/components/faq-test.mdx
7,961
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/components/register-esbuild-plugin.mdx
```js title="modern.config.ts" import { myEsbuildPlugin } from './myEsbuildPlugin'; export default defineConfig({ buildConfig: { esbuildOptions: options => { options.plugins = [myEsbuildPlugin, ...options.plugins]; return options; }, }, }); ``` 在增加 esbuild 插件时,请注意你需要将插件加在 plugins 数组的头部,因为 Mode...
7,962
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/advance/_category_.json
{ "label": "进阶指南", "sidebar_position": 3 }
7,963
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/advance/asset.mdx
--- sidebar_position: 7 --- # 处理静态资源 Modern.js Module 会对代码中使用的静态资源进行处理。如果需要配置,则可以使用 [`buildConfig.asset`](/api/config/build-config#asset) API。 ## 默认行为 默认情况下,Modern.js Module 会处理以下静态资源: - `'.svg'`、`'.png'`、`'.jpg'`、`'.jpeg'`、`'.gif'`、`'.webp'` - `'.ttf'`、`'.otf'`、`'.woff'`、`'.woff2'`、`'.eot'` - `'.mp3'`、`'.mp4'`、`'...
7,964
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/advance/build-umd.mdx
--- sidebar_position: 5 --- # 构建 umd 产物 umd 全称为 **Universal Module Definition**,这种格式的 JS 文件可以运行在多个运行环境: - 浏览器环境:基于 AMD 规范进行模块加载 - Node.js 环境:基于 CommonJS 进行模块加载 - 其他情况:将模块挂载在全局对象上。 因此我们可以通过下面的方式,将项目的构建产物指定为 umd 产物: ```ts export default defineConfig({ buildConfig: { format: 'umd', }, }); ``` ## umd 产物的第三方依赖...
7,965
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/advance/copy.md
--- sidebar_position: 3 --- # 使用 Copy 工具 Modern.js Module 提供了 Copy 工具用于将已经存在的单个文件或整个目录复制到产物目录中。接下来我们学习如何使用它。 ## 了解 Copy API 我们可以通过 [`buildConfig.copy`](/api/config/build-config#copy) API 来使用 Copy 工具,它包含以下两个主要配置: - [`patterns`](/api/config/build-config#copypatterns) - [`options`](/api/config/build-config#copyoption...
7,966
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/advance/external-dependency.mdx
--- sidebar_position: 4 --- # 处理三方依赖 一般来说,项目所需要的第三方依赖可以通过包管理器的 `install` 命令安装,在安装第三方依赖成功后,这些第三方依赖一般会出现在项目 `package.json` 的 `dependencies` 和 `devDependencies` 下。 ```json title="pacakge.json" { "dependencies": {}, "devDependencies": {} } ``` `"dependencies"` 下的依赖通常来说是这个包运行所需的依赖, `"devDependencies"` 则代表着开发依赖。 除了 ...
7,967
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/advance/in-depth-about-build.md
--- sidebar_position: 1 --- # 深入理解构建 在 "基础使用" 的部分,我们已经知道可以通过 `buildConfig` 配置对项目的输出产物进行修改。`buildConfig` 不仅描述了产物的一些特性,同时还为构建产物提供了一些功能。 :::tip 如果你还不了解 `buildConfig` 的作用,请先阅读 [修改输出产物](/guide/basic/modify-output-product)。 ::: 而在本章里我们将要深入理解某些构建配置的作用以及了解执行 `modern build` 命令的时候发生了什么。 ## `bundle` / `bundleless` 那么首先我们来了解...
7,968
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/advance/in-depth-about-dev-command.md
--- sidebar_position: 2 --- # 深入理解 dev 命令 Modern.js Module 提供的 `dev` 命令主要用于代码的调试。 ## 命令运行的整体流程 1. 当执行 `dev` 命令的时候,Modern.js Module 开始寻找是否存在可以执行的调试工具或者任务。调试工具或者任务就是类似 doc 这样的 Modern.js Module 调试工具插件。 2. 当发现存在一个调试工具的时候,则会立即执行它。 3. 当发现多个调试工具的时候,则显示调试工具列表菜单。可以通过选择某个调试工具对应的名称选项启动它。 4. 当没有发现调试工具的时候,则告诉用户没有可用的调试工具。 我们除了可...
7,969
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/basic/_category_.json
{ "label": "基础使用", "sidebar_position": 2 }
7,970
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/basic/before-getting-started.md
--- sidebar_position: 1 --- # 开始之前 ## 环境准备 为了使用 Modern.js Module,首先需要 [NodeJS](https://nodejs.org/zh/),我们推荐最新的[长期维护版本](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **14.18.0**。因为非稳定的 NodeJS 时常有一些 Bug,你可以使用 [nvm-windows](https://github.com/coreybutler/nvm-windows) 和 [nvm](https://github.com/nvm-sh/nvm)(Mac / Li...
7,971
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/basic/command-preview.md
--- sidebar_position: 2 --- # CLI 命令 Modern.js Module 项目可以使用的 CLI 命令如下: ## `modern build` ```bash Usage: modern build [options] 构建生产环境产物 Options: -w, --watch 使用监听模式构建代码 --tsconfig [tsconfig] 指定 tsconfig.json 文件的路径 (default: "./tsconfig.json") --platform [platform] 构建所有或...
7,972
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/basic/modify-output-product.md
--- sidebar_position: 3 --- # 修改输出产物 ## 默认输出产物 当你在初始化的项目里使用 `modern build` 命令的时候,Modern.js Module 会根据当前配置内容,生成相应的构建产物。 模板创建的默认配置内容如下: ```ts title="modern.config.ts" import { moduleTools, defineConfig } from '@modern-js/module-tools'; export default defineConfig({ // 注册 Modern.js Module 的 CLI 工具 plugins: [modu...
7,973
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/basic/publish-your-project.md
--- sidebar_position: 7 --- # 版本管理与发布 一个 npm 类型的模块项目发布流程包含了两个阶段: - 第一阶段是在开发期间,开发者需要提供变更文件,该文件记录了在发布期间需要的变更内容; - 第二阶段是在发布期间,Modern.js Module 会收集所有的变更文件来更新版本、更新发布日志,并发布新的包到 [npm Registry](https://www.npmjs.com/) 上。 ## 跟踪变更 **当项目发生变化的时候需要将变化的内容记录下来**。项目发生的变化一般是指: - 新功能 - 修复问题 - 配置文件修改 - ... 当这些任务一旦开发完成后,需要通过以下命令来对当...
7,974
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/basic/test-your-project.mdx
--- sidebar_position: 6 --- # 测试项目 本章将要介绍如何测试可复用模块。 ## 先决条件和约定 想要使用项目的测试功能,需要确保项目中包含依赖:`"@modern-js/plugin-testing"`,以及按照类似下面的内容进行配置: ```ts import { moduleTools, defineConfig } from '@modern-js/module-tools'; import { testingPlugin } from '@modern-js/plugin-testing'; export default defineConfig({ plugins: [ ...
7,975
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/basic/use-micro-generator.md
--- sidebar_position: 4 --- # 使用微生成器 Modern.js Module 提供了微生成器工具,它可以为当前项目: - 新增目录和文件 - 修改 `package.json` - 执行命令 因此通过这些能力,**微生成器可以为项目开启额外的特性功能**。 可以通过 [`modern new`](/guide/basic/command-preview) 启动微生成器。目前 Modern.js Module 支持的微生成器功能有: ## 开发模块文档 当我们想要为模块编写文档的时候,可以启用模块文档功能。**会在项目目录下创建 `docs` 目录以及相关文件,在 package.json ...
7,976
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/basic/use-module-doc.mdx
--- sidebar_position: 5 --- # 开发模块文档 本章介绍如何为模块项目快速搭建一个静态文档站点。 ## 开始之前 ### 为什么我们需要为模块搭建一个文档站点 1. 文档站点可以帮助我们更好地组织文档的结构。 2. 文档站点具有更好的表现形式,例如可以在页面中执行函数,渲染组件等。 3. 可以更好地利用 AI 搜索的能力。 ### 前置准备 1. 通过[微生成器](/guide/basic/use-micro-generator)开启文档功能。 2. 阅读[Rspress 介绍](https://rspress.dev/zh/guide/start/introduction.html)。 完...
7,977
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/basic/using-storybook.mdx
--- sidebar_position: 5 --- # 使用 Storybook [Storybook](https://storybook.js.org/) 是一个专门用于组件调试的工具,它围绕着组件开发提供了: - 丰富多样的调试能力 - 可与一些测试工具结合使用 - 可重复使用的文档内容 - 可分享能力 - 工作流程自动化 在使用 Storybook 时,难免会遇到各种配置问题,需要手动配置 Babel 插件,手动配置 Webpack 去支持 less,sass 等。 Modern.js 集成了 Storybook,这对于我们开发 Storybook 项目来说极大地简化了配置工作。 ## V7 (推荐) ###...
7,978
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/best-practices/_category_.json
{ "label": "最佳实践", "sidebar_position": 4 }
7,979
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/best-practices/components.mdx
--- sidebar_position: 1 --- # 开发组件 本章将要介绍如何使用 Modern.js Module 开发组件项目。 ## 初始化项目 1. 推荐使用 `@modern-js/create` 命令来初始化一个 npm 项目。 ```text title="交互式问题" npx @modern-js/create@latest components-project ? 请选择你想创建的工程类型:Npm 模块 ? 请填写项目名称:components-demo ? 请选择开发语言:TS ? 请选择包管理工具:pnpm ``` 2. 初始化的目录结构如下: ```bash . ├── README....
7,980
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/best-practices/use-tailwindcss.mdx
--- sidebar_position: 2 --- # 使用 Tailwind CSS [Tailwind CSS](https://tailwindcss.com/) 是一个以 Utility Class 为基础的 CSS 框架和设计系统,可以快速地为组件添加常用样式,同时支持主题样式的灵活扩展。 Modern.js Module 支持使用 Tailwind CSS 开发组件样式。 ## 启用 Tailwind CSS 在 Modern.js Module 中使用 [Tailwind CSS](https://tailwindcss.com/),你只需要按照以下步骤操作: 1. 在项目根目录下执行 `pnpm ru...
7,981
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/faq/_category_.json
{ "label": "常见问题", "sidebar_position": 5 }
7,982
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/faq/build.mdx
# 构建相关问题 ## 产物问题 import BuildProductFAQ from '@site-docs/components/faq-build-product'; <BuildProductFAQ /> ### Class Fields 的初始化处理 TypeSript 提供了 `useDefineForClassFields` 配置用于控制对于 `public class fields` 的转换处理。 如果有一段代码: ```ts class C { foo = 100; bar: string; } ``` 当 `useDefineForClassFields` 为 `false` 的时候,则...
7,983
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/faq/index.md
# 常见问题 这里是 Modern.js Module 常见问题分类列表: - [代码构建相关的问题](./build.mdx) - [测试相关的问题](./test.mdx) - [Storybook 相关的问题](./storybook.mdx)
7,984
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/faq/storybook.mdx
# Storybook 相关问题 import BuildStorybookFAQ from '@site-docs/components/faq-storybook'; <BuildStorybookFAQ /> ## 支持 Storybook v7 Storybook v7 目前已全面支持并已成为我们的推荐使用版本。 ## 使用 Storybook Addon 或者其他配置不生效 Modern.js Module 目前使用的 Storybook 版本是 v6,如果使用了 v7 版本的 Addon 可能会出现插件不生效的情况。 除了 Addon 以外,其他配置也可能会有区别。比如修改 `preview.js` 配置文...
7,985
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/faq/test.mdx
# 测试相关问题 import TestFAQ from '@site-docs/components/faq-test'; <TestFAQ /> ## 执行 `test` 命令报错 `TypeError: Cannot read property 'testEnvironmentOptions' of undefined` ![jest-error](https://lf3-static.bytednsdoc.com/obj/eden-cn/shylnyhaeh7uldvivhn/jest-error-testEnvironmentOptions-of-undefined.jpeg) 问题原因多是存在多个版本的 `je...
7,986
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/intro/_category_.json
{ "label": "介绍", "sidebar_position": 1 }
7,987
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/intro/getting-started.mdx
--- sidebar_position: 3 --- # 快速开始 ## 三分钟快速上手 想要实际体验 Modern.js Module?首先你需要安装 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **14.18.0**。我们推荐使用 Node.js 18 的 LTS 版本。 ### 创建新项目 **如果你想要创建一个完整的 Modern.js Module 项目,可以执行以下命令:** ```bash npx @modern-js/create your-project-dir-name ``` :::info 执行 `npx @...
7,988
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/intro/welcome.md
--- sidebar_position: 1 --- # 欢迎使用 Modern.js Module 是 Modern.js 的模块工程解决方案,同时也是核心依赖。它可以让开发者更轻松地构建、调试、发布模块类型的项目。模块类型的项目大多数情况可以认为是 npm 包类型的项目,它可能是一个组件、组件库或者工具库项目。 如果你正打算开发一个 npm 包类型的项目,那么你就来对地方了!Modern.js 提供了专业的模块工程解决方案。它带来了: - **简单的项目初始化**:仅需执行 `npx @modern-js/create project-dir` 命令,然后进行几个交互问题,就可以创建一个完整的模块类型项目。创建的项目还...
7,989
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/guide/intro/why-module-engineering-solution.md
--- sidebar_position: 2 --- # 为什么需要 Modern.js Module 大家可能都经历过:从零开始开发一个组件库或者工具库的过程中,我们不仅要考虑项目本身的代码逻辑如何编写,还要考虑项目的构建、调试、测试、代码格式化等等和代码逻辑无关的事情。 比如说,当我们考虑构建模块项目的代码是使用什么构建工具的时候,在之前我们可能会考虑使用 [webpack](https://webpack.js.org/) 还是 [Rollup](https://rollupjs.org/guide/en/),然而现在的话,也许还会考虑是使用 [esbuild](https://esbuild.github.io/) ...
7,990
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins/guide/_category_.json
{ "label": "指南", "sidebar_position": 1 }
7,991
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins/guide/getting-started.mdx
--- sidebar_position: 1 --- # 快速开始 Modern.js Module 不仅提供了丰富的功能,同时也支持通过插件的方式为当前项目扩展能力。 我们可以通过下面的例子来快速了解如何编写一个 Modern.js Module 插件: 1. 首先我们在初始化的项目下创建 `./plugins/example.ts` 文件。 ```md title="./project" ./ ├── plugins │ └── example.ts ├── src/ └── modern.config.ts ``` 2. 接着在 `example.ts` 文件中增加插件的代码。 ```ts import typ...
7,992
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins/guide/plugin-object.mdx
--- sidebar_position: 2 --- # 插件对象 Modern.js Module 的插件是一个对象,对象包含以下属性: - `name`:插件的名称,唯一标识符。 - `setup`:插件初始化函数,只会执行一次。setup 函数可以返回一个 Hooks 对象,Modern.js Module 会在特定的时机执行 Hooks 对象上定义的 Hook 对应的函数。 例如在下面的插件代码示例中,在项目开始执行构建任务之前会触发 `beforeBuild` 函数的执行,并打印 `build start` 的 log 内容。 ```ts title="./plugins/demo.tsx" import ty...
7,993
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins/guide/setup-function.mdx
--- sidebar_position: 3 --- # Setup 函数 在[「插件对象」](/plugins/guide/plugin-object) 部分我们知道插件对象包含了一个 `setup` 函数,该函数不仅包含了一个 `api` 对象参数,同时还可以返回一个 Hooks 对象。 ## 插件 API 对象 插件的 `setup` 函数会提供一个 `api` 对象参数,你可以调用该对象上提供的一些方法来获取到配置、项目上下文等信息。 ```ts export const myPlugin = (): CliPlugin<ModuleTools> => ({ name: 'my-plugin', set...
7,994
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins/official-list/_category_.json
{ "label": "插件列表", "sidebar_position": 2 }
7,995
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins/official-list/overview.md
# 总览 ## 官方插件 - [@modern-js/plugin-module-import](./plugin-import.md):使用 SWC 提供与 `babel-plugin-import` 一样的能力。 - [@modern-js/plugin-module-banner](./plugin-banner.md):为每个 JS 和 CSS 文件的顶部和底部添加自定义内容,例如版权信息。 - [@modern-js/plugin-module-node-polyfill](./plugin-node-polyfill.mdx):会自动注入 Node 核心模块在浏览器端的 polyfills。 - [@modern-j...
7,996
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins/official-list/plugin-babel.mdx
# Babel 插件 :::tip 通常情况下,我们无需使用 Babel 转换我们的代码,此插件仅作为一种降级方式。 ::: ## 快速开始 ### 安装 import { PackageManagerTabs } from '@theme'; <PackageManagerTabs command="add @modern-js/plugin-module-babel -D" /> ### 注册插件 在 Modern.js Module 中,你可以按照如下方式注册插件: ```ts import { moduleTools, defineConfig } from '@modern-js/module-tools'...
7,997
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins/official-list/plugin-banner.mdx
# Banner 插件 提供为每个 JS 和 CSS 文件的顶部和底部注入内容的能力。 :::tip 从 `@modern-js/module-tools` MAJOR_VERSION.36.0 版本开始,该插件功能内置在 Modern.js Module 中,由 [`banner`](/api/config/build-config#banner) 和 [`footer`](/api/config/build-config#footer) 配置提供。 ::: ## 快速开始 ### 安装 import { PackageManagerTabs } from '@theme'; <PackageManagerTabs c...
7,998
0
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins
petrpan-code/web-infra-dev/modern.js/packages/document/module-doc/docs/zh/plugins/official-list/plugin-import.mdx
# Import 插件 提供与 [babel-plugin-import](https://github.com/umijs/babel-plugin-import) 等价的能力和配置,基于 [SWC](https://swc.rs/) 实现。 :::tip 从 `@modern-js/module-tools` MAJOR_VERSION.16.0 版本开始,该插件功能内置在 Modern.js Module 中,由 [`transformImport`](api/config/build-config.html#transformimport) 配置提供。 ::: ## 快速开始 ### 安装 import { Pac...
7,999