Skip to content

Commit

Permalink
feat: Add mdCodeModulesLoader options.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed May 11, 2022
1 parent fc2adaf commit 167729e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
13 changes: 13 additions & 0 deletions core/README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ export default (conf: WebpackConfiguration, env: 'development' | 'production', o
};
```

```ts
import webpack from 'webpack';
import { Options } from 'markdown-react-code-preview-loader';
/**
* 用于修改 webpack 配置 loader 的方法
* @param {webpack.Configuration} config webpack 配置
* @param {string[]} lang 解析语言
* @param {Options} option Loader Options
* @returns {webpack.Configuration}
* **/
export declare const mdCodeModulesLoader: (config: webpack.Configuration, lang?: string[], option?: Options) => webpack.Configuration;
```

**第 ② 种方法,手动添加配置**

在 Webpack 中配置使用方法是一致的。
Expand Down
13 changes: 13 additions & 0 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ export default (conf: WebpackConfiguration, env: 'development' | 'production', o
};
```

```ts
import webpack from 'webpack';
import { Options } from 'markdown-react-code-preview-loader';
/**
* `mdCodeModulesLoader` method for adding `markdown-react-code-preview-loader` to webpack config.
* @param {webpack.Configuration} config webpack config
* @param {string[]} lang Parsing language
* @param {Options} option Loader Options
* @returns {webpack.Configuration}
* **/
export declare const mdCodeModulesLoader: (config: webpack.Configuration, lang?: string[], option?: Options) => webpack.Configuration;
```

**② The second method is to manually add the configuration**

The configuration and usage methods are consistent in Webpack.
Expand Down
17 changes: 11 additions & 6 deletions core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,17 @@ export const getCodeBlockString = (scope: string, opts: Options = {}) => {
};

/**
* 用于修改 webpack 配置 loader 的方法
* @param {webpack.Configuration} config webpack配置
* @param {string[]} lang 解析语言
* `mdCodeModulesLoader` method for adding `markdown-react-code-preview-loader` to webpack config.
* @param {webpack.Configuration} config webpack config
* @param {string[]} lang Parsing language
* @param {Options} option Loader Options
* @returns {webpack.Configuration}
* **/
export const mdCodeModulesLoader = (config: webpack.Configuration, lang?: string[]): webpack.Configuration => {
*/
export const mdCodeModulesLoader = (
config: webpack.Configuration,
lang?: string[],
option: Options = {},
): webpack.Configuration => {
config.module.rules.forEach((ruleItem) => {
if (typeof ruleItem === 'object') {
if (ruleItem.oneOf) {
Expand All @@ -105,7 +110,7 @@ export const mdCodeModulesLoader = (config: webpack.Configuration, lang?: string
use: [
{
loader: 'markdown-react-code-preview-loader',
options: { lang },
options: { lang, ...option },
},
],
});
Expand Down

0 comments on commit 167729e

Please sign in to comment.