@@ -14,40 +14,20 @@ const ScratchWebpackConfigBuilder = require('scratch-webpack-configuration');
14
14
15
15
// const STATIC_PATH = process.env.STATIC_PATH || '/static';
16
16
17
- const configBuilder = new ScratchWebpackConfigBuilder (
17
+ const baseConfig = new ScratchWebpackConfigBuilder (
18
18
{
19
19
rootPath : path . resolve ( __dirname ) ,
20
20
enableReact : true
21
21
} )
22
22
. setTarget ( 'browserslist' )
23
23
. merge ( {
24
- devServer : {
25
- client : {
26
- progress : true
27
- } ,
28
- hot : true ,
29
- port : process . env . PORT || 8602
30
- } ,
31
- entry : {
32
- // GUI as a library
33
- 'scratch-gui' : path . join ( __dirname , 'src/index.js' ) ,
34
-
35
- // to run editor examples
36
- 'lib.min' : [ 'react' , 'react-dom' ] ,
37
- 'gui' : './src/playground/index.jsx' ,
38
- 'blocksonly' : './src/playground/blocks-only.jsx' ,
39
- 'compatibilitytesting' : './src/playground/compatibility-testing.jsx' ,
40
- 'player' : './src/playground/player.jsx'
41
- } ,
42
24
output : {
43
25
assetModuleFilename : 'static/assets/[name].[hash][ext][query]' ,
44
26
chunkFilename : 'chunks/[name].js' ,
45
27
library : {
46
28
name : 'GUI' ,
47
29
type : 'umd2'
48
- } ,
49
- // publicPath: `${STATIC_PATH}/`,
50
- path : path . resolve ( __dirname , 'dist' )
30
+ }
51
31
} ,
52
32
resolve : {
53
33
fallback : {
@@ -137,6 +117,66 @@ const configBuilder = new ScratchWebpackConfigBuilder(
137
117
'process.env.GTM_ENV_AUTH' : `"${ process . env . GTM_ENV_AUTH || '' } "` ,
138
118
'process.env.GTM_ID' : process . env . GTM_ID ? `"${ process . env . GTM_ID } "` : null
139
119
} ) )
120
+ . addPlugin ( new CopyWebpackPlugin ( {
121
+ patterns : [
122
+ {
123
+ from : 'node_modules/scratch-blocks/media' ,
124
+ to : 'static/blocks-media/default'
125
+ } ,
126
+ {
127
+ from : 'node_modules/scratch-blocks/media' ,
128
+ to : 'static/blocks-media/high-contrast'
129
+ } ,
130
+ {
131
+ // overwrite some of the default block media with high-contrast versions
132
+ // this entry must come after copying scratch-blocks/media into the high-contrast directory
133
+ from : 'src/lib/themes/high-contrast/blocks-media' ,
134
+ to : 'static/blocks-media/high-contrast' ,
135
+ force : true
136
+ } ,
137
+ {
138
+ context : 'node_modules/scratch-vm/dist/web' ,
139
+ from : 'extension-worker.{js,js.map}' ,
140
+ noErrorOnMissing : true
141
+ }
142
+ ]
143
+ } ) ) ;
144
+
145
+ if ( ! process . env . CI ) {
146
+ baseConfig . addPlugin ( new webpack . ProgressPlugin ( ) ) ;
147
+ }
148
+
149
+ // build the shipping library in `dist/`
150
+ const distConfig = baseConfig . clone ( )
151
+ . merge ( {
152
+ entry : {
153
+ 'scratch-gui' : path . join ( __dirname , 'src/index.js' )
154
+ } ,
155
+ output : {
156
+ path : path . resolve ( __dirname , 'dist' )
157
+ }
158
+ } ) ;
159
+
160
+ // build the examples and debugging tools in `build/`
161
+ const buildConfig = baseConfig . clone ( )
162
+ . merge ( {
163
+ devServer : {
164
+ client : {
165
+ progress : true
166
+ } ,
167
+ hot : true ,
168
+ port : process . env . PORT || 8602
169
+ } ,
170
+ entry : {
171
+ gui : './src/playground/index.jsx' ,
172
+ blocksonly : './src/playground/blocks-only.jsx' ,
173
+ compatibilitytesting : './src/playground/compatibility-testing.jsx' ,
174
+ player : './src/playground/player.jsx'
175
+ } ,
176
+ output : {
177
+ path : path . resolve ( __dirname , 'build' )
178
+ }
179
+ } )
140
180
. addPlugin ( new HtmlWebpackPlugin ( {
141
181
chunks : [ 'gui' ] ,
142
182
template : 'src/playground/index.ejs' ,
@@ -170,36 +210,16 @@ const configBuilder = new ScratchWebpackConfigBuilder(
170
210
from : 'extensions/**' ,
171
211
to : 'static' ,
172
212
context : 'src/examples'
173
- } ,
174
- {
175
- from : 'src/lib/themes/high-contrast/blocks-media' ,
176
- to : 'static/blocks-media/high-contrast' ,
177
- force : true
178
- } ,
179
- {
180
- // Include library JSON files for scratch-desktop to use for downloading
181
- from : 'src/lib/libraries/*.json' ,
182
- to : 'libraries' ,
183
- flatten : true
184
- } ,
185
- {
186
- from : 'node_modules/scratch-blocks/media' ,
187
- to : 'static/blocks-media/default'
188
- } ,
189
- {
190
- from : 'node_modules/scratch-blocks/media' ,
191
- to : 'static/blocks-media/high-contrast'
192
- } ,
193
- {
194
- context : 'node_modules/scratch-vm/dist/web' ,
195
- from : 'extension-worker.{js,js.map}' ,
196
- noErrorOnMissing : true
197
213
}
198
214
]
199
215
} ) ) ;
200
216
201
- if ( ! process . env . CI ) {
202
- configBuilder . addPlugin ( new webpack . ProgressPlugin ( ) ) ;
203
- }
217
+ // Skip building `dist/` unless explicitly requested
218
+ // It roughly doubles build time and isn't needed for `scratch-gui` development
219
+ // If you need non-production `dist/` for local dev, such as for `scratch-www` work, you can run something like:
220
+ // `BUILD_MODE=dist npm run build`
221
+ const buildDist = process . env . NODE_ENV === 'production' || process . env . BUILD_MODE === 'dist' ;
204
222
205
- module . exports = configBuilder . get ( ) ;
223
+ module . exports = buildDist ?
224
+ [ buildConfig . get ( ) , distConfig . get ( ) ] :
225
+ buildConfig . get ( ) ;
0 commit comments