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

Can't resolve '~/app' for cssFile  #587

Closed

Description

@mid787

Empty new project : tns create aaa --ng :

We wanted to apply different GLOBAL CSS file according to some logic. ( css which includes different font names for different languages etc...)

So we did a small test just to check if applying a custom name ( not app.css but app1.css) is working :

We've used the sample project : tns create aaa --ng & webpack (all latest versions )

//main.ts:
platformNativeScriptDynamic({
                                startPageActionBarHidden: false ,
                                cssFile:"app1.css"
                            }) .bootstrapModule(AppModule);

It DOES work (without --bundle).

image

So you can see that Items are red :

image

BUT - Now we wanted to test with --bundle , so we've modified the webpack json file also to search for app1.css and not app.css

(also modified main.aot.ts) with :

import { setCssFileName } from "application";
setCssFileName("./app1.css");

However - running tns run android --bundle does NOT work :

image

ERROR in ../node_modules/nativescript-dev-webpack/load-application-css-angular.js
Module not found: Error: Can't resolve '~/app' in 'C:\Users\sff\Desktop\delme1\ddd\node_modules\nativescript-dev-webpack'
 @ ../node_modules/nativescript-dev-webpack/load-application-css-angular.js 5:49-65
 @ ./main.ts

I've also tried with :

import { setCssFileName } from "application";
setCssFileName("./app1.css");

It run to completion but the app1.css file is not applied ( no reds here) :

image

We've tried many variations :

  cssFile:"app1.css"
  cssFile:"./app1.css"
  cssFile:"~/app1.css"
  cssFile:"/app1.css"

But when I think about it , this ^ is not related - becuase if I do cssFile:"app1.css" without --bundle then - app1.css is respected.
the problem is that it's not respected with --bundle

None of them worked.

It seems that app1.css with --bundle is not respected. Only app.css is respected.


package.json
project sample : https://ufile.io/ge4to

nativescript@4.1.1
Windows 10

Activity

  1. changed the title [-]Applying global custom `cssFile` for the app using --bundle , is not respected[/-] [+]Applying global custom `cssFile` using --bundle , is not respected[/+] on Jun 26, 2018
  2. changed the title [-]Applying global custom `cssFile` using --bundle , is not respected[/-] [+]Can't resolve '~/app' when applying global custom `cssFile` using --bundle [/+] on Jun 27, 2018
  3. changed the title [-]Can't resolve '~/app' when applying global custom `cssFile` using --bundle [/-] [+]Can't resolve '~/app' when applying a global custom `cssFile` (problem only with --bundle )[/+] on Jun 27, 2018
  4. changed the title [-]Can't resolve '~/app' when applying a global custom `cssFile` (problem only with --bundle )[/-] [+]Can't resolve '~/app' for `cssFile` [/+] on Jun 28, 2018
  5. assigned and unassigned on Jul 4, 2018
  6. sis0k0 commented on Jul 4, 2018

    @sis0k0
    Contributor

    Hi, @RoyiNamir!

    The nativescript-dev-webpack plugin uses different logic for loading the global css file compared to the build without webpack. The loading is performed by the bundle-config-loader and the code looks something like this (for Angular apps):

    var application = require("tns-core-modules/application");
    require("tns-core-modules/ui/styling/style-scope");
    global.registerModule("./app.css", function () { return require("~/app"); });
    application.loadAppCss();
    

    As you can see it looks for ~/app by default. This should resolve to app.css. However, you can disable that loading and write a custom loader. Check out the repo bellow and follow the commits. Ping me if you have any questions.
    https://github.com/sis0k0/ns-custom-global-css

  7. vakrilov commented on Aug 8, 2019

    @vakrilov
    Contributor

    Update: Looks like we introduced some changes in NativeScript@6 that require changes in workaround provided by @sis0k0.

    The global.registerModule should register "app.css" instead of "./app.css" (although you can register both - it does not hurt).
    Here is how the fix looks like, just in case someone is using this approach or stumbles upon this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions