scratch-storage/webpack.config.js
Georgi Angelov 3d0b429526 feat!: upgrade webpack to 5 and add TS support
Breaking flag is because it may have some differences in the way the library is exported -
`module.exports = ` vs `module.exports.default = `. That would depend on the Webpack config,
so it should continue working, but just to be safe.
2024-10-10 11:45:50 +03:00

74 lines
1.8 KiB
JavaScript

const path = require('path');
const webpack = require('webpack');
const ScratchWebpackConfigBuilder = require('scratch-webpack-configuration');
const baseConfig = new ScratchWebpackConfigBuilder(
{
rootPath: path.resolve(__dirname),
enableReact: false,
enableTs: true,
shouldSplitChunks: false
})
.setTarget('browserslist')
.merge({
resolve: {
fallback: {
Buffer: require.resolve('buffer/')
}
}
});
if (!process.env.CI) {
baseConfig.addPlugin(new webpack.ProgressPlugin());
}
// Web-compatible
const webConfig = baseConfig.clone()
.merge({
output: {
library: 'ScratchStorage',
libraryTarget: 'umd',
path: path.resolve(__dirname, 'dist', 'web'),
filename: '[name].js',
clean: false
}
});
const webNonMinConfig = webConfig.clone()
.merge({
entry: {
'scratch-storage': path.join(__dirname, './src/index.ts')
},
optimization: {
minimize: false
}
});
const webMinConfig = webConfig.clone()
.merge({
entry: {
'scratch-storage.min': path.join(__dirname, './src/index.ts')
},
optimization: {
minimize: true
}
});
// Node-compatible
const nodeConfig = baseConfig.clone()
.merge({
entry: {
'scratch-storage': path.join(__dirname, './src/index.ts')
},
output: {
library: 'ScratchStorage',
libraryTarget: 'commonjs2',
path: path.resolve(__dirname, 'dist', 'node'),
filename: '[name].js',
clean: false
}
})
.addExternals(['base64-js', 'js-md5', 'localforage', 'text-encoding']);
module.exports = [webNonMinConfig.get(), webMinConfig.get(), nodeConfig.get()];