@nativescript/webpack 3.1.0-hmr.0 → 4.1.0

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.
@@ -4,450 +4,372 @@ const fs = require('fs');
4
4
  const webpack = require('webpack');
5
5
  const nsWebpack = require('@nativescript/webpack');
6
6
  const nativescriptTarget = require('@nativescript/webpack/nativescript-target');
7
- const {
8
- nsSupportHmrNg
9
- } = require('@nativescript/webpack/transformers/ns-support-hmr-ng');
10
- const { nsTransformNativeClassesNg } = require("@nativescript/webpack/transformers/ns-transform-native-classes-ng");
11
- const {
12
- parseWorkspaceConfig, hasConfigurations
13
- } = require('@nativescript/webpack/helpers/angular-config-parser');
14
- const {
15
- getMainModulePath
16
- } = require('@nativescript/webpack/utils/ast-utils');
17
- const { getNoEmitOnErrorFromTSConfig, getCompilerOptionsFromTSConfig } = require("@nativescript/webpack/utils/tsconfig-utils");
7
+ const { nsSupportHmrNg } = require('@nativescript/webpack/transformers/ns-support-hmr-ng');
8
+ const { nsTransformNativeClassesNg } = require('@nativescript/webpack/transformers/ns-transform-native-classes-ng');
9
+ const { parseWorkspaceConfig, hasConfigurations } = require('@nativescript/webpack/helpers/angular-config-parser');
10
+ const { getMainModulePath } = require('@nativescript/webpack/utils/ast-utils');
11
+ const { getNoEmitOnErrorFromTSConfig, getCompilerOptionsFromTSConfig } = require('@nativescript/webpack/utils/tsconfig-utils');
18
12
  const { CleanWebpackPlugin } = require('clean-webpack-plugin');
19
13
  const CopyWebpackPlugin = require('copy-webpack-plugin');
20
14
  const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
21
- const {
22
- NativeScriptWorkerPlugin
23
- } = require('nativescript-worker-loader/NativeScriptWorkerPlugin');
15
+ const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeScriptWorkerPlugin');
24
16
  const TerserPlugin = require('terser-webpack-plugin');
25
- const {
26
- getAngularCompilerPlugin
27
- } = require('@nativescript/webpack/plugins/NativeScriptAngularCompilerPlugin');
17
+ const { getAngularCompilerPlugin } = require('@nativescript/webpack/plugins/NativeScriptAngularCompilerPlugin');
28
18
  const hashSalt = Date.now().toString();
29
19
 
30
- module.exports = env => {
31
- // Add your custom Activities, Services and other Android app components here.
32
- const appComponents = [
33
- "@nativescript/core/ui/frame", "@nativescript/core/ui/frame/activity"
34
- ];
20
+ module.exports = (env) => {
21
+ const platform = env && ((env.android && 'android') || (env.ios && 'ios'));
22
+ if (!platform) {
23
+ throw new Error('You need to provide a target platform!');
24
+ }
35
25
 
36
- const platform = env && ((env.android && 'android') || (env.ios && 'ios'));
37
- if (!platform) {
38
- throw new Error('You need to provide a target platform!');
39
- }
26
+ const AngularCompilerPlugin = getAngularCompilerPlugin(platform);
27
+ const projectRoot = __dirname;
40
28
 
41
- const AngularCompilerPlugin = getAngularCompilerPlugin(platform);
42
- const projectRoot = __dirname;
29
+ // Default destination inside platforms/<platform>/...
30
+ const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
43
31
 
44
- // Default destination inside platforms/<platform>/...
45
- const dist = resolve(
46
- projectRoot,
47
- nsWebpack.getAppPath(platform, projectRoot)
48
- );
32
+ const {
33
+ // The 'appPath' and 'appResourcesPath' values are fetched from
34
+ // the nsconfig.json configuration file
35
+ // when bundling with `tns run android|ios --bundle`.
36
+ appPath = 'src',
37
+ appResourcesPath = 'App_Resources',
49
38
 
50
- const {
51
- // The 'appPath' and 'appResourcesPath' values are fetched from
52
- // the nsconfig.json configuration file
53
- // when bundling with `tns run android|ios --bundle`.
54
- appPath = 'src',
55
- appResourcesPath = 'App_Resources',
39
+ // You can provide the following flags when running 'tns run android|ios'
40
+ snapshot, // --env.snapshot,
41
+ production, // --env.production
42
+ configuration, // --env.configuration (consistent with angular cli usage)
43
+ projectName, // --env.projectName (drive configuration through angular projects)
44
+ uglify, // --env.uglify
45
+ report, // --env.report
46
+ sourceMap, // --env.sourceMap
47
+ hiddenSourceMap, // --env.hiddenSourceMap
48
+ hmr, // --env.hmr,
49
+ unitTesting, // --env.unitTesting
50
+ testing, // --env.testing
51
+ verbose, // --env.verbose
52
+ ci, // --env.ci
53
+ snapshotInDocker, // --env.snapshotInDocker
54
+ skipSnapshotTools, // --env.skipSnapshotTools
55
+ compileSnapshot, // --env.compileSnapshot
56
+ appComponents = [],
57
+ entries = {},
58
+ } = env;
56
59
 
57
- // You can provide the following flags when running 'tns run android|ios'
58
- snapshot, // --env.snapshot,
59
- production, // --env.production
60
- configuration, // --env.configuration (consistent with angular cli usage)
61
- projectName, // --env.projectName (drive configuration through angular projects)
62
- uglify, // --env.uglify
63
- report, // --env.report
64
- sourceMap, // --env.sourceMap
65
- hiddenSourceMap, // --env.hiddenSourceMap
66
- hmr, // --env.hmr,
67
- unitTesting, // --env.unitTesting
68
- testing, // --env.testing
69
- verbose, // --env.verbose
70
- ci, // --env.ci
71
- snapshotInDocker, // --env.snapshotInDocker
72
- skipSnapshotTools, // --env.skipSnapshotTools
73
- compileSnapshot // --env.compileSnapshot
74
- } = env;
60
+ const { fileReplacements, copyReplacements } = parseWorkspaceConfig(platform, configuration, projectName);
75
61
 
76
- const { fileReplacements, copyReplacements } = parseWorkspaceConfig(platform, configuration, projectName);
62
+ const useLibs = compileSnapshot;
63
+ const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap;
64
+ const externals = nsWebpack.getConvertedExternals(env.externals);
65
+ const appFullPath = resolve(projectRoot, appPath);
66
+ const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
67
+ let tsConfigName = 'tsconfig.json';
68
+ let tsConfigPath = resolve(projectRoot, tsConfigName);
69
+ const tsConfigTnsName = 'tsconfig.tns.json';
70
+ const tsConfigTnsPath = resolve(projectRoot, tsConfigTnsName);
71
+ if (fs.existsSync(tsConfigTnsPath)) {
72
+ // support shared angular app configurations
73
+ tsConfigName = tsConfigTnsName;
74
+ tsConfigPath = tsConfigTnsPath;
75
+ }
76
+ const tsConfigEnvName = 'tsconfig.env.json';
77
+ const tsConfigEnvPath = resolve(projectRoot, tsConfigEnvName);
78
+ if (hasConfigurations(configuration) && fs.existsSync(tsConfigEnvPath)) {
79
+ // when configurations are used, switch to environments supported config
80
+ tsConfigName = tsConfigEnvName;
81
+ tsConfigPath = tsConfigEnvPath;
82
+ }
83
+ const entryModule = `${nsWebpack.getEntryModule(appFullPath, platform)}.ts`;
84
+ const entryPath = `.${sep}${entryModule}`;
85
+ Object.assign(entries, { bundle: entryPath }, entries);
86
+ const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some((e) => e.indexOf('@nativescript') > -1);
87
+ if (platform === 'ios' && !areCoreModulesExternal && !testing) {
88
+ entries['tns_modules/inspector_modules'] = '@nativescript/core/inspector_modules';
89
+ }
77
90
 
78
- const useLibs = compileSnapshot;
79
- const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap;
80
- const externals = nsWebpack.getConvertedExternals(env.externals);
81
- const appFullPath = resolve(projectRoot, appPath);
82
- const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
83
- let tsConfigName = 'tsconfig.json';
84
- let tsConfigPath = resolve(projectRoot, tsConfigName);
85
- const tsConfigTnsName = 'tsconfig.tns.json';
86
- const tsConfigTnsPath = resolve(projectRoot, tsConfigTnsName);
87
- if (fs.existsSync(tsConfigTnsPath)) {
88
- // support shared angular app configurations
89
- tsConfigName = tsConfigTnsName;
90
- tsConfigPath = tsConfigTnsPath;
91
- }
92
- const tsConfigEnvName = 'tsconfig.env.json';
93
- const tsConfigEnvPath = resolve(projectRoot, tsConfigEnvName);
94
- if (hasConfigurations(configuration) && fs.existsSync(tsConfigEnvPath)) {
95
- // when configurations are used, switch to environments supported config
96
- tsConfigName = tsConfigEnvName;
97
- tsConfigPath = tsConfigEnvPath;
98
- }
99
- const entryModule = `${nsWebpack.getEntryModule(appFullPath, platform)}.ts`;
100
- const entryPath = `.${sep}${entryModule}`;
101
- const entries = { bundle: entryPath };
102
- const areCoreModulesExternal =
103
- Array.isArray(env.externals) &&
104
- env.externals.some(e => e.indexOf('@nativescript') > -1);
105
- if (platform === 'ios' && !areCoreModulesExternal && !testing) {
106
- entries['tns_modules/@nativescript/core/inspector_modules'] =
107
- 'inspector_modules';
108
- }
91
+ const compilerOptions = getCompilerOptionsFromTSConfig(tsConfigPath);
92
+ nsWebpack.processTsPathsForScopedModules({ compilerOptions });
93
+ nsWebpack.processTsPathsForScopedAngular({ compilerOptions });
109
94
 
110
- const compilerOptions = getCompilerOptionsFromTSConfig(tsConfigPath);
111
- nsWebpack.processTsPathsForScopedModules({ compilerOptions });
112
- nsWebpack.processTsPathsForScopedAngular({ compilerOptions });
95
+ const ngCompilerTransformers = [nsTransformNativeClassesNg];
96
+ const additionalLazyModuleResources = [];
113
97
 
114
- const ngCompilerTransformers = [nsTransformNativeClassesNg];
115
- const additionalLazyModuleResources = [];
98
+ const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] };
99
+ const copyTargets = [{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, ...copyReplacements];
116
100
 
117
- const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] };
118
- const copyTargets = [
119
- { from: { glob: 'assets/**', dot: false } },
120
- { from: { glob: 'fonts/**', dot: false } },
121
- ...copyReplacements,
122
- ];
101
+ if (!production) {
102
+ // for development purposes only
103
+ // for example, include mock json folder
104
+ // copyTargets.push({ from: 'tools/mockdata', to: 'assets/mockdata' });
123
105
 
124
- if (!production) {
125
- // for development purposes only
126
- // for example, include mock json folder
127
- // copyTargets.push({ from: 'tools/mockdata', to: 'assets/mockdata' });
106
+ if (hmr) {
107
+ ngCompilerTransformers.push(nsSupportHmrNg);
108
+ }
109
+ }
128
110
 
129
- if (hmr) {
130
- ngCompilerTransformers.push(nsSupportHmrNg);
131
- }
132
- }
111
+ // when "@angular/core" is external, it's not included in the bundles. In this way, it will be used
112
+ // directly from node_modules and the Angular modules loader won't be able to resolve the lazy routes
113
+ // fixes https://github.com/NativeScript/nativescript-cli/issues/4024
114
+ if (env.externals && env.externals.indexOf('@angular/core') > -1) {
115
+ const appModuleRelativePath = getMainModulePath(resolve(appFullPath, entryModule), tsConfigName);
116
+ if (appModuleRelativePath) {
117
+ const appModuleFolderPath = dirname(resolve(appFullPath, appModuleRelativePath));
118
+ // include the new lazy loader path in the allowed ones
119
+ additionalLazyModuleResources.push(appModuleFolderPath);
120
+ }
121
+ }
133
122
 
134
- // when "@angular/core" is external, it's not included in the bundles. In this way, it will be used
135
- // directly from node_modules and the Angular modules loader won't be able to resolve the lazy routes
136
- // fixes https://github.com/NativeScript/nativescript-cli/issues/4024
137
- if (env.externals && env.externals.indexOf('@angular/core') > -1) {
138
- const appModuleRelativePath = getMainModulePath(
139
- resolve(appFullPath, entryModule),
140
- tsConfigName
141
- );
142
- if (appModuleRelativePath) {
143
- const appModuleFolderPath = dirname(
144
- resolve(appFullPath, appModuleRelativePath)
145
- );
146
- // include the new lazy loader path in the allowed ones
147
- additionalLazyModuleResources.push(appModuleFolderPath);
148
- }
149
- }
123
+ const ngCompilerPlugin = new AngularCompilerPlugin({
124
+ hostReplacementPaths: nsWebpack.getResolver([platform, 'tns']),
125
+ platformTransformers: ngCompilerTransformers.map((t) => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule), projectRoot)),
126
+ mainPath: join(appFullPath, entryModule),
127
+ tsConfigPath,
128
+ skipCodeGeneration: false,
129
+ sourceMap: !!isAnySourceMapEnabled,
130
+ additionalLazyModuleResources: additionalLazyModuleResources,
131
+ compilerOptions: { paths: compilerOptions.paths },
132
+ });
150
133
 
151
- const ngCompilerPlugin = new AngularCompilerPlugin({
152
- hostReplacementPaths: nsWebpack.getResolver([platform, 'tns']),
153
- platformTransformers: ngCompilerTransformers.map(t =>
154
- t(() => ngCompilerPlugin, resolve(appFullPath, entryModule), projectRoot)
155
- ),
156
- mainPath: join(appFullPath, entryModule),
157
- tsConfigPath,
158
- skipCodeGeneration: false,
159
- sourceMap: !!isAnySourceMapEnabled,
160
- additionalLazyModuleResources: additionalLazyModuleResources,
161
- compilerOptions: { paths: compilerOptions.paths }
162
- });
134
+ let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);
163
135
 
164
- let sourceMapFilename = nsWebpack.getSourceMapFilename(
165
- hiddenSourceMap,
166
- __dirname,
167
- dist
168
- );
136
+ const itemsToClean = [`${dist}/**/*`];
137
+ if (platform === 'android') {
138
+ itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'assets', 'snapshots')}`);
139
+ itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'build', 'configurations', 'nativescript-android-snapshot')}`);
140
+ }
169
141
 
170
- const itemsToClean = [`${dist}/**/*`];
171
- if (platform === 'android') {
172
- itemsToClean.push(
173
- `${join(
174
- projectRoot,
175
- 'platforms',
176
- 'android',
177
- 'app',
178
- 'src',
179
- 'main',
180
- 'assets',
181
- 'snapshots'
182
- )}`
183
- );
184
- itemsToClean.push(
185
- `${join(
186
- projectRoot,
187
- 'platforms',
188
- 'android',
189
- 'app',
190
- 'build',
191
- 'configurations',
192
- 'nativescript-android-snapshot'
193
- )}`
194
- );
195
- }
142
+ const noEmitOnErrorFromTSConfig = getNoEmitOnErrorFromTSConfig(tsConfigName);
196
143
 
197
- const noEmitOnErrorFromTSConfig = getNoEmitOnErrorFromTSConfig(tsConfigName);
144
+ // Add your custom Activities, Services and other android app components here.
145
+ appComponents.push('@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity');
198
146
 
199
- nsWebpack.processAppComponents(appComponents, platform);
200
- const config = {
201
- mode: production ? 'production' : 'development',
202
- context: appFullPath,
203
- externals,
204
- watchOptions: {
205
- ignored: [
206
- appResourcesFullPath,
207
- // Don't watch hidden files
208
- '**/.*'
209
- ]
210
- },
211
- target: nativescriptTarget,
212
- entry: entries,
213
- output: {
214
- pathinfo: false,
215
- path: dist,
216
- sourceMapFilename,
217
- libraryTarget: 'commonjs2',
218
- filename: '[name].js',
219
- globalObject: 'global',
220
- hashSalt
221
- },
222
- resolve: {
223
- extensions: ['.ts', '.js', '.scss', '.css'],
224
- // Resolve {N} system modules from @nativescript/core
225
- modules: [
226
- resolve(__dirname, 'node_modules/@nativescript/core'),
227
- resolve(__dirname, 'node_modules'),
228
- 'node_modules/@nativescript/core',
229
- 'node_modules'
230
- ],
231
- alias: {
232
- '~/package.json': resolve(projectRoot, 'package.json'),
233
- '~': appFullPath,
234
- "tns-core-modules": "@nativescript/core",
235
- "nativescript-angular": "@nativescript/angular",
236
- ...fileReplacements
237
- },
238
- symlinks: true
239
- },
240
- resolveLoader: {
241
- symlinks: false
242
- },
243
- node: {
244
- // Disable node shims that conflict with NativeScript
245
- http: false,
246
- timers: false,
247
- setImmediate: false,
248
- fs: 'empty',
249
- __dirname: false
250
- },
251
- devtool: hiddenSourceMap
252
- ? 'hidden-source-map'
253
- : sourceMap
254
- ? 'inline-source-map'
255
- : 'none',
256
- optimization: {
257
- runtimeChunk: 'single',
258
- noEmitOnErrors: noEmitOnErrorFromTSConfig,
259
- splitChunks: {
260
- cacheGroups: {
261
- vendor: {
262
- name: 'vendor',
263
- chunks: 'all',
264
- test: (module, chunks) => {
265
- const moduleName = module.nameForCondition
266
- ? module.nameForCondition()
267
- : '';
268
- return (
269
- /[\\/]node_modules[\\/]/.test(moduleName) ||
270
- appComponents.some(comp => comp === moduleName)
271
- );
272
- },
273
- enforce: true
274
- }
275
- }
276
- },
277
- minimize: !!uglify,
278
- minimizer: [
279
- new TerserPlugin({
280
- parallel: true,
281
- cache: !ci,
282
- sourceMap: isAnySourceMapEnabled,
283
- terserOptions: {
284
- output: {
285
- comments: false,
286
- semicolons: !isAnySourceMapEnabled
287
- },
288
- compress: {
289
- // The Android SBG has problems parsing the output
290
- // when these options are enabled
291
- collapse_vars: platform !== 'android',
292
- sequences: platform !== 'android',
293
- // custom
294
- drop_console: true,
295
- drop_debugger: true,
296
- ecma: 6,
297
- keep_infinity: platform === 'android', // for Chrome/V8
298
- reduce_funcs: platform !== 'android', // for Chrome/V8
299
- global_defs: {
300
- __UGLIFIED__: true
301
- }
302
- },
303
- // custom
304
- ecma: 6,
305
- safari10: platform !== 'android'
306
- }
307
- })
308
- ]
309
- },
310
- module: {
311
- rules: [
312
- {
313
- include: join(appFullPath, entryPath),
314
- use: [
315
- // Require all Android app components
316
- platform === 'android' && {
317
- loader: '@nativescript/webpack/helpers/android-app-components-loader',
318
- options: { modules: appComponents }
319
- },
147
+ nsWebpack.processAppComponents(appComponents, platform);
148
+ const config = {
149
+ mode: production ? 'production' : 'development',
150
+ context: appFullPath,
151
+ externals,
152
+ watchOptions: {
153
+ ignored: [
154
+ appResourcesFullPath,
155
+ // Don't watch hidden files
156
+ '**/.*',
157
+ ],
158
+ },
159
+ target: nativescriptTarget,
160
+ entry: entries,
161
+ output: {
162
+ pathinfo: false,
163
+ path: dist,
164
+ sourceMapFilename,
165
+ libraryTarget: 'commonjs2',
166
+ filename: '[name].js',
167
+ globalObject: 'global',
168
+ hashSalt,
169
+ },
170
+ resolve: {
171
+ extensions: ['.ts', '.js', '.scss', '.css'],
172
+ // Resolve {N} system modules from @nativescript/core
173
+ modules: [resolve(__dirname, 'node_modules/@nativescript/core'), resolve(__dirname, 'node_modules'), 'node_modules/@nativescript/core', 'node_modules'],
174
+ alias: {
175
+ '~/package.json': resolve(projectRoot, 'package.json'),
176
+ '~': appFullPath,
177
+ 'tns-core-modules': '@nativescript/core',
178
+ 'nativescript-angular': '@nativescript/angular',
179
+ ...fileReplacements,
180
+ },
181
+ symlinks: true,
182
+ },
183
+ resolveLoader: {
184
+ symlinks: false,
185
+ },
186
+ node: {
187
+ // Disable node shims that conflict with NativeScript
188
+ http: false,
189
+ timers: false,
190
+ setImmediate: false,
191
+ fs: 'empty',
192
+ __dirname: false,
193
+ },
194
+ devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none',
195
+ optimization: {
196
+ runtimeChunk: 'single',
197
+ noEmitOnErrors: noEmitOnErrorFromTSConfig,
198
+ splitChunks: {
199
+ cacheGroups: {
200
+ vendor: {
201
+ name: 'vendor',
202
+ chunks: 'all',
203
+ test: (module, chunks) => {
204
+ const moduleName = module.nameForCondition ? module.nameForCondition() : '';
205
+ return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some((comp) => comp === moduleName);
206
+ },
207
+ enforce: true,
208
+ },
209
+ },
210
+ },
211
+ minimize: !!uglify,
212
+ minimizer: [
213
+ new TerserPlugin({
214
+ parallel: true,
215
+ cache: !ci,
216
+ sourceMap: isAnySourceMapEnabled,
217
+ terserOptions: {
218
+ output: {
219
+ comments: false,
220
+ semicolons: !isAnySourceMapEnabled,
221
+ },
222
+ compress: {
223
+ // The Android SBG has problems parsing the output
224
+ // when these options are enabled
225
+ collapse_vars: platform !== 'android',
226
+ sequences: platform !== 'android',
227
+ // For v8 Compatibility
228
+ keep_infinity: true, // for V8
229
+ reduce_funcs: false, // for V8
230
+ // custom
231
+ drop_console: production,
232
+ drop_debugger: true,
233
+ ecma: 6,
234
+ global_defs: {
235
+ __UGLIFIED__: true,
236
+ },
237
+ },
238
+ // Required for Element Level CSS, Observable Events, & Android Frame
239
+ keep_classnames: true,
240
+ // custom
241
+ ecma: 6,
242
+ safari10: platform !== 'android',
243
+ },
244
+ }),
245
+ ],
246
+ },
247
+ module: {
248
+ rules: [
249
+ {
250
+ include: join(appFullPath, entryPath),
251
+ use: [
252
+ // Require all Android app components
253
+ platform === 'android' && {
254
+ loader: '@nativescript/webpack/helpers/android-app-components-loader',
255
+ options: { modules: appComponents },
256
+ },
320
257
 
321
- {
322
- loader: '@nativescript/webpack/bundle-config-loader',
323
- options: {
324
- angular: true,
325
- loadCss: !snapshot, // load the application css if in debug mode
326
- unitTesting,
327
- appFullPath,
328
- projectRoot,
329
- ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform)
330
- }
331
- }
332
- ].filter(loader => !!loader)
333
- },
258
+ {
259
+ loader: '@nativescript/webpack/bundle-config-loader',
260
+ options: {
261
+ angular: true,
262
+ loadCss: !snapshot, // load the application css if in debug mode
263
+ unitTesting,
264
+ appFullPath,
265
+ projectRoot,
266
+ ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform),
267
+ },
268
+ },
269
+ ].filter((loader) => !!loader),
270
+ },
334
271
 
335
- { test: /\.html$|\.xml$/, use: 'raw-loader' },
272
+ { test: /\.html$|\.xml$/, use: 'raw-loader' },
336
273
 
337
- {
338
- test: /[\/|\\]app\.css$/,
339
- use: [
340
- '@nativescript/webpack/helpers/style-hot-loader',
341
- {
342
- loader: "@nativescript/webpack/helpers/css2json-loader",
343
- options: { useForImports: true }
344
- },
345
- ],
346
- },
347
- {
348
- test: /[\/|\\]app\.scss$/,
349
- use: [
350
- '@nativescript/webpack/helpers/style-hot-loader',
351
- {
352
- loader: "@nativescript/webpack/helpers/css2json-loader",
353
- options: { useForImports: true }
354
- },
355
- 'sass-loader',
356
- ],
357
- },
274
+ {
275
+ test: /[\/|\\]app\.css$/,
276
+ use: [
277
+ '@nativescript/webpack/helpers/style-hot-loader',
278
+ {
279
+ loader: '@nativescript/webpack/helpers/css2json-loader',
280
+ options: { useForImports: true },
281
+ },
282
+ ],
283
+ },
284
+ {
285
+ test: /[\/|\\]app\.scss$/,
286
+ use: [
287
+ '@nativescript/webpack/helpers/style-hot-loader',
288
+ {
289
+ loader: '@nativescript/webpack/helpers/css2json-loader',
290
+ options: { useForImports: true },
291
+ },
292
+ 'sass-loader',
293
+ ],
294
+ },
358
295
 
359
- // Angular components reference css files and their imports using raw-loader
360
- { test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: 'raw-loader' },
361
- {
362
- test: /\.scss$/,
363
- exclude: /[\/|\\]app\.scss$/,
364
- use: ['raw-loader', 'resolve-url-loader', 'sass-loader']
365
- },
296
+ // Angular components reference css files and their imports using raw-loader
297
+ { test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: 'raw-loader' },
298
+ {
299
+ test: /\.scss$/,
300
+ exclude: /[\/|\\]app\.scss$/,
301
+ use: ['raw-loader', 'resolve-url-loader', 'sass-loader'],
302
+ },
366
303
 
367
- {
368
- test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
369
- use: [
370
- '@nativescript/webpack/helpers/moduleid-compat-loader',
371
- '@nativescript/webpack/helpers/lazy-ngmodule-hot-loader',
372
- '@ngtools/webpack'
373
- ]
374
- },
304
+ {
305
+ test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
306
+ use: ['@nativescript/webpack/helpers/moduleid-compat-loader', '@nativescript/webpack/helpers/lazy-ngmodule-hot-loader', '@ngtools/webpack'],
307
+ },
375
308
 
376
- // Mark files inside `@angular/core` as using SystemJS style dynamic imports.
377
- // Removing this will cause deprecation warnings to appear.
378
- {
379
- test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/,
380
- parser: { system: true }
381
- }
382
- ]
383
- },
384
- plugins: [
385
- // Define useful constants like TNS_WEBPACK
386
- new webpack.DefinePlugin({
387
- 'global.TNS_WEBPACK': 'true',
388
- 'global.isAndroid': platform === 'android',
389
- 'global.isIOS': platform === 'ios',
390
- process: 'global.process'
391
- }),
392
- // Remove all files from the out dir.
393
- new CleanWebpackPlugin({
394
- cleanOnceBeforeBuildPatterns: itemsToClean,
395
- verbose: !!verbose
396
- }),
397
- // Copy assets
398
- new CopyWebpackPlugin([
399
- ...copyTargets,
400
- { from: { glob: '**/*.jpg', dot: false } },
401
- { from: { glob: '**/*.png', dot: false } },
402
- ], copyIgnore),
403
- new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'),
404
- // For instructions on how to set up workers with webpack
405
- // check out https://github.com/nativescript/worker-loader
406
- new NativeScriptWorkerPlugin(),
407
- ngCompilerPlugin,
408
- // Does IPC communication with the {N} CLI to notify events when running in watch mode.
409
- new nsWebpack.WatchStateLoggerPlugin()
410
- ]
411
- };
309
+ // Mark files inside `@angular/core` as using SystemJS style dynamic imports.
310
+ // Removing this will cause deprecation warnings to appear.
311
+ {
312
+ test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/,
313
+ parser: { system: true },
314
+ },
315
+ ],
316
+ },
317
+ plugins: [
318
+ // Define useful constants like TNS_WEBPACK
319
+ new webpack.DefinePlugin({
320
+ 'global.TNS_WEBPACK': 'true',
321
+ 'global.isAndroid': platform === 'android',
322
+ 'global.isIOS': platform === 'ios',
323
+ process: 'global.process',
324
+ }),
325
+ // Remove all files from the out dir.
326
+ new CleanWebpackPlugin({
327
+ cleanOnceBeforeBuildPatterns: itemsToClean,
328
+ verbose: !!verbose,
329
+ }),
330
+ // Copy assets
331
+ new CopyWebpackPlugin([...copyTargets, { from: { glob: '**/*.jpg', dot: false } }, { from: { glob: '**/*.png', dot: false } }], copyIgnore),
332
+ new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'),
333
+ // For instructions on how to set up workers with webpack
334
+ // check out https://github.com/nativescript/worker-loader
335
+ new NativeScriptWorkerPlugin(),
336
+ ngCompilerPlugin,
337
+ // Does IPC communication with the {N} CLI to notify events when running in watch mode.
338
+ new nsWebpack.WatchStateLoggerPlugin(),
339
+ ],
340
+ };
412
341
 
413
- if (report) {
414
- // Generate report files for bundles content
415
- config.plugins.push(
416
- new BundleAnalyzerPlugin({
417
- analyzerMode: 'static',
418
- openAnalyzer: false,
419
- generateStatsFile: true,
420
- reportFilename: resolve(projectRoot, 'report', `report.html`),
421
- statsFilename: resolve(projectRoot, 'report', `stats.json`)
422
- })
423
- );
424
- }
342
+ if (report) {
343
+ // Generate report files for bundles content
344
+ config.plugins.push(
345
+ new BundleAnalyzerPlugin({
346
+ analyzerMode: 'static',
347
+ openAnalyzer: false,
348
+ generateStatsFile: true,
349
+ reportFilename: resolve(projectRoot, 'report', `report.html`),
350
+ statsFilename: resolve(projectRoot, 'report', `stats.json`),
351
+ })
352
+ );
353
+ }
425
354
 
426
- if (snapshot) {
427
- config.plugins.push(
428
- new nsWebpack.NativeScriptSnapshotPlugin({
429
- chunk: 'vendor',
430
- angular: true,
431
- requireModules: [
432
- 'reflect-metadata',
433
- '@angular/platform-browser',
434
- '@angular/core',
435
- '@angular/common',
436
- '@angular/router',
437
- '@nativescript/angular'
438
- ],
439
- projectRoot,
440
- webpackConfig: config,
441
- snapshotInDocker,
442
- skipSnapshotTools,
443
- useLibs
444
- })
445
- );
446
- }
355
+ if (snapshot) {
356
+ config.plugins.push(
357
+ new nsWebpack.NativeScriptSnapshotPlugin({
358
+ chunk: 'vendor',
359
+ angular: true,
360
+ requireModules: ['reflect-metadata', '@angular/platform-browser', '@angular/core', '@angular/common', '@angular/router', '@nativescript/angular'],
361
+ projectRoot,
362
+ webpackConfig: config,
363
+ snapshotInDocker,
364
+ skipSnapshotTools,
365
+ useLibs,
366
+ })
367
+ );
368
+ }
447
369
 
448
- if (!production && hmr) {
449
- config.plugins.push(new webpack.HotModuleReplacementPlugin());
450
- }
370
+ if (!production && hmr) {
371
+ config.plugins.push(new webpack.HotModuleReplacementPlugin());
372
+ }
451
373
 
452
- return config;
453
- };
374
+ return config;
375
+ };