Skip to content

Commit

Permalink
fix(build): bring back BUILD_MODE now that the dust is settling
Browse files Browse the repository at this point in the history
  • Loading branch information
cwillisf committed Mar 14, 2024
1 parent 48fb28a commit 3b89677
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 59 deletions.
9 changes: 5 additions & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/*
dist/*
test/*
src/examples/*
/node_modules/
/build/
/dist/
/test/
/src/examples/
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
120 changes: 70 additions & 50 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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();

0 comments on commit 3b89677

Please sign in to comment.