Skip to content

[QUESTION] main.tns.ts is missing from the TypeScript compilation Nativescript / Angular + Nativescript/webpack Shared project. #9519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pandabuilt opened this issue Aug 19, 2021 · 8 comments

Comments

@pandabuilt
Copy link

How do we move forward with a tsconfig.app.json file for web (angular.json) and a tsconfig.tns.json file for Nativescript?

in a @nativescript/schematics project we had a tsconfig.json and a tsconfig.tns.json file. Inside the webpack.config.js file we had several lines where they mapped the tsconfig file based on the one in the angular.json file to the tns.json file to the env.json file and it would use the most detailed one by default.

in Nativescript/Webpack 5 beta we can see it points us to use TsconfigPathsPlugin

So I still have the tsconfig json file for angular web. This includes main.ts, polyfills.ts, etc. However, when I run the app vis ns debug - it uses the tsconfig.json file from angular.json. Okay, so I figured I needed to update the new webpack.config file to tell it what one to use. I see it tells me to add 'TsconfigPathsPlugin' based on the docs. However, I added the code below to my config file and it's still using the other tsConfig.app.js file


const webpack = require('@nativescript/webpack');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

module.exports = env => {
  webpack.init(env)
  webpack.useConfig('angular');

  webpack.chainWebpack(config => {
    config.resolve.plugin('TsconfigPathsPlugin').use(
      new TsconfigPathsPlugin({
        configFile: './tsconfig.tns.json',
        logLevel: "info",
      })
    )
  });

  return webpack.resolveConfig();
}
@pandabuilt
Copy link
Author

Here is my TsConfig.tns.json file:
{ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/app", "paths": { "@src/*": [ "src/*.tns.ts", "src/*.ts", "src/*.prod.ts" ] } }, "files": [ "./src/main.tns.ts", "./src/polyfills.tns.ts" ], "include": [ "./src/**/*.tns.ts", "./src/**/*.d.ts", "src/environments/environment.prod.ts" ], }
here is my tsconfig.app.json file:
{ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/app", "paths": { "@src/*": [ "src/*.web", "src/*" ] } }, "files": [ "./src/main.ts", "./src/polyfills.ts" ], "include": [ "./src/**/*.d.ts" ], }

@pandabuilt
Copy link
Author

interesting to note it does show me that it's using... tsconfig-paths-webpack-plugin: Using config file at ./tsconfig.tns.json

@pandabuilt
Copy link
Author

Seems this was unanswered here: NativeScript/nativescript-dev-webpack#1154

@bufke do you have any insight?

@bufke
Copy link

bufke commented Aug 19, 2021

You would be better served by someone on the NativeScript team. However, to my best understanding, you will never succeed in trying to use a NS shared project using the .tns. method. The previously shared approach was done by the telerek team and the current maintainers do not agree with it nor have time to support it. I can understand the position the current maintainers are in is tough and find no blame on them.

The current recommended approach is to rewrite your app using something like NX. I started doing this for a smaller app I have and found it to really be on the level of rewrite. For me, it resulted in about 50% more lines of code. My app and web code are really intended to have feature parity, making the .tns.* method highly effective for me. If your web/app code are not tightly coupled, then it may not be such a big deal for you. NX makes it easy to share packages between projects but it does not work well if you only want to replace html with nativescript templates. You may want to consider other options like Flutter which make it much easier to reuse app/web presentation code.

@pandabuilt
Copy link
Author

@bufke I figured they put the tsconfig plugin inside @nativescript/webpack to showcase how you can dynamically use a different tsconfig file. However, show cases tsConfigPath that we need to be able to edit.

Literally adding the lines from nativescript-dev-webpack (4 or before) checking if a path resolves to tsconfig.tns.json

Could we edit our webpack.config file to

function getAngularCompilerPlugin(): any {
	const { AngularCompilerPlugin } = require('@ngtools/webpack');
	return AngularCompilerPlugin;
}

and pass in the tns config file?

@pandabuilt
Copy link
Author

@pandabuilt
Copy link
Author

pandabuilt commented Aug 19, 2021

Okay, even when I edit that.... to tns.json I run into polyfills.ts vs polyfills.tns.ts.

Lower down that file, I can edit polyfills to tns as well - but still have tons of build issues

@pandabuilt
Copy link
Author

Closed based off the response from core team:NativeScript/angular#28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants