Skip to content

Commit 35f0c08

Browse files
chore: migrate deps to 6.0.0
1 parent 26c902b commit 35f0c08

5 files changed

Lines changed: 365 additions & 41 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig",
3+
"compilerOptions": {
4+
"module": "es2015",
5+
"moduleResolution": "node"
6+
}
7+
}
Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
const { join, relative, resolve, sep, dirname } = require("path");
2+
3+
const webpack = require("webpack");
4+
const nsWebpack = require("nativescript-dev-webpack");
5+
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
6+
const { nsReplaceBootstrap } = require("nativescript-dev-webpack/transformers/ns-replace-bootstrap");
7+
const { nsReplaceLazyLoader } = require("nativescript-dev-webpack/transformers/ns-replace-lazy-loader");
8+
const { nsSupportHmrNg } = require("nativescript-dev-webpack/transformers/ns-support-hmr-ng");
9+
const { getMainModulePath } = require("nativescript-dev-webpack/utils/ast-utils");
10+
const CleanWebpackPlugin = require("clean-webpack-plugin");
11+
const CopyWebpackPlugin = require("copy-webpack-plugin");
12+
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
13+
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
14+
const TerserPlugin = require("terser-webpack-plugin");
15+
const { getAngularCompilerPlugin } = require("nativescript-dev-webpack/plugins/NativeScriptAngularCompilerPlugin");
16+
const hashSalt = Date.now().toString();
17+
18+
module.exports = env => {
19+
// Add your custom Activities, Services and other Android app components here.
20+
const appComponents = [
21+
"tns-core-modules/ui/frame",
22+
"tns-core-modules/ui/frame/activity",
23+
];
24+
25+
const platform = env && (env.android && "android" || env.ios && "ios");
26+
if (!platform) {
27+
throw new Error("You need to provide a target platform!");
28+
}
29+
30+
const AngularCompilerPlugin = getAngularCompilerPlugin(platform);
31+
const projectRoot = __dirname;
32+
33+
// Default destination inside platforms/<platform>/...
34+
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
35+
const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";
36+
37+
const {
38+
// The 'appPath' and 'appResourcesPath' values are fetched from
39+
// the nsconfig.json configuration file
40+
// when bundling with `tns run android|ios --bundle`.
41+
appPath = "src",
42+
appResourcesPath = "App_Resources",
43+
44+
// You can provide the following flags when running 'tns run android|ios'
45+
aot, // --env.aot
46+
snapshot, // --env.snapshot
47+
uglify, // --env.uglify
48+
report, // --env.report
49+
sourceMap, // --env.sourceMap
50+
hiddenSourceMap, // --env.hiddenSourceMap
51+
hmr, // --env.hmr,
52+
unitTesting, // --env.unitTesting
53+
} = env;
54+
55+
const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap;
56+
const externals = nsWebpack.getConvertedExternals(env.externals);
57+
const appFullPath = resolve(projectRoot, appPath);
58+
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
59+
const tsConfigName = "tsconfig.tns.json";
60+
const entryModule = `${nsWebpack.getEntryModule(appFullPath, platform)}.ts`;
61+
const entryPath = `.${sep}${entryModule}`;
62+
const entries = { bundle: entryPath };
63+
if (platform === "ios") {
64+
entries["tns_modules/tns-core-modules/inspector_modules"] = "inspector_modules.js";
65+
};
66+
67+
const ngCompilerTransformers = [];
68+
const additionalLazyModuleResources = [];
69+
if (aot) {
70+
ngCompilerTransformers.push(nsReplaceBootstrap);
71+
}
72+
73+
if (hmr) {
74+
ngCompilerTransformers.push(nsSupportHmrNg);
75+
}
76+
77+
// when "@angular/core" is external, it's not included in the bundles. In this way, it will be used
78+
// directly from node_modules and the Angular modules loader won't be able to resolve the lazy routes
79+
// fixes https://github.com/NativeScript/nativescript-cli/issues/4024
80+
if (env.externals && env.externals.indexOf("@angular/core") > -1) {
81+
const appModuleRelativePath = getMainModulePath(resolve(appFullPath, entryModule), tsConfigName);
82+
if (appModuleRelativePath) {
83+
const appModuleFolderPath = dirname(resolve(appFullPath, appModuleRelativePath));
84+
// include the lazy loader inside app module
85+
ngCompilerTransformers.push(nsReplaceLazyLoader);
86+
// include the new lazy loader path in the allowed ones
87+
additionalLazyModuleResources.push(appModuleFolderPath);
88+
}
89+
}
90+
91+
const ngCompilerPlugin = new AngularCompilerPlugin({
92+
hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
93+
platformTransformers: ngCompilerTransformers.map(t => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule), projectRoot)),
94+
mainPath: join(appFullPath, entryModule),
95+
tsConfigPath: join(__dirname, tsConfigName),
96+
skipCodeGeneration: !aot,
97+
sourceMap: !!isAnySourceMapEnabled,
98+
additionalLazyModuleResources: additionalLazyModuleResources
99+
});
100+
101+
let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);
102+
103+
const config = {
104+
mode: uglify ? "production" : "development",
105+
context: appFullPath,
106+
externals,
107+
watchOptions: {
108+
ignored: [
109+
appResourcesFullPath,
110+
// Don't watch hidden files
111+
"**/.*",
112+
]
113+
},
114+
target: nativescriptTarget,
115+
entry: entries,
116+
output: {
117+
pathinfo: false,
118+
path: dist,
119+
sourceMapFilename,
120+
libraryTarget: "commonjs2",
121+
filename: "[name].js",
122+
globalObject: "global",
123+
hashSalt
124+
},
125+
resolve: {
126+
extensions: [".ts", ".js", ".scss", ".css"],
127+
// Resolve {N} system modules from tns-core-modules
128+
modules: [
129+
resolve(__dirname, "node_modules/tns-core-modules"),
130+
resolve(__dirname, "node_modules"),
131+
"node_modules/tns-core-modules",
132+
"node_modules",
133+
],
134+
alias: {
135+
'~': appFullPath
136+
},
137+
symlinks: true
138+
},
139+
resolveLoader: {
140+
symlinks: false
141+
},
142+
node: {
143+
// Disable node shims that conflict with NativeScript
144+
"http": false,
145+
"timers": false,
146+
"setImmediate": false,
147+
"fs": "empty",
148+
"__dirname": false,
149+
},
150+
devtool: hiddenSourceMap ? "hidden-source-map" : (sourceMap ? "inline-source-map" : "none"),
151+
optimization: {
152+
runtimeChunk: "single",
153+
splitChunks: {
154+
cacheGroups: {
155+
vendor: {
156+
name: "vendor",
157+
chunks: "all",
158+
test: (module, chunks) => {
159+
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
160+
return /[\\/]node_modules[\\/]/.test(moduleName) ||
161+
appComponents.some(comp => comp === moduleName);
162+
},
163+
enforce: true,
164+
},
165+
}
166+
},
167+
minimize: !!uglify,
168+
minimizer: [
169+
new TerserPlugin({
170+
parallel: true,
171+
cache: true,
172+
sourceMap: isAnySourceMapEnabled,
173+
terserOptions: {
174+
output: {
175+
comments: false,
176+
semicolons: !isAnySourceMapEnabled
177+
},
178+
compress: {
179+
// The Android SBG has problems parsing the output
180+
// when these options are enabled
181+
'collapse_vars': platform !== "android",
182+
sequences: platform !== "android",
183+
}
184+
}
185+
})
186+
],
187+
},
188+
module: {
189+
rules: [
190+
{
191+
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
192+
use: [
193+
// Require all Android app components
194+
platform === "android" && {
195+
loader: "nativescript-dev-webpack/android-app-components-loader",
196+
options: { modules: appComponents }
197+
},
198+
199+
{
200+
loader: "nativescript-dev-webpack/bundle-config-loader",
201+
options: {
202+
angular: true,
203+
loadCss: !snapshot, // load the application css if in debug mode
204+
unitTesting,
205+
appFullPath,
206+
projectRoot,
207+
}
208+
},
209+
].filter(loader => !!loader)
210+
},
211+
212+
{ test: /\.html$|\.xml$/, use: "raw-loader" },
213+
214+
// tns-core-modules reads the app.css and its imports using css-loader
215+
{
216+
test: /[\/|\\]app\.css$/,
217+
use: [
218+
"nativescript-dev-webpack/style-hot-loader",
219+
{ loader: "css-loader", options: { url: false } }
220+
]
221+
},
222+
{
223+
test: /[\/|\\]app\.scss$/,
224+
use: [
225+
"nativescript-dev-webpack/style-hot-loader",
226+
{ loader: "css-loader", options: { url: false } },
227+
"sass-loader"
228+
]
229+
},
230+
231+
// Angular components reference css files and their imports using raw-loader
232+
{ test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: "raw-loader" },
233+
{ test: /\.scss$/, exclude: /[\/|\\]app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },
234+
235+
{
236+
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
237+
use: [
238+
"nativescript-dev-webpack/moduleid-compat-loader",
239+
"nativescript-dev-webpack/lazy-ngmodule-hot-loader",
240+
"@ngtools/webpack",
241+
]
242+
},
243+
244+
// Mark files inside `@angular/core` as using SystemJS style dynamic imports.
245+
// Removing this will cause deprecation warnings to appear.
246+
{
247+
test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/,
248+
parser: { system: true },
249+
},
250+
],
251+
},
252+
plugins: [
253+
// Define useful constants like TNS_WEBPACK
254+
new webpack.DefinePlugin({
255+
"global.TNS_WEBPACK": "true",
256+
"process": undefined,
257+
}),
258+
// Remove all files from the out dir.
259+
new CleanWebpackPlugin([`${dist}/**/*`]),
260+
// Copy assets to out dir. Add your own globs as needed.
261+
new CopyWebpackPlugin([
262+
{ from: { glob: "fonts/**" } },
263+
{ from: { glob: "**/*.jpg" } },
264+
{ from: { glob: "**/*.png" } },
265+
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
266+
// Generate a bundle starter script and activate it in package.json
267+
new nsWebpack.GenerateBundleStarterPlugin(
268+
// Don't include `runtime.js` when creating a snapshot. The plugin
269+
// configures the WebPack runtime to be generated inside the snapshot
270+
// module and no `runtime.js` module exist.
271+
(snapshot ? [] : ["./runtime"])
272+
.concat([
273+
"./vendor",
274+
"./bundle",
275+
])
276+
),
277+
// For instructions on how to set up workers with webpack
278+
// check out https://github.com/nativescript/worker-loader
279+
new NativeScriptWorkerPlugin(),
280+
ngCompilerPlugin,
281+
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
282+
new nsWebpack.WatchStateLoggerPlugin(),
283+
],
284+
};
285+
286+
// Copy the native app resources to the out dir
287+
// only if doing a full build (tns run/build) and not previewing (tns preview)
288+
if (!externals || externals.length === 0) {
289+
config.plugins.push(new CopyWebpackPlugin([
290+
{
291+
from: `${appResourcesFullPath}/${appResourcesPlatformDir}`,
292+
to: `${dist}/App_Resources/${appResourcesPlatformDir}`,
293+
context: projectRoot
294+
},
295+
]));
296+
}
297+
298+
299+
if (report) {
300+
// Generate report files for bundles content
301+
config.plugins.push(new BundleAnalyzerPlugin({
302+
analyzerMode: "static",
303+
openAnalyzer: false,
304+
generateStatsFile: true,
305+
reportFilename: resolve(projectRoot, "report", `report.html`),
306+
statsFilename: resolve(projectRoot, "report", `stats.json`),
307+
}));
308+
}
309+
310+
if (snapshot) {
311+
config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
312+
chunk: "vendor",
313+
angular: true,
314+
requireModules: [
315+
"reflect-metadata",
316+
"@angular/platform-browser",
317+
"@angular/core",
318+
"@angular/common",
319+
"@angular/router",
320+
"nativescript-angular/platform-static",
321+
"nativescript-angular/router",
322+
],
323+
projectRoot,
324+
webpackConfig: config,
325+
}));
326+
}
327+
328+
if (hmr) {
329+
config.plugins.push(new webpack.HotModuleReplacementPlugin());
330+
}
331+
332+
return config;
333+
};

nsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{
2-
"useLegacyWorkflow": false
3-
}
1+
{}

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
"nativescript": {
1919
"id": "org.nativescript.groceries",
2020
"tns-android": {
21-
"version": "5.4.0"
21+
"version": "6.0.0"
2222
},
2323
"tns-ios": {
24-
"version": "5.4.2"
24+
"version": "6.0.1"
2525
}
2626
},
2727
"scripts": {
@@ -52,10 +52,10 @@
5252
"nativescript-angular": "~8.0.0",
5353
"nativescript-iqkeyboardmanager": "~1.3.0",
5454
"nativescript-social-share": "~1.5.1",
55-
"nativescript-unit-test-runner": "^0.3.3",
55+
"nativescript-unit-test-runner": "^0.6.4",
5656
"reflect-metadata": "~0.1.8",
5757
"rxjs": "^6.3.3",
58-
"tns-core-modules": "~5.4.0",
58+
"tns-core-modules": "~6.0.1",
5959
"zone.js": "^0.8.4"
6060
},
6161
"devDependencies": {
@@ -78,9 +78,8 @@
7878
"mocha-junit-reporter": "~1.18.0",
7979
"mocha-multi": "~1.0.1",
8080
"nativescript-dev-appium": "~5.0.0",
81-
"nativescript-dev-typescript": "~0.10.0",
82-
"nativescript-dev-webpack": "~0.24.0",
81+
"nativescript-dev-webpack": "1.0.0",
8382
"tslint": "^5.4.2",
84-
"typescript": "~3.4.5"
83+
"typescript": "3.4.5"
8584
}
8685
}

0 commit comments

Comments
 (0)