File tree Expand file tree Collapse file tree 8 files changed +64
-29
lines changed Expand file tree Collapse file tree 8 files changed +64
-29
lines changed Original file line number Diff line number Diff line change 4
4
< meta charset ="UTF-8 ">
5
5
< meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
6
< title > Document</ title >
7
- < script src ="https://cdn.jsdelivr.net/npm/eruda "> </ script >
8
- < script > eruda . init ( ) ; </ script >
7
+ <!--< script src="https://cdn.jsdelivr.net/npm/eruda"></script>
8
+ <script>eruda.init();</script>-->
9
9
</ head >
10
10
< body >
11
11
< script src ="/playground/main.jsx " type ="module "> </ script >
Original file line number Diff line number Diff line change 170
170
}
171
171
},
172
172
"patchedDependencies" : {
173
- "@scratch/paper@0.11.0" : " patches/@scratch%2Fpaper@0.11.0.patch" ,
174
- "scratch-paint@3.0.20" : " patches/scratch-paint@3.0.20.patch" ,
175
- "parse-color@1.0.0" : " patches/parse-color@1.0.0.patch"
173
+ "scratch-paint@3.0.20" : " patches/scratch-paint@3.0.20.patch"
176
174
}
177
175
}
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import type { Plugin } from 'vite'
2
+ import * as esbuild from 'esbuild'
3
+ import * as path from 'node:path'
4
+
5
+ const CJS_PATCHES = [
6
+ '@scratch/paper' ,
7
+ 'parse-color' ,
8
+ 'react-popover'
9
+ ]
10
+
11
+ const cached = new Map < string , string > ( )
12
+ const getBuild = async ( id : string ) => {
13
+ if ( cached . has ( id ) ) {
14
+ return cached . get ( id )
15
+ }
16
+ const result = await esbuild . build ( {
17
+ entryPoints : [ id ] ,
18
+ format : 'esm' ,
19
+ platform : 'browser' ,
20
+ target : 'esnext' ,
21
+ bundle : true ,
22
+ write : false ,
23
+ logLevel : 'error' ,
24
+ } )
25
+ const code = result . outputFiles ?. [ 0 ] . text
26
+ if ( ! code ) {
27
+ throw result . errors [ 0 ]
28
+ }
29
+ cached . set ( id , code )
30
+ return code
31
+ }
32
+
33
+ export const cjsPlugin = ( ) : Plugin => {
34
+ return {
35
+ name : 'vite-plugin-cjs' ,
36
+ async load ( id , options ) {
37
+ let isPatch = false
38
+ for ( const patch of CJS_PATCHES ) {
39
+ if ( id . includes ( `node_modules/${ patch } ` ) ) {
40
+ isPatch = true
41
+ break
42
+ }
43
+ }
44
+ if ( ! isPatch ) {
45
+ return
46
+ }
47
+ const code = await getBuild ( id )
48
+ if ( ! code ) {
49
+ return
50
+ }
51
+ console . log ( 'patched' , id )
52
+ return {
53
+ code
54
+ }
55
+ } ,
56
+ }
57
+ }
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
2
2
import React from 'react' ;
3
3
import bindAll from 'lodash.bindall' ;
4
4
import VM from 'scratch-vm' ;
5
- // import PaintEditor from 'scratch-paint';
5
+ import PaintEditor from 'scratch-paint' ;
6
6
import { inlineSvgFonts } from 'scratch-svg-renderer' ;
7
7
8
8
import { connect } from 'react-redux' ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import * as path from 'node:path'
4
4
import * as fs from 'node:fs/promises'
5
5
import * as url from 'node:url'
6
6
import { existsSync } from 'node:fs'
7
+ import { cjsPlugin } from './plugins/cjs.ts'
7
8
8
9
const scratchGuiPlugin = ( ) : Plugin => {
9
10
let resolvedConfig ! : ResolvedConfig
@@ -120,9 +121,11 @@ const allModuleCSSPlugin = (): Plugin => {
120
121
}*/
121
122
}
122
123
}
124
+
123
125
export default defineConfig ( {
124
126
plugins : [
125
127
allModuleCSSPlugin ( ) ,
128
+ cjsPlugin ( ) ,
126
129
reactVirtualized ( ) ,
127
130
scratchGuiPlugin ( )
128
131
] ,
You can’t perform that action at this time.
0 commit comments