From 403fa6b30fc09ef3395e7bb45acee2c15dc4cbe3 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Sun, 22 Nov 2020 14:54:26 +0100 Subject: [PATCH] fix: load globals first --- packages/webpack5/src/configuration/base.ts | 26 ++++++++++++--------- packages/webpack5/src/helpers/index.ts | 4 +++- packages/webpack5/src/helpers/log.ts | 6 ++--- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/webpack5/src/configuration/base.ts b/packages/webpack5/src/configuration/base.ts index 87f78d52c..937462b3a 100644 --- a/packages/webpack5/src/configuration/base.ts +++ b/packages/webpack5/src/configuration/base.ts @@ -21,8 +21,9 @@ export default function (config: Config, env: IWebpackEnv): Config { config.mode(mode); // package.json is generated by the CLI with runtime options - // this ensures it's not included in the bundle - config.externals(['package.json']); + // this ensures it's not included in the bundle, but rather + // resolved at runtime + config.externals(['package.json', '~/package.json']); // todo: devtool config.devtool('inline-source-map'); @@ -32,7 +33,18 @@ export default function (config: Config, env: IWebpackEnv): Config { // appears to be working - but we still have to deal with HMR config.target('node'); - config.entry('bundle').add(entryPath); + config + .entry('bundle') + // ensure we load nativescript globals first + .add('@nativescript/core/globals/index.js') + .add(entryPath); + + // inspector_modules + config.when(shouldIncludeInspectorModules(env), (config) => { + config + .entry('tns_modules/@nativescript/core/inspector_modules') + .add('@nativescript/core/inspector_modules'); + }); config.output .path(getAbsoluteDistPath()) @@ -74,13 +86,6 @@ export default function (config: Config, env: IWebpackEnv): Config { .add('node_modules/@nativescript/webpack/dist/loaders') .add('node_modules'); - // inspector_modules - config.when(shouldIncludeInspectorModules(env), (config) => { - config - .entry('tns_modules/@nativescript/core/inspector_modules') - .add('@nativescript/core/inspector_modules'); - }); - config.resolve.extensions .add(`.${platform}.ts`) .add('.ts') @@ -95,7 +100,6 @@ export default function (config: Config, env: IWebpackEnv): Config { // base aliases config.resolve.alias - .set('~/package.json', 'package.json') .set('~', 'appFullPath') .set('@', 'appFullPath'); diff --git a/packages/webpack5/src/helpers/index.ts b/packages/webpack5/src/helpers/index.ts index f80ab7c8c..f983b1b27 100644 --- a/packages/webpack5/src/helpers/index.ts +++ b/packages/webpack5/src/helpers/index.ts @@ -1,3 +1,4 @@ +import { merge } from 'webpack-merge'; import { getValue } from './config'; import { getAllDependencies, getDependencyPath } from './dependencies'; import { determineProjectFlavor } from './flavor'; @@ -16,6 +17,7 @@ import { // that show all the utils inline // rather than imports to types export default { + merge, config: { getValue, }, @@ -27,9 +29,9 @@ export default { determineProjectFlavor, }, log: { + error, info, warn, - error, }, project: { getProjectRootPath, diff --git a/packages/webpack5/src/helpers/log.ts b/packages/webpack5/src/helpers/log.ts index 9554e00a8..26dd6a703 100644 --- a/packages/webpack5/src/helpers/log.ts +++ b/packages/webpack5/src/helpers/log.ts @@ -11,7 +11,7 @@ function cleanup(data: any[]) { } export function error(...data: any): Error { - console.error(`[@nativescript/webpack]`, ...cleanup(data)); + console.error(`[@nativescript/webpack] Error: \n`, ...cleanup(data)); // we return the error - the caller can throw or ignore if (typeof data[0] === 'string') { @@ -22,11 +22,11 @@ export function error(...data: any): Error { } export function warn(...data: any): void { - console.warn(`[@nativescript/webpack]`, ...cleanup(data)); + console.warn(`[@nativescript/webpack] Warn: \n`, ...cleanup(data)); } export function info(...data: any): void { - console.info(`[@nativescript/webpack]`, ...cleanup(data)); + console.info(`[@nativescript/webpack] Info: \n`, ...cleanup(data)); } // todo: refine