Abozanona
Abozanona

Reputation: 2295

How to include xml files in app directory in Nativescript webpack

In my application I have two main screens for two types of users and a login page. When a user opens the app I check what is the type of the user, and based on the user type I open a specific app-root.xml file.

app.js

let currentLogin = appSettings.getString("login", "nothing");
if (currentLogin === 'customer') {
    application.run({ moduleName: "app-root-home" });
}
else if (currentLogin === 'shop') {
    application.run({ moduleName: "app-root-shop" });
}
else {
    application.run({ moduleName: "app-root" });
}

I have three different XML files in my app directory (app-root, app-root-home & app-root-shop). each of them has a different frame wrapped in different layouts.

When I execute without Webpack everything works fine, but when I enable Webpack from sidekick, if the following statement is executed application.run({ moduleName: "app-root-home" }); I receive an error: TypeError: Cannot read property '_domid' of undefined.

I tried to decompile the application and see the bundle.js file and I found that webpack didn't add app-root-home.xml nor app-root-shop.xml. Only app-root.xml was there.

I'm using nativescript sidekick and I'm building my project on cloud; I don't type command lines a lot, the cloud does that for me.

My nativescript-dev-webpack dev version is 0.19.0.

I'm developing in JS.

I tried to find a solution on github for similar issues like mine, and to be able to include xml files in the app directory, and all the solutions included modifications in bundle-config.js which I don't have in my project.

It looks like in new versions of webpack the bundle-config.js file doesn't exist anymore in the app directory, instead it exists in the same plugin folders. Reference

I only have webpack.config.js in my app directory, so I need to know to can I add the xml files to it in JS, but I couldn't find a way to do this.

How can I include all xml files in app directory in the latest version of webpack plugin to my application and run on sidekick.

Upvotes: 2

Views: 387

Answers (2)

mahmoud310
mahmoud310

Reputation: 300

Instead of creating a separated app-root-home.xml & app-root-shop.xml files, you can create two new pages(app-root-home & app-root-shop). For each page, nativescript will create *-page.js, *-view-model.js & *-page.xml files, and webpack won't delete those files when you release a version.

After creating the two new pages, you can include the *-page.xml files instead of the app-root-home & app-root-shop xml files.

Upvotes: 2

Abozanona
Abozanona

Reputation: 2295

I was able to solve my problem temporarily by putting the other app-root files in new folders of their names as the below tree shows:

  app
    |-- app-root.xml
    |-- app-root-home
    |   |-- app-root-home-page.js        //empty JS file
    |   |-- app-root-home-view-model.js  //empty JS file
    |   `-- app-root-home-page.xml
    `-- app-root-shop
        |-- app-root-shop-page.js        //empty JS file
        |-- app-root-shop-view-model.js  //empty JS file
        `-- app-root-shop-page.xml

and in my app.js file:

let currentLogin = appSettings.getString("login", "nothing");
if (currentLogin === 'customer') {
    application.run({ moduleName: "app-root-home/app-root-home-page" });
}
else if (currentLogin === 'shop') {
    application.run({ moduleName: "app-root-shop/app-root-shop-page" });
}
else {
    application.run({ moduleName: "app-root" });
}

This is not the answer to my question; it's just a fast fix.

Upvotes: 1

Related Questions