@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.
- package/helpers/angular-config-parser.js +31 -24
- package/host/resolver.js +0 -9
- package/host/resolver.js.map +1 -1
- package/package.json +1 -1
- package/templates/webpack.angular.js +335 -413
- package/templates/webpack.javascript.js +263 -267
- package/templates/webpack.react.js +73 -74
- package/templates/webpack.svelte.js +131 -137
- package/templates/webpack.typescript.js +299 -305
- package/templates/webpack.vue.js +326 -337
|
@@ -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
|
-
|
|
9
|
-
} = require('@nativescript/webpack/
|
|
10
|
-
const {
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
throw new Error('You need to provide a target platform!');
|
|
39
|
-
}
|
|
26
|
+
const AngularCompilerPlugin = getAngularCompilerPlugin(platform);
|
|
27
|
+
const projectRoot = __dirname;
|
|
40
28
|
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
// Default destination inside platforms/<platform>/...
|
|
30
|
+
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
|
|
43
31
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
nsWebpack.processTsPathsForScopedAngular({ compilerOptions });
|
|
95
|
+
const ngCompilerTransformers = [nsTransformNativeClassesNg];
|
|
96
|
+
const additionalLazyModuleResources = [];
|
|
113
97
|
|
|
114
|
-
|
|
115
|
-
|
|
98
|
+
const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] };
|
|
99
|
+
const copyTargets = [{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, ...copyReplacements];
|
|
116
100
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
106
|
+
if (hmr) {
|
|
107
|
+
ngCompilerTransformers.push(nsSupportHmrNg);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
128
110
|
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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
|
-
|
|
272
|
+
{ test: /\.html$|\.xml$/, use: 'raw-loader' },
|
|
336
273
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
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
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
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
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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
|
-
|
|
449
|
-
|
|
450
|
-
|
|
370
|
+
if (!production && hmr) {
|
|
371
|
+
config.plugins.push(new webpack.HotModuleReplacementPlugin());
|
|
372
|
+
}
|
|
451
373
|
|
|
452
|
-
|
|
453
|
-
};
|
|
374
|
+
return config;
|
|
375
|
+
};
|