Skip to content

Commit

Permalink
docs: 修复 DEMO 插件
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidKk committed Oct 23, 2023
1 parent 362a81d commit 28d7635
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.workflow.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build.workflow
name: build

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.workflow.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: gh-pages.workflow
name: gh-pages

on: [workflow_dispatch]

Expand Down
3 changes: 1 addition & 2 deletions @dumi-plugin/dumi-plugin-node-stackblitz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"dependencies": {
"tslib": "^2.5.0",
"@dumlj/stackblitz-webpack-plugin": "^0.0.1",
"@dumlj/dumi-plugin-seed": "^0.0.1",
"lodash": "^4.17.21"
"@dumlj/dumi-plugin-seed": "^0.0.1"
},
"devDependencies": {
"@jest/types": "^29.6.3",
Expand Down
9 changes: 1 addition & 8 deletions @dumi-plugin/dumi-plugin-node-stackblitz/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { trimEnd } from 'lodash'
import { createDumiPlugin } from '@dumlj/dumi-plugin-seed'
import { StackblitzWebpackPlugin, type StackblitzWebpackPluginOptions } from '@dumlj/stackblitz-webpack-plugin'

Expand All @@ -24,11 +23,5 @@ export default createDumiPlugin<NodeStackblitzOptions>('nodeStackblitz', async (
},
})

pushWebpackPlugin(
StackblitzWebpackPlugin.PLUGIN_NAME,
new StackblitzWebpackPlugin({
...nodeStackblitz,
manifest: `${trimEnd(publicPath, '/')}/stackblitz-assets.json`,
})
)
pushWebpackPlugin(StackblitzWebpackPlugin.PLUGIN_NAME, new StackblitzWebpackPlugin({ ...nodeStackblitz, publicPath }))
})
3 changes: 2 additions & 1 deletion @webpack-plugin/stackblitz-webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"glob": "^10.3.4",
"tslib": "^2.5.0",
"jszip": "^3.10.1",
"utility-types": "^3.10.0"
"utility-types": "^3.10.0",
"lodash": "^4.17.21"
},
"devDependencies": {
"@jest/types": "^29.6.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { trimEnd, trimStart } from 'lodash'
import { SeedWebpackPlugin, type SeedWebpackPluginOptions } from '@dumlj/seed-webpack-plugin'
import { yarnWorkspaces, type ProjectInWorkspaces } from '@dumlj/shell-lib'
import fs from 'fs-extra'
Expand All @@ -12,6 +13,7 @@ export interface Project extends ProjectInWorkspaces {
}

export interface StackblitzWebpackPluginOptions extends SeedWebpackPluginOptions {
publicPath?: string
manifest?: string
ignored?: string[]
files?: string[]
Expand All @@ -20,13 +22,15 @@ export interface StackblitzWebpackPluginOptions extends SeedWebpackPluginOptions
export class StackblitzWebpackPlugin extends SeedWebpackPlugin {
static PLUGIN_NAME = 'stackblitz-webpack-plugin'

protected publicPath: string
protected manifest: string
protected ignored: string[]
protected files: string[]

constructor(options?: StackblitzWebpackPluginOptions) {
super(options)

this.publicPath = options?.publicPath
this.manifest = options?.manifest || '/stackblitz-assets.json'
this.ignored = [].concat(options?.ignored || [], [
'**/node_modules/**',
Expand Down Expand Up @@ -195,9 +199,14 @@ export class StackblitzWebpackPlugin extends SeedWebpackPlugin {
}

public applyScript(compiler: Compiler) {
const { context, webpack } = compiler
const { context, webpack, options } = compiler
const { output } = options || {}

const publicPath = this.publicPath || (typeof output.publicPath === 'string' ? output.publicPath : '/')
const finalPublicPath = trimEnd(publicPath, '/') + '/' + trimStart(this.manifest, '/')

const plugins = [
new webpack.DefinePlugin({ __STACKBLITZ_MANIFEST__: JSON.stringify(this.manifest) }),
new webpack.DefinePlugin({ __STACKBLITZ_MANIFEST__: JSON.stringify(finalPublicPath) }),
new webpack.EntryPlugin(context, path.join(__dirname, 'client'), {
filename: 'dumlj.stackblitz-webpack-plugin.js',
}),
Expand Down

0 comments on commit 28d7635

Please sign in to comment.