Skip to content

Commit e549d9d

Browse files
committed
validate scenario used
1 parent 109ab9e commit e549d9d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

scenarios/browser/webpack.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
const path = require('path');
2+
const { readdirSync } = require('fs')
23

34
const webpack = require('webpack');
45
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
56
const HtmlWebpackPlugin = require('html-webpack-plugin');
67

8+
const CURRENT_SCENARIO = 'basic';
9+
10+
const hasCurrentScenario = () =>
11+
readdirSync(__dirname, { withFileTypes: true })
12+
.filter(dir => dir.isDirectory())
13+
.find(dir => dir.name === CURRENT_SCENARIO)
14+
15+
if (!hasCurrentScenario()) {
16+
throw new Error(`Scenario "${CURRENT_SCENARIO}" does not exist`)
17+
}
18+
19+
// eslint-disable-next-line no-console
20+
console.log(`Bundling scenario: ${CURRENT_SCENARIO}`)
21+
722
webpack(
823
{
9-
mode: 'development',
10-
entry: path.resolve(__dirname, 'perf-auto'),
24+
mode: 'production',
25+
entry: path.resolve(__dirname, CURRENT_SCENARIO),
1126
output: {
1227
filename: 'main.js',
13-
path: path.resolve(__dirname, 'dist', 'perf-auto'),
28+
path: path.resolve(__dirname, 'dist', CURRENT_SCENARIO),
1429
},
1530
plugins: [new BundleAnalyzerPlugin({ analyzerMode: 'static' }), new HtmlWebpackPlugin()],
1631
},

0 commit comments

Comments
 (0)