Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 2de4c68

Browse files
Fatmerosen-vladimirov
authored andcommitted
feat: introduce webpack only workflow (#882)
* fix: don't provide fake paths to the {N} CLI - relative to the `app` folder * feat: remove not needed hooks * feat: remove webpack compiler logic * fix: don't copy app_resources to the platforms folder * fix: respect --env.verbose * feat: respect production mode based on release option Implements: #911 * fix: watch platform specific files from node_modules Rel to: NativeScript/nativescript-cli#4480 * fix: don't emit absolute webpack's runtime files Previously we needed to emit files with full paths as {N} CLI relies on this and expected them in a such format. With the changes for "webpack-only" mode, {N} CLI expects only relative paths. So we need to fix this in order to ensure that runtime.js file will not be transferred on device on change in hmr mode. * fix: don't process runtime.js files We needed a special processing for `runtime.js` files as we excluded them when transferring the files on device. As the CLI is filtering and emit only hot-update files we don't need this logic anymore. * fix: emit runtime files and entry point files * fix: update webpack config files of demo apps * fix: don't use short imports in demo apps * fix: update dependencies of demo apps so they are compatible with 6.0 release
1 parent fc4e415 commit 2de4c68

32 files changed

+163
-622
lines changed

demo/AngularApp/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@
4242
"mocha": "~5.2.0",
4343
"mochawesome": "~3.1.2",
4444
"nativescript-dev-appium": "next",
45-
"nativescript-dev-sass": "next",
46-
"nativescript-dev-typescript": "next",
4745
"nativescript-dev-webpack": "next",
46+
"node-sass": "^4.12.0",
4847
"typescript": "~3.4.5"
4948
},
5049
"scripts": {

demo/AngularApp/webpack.config.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ module.exports = env => {
4444

4545
// You can provide the following flags when running 'tns run android|ios'
4646
aot, // --env.aot
47-
snapshot, // --env.snapshot
47+
snapshot, // --env.snapshot,
48+
production, // --env.production
4849
uglify, // --env.uglify
4950
report, // --env.report
5051
sourceMap, // --env.sourceMap
5152
hiddenSourceMap, // --env.hiddenSourceMap
5253
hmr, // --env.hmr,
5354
unitTesting, // --env.unitTesting
55+
verbose, // --env.verbose
5456
} = env;
5557

5658
const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap;
@@ -60,8 +62,9 @@ module.exports = env => {
6062
const tsConfigName = "tsconfig.tns.json";
6163
const entryModule = `${nsWebpack.getEntryModule(appFullPath, platform)}.ts`;
6264
const entryPath = `.${sep}${entryModule}`;
63-
const entries = { bundle: entryPath, application: "./application.android" };
64-
if (platform === "ios") {
65+
const entries = { bundle: entryPath };
66+
const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some(e => e.indexOf("tns-core-modules") > -1);
67+
if (platform === "ios" && !areCoreModulesExternal) {
6568
entries["tns_modules/tns-core-modules/inspector_modules"] = "inspector_modules";
6669
};
6770

@@ -101,8 +104,14 @@ module.exports = env => {
101104

102105
let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);
103106

107+
const itemsToClean = [`${dist}/**/*`];
108+
if (platform === "android") {
109+
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "src", "main", "assets", "snapshots")}`);
110+
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`);
111+
}
112+
104113
const config = {
105-
mode: uglify ? "production" : "development",
114+
mode: production ? "production" : "development",
106115
context: appFullPath,
107116
externals,
108117
watchOptions: {
@@ -257,7 +266,7 @@ module.exports = env => {
257266
"process": undefined,
258267
}),
259268
// Remove all files from the out dir.
260-
new CleanWebpackPlugin([`${dist}/**/*`]),
269+
new CleanWebpackPlugin(itemsToClean, { verbose: !!verbose }),
261270
// Copy assets to out dir. Add your own globs as needed.
262271
new CopyWebpackPlugin([
263272
{ from: { glob: "fonts/**" } },
@@ -274,19 +283,6 @@ module.exports = env => {
274283
],
275284
};
276285

277-
// Copy the native app resources to the out dir
278-
// only if doing a full build (tns run/build) and not previewing (tns preview)
279-
if (!externals || externals.length === 0) {
280-
config.plugins.push(new CopyWebpackPlugin([
281-
{
282-
from: `${appResourcesFullPath}/${appResourcesPlatformDir}`,
283-
to: `${dist}/App_Resources/${appResourcesPlatformDir}`,
284-
context: projectRoot
285-
},
286-
]));
287-
}
288-
289-
290286
if (report) {
291287
// Generate report files for bundles content
292288
config.plugins.push(new BundleAnalyzerPlugin({

demo/JavaScriptApp/app/activity.android.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const frame = require("ui/frame");
1+
const frame = require("tns-core-modules/ui/frame");
22

33
const superProto = androidx.appcompat.app.AppCompatActivity.prototype;
44
androidx.appcompat.app.AppCompatActivity.extend("org.myApp.MainActivity", {

demo/JavaScriptApp/app/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You can use this file to perform app-level initialization, but the primary
44
purpose of the file is to pass control to the app’s first module.
55
*/
66

7-
var application = require("application");
7+
var application = require("tns-core-modules/application");
88

99
application.start({ moduleName: "main-page" });
1010

demo/JavaScriptApp/app/main-page.android.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var frameModule = require("ui/frame");
1+
var frameModule = require("tns-core-modules/ui/frame");
22
var createViewModel = require("./main-view-model").createViewModel;
33

44
function onNavigatingTo(args) {

demo/JavaScriptApp/app/main-page.ios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var frameModule = require("ui/frame");
1+
var frameModule = require("tns-core-modules/ui/frame");
22
var createViewModel = require("./main-view-model").createViewModel;
33

44
function onNavigatingTo(args) {

demo/JavaScriptApp/app/main-view-model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var Observable = require("data/observable").Observable;
1+
var Observable = require("tns-core-modules/data/observable").Observable;
22

33
function getMessage(counter) {
44
if (counter <= 0) {

demo/JavaScriptApp/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
"mocha": "~5.2.0",
2828
"mochawesome": "~3.1.2",
2929
"nativescript-dev-appium": "next",
30-
"nativescript-dev-sass": "next",
3130
"nativescript-dev-webpack": "next",
32-
"node-sass": "^4.7.1"
31+
"node-sass": "4.12.0"
3332
},
3433
"scripts": {
3534
"setup": "npm pack ../../ && npm i -D nativescript-dev-webpack*.tgz",

demo/JavaScriptApp/webpack.config.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const nsWebpack = require("nativescript-dev-webpack");
55
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
66
const CleanWebpackPlugin = require("clean-webpack-plugin");
77
const CopyWebpackPlugin = require("copy-webpack-plugin");
8+
const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
89
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
910
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
1011
const TerserPlugin = require("terser-webpack-plugin");
@@ -39,12 +40,14 @@ module.exports = env => {
3940

4041
// You can provide the following flags when running 'tns run android|ios'
4142
snapshot, // --env.snapshot
43+
production, // --env.production
4244
uglify, // --env.uglify
4345
report, // --env.report
4446
sourceMap, // --env.sourceMap
4547
hiddenSourceMap, // --env.hiddenSourceMap
4648
hmr, // --env.hmr,
47-
unitTesting, // --env.unitTesting
49+
unitTesting, // --env.unitTesting,
50+
verbose, // --env.verbose
4851
} = env;
4952

5053
const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap;
@@ -55,14 +58,21 @@ module.exports = env => {
5558
const entryModule = nsWebpack.getEntryModule(appFullPath, platform);
5659
const entryPath = `.${sep}${entryModule}.js`;
5760
const entries = { bundle: entryPath, application: "./application.android" };
58-
if (platform === "ios") {
61+
const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some(e => e.indexOf("tns-core-modules") > -1);
62+
if (platform === "ios" && !areCoreModulesExternal) {
5963
entries["tns_modules/tns-core-modules/inspector_modules"] = "inspector_modules";
6064
};
6165

6266
let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);
6367

68+
const itemsToClean = [`${dist}/**/*`];
69+
if (platform === "android") {
70+
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "src", "main", "assets", "snapshots")}`);
71+
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`);
72+
}
73+
6474
const config = {
65-
mode: uglify ? "production" : "development",
75+
mode: production ? "production" : "development",
6676
context: appFullPath,
6777
externals,
6878
watchOptions: {
@@ -208,7 +218,7 @@ module.exports = env => {
208218
"process": undefined,
209219
}),
210220
// Remove all files from the out dir.
211-
new CleanWebpackPlugin([`${dist}/**/*`]),
221+
new CleanWebpackPlugin(itemsToClean, { verbose: !!verbose }),
212222
// Copy assets to out dir. Add your own globs as needed.
213223
new CopyWebpackPlugin([
214224
{ from: { glob: "fonts/**" } },
@@ -226,21 +236,12 @@ module.exports = env => {
226236
}),
227237
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
228238
new nsWebpack.WatchStateLoggerPlugin(),
239+
new ExtraWatchWebpackPlugin({
240+
files: [`node_modules/**/*.${platform}.js`]
241+
})
229242
],
230243
};
231244

232-
// Copy the native app resources to the out dir
233-
// only if doing a full build (tns run/build) and not previewing (tns preview)
234-
if (!externals || externals.length === 0) {
235-
config.plugins.push(new CopyWebpackPlugin([
236-
{
237-
from: `${appResourcesFullPath}/${appResourcesPlatformDir}`,
238-
to: `${dist}/App_Resources/${appResourcesPlatformDir}`,
239-
context: projectRoot
240-
},
241-
]));
242-
}
243-
244245
if (report) {
245246
// Generate report files for bundles content
246247
config.plugins.push(new BundleAnalyzerPlugin({

demo/TypeScriptApp/app/activity.android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {setActivityCallbacks, AndroidActivityCallbacks} from "ui/frame";
1+
import {setActivityCallbacks, AndroidActivityCallbacks} from "tns-core-modules/ui/frame";
22

33
@JavaProxy("org.myApp.MainActivity")
44
class Activity extends androidx.appcompat.app.AppCompatActivity {

0 commit comments

Comments
 (0)