From 167729e294210c0ac2f3ca305ba68665381fcc47 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Wed, 11 May 2022 15:24:07 +0800 Subject: [PATCH] feat: Add mdCodeModulesLoader options. --- core/README-zh.md | 13 +++++++++++++ core/README.md | 13 +++++++++++++ core/src/utils/index.ts | 17 +++++++++++------ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/core/README-zh.md b/core/README-zh.md index cc48b8f..36724c8 100644 --- a/core/README-zh.md +++ b/core/README-zh.md @@ -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 中配置使用方法是一致的。 diff --git a/core/README.md b/core/README.md index b64080a..b9e223d 100644 --- a/core/README.md +++ b/core/README.md @@ -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. diff --git a/core/src/utils/index.ts b/core/src/utils/index.ts index 5749664..7002b9f 100644 --- a/core/src/utils/index.ts +++ b/core/src/utils/index.ts @@ -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) { @@ -105,7 +110,7 @@ export const mdCodeModulesLoader = (config: webpack.Configuration, lang?: string use: [ { loader: 'markdown-react-code-preview-loader', - options: { lang }, + options: { lang, ...option }, }, ], });