diff --git a/core/package.json b/core/package.json index 3a1f611..c6b2fa7 100644 --- a/core/package.json +++ b/core/package.json @@ -14,7 +14,7 @@ "url": "https://github.com/kktjs/markdown-react-code-preview-loader" }, "license": "MIT", - "main": "./lib/index.js", + "main": "lib/index.js", "module": "esm/index.js", "types": "lib/index.d.ts", "files": [ @@ -25,18 +25,18 @@ "esm" ], "scripts": { - "build": "tsbb build", - "watch": "tsbb watch" + "build": "tsbb build src/**/*.ts --use-babel", + "watch": "tsbb watch src/**/*.ts --use-babel" }, "dependencies": { "@babel/plugin-syntax-unicode-sets-regex": "~7.18.6", "@babel/standalone": "^7.22.2", - "babel-plugin-transform-remove-imports": "^1.7.0", - "babel-plugin-transform-replace-export-default": "^1.0.3", + "babel-plugin-transform-remove-imports": "^1.8.0", + "babel-plugin-transform-replace-export-default": "^1.0.4", "remark": "~13.0.0" }, "devDependencies": { "@types/babel__standalone": "^7.1.4", - "webpack": "^5.72.0" + "webpack": "^5.95.0" } } diff --git a/core/src/index.ts b/core/src/index.ts index 484c157..4a75ab3 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -1,8 +1,9 @@ import React from 'react'; -import { PluginItem } from '@babel/core'; -import { Options as RIOptions } from 'babel-plugin-transform-remove-imports'; -import { getProcessor, getCodeBlock, getHeadings, HeadingItem, HeadingListType } from './utils'; -import { LoaderDefinitionFunction } from 'webpack'; +import { type LoaderDefinitionFunction } from 'webpack'; +import { type PluginItem } from '@babel/core'; +import { type Options as RIOptions } from 'babel-plugin-transform-remove-imports'; +import { getProcessor, getCodeBlock, getHeadings, type HeadingItem, type HeadingListType } from './utils'; + export * from './utils'; export type CodeBlockItem = { diff --git a/core/src/utils/index.ts b/core/src/utils/index.ts index a8cde0c..63d2620 100644 --- a/core/src/utils/index.ts +++ b/core/src/utils/index.ts @@ -1,8 +1,8 @@ -import { Parent, Node } from 'unist'; +import { type Node } from 'unist'; import webpack from 'webpack'; import remark from 'remark'; import { getTransformValue } from './transform'; -import { Options, FUNNAME_PREFIX, CodeBlockItem, CodeBlockData } from '../'; +import { type Options, FUNNAME_PREFIX, CodeBlockItem, CodeBlockData } from '../'; /** * Creates an object containing the parameters of the current URL. @@ -32,11 +32,12 @@ export interface MarkdownDataChild extends Node { children?: Array; } -export interface MarkdownParseData extends Parent {} +export interface MarkdownParseData extends MarkdownDataChild {} /** 转换 代码*/ export const getProcessor = (source: string) => { try { + // @ts-ignore const child = remark.parse(source) as MarkdownParseData; return child.children; } catch (err) { diff --git a/package.json b/package.json index 033896a..37005e0 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "⬆️⬆️⬆️⬆️⬆️ package ⬆️⬆️⬆️⬆️⬆️": "▲▲▲▲▲ package ▲▲▲▲▲", "test": "tsbb test", "coverage": "tsbb test --coverage --bail", - "prepare": "husky install", + "prepare": "husky", "version": "lerna version --exact --force-publish --no-push --no-git-tag-version", "prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'", "remove": "npm run clean && lerna exec \"rm -rf package-lock.json\" --scope markdown-react-code-preview-loader --scope website", @@ -45,4 +45,4 @@ "pretty-quick": "~4.0.0", "tsbb": "^4.4.0" } -} \ No newline at end of file +} diff --git a/website/.kktrc.ts b/website/.kktrc.ts index 55de723..f742bcc 100644 --- a/website/.kktrc.ts +++ b/website/.kktrc.ts @@ -5,7 +5,7 @@ import rawModules from '@kkt/raw-modules'; import scopePluginOptions from '@kkt/scope-plugin-options'; import { LoaderConfOptions, WebpackConfiguration } from 'kkt'; import pkg from './package.json'; -import { mdCodeModulesLoader } from 'markdown-react-code-preview-loader'; +// import { mdCodeModulesLoader } from 'markdown-react-code-preview-loader'; export default (conf: WebpackConfiguration, env: 'development' | 'production', options: LoaderConfOptions) => { conf = lessModules(conf, env, options); @@ -19,8 +19,28 @@ export default (conf: WebpackConfiguration, env: 'development' | 'production', o VERSION: JSON.stringify(pkg.version), }), ); - conf = mdCodeModulesLoader(conf); + + if (Array.isArray(conf.module?.rules)) { + conf.module?.rules.forEach((ruleItem) => { + if (typeof ruleItem === 'object' && ruleItem !== null) { + if (ruleItem.oneOf) { + ruleItem.oneOf.unshift({ + test: /.md$/, + use: [ + { + loader: 'markdown-react-code-preview-loader', + options: {}, + }, + ], + }); + } + } + }); + } + conf.module!.exprContextCritical = false; + /** https://github.com/kktjs/kkt/issues/446 */ + conf.ignoreWarnings = [{ module: /node_modules[\\/]parse5[\\/]/ }]; if (process.env.NODE_ENV === 'production') { conf.output = { ...conf.output, publicPath: './' };