@nativescript/webpack 4.0.1 → 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/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
|
@@ -1,338 +1,332 @@
|
|
|
1
|
-
const { join, relative, resolve, sep } = require(
|
|
1
|
+
const { join, relative, resolve, sep } = require('path');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
|
|
4
|
-
const webpack = require(
|
|
5
|
-
const nsWebpack = require(
|
|
6
|
-
const nativescriptTarget = require(
|
|
7
|
-
const { getNoEmitOnErrorFromTSConfig } = require(
|
|
8
|
-
const { CleanWebpackPlugin } = require(
|
|
9
|
-
const CopyWebpackPlugin = require(
|
|
4
|
+
const webpack = require('webpack');
|
|
5
|
+
const nsWebpack = require('@nativescript/webpack');
|
|
6
|
+
const nativescriptTarget = require('@nativescript/webpack/nativescript-target');
|
|
7
|
+
const { getNoEmitOnErrorFromTSConfig } = require('@nativescript/webpack/utils/tsconfig-utils');
|
|
8
|
+
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
9
|
+
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
10
10
|
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
|
11
|
-
const { BundleAnalyzerPlugin } = require(
|
|
12
|
-
const { NativeScriptWorkerPlugin } = require(
|
|
13
|
-
const TerserPlugin = require(
|
|
11
|
+
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
|
12
|
+
const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeScriptWorkerPlugin');
|
|
13
|
+
const TerserPlugin = require('terser-webpack-plugin');
|
|
14
14
|
const hashSalt = Date.now().toString();
|
|
15
15
|
|
|
16
|
-
module.exports = env => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"@nativescript/core/ui/frame/activity",
|
|
22
|
-
]);
|
|
16
|
+
module.exports = (env) => {
|
|
17
|
+
const platform = env && ((env.android && 'android') || (env.ios && 'ios') || env.platform);
|
|
18
|
+
if (!platform) {
|
|
19
|
+
throw new Error('You need to provide a target platform!');
|
|
20
|
+
}
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
throw new Error("You need to provide a target platform!");
|
|
27
|
-
}
|
|
22
|
+
const platforms = ['ios', 'android'];
|
|
23
|
+
const projectRoot = __dirname;
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
if (env.platform) {
|
|
26
|
+
platforms.push(env.platform);
|
|
27
|
+
}
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
29
|
+
// Default destination inside platforms/<platform>/...
|
|
30
|
+
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
const {
|
|
33
|
+
// The 'appPath' and 'appResourcesPath' values are fetched from
|
|
34
|
+
// the nsconfig.json configuration file.
|
|
35
|
+
appPath = 'src',
|
|
36
|
+
appResourcesPath = 'App_Resources',
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
// You can provide the following flags when running 'tns run android|ios'
|
|
39
|
+
snapshot, // --env.snapshot
|
|
40
|
+
production, // --env.production
|
|
41
|
+
uglify, // --env.uglify
|
|
42
|
+
report, // --env.report
|
|
43
|
+
sourceMap, // --env.sourceMap
|
|
44
|
+
hiddenSourceMap, // --env.hiddenSourceMap
|
|
45
|
+
hmr, // --env.hmr,
|
|
46
|
+
unitTesting, // --env.unitTesting,
|
|
47
|
+
testing, // --env.testing
|
|
48
|
+
verbose, // --env.verbose
|
|
49
|
+
ci, // --env.ci
|
|
50
|
+
snapshotInDocker, // --env.snapshotInDocker
|
|
51
|
+
skipSnapshotTools, // --env.skipSnapshotTools
|
|
52
|
+
compileSnapshot, // --env.compileSnapshot
|
|
53
|
+
appComponents = [],
|
|
54
|
+
entries = {},
|
|
55
|
+
} = env;
|
|
44
56
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
uglify, // --env.uglify
|
|
49
|
-
report, // --env.report
|
|
50
|
-
sourceMap, // --env.sourceMap
|
|
51
|
-
hiddenSourceMap, // --env.hiddenSourceMap
|
|
52
|
-
hmr, // --env.hmr,
|
|
53
|
-
unitTesting, // --env.unitTesting,
|
|
54
|
-
testing, // --env.testing
|
|
55
|
-
verbose, // --env.verbose
|
|
56
|
-
snapshotInDocker, // --env.snapshotInDocker
|
|
57
|
-
skipSnapshotTools, // --env.skipSnapshotTools
|
|
58
|
-
compileSnapshot // --env.compileSnapshot
|
|
59
|
-
} = env;
|
|
57
|
+
const useLibs = compileSnapshot;
|
|
58
|
+
const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap;
|
|
59
|
+
const externals = nsWebpack.getConvertedExternals(env.externals);
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
let appFullPath = resolve(projectRoot, appPath);
|
|
62
|
+
if (!fs.existsSync(appFullPath)) {
|
|
63
|
+
// some apps use 'app' directory
|
|
64
|
+
appFullPath = resolve(projectRoot, 'app');
|
|
65
|
+
}
|
|
66
|
+
const hasRootLevelScopedModules = nsWebpack.hasRootLevelScopedModules({ projectDir: projectRoot });
|
|
67
|
+
let coreModulesPackageName = 'tns-core-modules';
|
|
68
|
+
const alias = env.alias || {};
|
|
69
|
+
alias['~/package.json'] = resolve(projectRoot, 'package.json');
|
|
70
|
+
alias['~'] = appFullPath;
|
|
64
71
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const hasRootLevelScopedModules = nsWebpack.hasRootLevelScopedModules({ projectDir: projectRoot });
|
|
71
|
-
let coreModulesPackageName = "tns-core-modules";
|
|
72
|
-
const alias = env.alias || {};
|
|
73
|
-
alias['~/package.json'] = resolve(projectRoot, 'package.json');
|
|
74
|
-
alias['~'] = appFullPath;
|
|
72
|
+
if (hasRootLevelScopedModules) {
|
|
73
|
+
coreModulesPackageName = '@nativescript/core';
|
|
74
|
+
alias['tns-core-modules'] = coreModulesPackageName;
|
|
75
|
+
}
|
|
76
|
+
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
coreModulesPackageName = "@nativescript/core";
|
|
78
|
-
alias["tns-core-modules"] = coreModulesPackageName;
|
|
79
|
-
}
|
|
80
|
-
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
|
|
78
|
+
const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] };
|
|
81
79
|
|
|
82
|
-
|
|
80
|
+
const entryModule = nsWebpack.getEntryModule(appFullPath, platform);
|
|
81
|
+
const entryPath = `.${sep}${entryModule}.ts`;
|
|
82
|
+
Object.assign(entries, { bundle: entryPath }, entries);
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
const entryPath = `.${sep}${entryModule}.ts`;
|
|
86
|
-
const entries = env.entries || {};
|
|
87
|
-
entries.bundle = entryPath;
|
|
84
|
+
const tsConfigPath = resolve(projectRoot, 'tsconfig.json');
|
|
88
85
|
|
|
89
|
-
|
|
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
|
+
}
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
if (platform === "ios" && !areCoreModulesExternal && !testing) {
|
|
93
|
-
entries["tns_modules/@nativescript/core/inspector_modules"] = "inspector_modules";
|
|
94
|
-
};
|
|
91
|
+
let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);
|
|
95
92
|
|
|
96
|
-
|
|
93
|
+
const itemsToClean = [`${dist}/**/*`];
|
|
94
|
+
if (platform === 'android') {
|
|
95
|
+
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'assets', 'snapshots')}`);
|
|
96
|
+
itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'build', 'configurations', 'nativescript-android-snapshot')}`);
|
|
97
|
+
}
|
|
97
98
|
|
|
98
|
-
|
|
99
|
-
if (platform === "android") {
|
|
100
|
-
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "src", "main", "assets", "snapshots")}`);
|
|
101
|
-
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`);
|
|
102
|
-
}
|
|
99
|
+
const noEmitOnErrorFromTSConfig = getNoEmitOnErrorFromTSConfig(tsConfigPath);
|
|
103
100
|
|
|
104
|
-
|
|
101
|
+
// Add your custom Activities, Services and other android app components here.
|
|
102
|
+
appComponents.push('@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity');
|
|
105
103
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
104
|
+
nsWebpack.processAppComponents(appComponents, platform);
|
|
105
|
+
const config = {
|
|
106
|
+
mode: production ? 'production' : 'development',
|
|
107
|
+
context: appFullPath,
|
|
108
|
+
externals,
|
|
109
|
+
watchOptions: {
|
|
110
|
+
ignored: [
|
|
111
|
+
appResourcesFullPath,
|
|
112
|
+
// Don't watch hidden files
|
|
113
|
+
'**/.*',
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
target: nativescriptTarget,
|
|
117
|
+
entry: entries,
|
|
118
|
+
output: {
|
|
119
|
+
pathinfo: false,
|
|
120
|
+
path: dist,
|
|
121
|
+
sourceMapFilename,
|
|
122
|
+
libraryTarget: 'commonjs2',
|
|
123
|
+
filename: '[name].js',
|
|
124
|
+
globalObject: 'global',
|
|
125
|
+
hashSalt,
|
|
126
|
+
},
|
|
127
|
+
resolve: {
|
|
128
|
+
extensions: ['.ts', '.js', '.scss', '.css'],
|
|
129
|
+
// Resolve {N} system modules from @nativescript/core
|
|
130
|
+
modules: [resolve(__dirname, `node_modules/${coreModulesPackageName}`), resolve(__dirname, 'node_modules'), `node_modules/${coreModulesPackageName}`, 'node_modules'],
|
|
131
|
+
alias,
|
|
132
|
+
// resolve symlinks to symlinked modules
|
|
133
|
+
symlinks: true,
|
|
134
|
+
},
|
|
135
|
+
resolveLoader: {
|
|
136
|
+
// don't resolve symlinks to symlinked loaders
|
|
137
|
+
symlinks: false,
|
|
138
|
+
},
|
|
139
|
+
node: {
|
|
140
|
+
// Disable node shims that conflict with NativeScript
|
|
141
|
+
http: false,
|
|
142
|
+
timers: false,
|
|
143
|
+
setImmediate: false,
|
|
144
|
+
fs: 'empty',
|
|
145
|
+
__dirname: false,
|
|
146
|
+
},
|
|
147
|
+
devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none',
|
|
148
|
+
optimization: {
|
|
149
|
+
runtimeChunk: 'single',
|
|
150
|
+
noEmitOnErrors: noEmitOnErrorFromTSConfig,
|
|
151
|
+
splitChunks: {
|
|
152
|
+
cacheGroups: {
|
|
153
|
+
vendor: {
|
|
154
|
+
name: 'vendor',
|
|
155
|
+
chunks: 'all',
|
|
156
|
+
test: (module, chunks) => {
|
|
157
|
+
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
|
|
158
|
+
return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some((comp) => comp === moduleName);
|
|
159
|
+
},
|
|
160
|
+
enforce: true,
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
minimize: !!uglify,
|
|
165
|
+
minimizer: [
|
|
166
|
+
new TerserPlugin({
|
|
167
|
+
parallel: true,
|
|
168
|
+
cache: !ci,
|
|
169
|
+
sourceMap: isAnySourceMapEnabled,
|
|
170
|
+
terserOptions: {
|
|
171
|
+
output: {
|
|
172
|
+
comments: false,
|
|
173
|
+
semicolons: !isAnySourceMapEnabled,
|
|
174
|
+
},
|
|
175
|
+
compress: {
|
|
176
|
+
// The Android SBG has problems parsing the output
|
|
177
|
+
// when these options are enabled
|
|
178
|
+
collapse_vars: platform !== 'android',
|
|
179
|
+
sequences: platform !== 'android',
|
|
180
|
+
// For v8 Compatibility
|
|
181
|
+
keep_infinity: true, // for V8
|
|
182
|
+
reduce_funcs: false, // for V8
|
|
183
|
+
// custom
|
|
184
|
+
drop_console: production,
|
|
185
|
+
drop_debugger: true,
|
|
186
|
+
global_defs: {
|
|
187
|
+
__UGLIFIED__: true,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
// Required for Element Level CSS, Observable Events, & Android Frame
|
|
191
|
+
keep_classnames: true,
|
|
192
|
+
},
|
|
193
|
+
}),
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
module: {
|
|
197
|
+
rules: [
|
|
198
|
+
{
|
|
199
|
+
include: join(appFullPath, entryPath),
|
|
200
|
+
use: [
|
|
201
|
+
// Require all Android app components
|
|
202
|
+
platform === 'android' && {
|
|
203
|
+
loader: '@nativescript/webpack/helpers/android-app-components-loader',
|
|
204
|
+
options: { modules: appComponents },
|
|
205
|
+
},
|
|
167
206
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
output: {
|
|
181
|
-
comments: false,
|
|
182
|
-
semicolons: !isAnySourceMapEnabled
|
|
183
|
-
},
|
|
184
|
-
compress: {
|
|
185
|
-
// The Android SBG has problems parsing the output
|
|
186
|
-
// when these options are enabled
|
|
187
|
-
'collapse_vars': platform !== "android",
|
|
188
|
-
sequences: platform !== "android",
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
})
|
|
192
|
-
],
|
|
193
|
-
},
|
|
194
|
-
module: {
|
|
195
|
-
rules: [
|
|
196
|
-
{
|
|
197
|
-
include: join(appFullPath, entryPath),
|
|
198
|
-
use: [
|
|
199
|
-
// Require all Android app components
|
|
200
|
-
platform === "android" && {
|
|
201
|
-
loader: "@nativescript/webpack/helpers/android-app-components-loader",
|
|
202
|
-
options: { modules: appComponents }
|
|
203
|
-
},
|
|
207
|
+
{
|
|
208
|
+
loader: '@nativescript/webpack/bundle-config-loader',
|
|
209
|
+
options: {
|
|
210
|
+
loadCss: !snapshot, // load the application css if in debug mode
|
|
211
|
+
unitTesting,
|
|
212
|
+
appFullPath,
|
|
213
|
+
projectRoot,
|
|
214
|
+
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform),
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
].filter((loader) => !!loader),
|
|
218
|
+
},
|
|
204
219
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
unitTesting,
|
|
210
|
-
appFullPath,
|
|
211
|
-
projectRoot,
|
|
212
|
-
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform)
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
].filter(loader => !!loader)
|
|
216
|
-
},
|
|
220
|
+
{
|
|
221
|
+
test: /\.(ts|css|scss|html|xml)$/,
|
|
222
|
+
use: '@nativescript/webpack/hmr/hot-loader',
|
|
223
|
+
},
|
|
217
224
|
|
|
218
|
-
|
|
219
|
-
test: /\.(ts|css|scss|html|xml)$/,
|
|
220
|
-
use: "@nativescript/webpack/hmr/hot-loader"
|
|
221
|
-
},
|
|
225
|
+
{ test: /\.(html|xml)$/, use: '@nativescript/webpack/helpers/xml-namespace-loader' },
|
|
222
226
|
|
|
223
|
-
|
|
227
|
+
{
|
|
228
|
+
test: /\.css$/,
|
|
229
|
+
use: '@nativescript/webpack/helpers/css2json-loader',
|
|
230
|
+
},
|
|
224
231
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
232
|
+
{
|
|
233
|
+
test: /\.scss$/,
|
|
234
|
+
use: ['@nativescript/webpack/helpers/css2json-loader', 'sass-loader'],
|
|
235
|
+
},
|
|
229
236
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
+
{
|
|
238
|
+
test: /\.ts$/,
|
|
239
|
+
use: {
|
|
240
|
+
loader: 'ts-loader',
|
|
241
|
+
options: {
|
|
242
|
+
configFile: tsConfigPath,
|
|
243
|
+
// https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#faster-builds
|
|
244
|
+
// https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#hot-module-replacement
|
|
245
|
+
transpileOnly: true,
|
|
246
|
+
allowTsInNodeModules: true,
|
|
247
|
+
compilerOptions: {
|
|
248
|
+
sourceMap: isAnySourceMapEnabled,
|
|
249
|
+
declaration: false,
|
|
250
|
+
},
|
|
251
|
+
getCustomTransformers: (program) => ({
|
|
252
|
+
before: [require('@nativescript/webpack/transformers/ns-transform-native-classes').default],
|
|
253
|
+
}),
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
},
|
|
259
|
+
plugins: [
|
|
260
|
+
// Define useful constants like TNS_WEBPACK
|
|
261
|
+
new webpack.DefinePlugin({
|
|
262
|
+
'global.TNS_WEBPACK': 'true',
|
|
263
|
+
'global.isAndroid': platform === 'android',
|
|
264
|
+
'global.isIOS': platform === 'ios',
|
|
265
|
+
process: 'global.process',
|
|
266
|
+
}),
|
|
267
|
+
// Remove all files from the out dir.
|
|
268
|
+
new CleanWebpackPlugin({
|
|
269
|
+
cleanOnceBeforeBuildPatterns: itemsToClean,
|
|
270
|
+
verbose: !!verbose,
|
|
271
|
+
}),
|
|
272
|
+
// Copy assets
|
|
273
|
+
new CopyWebpackPlugin([{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, { from: { glob: '**/*.jpg', dot: false } }, { from: { glob: '**/*.png', dot: false } }], copyIgnore),
|
|
274
|
+
new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'),
|
|
275
|
+
// For instructions on how to set up workers with webpack
|
|
276
|
+
// check out https://github.com/nativescript/worker-loader
|
|
277
|
+
new NativeScriptWorkerPlugin(),
|
|
278
|
+
new nsWebpack.PlatformFSPlugin({
|
|
279
|
+
platform,
|
|
280
|
+
platforms,
|
|
281
|
+
}),
|
|
282
|
+
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
|
|
283
|
+
new nsWebpack.WatchStateLoggerPlugin(),
|
|
284
|
+
// https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#faster-builds
|
|
285
|
+
// https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#hot-module-replacement
|
|
286
|
+
new ForkTsCheckerWebpackPlugin({
|
|
287
|
+
async: false,
|
|
288
|
+
typescript: {
|
|
289
|
+
configFile: tsConfigPath,
|
|
290
|
+
memoryLimit: 4096,
|
|
291
|
+
diagnosticOptions: {
|
|
292
|
+
syntactic: true,
|
|
293
|
+
semantic: true,
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
}),
|
|
297
|
+
],
|
|
298
|
+
};
|
|
237
299
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
declaration: false
|
|
251
|
-
},
|
|
252
|
-
getCustomTransformers: (program) => ({
|
|
253
|
-
before: [
|
|
254
|
-
require("@nativescript/webpack/transformers/ns-transform-native-classes").default
|
|
255
|
-
]
|
|
256
|
-
})
|
|
257
|
-
},
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
]
|
|
261
|
-
},
|
|
262
|
-
plugins: [
|
|
263
|
-
// Define useful constants like TNS_WEBPACK
|
|
264
|
-
new webpack.DefinePlugin({
|
|
265
|
-
"global.TNS_WEBPACK": "true",
|
|
266
|
-
"global.isAndroid": platform === 'android',
|
|
267
|
-
"global.isIOS": platform === 'ios',
|
|
268
|
-
"process": "global.process",
|
|
269
|
-
}),
|
|
270
|
-
// Remove all files from the out dir.
|
|
271
|
-
new CleanWebpackPlugin({
|
|
272
|
-
cleanOnceBeforeBuildPatterns: itemsToClean,
|
|
273
|
-
verbose: !!verbose
|
|
274
|
-
}),
|
|
275
|
-
// Copy assets
|
|
276
|
-
new CopyWebpackPlugin([
|
|
277
|
-
{ from: { glob: 'assets/**', dot: false } },
|
|
278
|
-
{ from: { glob: 'fonts/**', dot: false } },
|
|
279
|
-
{ from: { glob: '**/*.jpg', dot: false } },
|
|
280
|
-
{ from: { glob: '**/*.png', dot: false } },
|
|
281
|
-
], copyIgnore),
|
|
282
|
-
new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),
|
|
283
|
-
// For instructions on how to set up workers with webpack
|
|
284
|
-
// check out https://github.com/nativescript/worker-loader
|
|
285
|
-
new NativeScriptWorkerPlugin(),
|
|
286
|
-
new nsWebpack.PlatformFSPlugin({
|
|
287
|
-
platform,
|
|
288
|
-
platforms,
|
|
289
|
-
}),
|
|
290
|
-
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
|
|
291
|
-
new nsWebpack.WatchStateLoggerPlugin(),
|
|
292
|
-
// https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#faster-builds
|
|
293
|
-
// https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#hot-module-replacement
|
|
294
|
-
new ForkTsCheckerWebpackPlugin({
|
|
295
|
-
async: false,
|
|
296
|
-
typescript: {
|
|
297
|
-
configFile: tsConfigPath,
|
|
298
|
-
memoryLimit: 4096,
|
|
299
|
-
diagnosticOptions: {
|
|
300
|
-
syntactic: true,
|
|
301
|
-
semantic: true
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
})
|
|
305
|
-
],
|
|
306
|
-
};
|
|
300
|
+
if (report) {
|
|
301
|
+
// Generate report files for bundles content
|
|
302
|
+
config.plugins.push(
|
|
303
|
+
new BundleAnalyzerPlugin({
|
|
304
|
+
analyzerMode: 'static',
|
|
305
|
+
openAnalyzer: false,
|
|
306
|
+
generateStatsFile: true,
|
|
307
|
+
reportFilename: resolve(projectRoot, 'report', `report.html`),
|
|
308
|
+
statsFilename: resolve(projectRoot, 'report', `stats.json`),
|
|
309
|
+
})
|
|
310
|
+
);
|
|
311
|
+
}
|
|
307
312
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
313
|
+
if (snapshot) {
|
|
314
|
+
config.plugins.push(
|
|
315
|
+
new nsWebpack.NativeScriptSnapshotPlugin({
|
|
316
|
+
chunk: 'vendor',
|
|
317
|
+
requireModules: ['@nativescript/core/bundle-entry-points'],
|
|
318
|
+
projectRoot,
|
|
319
|
+
webpackConfig: config,
|
|
320
|
+
snapshotInDocker,
|
|
321
|
+
skipSnapshotTools,
|
|
322
|
+
useLibs,
|
|
323
|
+
})
|
|
324
|
+
);
|
|
325
|
+
}
|
|
318
326
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
requireModules: [
|
|
323
|
-
"@nativescript/core/bundle-entry-points",
|
|
324
|
-
],
|
|
325
|
-
projectRoot,
|
|
326
|
-
webpackConfig: config,
|
|
327
|
-
snapshotInDocker,
|
|
328
|
-
skipSnapshotTools,
|
|
329
|
-
useLibs
|
|
330
|
-
}));
|
|
331
|
-
}
|
|
327
|
+
if (hmr) {
|
|
328
|
+
config.plugins.push(new webpack.HotModuleReplacementPlugin());
|
|
329
|
+
}
|
|
332
330
|
|
|
333
|
-
|
|
334
|
-
config.plugins.push(new webpack.HotModuleReplacementPlugin());
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return config;
|
|
331
|
+
return config;
|
|
338
332
|
};
|