fix(build): simplify webpack config using clone()

This commit is contained in:
Christopher Willis-Ford 2024-03-08 20:10:00 -08:00
parent 9261909f90
commit e7962b101d
3 changed files with 16 additions and 39 deletions

8
package-lock.json generated
View file

@ -58,7 +58,7 @@
"scratch-l10n": "3.18.53",
"scratch-render-fonts": "1.0.20",
"scratch-semantic-release-config": "1.0.14",
"scratch-webpack-configuration": "1.0.0",
"scratch-webpack-configuration": "1.1.0",
"script-loader": "0.7.2",
"semantic-release": "19.0.5",
"stats.js": "0.17.0",
@ -18704,9 +18704,9 @@
"integrity": "sha512-lC0ohKbx1g+q5fvYUmG0sFxEdlWL7BUcUxkah5UzUAFE5eqhW+JS7U9bFm4HbwqSovuuI1Xpl4qyu/9yJtrW5w=="
},
"node_modules/scratch-webpack-configuration": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/scratch-webpack-configuration/-/scratch-webpack-configuration-1.0.0.tgz",
"integrity": "sha512-8t3Lda+kOPR/C+0jR1eOmyLO4pjDjT0BAWtmrZ1sXYfCmDhZreOwZMD6127aFYZbCWGK3qn0j2fjSi+unBnG4g==",
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/scratch-webpack-configuration/-/scratch-webpack-configuration-1.1.0.tgz",
"integrity": "sha512-YjdOWGphdgOa/0HA3D6f2+WVLd0rj5UuwqowyLMZsXDGeoqlOHz2RVObWCkZ+/HBcQxsyy7gMjPX3dV6Mj+rbQ==",
"dev": true,
"dependencies": {
"lodash.merge": "^4.6.2",

View file

@ -96,7 +96,7 @@
"scratch-l10n": "3.18.53",
"scratch-render-fonts": "1.0.20",
"scratch-semantic-release-config": "1.0.14",
"scratch-webpack-configuration": "1.0.0",
"scratch-webpack-configuration": "1.1.0",
"script-loader": "0.7.2",
"semantic-release": "19.0.5",
"stats.js": "0.17.0",

View file

@ -10,15 +10,14 @@ const common = {
rootPath: path.resolve(__dirname)
};
const nodeConfig = new ScratchWebpackConfigBuilder(common)
const nodeBuilder = new ScratchWebpackConfigBuilder(common)
.setTarget('node')
.addModuleRule({
test: /\.mp3$/,
type: 'asset'
})
.get();
});
const webConfig = new ScratchWebpackConfigBuilder(common)
const webBuilder = new ScratchWebpackConfigBuilder(common)
.setTarget('browserslist')
.merge({
resolve: {
@ -40,11 +39,9 @@ const webConfig = new ScratchWebpackConfigBuilder(common)
})
.addPlugin(new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
}))
.get();
}));
const playgroundConfig = new ScratchWebpackConfigBuilder(common)
.setTarget('browserslist')
const playgroundBuilder = webBuilder.clone()
.merge({
devServer: {
contentBase: false,
@ -60,23 +57,11 @@ const playgroundConfig = new ScratchWebpackConfigBuilder(common)
},
output: {
path: path.resolve(__dirname, 'playground')
},
resolve: {
fallback: {
Buffer: require.resolve('buffer/')
}
}
})
.addModuleRule({
test: /\.mp3$/,
type: 'asset'
})
.addModuleRule({
test: require.resolve('./src/index.js'),
loader: 'expose-loader',
options: {
exposes: 'VirtualMachine'
}
test: require.resolve('stats.js/build/stats.min.js'),
loader: 'script-loader'
})
.addModuleRule({
test: require.resolve('./src/extensions/scratch3_video_sensing/debug.js'),
@ -85,10 +70,6 @@ const playgroundConfig = new ScratchWebpackConfigBuilder(common)
exposes: 'Scratch3VideoSensingDebug'
}
})
.addModuleRule({
test: require.resolve('stats.js/build/stats.min.js'),
loader: 'script-loader'
})
.addModuleRule({
test: require.resolve('scratch-blocks/dist/vertical.js'),
loader: 'expose-loader',
@ -117,9 +98,6 @@ const playgroundConfig = new ScratchWebpackConfigBuilder(common)
exposes: 'ScratchRender'
}
})
.addPlugin(new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
}))
.addPlugin(new CopyWebpackPlugin([
{
from: 'node_modules/scratch-blocks/media',
@ -137,11 +115,10 @@ const playgroundConfig = new ScratchWebpackConfigBuilder(common)
{
from: 'src/playground'
}
]))
.get();
]));
module.exports = [
nodeConfig,
webConfig,
playgroundConfig
nodeBuilder.get(),
webBuilder.get(),
playgroundBuilder.get()
];