From 475b83350865c406faa7a55718c5792378191d1d Mon Sep 17 00:00:00 2001 From: Brett Jia Date: Thu, 21 Sep 2023 23:07:32 -0400 Subject: [PATCH] sdk: configurable webpack entrypoint (#1076) --- sdk/bin/scrypted-webpack.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/sdk/bin/scrypted-webpack.js b/sdk/bin/scrypted-webpack.js index 60d17fff9..12dfa3161 100755 --- a/sdk/bin/scrypted-webpack.js +++ b/sdk/bin/scrypted-webpack.js @@ -128,8 +128,8 @@ else { out = path.resolve(cwd, 'out'); if (!entry) { - console.error('unable to locate src/main.js or src/main.ts'); - return 1; + console.warn('unable to locate src/main.js or src/main.ts'); + console.warn('if a custom webpack config is used, will fall back to an entry configured there'); } var webpackCmd = path.resolve(cwd, 'node_modules/.bin/webpack-cli'); @@ -177,9 +177,25 @@ else { process.env.SCRYPTED_DEFAULT_WEBPACK_CONFIG = defaultWebpackConfig; const config = require(webpackConfig); - config.entry = { - main: entry, - }; + if (entry) { + // a standard entrypoint was found + config.entry = { + main: entry, + }; + } else { + // try to use an entrypoint specified in the webpack config + if (!config?.entry?.main) { + console.error("webpack config does not supply an entry file"); + return 1; + } + var resolved = path.resolve(cwd, config.entry.main); + if (fs.existsSync(resolved)) { + config.entry.main = resolved + } else { + console.error("entry file specified in webpack config does not exist"); + return 1; + } + } config.output.path = out; config.output.filename = runtime.output;