Looking to learn as much as possible - so all advice and suggestions appreciated. Since this problem has been plaguing me for a while - maybe I'm using the tools incorrectly, so please advise.
Unfortunately I'm still having issues with getting paths correct in html import statements. I think the reason may be related to how I run the application. First, I'm trying to get a simple mortgage calculator component built. It is a basic calculator with a handful of inputs and a table output showing the payment schedule. Originally I did it all in one component library called finance. I decided to refactor by pulling out some of the input components into a separate component library called basic_components. The idea is maybe these could be used elsewhere by code unrelated to the mortgage calculator so storing them in their own package seems reasonable.
There are at least 4 ways to run an example:
(1) Select the html file directly and "Run in Dartium"
(2) Select the html file directly and "Run as Javascript"
(3) Build and then select the corresponding file under build and "Run in Dartium"
(4) Build and then select the corresponding file under build and "Run as Javascript"
I was under impression that you use (1) as much as possible since it is fastest turnaround for development. This is what I have been using almost exclusively since I've not gotten to a point to release to the web yet. I assume (4) is the most important when it is time to deploy and if your stuff works in (1) it should/will work in (4).
Question: Are all four supposed to work?
So, for reference I've shown the post-refactor structure of the two component libraries at bottom. As it stands (1), (3) and (4) all work for basic_input.html examples. (2) does not work: when running in javascript on the development html file I get a blank screen. So maybe (2) is not really needed/supported?
Basically the rule is:
- if your .html file is an entrypoint, make sure this file is under 'web/' and use 'packages/package_name/path_to_file_relative_to_lib'
- if your .html file is inside a lib/ directory, use '[../]{repeated_as_many_levels_deep_you_are_in_lib}/packages/package_name/path_to_file_relative_to_lib'
The problem is with the second piece of advice, regarding html files in the component library. For example, if I apply that rule to payment_schedule.html which imports a date_input component, the import should look like:
<link rel="import" href="../../packages/basic_input/components/date_input.html">
When run using (4) with this import I get:
Failed to load resource: the server responded with a status of 404 (Not Found)
So, it is throwing in an additional "packages" in the path. Naturally, I key in on that and change all imports to do Siggi rule 2 but leave off the "packages":
<link rel="import" href="../../basic_input/components/date_input.html">
Now it works when using run method (1). So I try to build the "working" project in order to try to run with (4). But the build fails with:
[Error in polymer (Linter) on mortgage_calculator|lib/components/payment_schedule.html]:
lib/components/payment_schedule.html:5:1: couldn't find imported asset "basic_input/components/date_input.html" in package "mortgage_calculator".
So now I see why Siggi put 'packages' in his second rule. But, if I add back the "packages" to all the mortage_calculator imports of basic_imports and then build again I still get an error:
[Error in polymer (Linter) on mortgage_calculator|lib/components/payment_schedule.html]:
lib/components/payment_schedule.html:5:1: couldn't find imported asset "packages/basic_input/components/date_input.html" in package "mortgage_calculator".
So, after many permutations I have it so that the calculator can work successfully using run method (1) (i.e. only dev using Dartium) as long as I adapt Siggi rule 2 by leaving off "packages" in the import.
Note: This project is at:
https://github.com/patefacio/finance and the checked in version is the one that works with run method (1). No others work. Any help making run method (4) work is greatly appreciated. (There is another bug I encountered when all components were in the same package unrelated to imports that prevents the table from displaying. I imagine that issue will still exist after the imports are figured out).
Thanks
Dan
The new structure is:
* basic_input *
|-- build
| '-- examples
| '-- basic_input
| '-- basic_input.html
|-- lib
| |-- components
| | |-- basic_input.css
| | |-- date_input.dart
| | |-- date_input.html
| | | (5 more...)
| | |-- rate_input.html
| | |-- year_input.dart
| | '-- year_input.html
| '-- formatting.dart
|-- pubspec.yaml
'-- web
'-- examples
'-- basic_input
'-- basic_input.html
* mortgage_calculator *
|-- lib
| |-- components
| | |-- finance.css
| | |-- mortgage_calculator.css
| | |-- mortgage_calculator.dart
| | |-- mortgage_calculator.html
| | |-- mortgage_details.dart
| | |-- mortgage_details.html
| | |-- payment_schedule.dart
| | '-- payment_schedule.html
| '-- mortgage.dart
|-- pubspec.yaml
'-- web
'-- examples
'-- mortgage_calculator
'-- mortgage_calculator.html