Skip to content

Commit 167729e

Browse files
committed
feat: Add mdCodeModulesLoader options.
1 parent fc2adaf commit 167729e

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

core/README-zh.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ export default (conf: WebpackConfiguration, env: 'development' | 'production', o
3535
};
3636
```
3737

38+
```ts
39+
import webpack from 'webpack';
40+
import { Options } from 'markdown-react-code-preview-loader';
41+
/**
42+
* 用于修改 webpack 配置 loader 的方法
43+
* @param {webpack.Configuration} config webpack 配置
44+
* @param {string[]} lang 解析语言
45+
* @param {Options} option Loader Options
46+
* @returns {webpack.Configuration}
47+
* **/
48+
export declare const mdCodeModulesLoader: (config: webpack.Configuration, lang?: string[], option?: Options) => webpack.Configuration;
49+
```
50+
3851
**第 ② 种方法,手动添加配置**
3952

4053
在 Webpack 中配置使用方法是一致的。

core/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ export default (conf: WebpackConfiguration, env: 'development' | 'production', o
3535
};
3636
```
3737

38+
```ts
39+
import webpack from 'webpack';
40+
import { Options } from 'markdown-react-code-preview-loader';
41+
/**
42+
* `mdCodeModulesLoader` method for adding `markdown-react-code-preview-loader` to webpack config.
43+
* @param {webpack.Configuration} config webpack config
44+
* @param {string[]} lang Parsing language
45+
* @param {Options} option Loader Options
46+
* @returns {webpack.Configuration}
47+
* **/
48+
export declare const mdCodeModulesLoader: (config: webpack.Configuration, lang?: string[], option?: Options) => webpack.Configuration;
49+
```
50+
3851
**② The second method is to manually add the configuration**
3952

4053
The configuration and usage methods are consistent in Webpack.

core/src/utils/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,17 @@ export const getCodeBlockString = (scope: string, opts: Options = {}) => {
9191
};
9292

9393
/**
94-
* 用于修改 webpack 配置 loader 的方法
95-
* @param {webpack.Configuration} config webpack配置
96-
* @param {string[]} lang 解析语言
94+
* `mdCodeModulesLoader` method for adding `markdown-react-code-preview-loader` to webpack config.
95+
* @param {webpack.Configuration} config webpack config
96+
* @param {string[]} lang Parsing language
97+
* @param {Options} option Loader Options
9798
* @returns {webpack.Configuration}
98-
* **/
99-
export const mdCodeModulesLoader = (config: webpack.Configuration, lang?: string[]): webpack.Configuration => {
99+
*/
100+
export const mdCodeModulesLoader = (
101+
config: webpack.Configuration,
102+
lang?: string[],
103+
option: Options = {},
104+
): webpack.Configuration => {
100105
config.module.rules.forEach((ruleItem) => {
101106
if (typeof ruleItem === 'object') {
102107
if (ruleItem.oneOf) {
@@ -105,7 +110,7 @@ export const mdCodeModulesLoader = (config: webpack.Configuration, lang?: string
105110
use: [
106111
{
107112
loader: 'markdown-react-code-preview-loader',
108-
options: { lang },
113+
options: { lang, ...option },
109114
},
110115
],
111116
});

0 commit comments

Comments
 (0)