Skip to content

Commit 3b89677

Browse files
committed
fix(build): bring back BUILD_MODE now that the dust is settling
1 parent 48fb28a commit 3b89677

File tree

4 files changed

+78
-59
lines changed

4 files changed

+78
-59
lines changed

.eslintignore

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
node_modules/*
2-
dist/*
3-
test/*
4-
src/examples/*
1+
/node_modules/
2+
/build/
3+
/dist/
4+
/test/
5+
/src/examples/

package-lock.json

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
},
1212
"main": "./dist/scratch-gui.js",
1313
"scripts": {
14-
"build": "npm run clean && mkdirp dist && webpack",
15-
"clean": "rimraf ./dist",
16-
"deploy": "touch build/.nojekyll && gh-pages -t -d dist -m \"[skip ci] Build for $(git log --pretty=format:%H -n1)\"",
14+
"build": "npm run clean && webpack",
15+
"clean": "rimraf ./build ./dist",
16+
"deploy": "touch build/.nojekyll && gh-pages -t -d build -m \"[skip ci] Build for $(git log --pretty=format:%H -n1)\"",
1717
"prepublish": "node scripts/prepublish.mjs",
1818
"prune": "./prune-gh-pages.sh",
1919
"i18n:push": "tx-push-src scratch-editor interface translations/en.json",
@@ -130,7 +130,6 @@
130130
"husky": "8.0.3",
131131
"jest": "21.2.1",
132132
"jest-junit": "7.0.0",
133-
"mkdirp": "1.0.4",
134133
"raf": "3.4.1",
135134
"react-test-renderer": "16.14.0",
136135
"redux-mock-store": "1.5.4",

webpack.config.js

+70-50
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,20 @@ const ScratchWebpackConfigBuilder = require('scratch-webpack-configuration');
1414

1515
// const STATIC_PATH = process.env.STATIC_PATH || '/static';
1616

17-
const configBuilder = new ScratchWebpackConfigBuilder(
17+
const baseConfig = new ScratchWebpackConfigBuilder(
1818
{
1919
rootPath: path.resolve(__dirname),
2020
enableReact: true
2121
})
2222
.setTarget('browserslist')
2323
.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-
},
4224
output: {
4325
assetModuleFilename: 'static/assets/[name].[hash][ext][query]',
4426
chunkFilename: 'chunks/[name].js',
4527
library: {
4628
name: 'GUI',
4729
type: 'umd2'
48-
},
49-
// publicPath: `${STATIC_PATH}/`,
50-
path: path.resolve(__dirname, 'dist')
30+
}
5131
},
5232
resolve: {
5333
fallback: {
@@ -137,6 +117,66 @@ const configBuilder = new ScratchWebpackConfigBuilder(
137117
'process.env.GTM_ENV_AUTH': `"${process.env.GTM_ENV_AUTH || ''}"`,
138118
'process.env.GTM_ID': process.env.GTM_ID ? `"${process.env.GTM_ID}"` : null
139119
}))
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+
})
140180
.addPlugin(new HtmlWebpackPlugin({
141181
chunks: ['gui'],
142182
template: 'src/playground/index.ejs',
@@ -170,36 +210,16 @@ const configBuilder = new ScratchWebpackConfigBuilder(
170210
from: 'extensions/**',
171211
to: 'static',
172212
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
197213
}
198214
]
199215
}));
200216

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';
204222

205-
module.exports = configBuilder.get();
223+
module.exports = buildDist ?
224+
[buildConfig.get(), distConfig.get()] :
225+
buildConfig.get();

0 commit comments

Comments
 (0)