fix(build): bring back BUILD_MODE now that the dust is settling

This commit is contained in:
Christopher Willis-Ford 2024-03-14 14:58:00 -07:00
parent 48fb28a685
commit 3b8967756c
4 changed files with 78 additions and 59 deletions

View File

@ -1,4 +1,5 @@
node_modules/*
dist/*
test/*
src/examples/*
/node_modules/
/build/
/dist/
/test/
/src/examples/

1
package-lock.json generated
View File

@ -103,7 +103,6 @@
"husky": "8.0.3",
"jest": "21.2.1",
"jest-junit": "7.0.0",
"mkdirp": "1.0.4",
"raf": "3.4.1",
"react-test-renderer": "16.14.0",
"redux-mock-store": "1.5.4",

View File

@ -11,9 +11,9 @@
},
"main": "./dist/scratch-gui.js",
"scripts": {
"build": "npm run clean && mkdirp dist && webpack",
"clean": "rimraf ./dist",
"deploy": "touch build/.nojekyll && gh-pages -t -d dist -m \"[skip ci] Build for $(git log --pretty=format:%H -n1)\"",
"build": "npm run clean && webpack",
"clean": "rimraf ./build ./dist",
"deploy": "touch build/.nojekyll && gh-pages -t -d build -m \"[skip ci] Build for $(git log --pretty=format:%H -n1)\"",
"prepublish": "node scripts/prepublish.mjs",
"prune": "./prune-gh-pages.sh",
"i18n:push": "tx-push-src scratch-editor interface translations/en.json",
@ -130,7 +130,6 @@
"husky": "8.0.3",
"jest": "21.2.1",
"jest-junit": "7.0.0",
"mkdirp": "1.0.4",
"raf": "3.4.1",
"react-test-renderer": "16.14.0",
"redux-mock-store": "1.5.4",

View File

@ -14,40 +14,20 @@ const ScratchWebpackConfigBuilder = require('scratch-webpack-configuration');
// const STATIC_PATH = process.env.STATIC_PATH || '/static';
const configBuilder = new ScratchWebpackConfigBuilder(
const baseConfig = new ScratchWebpackConfigBuilder(
{
rootPath: path.resolve(__dirname),
enableReact: true
})
.setTarget('browserslist')
.merge({
devServer: {
client: {
progress: true
},
hot: true,
port: process.env.PORT || 8602
},
entry: {
// GUI as a library
'scratch-gui': path.join(__dirname, 'src/index.js'),
// to run editor examples
'lib.min': ['react', 'react-dom'],
'gui': './src/playground/index.jsx',
'blocksonly': './src/playground/blocks-only.jsx',
'compatibilitytesting': './src/playground/compatibility-testing.jsx',
'player': './src/playground/player.jsx'
},
output: {
assetModuleFilename: 'static/assets/[name].[hash][ext][query]',
chunkFilename: 'chunks/[name].js',
library: {
name: 'GUI',
type: 'umd2'
},
// publicPath: `${STATIC_PATH}/`,
path: path.resolve(__dirname, 'dist')
}
},
resolve: {
fallback: {
@ -137,6 +117,66 @@ const configBuilder = new ScratchWebpackConfigBuilder(
'process.env.GTM_ENV_AUTH': `"${process.env.GTM_ENV_AUTH || ''}"`,
'process.env.GTM_ID': process.env.GTM_ID ? `"${process.env.GTM_ID}"` : null
}))
.addPlugin(new CopyWebpackPlugin({
patterns: [
{
from: 'node_modules/scratch-blocks/media',
to: 'static/blocks-media/default'
},
{
from: 'node_modules/scratch-blocks/media',
to: 'static/blocks-media/high-contrast'
},
{
// overwrite some of the default block media with high-contrast versions
// this entry must come after copying scratch-blocks/media into the high-contrast directory
from: 'src/lib/themes/high-contrast/blocks-media',
to: 'static/blocks-media/high-contrast',
force: true
},
{
context: 'node_modules/scratch-vm/dist/web',
from: 'extension-worker.{js,js.map}',
noErrorOnMissing: true
}
]
}));
if (!process.env.CI) {
baseConfig.addPlugin(new webpack.ProgressPlugin());
}
// build the shipping library in `dist/`
const distConfig = baseConfig.clone()
.merge({
entry: {
'scratch-gui': path.join(__dirname, 'src/index.js')
},
output: {
path: path.resolve(__dirname, 'dist')
}
});
// build the examples and debugging tools in `build/`
const buildConfig = baseConfig.clone()
.merge({
devServer: {
client: {
progress: true
},
hot: true,
port: process.env.PORT || 8602
},
entry: {
gui: './src/playground/index.jsx',
blocksonly: './src/playground/blocks-only.jsx',
compatibilitytesting: './src/playground/compatibility-testing.jsx',
player: './src/playground/player.jsx'
},
output: {
path: path.resolve(__dirname, 'build')
}
})
.addPlugin(new HtmlWebpackPlugin({
chunks: ['gui'],
template: 'src/playground/index.ejs',
@ -170,36 +210,16 @@ const configBuilder = new ScratchWebpackConfigBuilder(
from: 'extensions/**',
to: 'static',
context: 'src/examples'
},
{
from: 'src/lib/themes/high-contrast/blocks-media',
to: 'static/blocks-media/high-contrast',
force: true
},
{
// Include library JSON files for scratch-desktop to use for downloading
from: 'src/lib/libraries/*.json',
to: 'libraries',
flatten: true
},
{
from: 'node_modules/scratch-blocks/media',
to: 'static/blocks-media/default'
},
{
from: 'node_modules/scratch-blocks/media',
to: 'static/blocks-media/high-contrast'
},
{
context: 'node_modules/scratch-vm/dist/web',
from: 'extension-worker.{js,js.map}',
noErrorOnMissing: true
}
]
}));
if (!process.env.CI) {
configBuilder.addPlugin(new webpack.ProgressPlugin());
}
// Skip building `dist/` unless explicitly requested
// It roughly doubles build time and isn't needed for `scratch-gui` development
// If you need non-production `dist/` for local dev, such as for `scratch-www` work, you can run something like:
// `BUILD_MODE=dist npm run build`
const buildDist = process.env.NODE_ENV === 'production' || process.env.BUILD_MODE === 'dist';
module.exports = configBuilder.get();
module.exports = buildDist ?
[buildConfig.get(), distConfig.get()] :
buildConfig.get();