Skip to content

Commit 4fc480e

Browse files
committed
Refactor CI workflow to simplify bundler configuration logic, replacing case statements with if-elif conditions for better readability and maintainability. This change enhances the setup process for various bundlers including Vite, Webpack, Rollup, and Esbuild.
1 parent e025a35 commit 4fc480e

File tree

1 file changed

+60
-65
lines changed

1 file changed

+60
-65
lines changed

.github/workflows/ci.yml

Lines changed: 60 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -205,69 +205,64 @@ jobs:
205205
EOF
206206
207207
# Configure bundler-specific setup and build
208-
case "${{ matrix.bundler }}" in
209-
vite)
210-
npm install --save-dev vite
211-
cat > vite.config.js << 'EOF'
212-
export default {
213-
build: {
214-
lib: {
215-
entry: 'index.js',
216-
formats: ['es'],
217-
fileName: 'bundle'
218-
}
219-
}
208+
if [ "${{ matrix.bundler }}" = "vite" ]; then
209+
npm install --save-dev vite
210+
cat > vite.config.js << 'EOF'
211+
export default {
212+
build: {
213+
lib: {
214+
entry: 'index.js',
215+
formats: ['es'],
216+
fileName: 'bundle'
220217
}
221-
EOF
222-
npx vite build
223-
;;
224-
225-
webpack)
226-
npm install --save-dev webpack webpack-cli
227-
cat > webpack.config.js << 'EOF'
228-
const path = require('path');
229-
module.exports = {
230-
entry: './index.js',
231-
output: {
232-
filename: 'bundle.js',
233-
path: path.resolve(__dirname, 'dist'),
234-
library: { type: 'commonjs2' }
235-
},
236-
mode: 'production',
237-
resolve: {
238-
extensions: ['.js']
239-
}
240-
};
241-
EOF
242-
npx webpack --mode=production
243-
# Test execution of bundled output
244-
node dist/bundle.js
245-
;;
246-
247-
rollup)
248-
npm install --save-dev rollup @rollup/plugin-node-resolve @rollup/plugin-commonjs
249-
cat > rollup.config.js << 'EOF'
250-
import { nodeResolve } from '@rollup/plugin-node-resolve';
251-
import commonjs from '@rollup/plugin-commonjs';
252-
253-
export default {
254-
input: 'index.js',
255-
output: {
256-
file: 'dist/bundle.js',
257-
format: 'cjs'
258-
},
259-
plugins: [nodeResolve(), commonjs()]
260-
};
261-
EOF
262-
npx rollup -c
263-
# Test execution of bundled output
264-
node dist/bundle.js
265-
;;
266-
267-
esbuild)
268-
npm install --save-dev esbuild
269-
npx esbuild index.js --bundle --outfile=dist/bundle.js --format=cjs --platform=node
270-
# Test execution of bundled output
271-
node dist/bundle.js
272-
;;
273-
esac
218+
}
219+
}
220+
EOF
221+
npx vite build
222+
223+
elif [ "${{ matrix.bundler }}" = "webpack" ]; then
224+
npm install --save-dev webpack webpack-cli
225+
cat > webpack.config.js << 'EOF'
226+
const path = require('path');
227+
module.exports = {
228+
entry: './index.js',
229+
output: {
230+
filename: 'bundle.js',
231+
path: path.resolve(__dirname, 'dist'),
232+
library: { type: 'commonjs2' }
233+
},
234+
mode: 'production',
235+
resolve: {
236+
extensions: ['.js']
237+
}
238+
};
239+
EOF
240+
npx webpack --mode=production
241+
# Test execution of bundled output
242+
node dist/bundle.js
243+
244+
elif [ "${{ matrix.bundler }}" = "rollup" ]; then
245+
npm install --save-dev rollup @rollup/plugin-node-resolve @rollup/plugin-commonjs
246+
cat > rollup.config.js << 'EOF'
247+
import { nodeResolve } from '@rollup/plugin-node-resolve';
248+
import commonjs from '@rollup/plugin-commonjs';
249+
250+
export default {
251+
input: 'index.js',
252+
output: {
253+
file: 'dist/bundle.js',
254+
format: 'cjs'
255+
},
256+
plugins: [nodeResolve(), commonjs()]
257+
};
258+
EOF
259+
npx rollup -c
260+
# Test execution of bundled output
261+
node dist/bundle.js
262+
263+
elif [ "${{ matrix.bundler }}" = "esbuild" ]; then
264+
npm install --save-dev esbuild
265+
npx esbuild index.js --bundle --outfile=dist/bundle.js --format=cjs --platform=node
266+
# Test execution of bundled output
267+
node dist/bundle.js
268+
fi

0 commit comments

Comments
 (0)