Skip to content

Commit

Permalink
docs(module-tools): add tip how to use hook to register module plugin (
Browse files Browse the repository at this point in the history
  • Loading branch information
10Derozan authored Oct 10, 2023
1 parent 5c89910 commit 2e6bcac
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ export default defineConfig({
});
```

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:

```ts
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](https://babeljs.io/docs/options).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ export default defineConfig({
});
```

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:

```ts
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**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ export default defineConfig({
});
```

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

```ts
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](https://babeljs.io/docs/options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ export default defineConfig({
});
```

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

```ts
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',
},
],
});
```

## 配置

- **类型:**
Expand Down

0 comments on commit 2e6bcac

Please sign in to comment.