@nativescript/webpack 5.1.0-alpha.0 → 5.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +100 -0
  3. package/dist/configuration/base.js +250 -102
  4. package/dist/configuration/base.js.map +1 -1
  5. package/dist/configuration/javascript.js +4 -1
  6. package/dist/configuration/javascript.js.map +1 -1
  7. package/dist/configuration/typescript.js +9 -2
  8. package/dist/configuration/typescript.js.map +1 -1
  9. package/dist/helpers/dependencies.d.ts +13 -0
  10. package/dist/helpers/dependencies.js +68 -0
  11. package/dist/helpers/dependencies.js.map +1 -1
  12. package/dist/helpers/platform.js +6 -1
  13. package/dist/helpers/platform.js.map +1 -1
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.js.map +1 -1
  16. package/dist/loaders/native-class-downlevel-loader/index.d.ts +2 -0
  17. package/dist/loaders/native-class-downlevel-loader/index.js +104 -0
  18. package/dist/loaders/native-class-downlevel-loader/index.js.map +1 -0
  19. package/dist/loaders/native-class-strip-loader/index.d.ts +2 -0
  20. package/dist/loaders/native-class-strip-loader/index.js +28 -0
  21. package/dist/loaders/native-class-strip-loader/index.js.map +1 -0
  22. package/dist/loaders/nativescript-hot-loader/hmr.runtime.js +10 -2
  23. package/dist/loaders/nativescript-hot-loader/hmr.runtime.js.map +1 -1
  24. package/dist/loaders/nativescript-hot-loader/index.js +1 -3
  25. package/dist/loaders/nativescript-hot-loader/index.js.map +1 -1
  26. package/dist/platforms/macos.d.ts +3 -0
  27. package/dist/platforms/macos.js +24 -0
  28. package/dist/platforms/macos.js.map +1 -0
  29. package/dist/plugins/CompatDefinePlugin.d.ts +5 -0
  30. package/dist/plugins/CompatDefinePlugin.js +16 -0
  31. package/dist/plugins/CompatDefinePlugin.js.map +1 -0
  32. package/dist/plugins/FixSourceMapUrlPlugin.d.ts +13 -0
  33. package/dist/plugins/FixSourceMapUrlPlugin.js +102 -0
  34. package/dist/plugins/FixSourceMapUrlPlugin.js.map +1 -0
  35. package/dist/plugins/PlatformSuffixPlugin.js +38 -18
  36. package/dist/plugins/PlatformSuffixPlugin.js.map +1 -1
  37. package/dist/plugins/WatchStatePlugin.js +1 -0
  38. package/dist/plugins/WatchStatePlugin.js.map +1 -1
  39. package/dist/polyfills/mdn-data-at-rules.d.ts +7 -0
  40. package/dist/polyfills/mdn-data-at-rules.js +8 -0
  41. package/dist/polyfills/mdn-data-at-rules.js.map +1 -0
  42. package/dist/polyfills/mdn-data-properties.d.ts +7 -0
  43. package/dist/polyfills/mdn-data-properties.js +8 -0
  44. package/dist/polyfills/mdn-data-properties.js.map +1 -0
  45. package/dist/polyfills/mdn-data-syntaxes.d.ts +7 -0
  46. package/dist/polyfills/mdn-data-syntaxes.js +8 -0
  47. package/dist/polyfills/mdn-data-syntaxes.js.map +1 -0
  48. package/dist/polyfills/module.d.ts +13 -0
  49. package/dist/polyfills/module.js +44 -0
  50. package/dist/polyfills/module.js.map +1 -0
  51. package/dist/stubs/virtual-entry-javascript.js +5 -1
  52. package/dist/stubs/virtual-entry-typescript.js +5 -1
  53. package/dist/stubs/virtual-entry-typescript.mjs +76 -0
  54. package/dist/transformers/NativeClass/index.d.ts +1 -4
  55. package/dist/transformers/NativeClass/index.js +264 -37
  56. package/dist/transformers/NativeClass/index.js.map +1 -1
  57. package/package.json +29 -5
package/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright OpenJS Foundation and other contributors, https://openjsf.org
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ <p align="center">
2
+ <a href="https://nativescript.org">
3
+ <img alt="NativeScript" src="https://raw.githubusercontent.com/NativeScript/artwork/main/logo/export/NativeScript_Logo_Dark_Transparent.png" width="100"/>
4
+ </a>
5
+ </p>
6
+
7
+ <h1 align="center">@nativescript/webpack</h1>
8
+
9
+ <p align="center">
10
+ <b>Webpack configuration for NativeScript apps.</b>
11
+ </p>
12
+
13
+ <p align="center">
14
+ <a href="https://www.npmjs.com/package/@nativescript/webpack"><img src="https://img.shields.io/npm/v/@nativescript/webpack.svg" alt="npm version"></a>
15
+ <a href="https://github.com/NativeScript/NativeScript/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license"></a>
16
+ <a href="https://www.npmjs.com/package/@nativescript/webpack"><img src="https://img.shields.io/npm/dm/@nativescript/webpack.svg" alt="downloads"></a>
17
+ </p>
18
+
19
+ <p align="center">
20
+ <a href="https://docs.nativescript.org/configuration/webpack">Documentation</a> ·
21
+ <a href="https://docs.nativescript.org/setup/">Environment Setup</a> ·
22
+ <a href="https://github.com/NativeScript/NativeScript/blob/main/tools/notes/CONTRIBUTING.md">Contribute</a> ·
23
+ <a href="https://nativescript.org/discord">Community</a>
24
+ </p>
25
+
26
+ ---
27
+
28
+ All NativeScript applications are bundled using webpack. This package provides the required configuration to build NativeScript apps with flexibility to customize as needed.
29
+
30
+ ## 📦 Installation
31
+
32
+ ```bash
33
+ npm install @nativescript/webpack --save-dev
34
+ ```
35
+
36
+ ## 🚀 Quick Start
37
+
38
+ All new projects come with a base `webpack.config.js` that's pre-configured:
39
+
40
+ ```js
41
+ const webpack = require('@nativescript/webpack')
42
+
43
+ module.exports = (env) => {
44
+ webpack.init(env)
45
+
46
+ // Learn how to customize:
47
+ // https://docs.nativescript.org/webpack
48
+
49
+ return webpack.resolveConfig()
50
+ }
51
+ ```
52
+
53
+ ## ✨ Features
54
+
55
+ - **Auto-discovery**: Automatically detects your project type (TypeScript, Angular, Vue, React, Svelte)
56
+ - **Hot Module Replacement**: HMR enabled by default for faster development
57
+ - **DotEnv Support**: Built-in support for `.env` files to manage environment variables
58
+ - **Bundle Analysis**: Generate bundle reports with `--env.report`
59
+ - **Production Optimization**: Minification with Terser in production mode
60
+
61
+ ## 🔧 Global Variables
62
+
63
+ Useful globally available variables in your app:
64
+
65
+ | Variable | Description |
66
+ |----------|-------------|
67
+ | `__DEV__` | `true` when building in development mode |
68
+ | `global.isAndroid` / `__ANDROID__` | `true` when platform is Android |
69
+ | `global.isIOS` / `__IOS__` | `true` when platform is iOS |
70
+ | `global.isVisionOS` / `__VISIONOS__` | `true` when platform is visionOS |
71
+ | `global.__APPLE__` | `true` when platform is iOS, visionOS, or macOS |
72
+
73
+ ## 📚 API
74
+
75
+ ### Core Methods
76
+
77
+ | Method | Description |
78
+ |--------|-------------|
79
+ | `webpack.init(env)` | Initialize the internal env object (required) |
80
+ | `webpack.chainWebpack(chainFn)` | Add chain functions to modify config |
81
+ | `webpack.mergeWebpack(obj)` | Merge objects into the final config |
82
+ | `webpack.resolveConfig()` | Resolve the final webpack configuration |
83
+
84
+ ## 🎛️ CLI Flags
85
+
86
+ | Flag | Description |
87
+ |------|-------------|
88
+ | `--no-hmr` | Disable Hot Module Replacement |
89
+ | `--env.production` | Enable production mode with minification |
90
+ | `--env.report` | Generate bundle analysis report |
91
+ | `--env.verbose` | Print verbose logs and internal config |
92
+ | `--env.e2e` | Enable E2E mode (enables `testID` property) |
93
+
94
+ ## 📖 Documentation
95
+
96
+ For complete documentation including configuration examples, visit the [webpack configuration guide](https://docs.nativescript.org/configuration/webpack).
97
+
98
+ ## 📄 License
99
+
100
+ [MIT licensed](https://github.com/NativeScript/NativeScript/blob/main/LICENSE).
@@ -7,36 +7,116 @@ exports.default = default_1;
7
7
  const path_1 = require("path");
8
8
  const webpack_1 = require("webpack");
9
9
  const semver_1 = require("semver");
10
+ const dependencies_1 = require("../helpers/dependencies");
10
11
  const fs_1 = require("fs");
11
12
  const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
12
13
  const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
13
14
  const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
14
15
  const project_1 = require("../helpers/project");
15
- const dependencies_1 = require("../helpers/dependencies");
16
+ const dependencies_2 = require("../helpers/dependencies");
16
17
  const PlatformSuffixPlugin_1 = require("../plugins/PlatformSuffixPlugin");
17
18
  const fileReplacements_1 = require("../helpers/fileReplacements");
18
19
  const copyRules_1 = require("../helpers/copyRules");
19
20
  const WatchStatePlugin_1 = require("../plugins/WatchStatePlugin");
21
+ const CompatDefinePlugin_1 = require("../plugins/CompatDefinePlugin");
20
22
  const dotEnv_1 = require("../helpers/dotEnv");
21
23
  const index_1 = require("../index");
22
24
  const config_1 = require("../helpers/config");
23
25
  const host_1 = require("../helpers/host");
26
+ const FixSourceMapUrlPlugin_1 = __importDefault(require("../plugins/FixSourceMapUrlPlugin"));
24
27
  const platform_1 = require("../helpers/platform");
28
+ function isApplePlatform(platform) {
29
+ return platform === 'ios' || platform === 'visionos' || platform === 'macos';
30
+ }
31
+ function getPlatformResolutionExtensions(platform) {
32
+ if (platform === 'visionos') {
33
+ return ['visionos', 'apple', 'ios'];
34
+ }
35
+ if (platform === 'macos') {
36
+ return ['macos', 'apple', 'ios'];
37
+ }
38
+ if (platform === 'ios') {
39
+ return ['ios', 'apple'];
40
+ }
41
+ return [platform];
42
+ }
25
43
  function default_1(config, env = index_1.env) {
26
- var _a, _b, _c, _d;
44
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
27
45
  const entryPath = (0, platform_1.getEntryPath)();
28
46
  const platform = (0, platform_1.getPlatformName)();
47
+ const platformResolutionExtensions = getPlatformResolutionExtensions(platform);
29
48
  const outputPath = (0, platform_1.getAbsoluteDistPath)();
30
49
  const mode = env.production ? 'production' : 'development';
31
50
  // set mode
32
51
  config.mode(mode);
52
+ // use source map files by default with v9+
53
+ function useSourceMapFiles() {
54
+ if (mode === 'development') {
55
+ // in development we always use source-map files with v9+ runtimes
56
+ // they are parsed and mapped to display in-flight app error screens
57
+ env.sourceMap = 'source-map';
58
+ }
59
+ }
60
+ // determine target output by @nativescript/* runtime version
61
+ // v9+ supports ESM output, anything below uses CommonJS
62
+ if ((0, dependencies_2.hasDependency)('@nativescript/ios') ||
63
+ (0, dependencies_2.hasDependency)('@nativescript/visionos') ||
64
+ (0, dependencies_2.hasDependency)('@nativescript/android')) {
65
+ const iosVersion = (0, dependencies_2.getDependencyVersion)('@nativescript/ios');
66
+ const visionosVersion = (0, dependencies_2.getDependencyVersion)('@nativescript/visionos');
67
+ const androidVersion = (0, dependencies_2.getDependencyVersion)('@nativescript/android');
68
+ if (platform === 'ios') {
69
+ const iosResolved = (_b = (_a = (0, dependencies_2.getResolvedDependencyVersionForCheck)('@nativescript/ios', '9.0.0')) !== null && _a !== void 0 ? _a : iosVersion) !== null && _b !== void 0 ? _b : undefined;
70
+ if ((0, dependencies_1.isVersionGteConsideringPrerelease)(iosResolved, '9.0.0')) {
71
+ useSourceMapFiles();
72
+ }
73
+ else {
74
+ env.commonjs = true;
75
+ }
76
+ }
77
+ else if (platform === 'visionos') {
78
+ const visionosResolved = (_d = (_c = (0, dependencies_2.getResolvedDependencyVersionForCheck)('@nativescript/visionos', '9.0.0')) !== null && _c !== void 0 ? _c : visionosVersion) !== null && _d !== void 0 ? _d : undefined;
79
+ if ((0, dependencies_1.isVersionGteConsideringPrerelease)(visionosResolved, '9.0.0')) {
80
+ useSourceMapFiles();
81
+ }
82
+ else {
83
+ env.commonjs = true;
84
+ }
85
+ }
86
+ else if (platform === 'android') {
87
+ const androidResolved = (_f = (_e = (0, dependencies_2.getResolvedDependencyVersionForCheck)('@nativescript/android', '9.0.0')) !== null && _e !== void 0 ? _e : androidVersion) !== null && _f !== void 0 ? _f : undefined;
88
+ if ((0, dependencies_1.isVersionGteConsideringPrerelease)(androidResolved, '9.0.0')) {
89
+ useSourceMapFiles();
90
+ }
91
+ else {
92
+ env.commonjs = true;
93
+ }
94
+ }
95
+ }
96
+ else {
97
+ env.commonjs = true;
98
+ }
99
+ if (env.hmr) {
100
+ // HMR webpack should use CommonJS
101
+ env.commonjs = true;
102
+ }
33
103
  // config.stats({
34
104
  // logging: 'verbose'
35
105
  // })
36
106
  // package.json is generated by the CLI with runtime options
37
107
  // this ensures it's not included in the bundle, but rather
38
108
  // resolved at runtime
39
- config.externals(['package.json', '~/package.json']);
109
+ config.externals([
110
+ 'package.json',
111
+ '~/package.json',
112
+ // Native addons are runtime-loaded binaries and must not be bundled.
113
+ ({ request }, callback) => {
114
+ if (request && /\.node(?:[?#].*)?$/.test(request)) {
115
+ return callback(null, `commonjs ${request}`);
116
+ }
117
+ callback();
118
+ },
119
+ ]);
40
120
  // disable marking built-in node modules as external
41
121
  // since they are not available at runtime and
42
122
  // should be bundled (requires polyfills)
@@ -45,6 +125,29 @@ function default_1(config, env = index_1.env) {
45
125
  config.set('externalsPresets', {
46
126
  node: false,
47
127
  });
128
+ // Mock Node.js built-ins that are not available in NativeScript runtime
129
+ // but are required by some packages like css-tree
130
+ config.resolve.merge({
131
+ fallback: {
132
+ module: require.resolve('../polyfills/module.js'),
133
+ },
134
+ alias: {
135
+ // Mock mdn-data modules that css-tree tries to load
136
+ 'mdn-data/css/properties.json': require.resolve('../polyfills/mdn-data-properties.js'),
137
+ 'mdn-data/css/syntaxes.json': require.resolve('../polyfills/mdn-data-syntaxes.js'),
138
+ 'mdn-data/css/at-rules.json': require.resolve('../polyfills/mdn-data-at-rules.js'),
139
+ // Ensure imports of the Node 'module' builtin resolve to our polyfill
140
+ module: require.resolve('../polyfills/module.js'),
141
+ },
142
+ // Allow extension-less ESM imports (fixes "fully specified" errors)
143
+ // Example: '../timer' -> resolves to index.<platform>.js without requiring explicit extension
144
+ fullySpecified: false,
145
+ });
146
+ // As an extra guard, ensure rule-level resolve also allows extension-less imports
147
+ config.module
148
+ .rule('esm-extensionless')
149
+ .test(/\.(mjs|js|ts|tsx)$/)
150
+ .resolve.set('fullySpecified', false);
48
151
  const getSourceMapType = (map) => {
49
152
  const defaultSourceMap = 'inline-source-map';
50
153
  if (typeof map === 'undefined') {
@@ -63,10 +166,18 @@ function default_1(config, env = index_1.env) {
63
166
  // pass any type of sourceMap with --env.sourceMap=<type>
64
167
  return map;
65
168
  };
66
- config.devtool(getSourceMapType(env.sourceMap));
169
+ const sourceMapType = getSourceMapType(env.sourceMap);
170
+ // Use devtool for both CommonJS and ESM - let webpack handle source mapping properly
171
+ config.devtool(sourceMapType);
172
+ // For ESM builds, fix the sourceMappingURL to use correct paths
173
+ if (sourceMapType && sourceMapType !== 'hidden-source-map') {
174
+ config
175
+ .plugin('FixSourceMapUrlPlugin')
176
+ .use(FixSourceMapUrlPlugin_1.default, [{ outputPath }]);
177
+ }
67
178
  // when using hidden-source-map, output source maps to the `platforms/{platformName}-sourceMaps` folder
68
179
  if (env.sourceMap === 'hidden-source-map') {
69
- const sourceMapAbsolutePath = (0, project_1.getProjectFilePath)(`./${(_a = env.buildPath) !== null && _a !== void 0 ? _a : 'platforms'}/${platform}-sourceMaps/[file].map[query]`);
180
+ const sourceMapAbsolutePath = (0, project_1.getProjectFilePath)(`./${(_g = env.buildPath) !== null && _g !== void 0 ? _g : 'platforms'}/${platform}-sourceMaps/[file].map[query]`);
70
181
  const sourceMapRelativePath = (0, path_1.relative)(outputPath, sourceMapAbsolutePath);
71
182
  config.output.sourceMapFilename(sourceMapRelativePath);
72
183
  }
@@ -75,12 +186,15 @@ function default_1(config, env = index_1.env) {
75
186
  // appears to be working - but we still have to deal with HMR
76
187
  config.target('node');
77
188
  // config.entry('globals').add('@nativescript/core/globals/index').end();
78
- config
79
- .entry('bundle')
189
+ const includeCoreGlobals = platform !== 'macos' || env.includeCore === true;
190
+ const bundleEntry = config.entry('bundle');
191
+ if (includeCoreGlobals) {
80
192
  // ensure we load nativescript globals first
81
- .add('@nativescript/core/globals/index')
82
- .add('@nativescript/core/bundle-entry-points')
83
- .add(entryPath);
193
+ bundleEntry
194
+ .add('@nativescript/core/globals/index')
195
+ .add('@nativescript/core/bundle-entry-points');
196
+ }
197
+ bundleEntry.add(entryPath);
84
198
  // Add android app components to the bundle to SBG can generate the java classes
85
199
  if (platform === 'android') {
86
200
  const appComponents = Array.isArray(env.appComponents)
@@ -98,28 +212,43 @@ function default_1(config, env = index_1.env) {
98
212
  .entry('tns_modules/inspector_modules')
99
213
  .add('@nativescript/core/inspector_modules');
100
214
  });
101
- // config.merge({
102
- // experiments: {
103
- // // enable ES module syntax (import/exports)
104
- // outputModule: true,
105
- // },
106
- // });
107
- config.output
108
- .path(outputPath)
109
- .pathinfo(false)
110
- .publicPath('')
111
- // .set('module', true)
112
- // .libraryTarget('module')
113
- .libraryTarget('commonjs')
114
- .globalObject('global')
115
- .set('clean', true);
116
- if (env === null || env === void 0 ? void 0 : env.uniqueBundle) {
117
- config.output.filename(`[name].${env.uniqueBundle}.js`);
215
+ if (env.commonjs) {
216
+ // CommonJS output
217
+ config.output
218
+ .path(outputPath)
219
+ .pathinfo(false)
220
+ .publicPath('')
221
+ .libraryTarget('commonjs')
222
+ .globalObject('global')
223
+ .set('clean', true);
224
+ if (env === null || env === void 0 ? void 0 : env.uniqueBundle) {
225
+ config.output.filename(`[name].${env.uniqueBundle}.js`);
226
+ }
227
+ }
228
+ else {
229
+ // ESM output
230
+ config.merge({
231
+ experiments: {
232
+ // enable ES module syntax (import/exports)
233
+ outputModule: true,
234
+ },
235
+ });
236
+ config.output
237
+ .path(outputPath)
238
+ .pathinfo(false)
239
+ .publicPath('file:///app/')
240
+ .set('module', true)
241
+ .libraryTarget('module')
242
+ .globalObject('global')
243
+ .set('clean', true);
244
+ if (env === null || env === void 0 ? void 0 : env.uniqueBundle) {
245
+ config.output.filename(`[name].${env.uniqueBundle}.mjs`);
246
+ }
118
247
  }
119
248
  config.watchOptions({
120
249
  ignored: [
121
- `${(0, project_1.getProjectFilePath)((_b = env.buildPath) !== null && _b !== void 0 ? _b : 'platforms')}/**`,
122
- `${(0, project_1.getProjectFilePath)((_c = env.appResourcesPath) !== null && _c !== void 0 ? _c : 'App_Resources')}/**`,
250
+ `${(0, project_1.getProjectFilePath)((_h = env.buildPath) !== null && _h !== void 0 ? _h : 'platforms')}/**`,
251
+ `${(0, project_1.getProjectFilePath)((_j = env.appResourcesPath) !== null && _j !== void 0 ? _j : 'App_Resources')}/**`,
123
252
  ],
124
253
  });
125
254
  // allow watching node_modules
@@ -151,29 +280,41 @@ function default_1(config, env = index_1.env) {
151
280
  },
152
281
  ]);
153
282
  config.optimization.runtimeChunk('single');
154
- config.optimization.splitChunks({
155
- // chunks: 'all',
156
- cacheGroups: {
157
- // globals: {
158
- // test: (module) =>
159
- // module.resource &&
160
- // /[\\/]@nativescript[\\/]core[\\/]globals[\\/]index\.(mjs|js|ts)$/.test(
161
- // module.resource,
162
- // ),
163
- // name: 'globals',
164
- // enforce: true, // ignore size/min-chunk thresholds
165
- // chunks: 'all',
166
- // priority: 30,
167
- // },
168
- defaultVendor: {
169
- test: /[\\/]node_modules[\\/]/,
170
- priority: -10,
171
- name: 'vendor',
172
- // enforce: true,
173
- chunks: 'all',
283
+ if (env.commonjs) {
284
+ // Set up CommonJS output
285
+ config.optimization.splitChunks({
286
+ cacheGroups: {
287
+ defaultVendor: {
288
+ test: /[\\/]node_modules[\\/]/,
289
+ priority: -10,
290
+ name: 'vendor',
291
+ chunks: 'all',
292
+ },
174
293
  },
175
- },
176
- });
294
+ });
295
+ }
296
+ else {
297
+ // Set up ESM output
298
+ config.output.chunkFilename('[name].mjs');
299
+ // now re‑add exactly what you want:
300
+ config.optimization.splitChunks({
301
+ // only split out vendor from the main bundle…
302
+ chunks: 'initial',
303
+ cacheGroups: {
304
+ // no “default” group
305
+ default: false,
306
+ // only pull node_modules into vendor.js from the *initial* chunk
307
+ vendor: {
308
+ test: /[\\/]node_modules[\\/]/,
309
+ name: 'vendor',
310
+ chunks: 'initial',
311
+ priority: -10,
312
+ reuseExistingChunk: true,
313
+ },
314
+ },
315
+ });
316
+ config.optimization.set('moduleIds', 'named').set('chunkIds', 'named');
317
+ }
177
318
  // look for loaders in
178
319
  // - node_modules/@nativescript/webpack/dist/loaders
179
320
  // - node_modules/@nativescript/webpack/node_modules
@@ -184,31 +325,30 @@ function default_1(config, env = index_1.env) {
184
325
  .add((0, path_1.resolve)(__dirname, '../../node_modules'))
185
326
  .add((0, project_1.getProjectFilePath)('node_modules'))
186
327
  .add('node_modules');
187
- config.resolve.extensions
188
- .add(`.${platform}.ts`)
189
- .add('.ts')
190
- .add(`.${platform}.js`)
191
- .add('.js')
192
- .add(`.${platform}.mjs`)
193
- .add('.mjs')
194
- .add(`.${platform}.css`)
195
- .add('.css')
196
- .add(`.${platform}.scss`)
197
- .add('.scss')
198
- .add(`.${platform}.json`)
199
- .add('.json');
200
- if (platform === 'visionos') {
201
- // visionOS allows for both .ios and .visionos extensions
202
- const extensions = config.resolve.extensions.values();
203
- const newExtensions = [];
204
- extensions.forEach((ext) => {
205
- newExtensions.push(ext);
206
- if (ext.includes('visionos')) {
207
- newExtensions.push(ext.replace('visionos', 'ios'));
208
- }
209
- });
210
- config.resolve.extensions.clear().merge(newExtensions);
211
- }
328
+ platformResolutionExtensions.forEach((platformTarget) => {
329
+ config.resolve.extensions.add(`.${platformTarget}.ts`);
330
+ });
331
+ config.resolve.extensions.add('.ts');
332
+ platformResolutionExtensions.forEach((platformTarget) => {
333
+ config.resolve.extensions.add(`.${platformTarget}.js`);
334
+ });
335
+ config.resolve.extensions.add('.js');
336
+ platformResolutionExtensions.forEach((platformTarget) => {
337
+ config.resolve.extensions.add(`.${platformTarget}.mjs`);
338
+ });
339
+ config.resolve.extensions.add('.mjs');
340
+ platformResolutionExtensions.forEach((platformTarget) => {
341
+ config.resolve.extensions.add(`.${platformTarget}.css`);
342
+ });
343
+ config.resolve.extensions.add('.css');
344
+ platformResolutionExtensions.forEach((platformTarget) => {
345
+ config.resolve.extensions.add(`.${platformTarget}.scss`);
346
+ });
347
+ config.resolve.extensions.add('.scss');
348
+ platformResolutionExtensions.forEach((platformTarget) => {
349
+ config.resolve.extensions.add(`.${platformTarget}.json`);
350
+ });
351
+ config.resolve.extensions.add('.json');
212
352
  // base aliases
213
353
  config.resolve.alias.set('~', (0, platform_1.getEntryDirPath)()).set('@', (0, platform_1.getEntryDirPath)());
214
354
  // resolve symlinks
@@ -277,9 +417,18 @@ function default_1(config, env = index_1.env) {
277
417
  before: [require('../transformers/NativeClass').default],
278
418
  };
279
419
  },
280
- });
420
+ })
421
+ .end()
422
+ // Ensure pre-loaders run BEFORE ts-loader (loaders execute right-to-left):
423
+ // order: [ts-loader, native-class-downlevel-loader, native-class-strip-loader]
424
+ // execution: strip -> downlevel -> ts-loader
425
+ .use('native-class-downlevel-loader')
426
+ .loader('native-class-downlevel-loader')
427
+ .end()
428
+ .use('native-class-strip-loader')
429
+ .loader('native-class-strip-loader');
281
430
  // Use Fork TS Checker to do type checking in a separate non-blocking process
282
- config.when((0, dependencies_1.hasDependency)('typescript'), (config) => {
431
+ config.when((0, dependencies_2.hasDependency)('typescript'), (config) => {
283
432
  config
284
433
  .plugin('ForkTsCheckerWebpackPlugin')
285
434
  .use(fork_ts_checker_webpack_plugin_1.default, [
@@ -318,8 +467,7 @@ function default_1(config, env = index_1.env) {
318
467
  // custom resolver to resolve platform extensions in @import statements
319
468
  // ie. @import "foo.css" would import "foo.ios.css" if the platform is ios and it exists
320
469
  resolve(id, baseDir, importOptions) {
321
- const extensions = platform === 'visionos' ? [platform, 'ios'] : [platform];
322
- for (const platformTarget of extensions) {
470
+ for (const platformTarget of platformResolutionExtensions) {
323
471
  const ext = (0, path_1.extname)(id);
324
472
  const platformExt = ext ? `.${platformTarget}${ext}` : '';
325
473
  if (!id.includes(platformExt)) {
@@ -373,7 +521,14 @@ function default_1(config, env = index_1.env) {
373
521
  .options(postCSSOptions)
374
522
  .end()
375
523
  .use('sass-loader')
376
- .loader('sass-loader');
524
+ .loader('sass-loader')
525
+ .options({
526
+ // helps ensure proper project compatibility
527
+ // particularly in cases of workspaces
528
+ // which may have different nested Sass implementations
529
+ // via transient dependencies
530
+ implementation: require('sass'),
531
+ });
377
532
  // config.plugin('NormalModuleReplacementPlugin').use(NormalModuleReplacementPlugin, [
378
533
  // /.*/,
379
534
  // request => {
@@ -383,19 +538,9 @@ function default_1(config, env = index_1.env) {
383
538
  // }
384
539
  // }
385
540
  // ])
386
- // config.plugin('globals-shim').use(BannerPlugin, [
387
- // {
388
- // // commonjs style
389
- // banner: `require("./globals");`,
390
- // // ESM style
391
- // // banner: `import "./globals";`,
392
- // raw: true,
393
- // entryOnly: true,
394
- // },
395
- // ]);
396
541
  config.plugin('PlatformSuffixPlugin').use(PlatformSuffixPlugin_1.PlatformSuffixPlugin, [
397
542
  {
398
- extensions: platform === 'visionos' ? [platform, 'ios'] : [platform],
543
+ extensions: platformResolutionExtensions,
399
544
  },
400
545
  ]);
401
546
  // Makes sure that require.context will never include
@@ -405,16 +550,18 @@ function default_1(config, env = index_1.env) {
405
550
  .use(webpack_1.ContextExclusionPlugin, [new RegExp(`(.*)App_Resources(.*)`)]);
406
551
  // Makes sure that require.context will never include code from
407
552
  // another platform (ie .android.ts when building for ios)
408
- const otherPlatformsRE = (0, platform_1.getAvailablePlatforms)()
409
- .filter((platform) => platform !== (0, platform_1.getPlatformName)())
410
- .join('|');
553
+ const otherPlatforms = (0, platform_1.getAvailablePlatforms)().filter((availablePlatform) => availablePlatform !== (0, platform_1.getPlatformName)());
554
+ if (!isApplePlatform(platform) && !otherPlatforms.includes('apple')) {
555
+ otherPlatforms.push('apple');
556
+ }
557
+ const otherPlatformsRE = otherPlatforms.join('|');
411
558
  config
412
559
  .plugin('ContextExclusionPlugin|Other_Platforms')
413
560
  .use(webpack_1.ContextExclusionPlugin, [
414
- new RegExp(`\\.(${otherPlatformsRE})\\.(\\w+)$`),
561
+ new RegExp(`\.(${otherPlatformsRE})\.(\w+)$`),
415
562
  ]);
416
563
  // Filter common undesirable warnings
417
- config.set('ignoreWarnings', ((_d = config.get('ignoreWarnings')) !== null && _d !== void 0 ? _d : []).concat([
564
+ config.set('ignoreWarnings', ((_k = config.get('ignoreWarnings')) !== null && _k !== void 0 ? _k : []).concat([
418
565
  /**
419
566
  * This rule hides
420
567
  * +-----------------------------------------------------------------------------------------+
@@ -426,7 +573,7 @@ function default_1(config, env = index_1.env) {
426
573
  /System.import\(\) is deprecated/,
427
574
  ]));
428
575
  // todo: refine defaults
429
- config.plugin('DefinePlugin').use(webpack_1.DefinePlugin, [
576
+ config.plugin('DefinePlugin').use(CompatDefinePlugin_1.CompatDefinePlugin, [
430
577
  {
431
578
  __DEV__: mode === 'development',
432
579
  __NS_WEBPACK__: true,
@@ -435,16 +582,17 @@ function default_1(config, env = index_1.env) {
435
582
  __CSS_PARSER__: JSON.stringify((0, config_1.getValue)('cssParser', 'css-tree')),
436
583
  __UI_USE_XML_PARSER__: true,
437
584
  __UI_USE_EXTERNAL_RENDERER__: false,
585
+ __COMMONJS__: !!env.commonjs,
438
586
  __ANDROID__: platform === 'android',
439
587
  __IOS__: platform === 'ios',
440
588
  __VISIONOS__: platform === 'visionos',
441
- __APPLE__: platform === 'ios' || platform === 'visionos',
589
+ __APPLE__: platform === 'ios' ||
590
+ platform === 'visionos' ||
591
+ platform === 'macos',
442
592
  /* for compat only */ 'global.isAndroid': platform === 'android',
443
593
  /* for compat only */ 'global.isIOS': platform === 'ios' || platform === 'visionos',
444
594
  /* for compat only */ 'global.isVisionOS': platform === 'visionos',
445
595
  process: 'global.process',
446
- // todo: ?!?!
447
- // profile: '() => {}',
448
596
  },
449
597
  ]);
450
598
  // enable DotEnv
@@ -475,7 +623,7 @@ function default_1(config, env = index_1.env) {
475
623
  }
476
624
  function shouldIncludeInspectorModules() {
477
625
  const platform = (0, platform_1.getPlatformName)();
478
- const coreVersion = (0, dependencies_1.getDependencyVersion)('@nativescript/core');
626
+ const coreVersion = (0, dependencies_2.getDependencyVersion)('@nativescript/core');
479
627
  if (coreVersion && (0, semver_1.satisfies)(coreVersion, '>=8.7.0')) {
480
628
  return platform === 'ios' || platform === 'android';
481
629
  }