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

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

Closed
RoyiNamir opened this issue Jun 26, 2018 · 2 comments
Closed

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

RoyiNamir opened this issue Jun 26, 2018 · 2 comments
Assignees
Labels

Comments

@RoyiNamir
Copy link

RoyiNamir commented Jun 26, 2018

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

[email protected]
Windows 10

@RoyiNamir RoyiNamir changed the title Applying global custom cssFile for the app using --bundle , is not respected Applying global custom cssFile using --bundle , is not respected Jun 26, 2018
@RoyiNamir RoyiNamir changed the title Applying global custom cssFile using --bundle , is not respected Can't resolve '~/app' when applying global custom cssFile using --bundle Jun 27, 2018
@RoyiNamir RoyiNamir 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 ) Jun 27, 2018
@RoyiNamir RoyiNamir changed the title Can't resolve '~/app' when applying a global custom cssFile (problem only with --bundle ) Can't resolve '~/app' for cssFile Jun 28, 2018
@sis0k0 sis0k0 assigned sis0k0 and unassigned NickIliev Jul 4, 2018
@sis0k0
Copy link
Contributor

sis0k0 commented Jul 4, 2018

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

@vakrilov
Copy link
Contributor

vakrilov commented Aug 8, 2019

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants