diff --git a/packages/duoyun-ui/README.md b/packages/duoyun-ui/README.md index f574da66..e63da7a7 100644 --- a/packages/duoyun-ui/README.md +++ b/packages/duoyun-ui/README.md @@ -10,5 +10,5 @@ pnpm test # build watch pnpm start # development, view example and api -pnpm docs +pnpm run docs ``` diff --git a/packages/gem-book/package.json b/packages/gem-book/package.json index 08611db9..24030baf 100644 --- a/packages/gem-book/package.json +++ b/packages/gem-book/package.json @@ -31,9 +31,9 @@ "build:cli": "esbuild ./src/bin/index.ts --tsconfig=./tsconfig.cli.json --outdir=./bin --platform=node --sourcemap --bundle --external:anymatch --external:cheerio --external:chokidar --external:jimp --external:marked --external:yaml --external:front-matter --external:commander --external:webpack --external:ts-loader --external:typescript --external:webpack-dev-server --external:html-webpack-plugin --external:copy-webpack-plugin --external:workbox-webpack-plugin", "start:cli": "pnpm build:cli --watch", "docs": "node ./bin docs", - "start:docs": "cross-env GEM_BOOK_DEV=true nodemon --watch bin --exec \"pnpm docs\"", + "start:docs": "cross-env GEM_BOOK_DEV=true nodemon --watch bin --exec \"pnpm run docs\"", "start": "concurrently npm:start:cli npm:start:docs", - "build:website": "pnpm build:cli && pnpm docs --build --ga G-7X2Z4B2KV0", + "build:website": "pnpm build:cli && pnpm run docs --build --ga G-7X2Z4B2KV0", "build": "pnpm build:cli && tsc -p ./tsconfig.build.json", "test": "cross-env NODE_OPTIONS=--no-experimental-fetch wtr", "prepublishOnly": "pnpm build" diff --git a/packages/gem-book/src/bin/builder.ts b/packages/gem-book/src/bin/builder.ts index 6b43101e..1df24f52 100644 --- a/packages/gem-book/src/bin/builder.ts +++ b/packages/gem-book/src/bin/builder.ts @@ -184,13 +184,22 @@ export async function buildApp(dir: string, options: Required, }), { apply(compiler: Compiler) { - options.fallbackLanguage && - compiler.hooks.compilation.tap('htmlWebpackInjectAttributesPlugin', (compilation) => { - HtmlWebpackPlugin.getHooks(compilation).afterTemplateExecution.tapAsync('MyPlugin', (data, cb) => { + compiler.hooks.compilation.tap('htmlWebpackInjectAttributesPlugin', (compilation) => { + HtmlWebpackPlugin.getHooks(compilation).afterTemplateExecution.tapAsync('MyPlugin', (data, cb) => { + if (options.fallbackLanguage) { data.html = data.html.replace('', ``); - cb(null, data); - }); + } + // 参数有 _html_ 时直接渲染 _html_ + data.html = + `` + data.html; + cb(null, data); }); + }); }, }, new DefinePlugin({ diff --git a/packages/gem-book/src/plugins/sandpack.ts b/packages/gem-book/src/plugins/sandpack.ts index 659af42f..392b6852 100644 --- a/packages/gem-book/src/plugins/sandpack.ts +++ b/packages/gem-book/src/plugins/sandpack.ts @@ -357,8 +357,13 @@ class _GbpSandpackElement extends GemBookPluginElement { .join('')} `; - URL.revokeObjectURL(iframe.src); - iframe.src = URL.createObjectURL(new Blob([htmlCode], { type: 'text/html' })); + if (document.head?.firstElementChild?.textContent?.includes('_html_')) { + const url = new URL(`./?${new URLSearchParams({ _html_: encodeURIComponent(htmlCode) })}`, location.href); + iframe.src = url.href; + } else { + URL.revokeObjectURL(iframe.src); + iframe.src = URL.createObjectURL(new Blob([htmlCode], { type: 'text/html' })); + } }; compile(); this.#state({ status: 'done' }); diff --git a/packages/gem-devtools/scripts/update.js b/packages/gem-devtools/scripts/update.js index 2efbd40e..2ebc57fd 100644 --- a/packages/gem-devtools/scripts/update.js +++ b/packages/gem-devtools/scripts/update.js @@ -1,3 +1,3 @@ -const pkg = require('../public/manifest.json'); +const pkg = require('../src/manifest.json'); pkg.version = require('../package.json').version; -require('fs').writeFileSync('./public/manifest.json', JSON.stringify(pkg, null, 2)); +require('fs').writeFileSync('./src/manifest.json', JSON.stringify(pkg, null, 2)); diff --git a/packages/gem/package.json b/packages/gem/package.json index 4fd68956..92ab3269 100644 --- a/packages/gem/package.json +++ b/packages/gem/package.json @@ -31,8 +31,8 @@ "typings": "index.d.ts", "scripts": { "docs": "GEM_BOOK_REPLACE=true gem-book docs", - "docs:remote": "pnpm docs", - "build:docs": "pnpm docs --build", + "docs:remote": "pnpm run docs", + "build:docs": "pnpm run docs --build", "build:module": "tsc -p tsconfig.build.json", "build:lib": "vite build", "build": "pnpm build:module && pnpm build:lib",