Reputation: 1209
I am starting a webaudio project in a team in which we are making audio effects, audio visualization and audio synthesis. We are now designing a basic folder structure. Each of us is thinking of a structure and in our next meeting we will choose the best one. One of the team-members is really experienced with Javascript, but I'm leaning more to Dart, cause it just feels more familiar and robust. I have a Java background, but I'm not really experienced with web development. Therefore I want to develop the software in both languages: Dart and Javascript, so that I can eventually get to a solid decision whether it is better to use Dart or Javascript for this project.
I want to subdivide the dart libraries in three main directories: effects, visualization and synthesis. But I don't know yet where to place those main directories. According to the Pub Package Layout Convention the libraries should be located in the lib directory. But since all libraries will strongly depend on the webaudio API, it will only run in a browser, and thus be web application. So my first question is: "Should I place my libraries in the package/libs directory or somewhere in the package/web directory?" And "Should I put the javascript counterparts in the same directory?" For example: both oscillator.js and oscillator.js in the synthesis folder.
Once that the directory structure is done I would like to be able to easily switch from the Dart version to the Javascript version and vice-versa, and since I need a browser with an embedded Dart VM that will be Dartium. So here goes my second question: "What would be the best way to easily switch between the Javascript and the Dart version?"
Thanks in advance!
PS: I know that I could just use the generated Javascript from dart2js, but I want actually readable Javascript. And the dart2js Javascript does not exactly meet that requirement. Furthermore I want to have good understanding on the differences between the two languages, and I think that the best way is to try them both.
Edit: I would like to clarify the idea of switching between Javascript and Dart on Günter's demand. I will make a Javascript port of every Dart file manually, just so that I can learn both. Since I will be developing both of them at the same time, I want to be able to test the site with the Dart version, but also with the Javascript version. So I want the HTML to load this if in Dartium:
<script type="application/dart" src="main.dart"></script>
But this if in any other browser:
<script src="main.js"></script>
I reccon that dart.js in the browser package does this to switch between *.dart and *.dart.js, depending on if the browser has a Dart VM or not. But I want it to switch between *.dart and *.js (my own js), without having to make two separate html files.
Upvotes: 1
Views: 87
Reputation: 76323
Question 1: All in lib/
except entry points is fine.
Question 2: You can use pub serve. This allows to access to the app from Dartium or any browser from the same url. Any update in a dart file will be compiled when a *.dart.js
file is request instead of a *.dart
file.
For your edit: you can have a look at the dart_to_js_script_rewriter package to do a transformer that will rewrite your <script type="application/dart" src="main.dart"></script>
to <script src="main.js"></script>
. Switching from JS to Dart will be done by adding/removing your created transformer to pubspec.yaml
and restarting pub serve
or pub build
.
Upvotes: 1