-
- Notifications
You must be signed in to change notification settings - Fork 22
feat: refactor shared structure #196
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
Conversation
… all NG project settings
This allows us to have a base instead of actions in the test tree. We need this in order to test the behaviour of the schematic when applied to tree without create actions.
3849f72 to 9fd675e Compare | ] | ||
| } | ||
| }, | ||
| "files": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of adding main.ts and polyfills.ts explicitly?
When I manually migrated this project: https://github.com/sebawita/angular-getting-started
Steps:
- update
angular.json- add ->"cli": { "defaultCollection": "@nativescript/schematics" } - run ng g
ng-add- make sure the this uses the schematics from the PR ng serve -o
I get this error:
Refused to load the image 'http://localhost:4200/favicon.ico' because it violates the following Content Security Policy directive: "default-src 'none'". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback. This can be fixed either by:
a) Changing the files to src/main.ts and src/polyfills.ts
b) removing the files array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! The file paths are relative to the src directory.
In Angular 7.0 the tsconfig.app.json file is in my-project/src. That's why the paths are main.ts and polyfills.ts. However, in Angular 8.0, the tsconfig.app.json file is on root level - in ./my-project. The paths should be changed to src/main.ts and src/polyfills.ts.
This problem will be addressed in the PR, upgrading to Angular 8.0.
| test |
The Problem
Imports for Web or Mobile-specific files cause errors in IDEs and build time.
Example:
service.tns.tsandservice.web.ts.import { xxx } from ".../service"The Solution
Configure typescript to resolve platform-specific files (with
.tns.ts/.web.tsextension) with priority over shared files (just*.ts). The configuration is done by settingpathsintsconfig. Here is how thetsconfig.tns.json(used for mobile) looks:Important Remarks
@src/to thesrcfolder of the project. Other symbols can be used - like@proj/. However, don’t use“~/"- this leads to confusing build-time errors and suffering. The reason:“~/"is reserved and is already used as an alias in webpack configuration it is needed for CSS files resolution.“paths”mapping only work for non-relative imports. This means that all imports that should be resolved to a plat-specific file should be defined with as non-relative paths starting with@src. Our suggestion is to adopt a convention to use@srcfor all project files imports and enforce it with a tslint rule.“*.ts”extension that is intended for web-only. It then fails with acomponent/module not usederror. To solve that we explicitly specify files intnsandwebts-configurations. These are the entry points to TS compilations. All lazy modules should be specified in“files”list in tsconfigs, as they are not directly imported in other TS files.Tasks
ng-newschematic to create apps using the ts-configuration described above.@srcscheme@srcandbasePathmappings@srcimports (instead of relative). We can just reuse the tslint rule. We can execute the rule with--fixto make it fix relative imports that we have generatedng-newadd-nssharedgenerate componentgenerate modulemaster-detail templatemigrate-modulemigrate-componentFixes #172