Automatic refresh the page when changes while running pub serve (dart) - dart

I'm using pub serve to run my page. I noticed that there are tools like lite-server for npm, that make sure that after file contents are changed, the web page is automatically refreshed.
Anyone got something like that working for dart using pub serve? I thought maybe some grinder script with the watcher package could make that work?

Pub should handle monitoring and autodeployment of changes itself when run in debug or release mode.
You can verify this works correctly by issuing from your project root
pub serve
then make a change to a html or dart file and verify that the project is automatically rebuilt.
If this is not working, you might try experimenting with the --force-poll option when running pub serve. Per documentation:
--[no-]force-poll Force the use of a polling filesystem watcher.

Related

Electron builder works on development but not on install

I'm trying to follow other people who had a similar issue like this one
Electron-Builder include external folder I wish i could be more specific on what my problem is, the reason is that i dont know whats wrong.
I am making a react app which has a server with an sqlite db and im trying to use electron.js to make it into an installable/executable
here is my dummy repo https://github.com/Juan321654/electron_react_with_build_installer_sqlite_db the master branch was just how to make electron work with react, the server branch is the one that i need help with
you can clone and just do npm i, npm run start to launch executable. npm run build to build
the code works fine in development mode and even after i make the build project with electron i can launch the executable and it works fine and it reads the data from the database, but as soon as i take the dist folder out of the project to send to someone or install the software, it stops working and it loads the app, but it does not read the data from the server/db, I am not sure if its missing node modules or the server folder, or maybe if im missing some kind of command in my scripts in the package.json?

Mimicking build_runner serve on a nodeJs server

With the expiration of Dartium that happened just a few days ago, I felt compelled to migrate from dart 1.24.3 to Dart2, even though it is still in dev.
I have although hit a few walls doing so, one of them being related to the architecture of my apps.
I run a nodeJs server, which also acts as a webserver with client side dart.
The problem that I experience with the new dart SDK is that in order for the .dart files to be read in Chrome, they must be served using webdev serve or build_runner serve.
Obviously, these 2 commands act as the file server, which is not what I want since I'm using a nodeJS server.
By using build_runner watch I think I am enabling the build and watch of the .dart files into .dart.js inside of the following directory :
.dart_tool/build/generated//lib
I am also able to serve them from my nodeJS server. What remains is the package directory, I can't seem to find where pub serves gets the following package files:
/packages/$sdk/dev_compiler/amd/require.js
/packages/$sdk/dev_compiler/amd/dart_sdk.js
Does anyone know what build_runner serve does to include them?
Thank you,
There are 2 options for using a different server during development.
Run build_runner serve on a different port and proxy the requests to it from your other server. This has the benefit of delaying requests while a build is ongoing so you don't get an inconsistent set of assets.
Run build_runner watch --output web:build and use the created build/ directory to serve files from. This will include a build/packages directory that has these files in it.
These files are served from the lib directory of the dart sdk itself.
Note that there is another option, which is to use the -o option from build_runner. This will create a merged directory with source and generated files, which you can serve directly without relying on any internal file layout.

Corodva serve command just reset the app erasing all my changes

I use the command cordova serve to test the app in browser. But when I issue the command, I find all the code changes I made to the app has been disappeared include newly added js files etc. The app just got a complete reset. How can I avoid this and still use cordova serve command to test in browser? Thanks.
I got the issue resolved. It took sometime to figure out what is happening under the hood. As I was making changes directly in platform IOS directory, the cordova prepare or serve statement just replaces the code from the parent www folder.
To conclude, I have to make changes in root www folder and then issue the prepare/serve command that copies the code to the platform to test it out.

Dart Editor Dartium: "could not start pub serve or connect to pub"

I just installed Dart Editor on Ubuntu 14.04, opened the Sunflower demo, right clicked on sunflower.html, chose Run in Dartium, and was faced with "Could not start pub serve or connect to pub." So I went to Google and found the following reasons why this happens:
"Run in Dartium" doesn't invoke "pub serve" correctly for Dart files that aren't in web/ or test/ (But the Sunflower demo files are all in web/)
https://code.google.com/p/dart/issues/detail?id=18990
Project files must be inside "C:\Users[username]\dart" instead of "C:\progs\Dart\projects" (Doesn't help; I'm not on Windows, but would demos that come with Dart Editor be in the wrong place?)
https://code.google.com/p/dart/issues/detail?id=19659
Same problem in recent release shows up on Mac OSX, bug fix promised in that next release (Doesn't help; I'm not on Mac OSX and that next release already came)
https://code.google.com/p/dart/issues/detail?id=19143
Another service is listening on port 8080 (Nope, I checked the ports and also made sure nothing with dart pub serve was already running, plus rebooted a couple of times)
dart error - could not start pub serve or connect to pub
So I found more information that gave me the idea to try pub serve from the command line. So I went to the directory where the sunflower project was placed by the Dart Editor (where the pubspec.yaml is found) and in the command line I typed:
sudo /opt/dart/dart-sdk/bin/pub serve
Which resulted in:
You don't have a lockfile, so we need to generate that:
Resolving dependencies... (1.1s)
Downloading browser 0.9.1...
Got dependencies!
Loading source assets...
Serving sunflower web on http:// localhost:8080
Build completed successfully
Great, I thought, so I opened Chrome and visited http:// localhost:8080 and saw this:
404 Not Found
Could not find asset web in package sunflower.
And in my command line console I saw this:
[web] GET / → Could not find asset sunflower|web.
[web] GET /favicon.ico → Could not find asset sunflower|web/favicon.ico.
I am about to get more aggressive with my Google search and investigation, but I thought I would have this question out here just in case I cannot find the answer. Even though I encounter many obstacles before running my first Dart demo, which makes for a poor introduction (I know, Dart is new), I keep liking what people say about it and I am compelled to get this working. Please help me like Dart. :)
Much appreciated!
I came across similar error and this solved it for me:
1) Move all html/css/dart files to /web directory.
2) Than create a pubspec.yaml with your projects dependences (usually it's "browser" only).
You may try like this, [run]-->[Manage Launches], then unmarked "Use pub serve to serve the application", good luck!

Trigger.io continuous development

I'd like to know if there is any way to develop continuously with Trigger.io and avoid the forge build step with every file change I want to test in my browser or simulator.
I was faced with the same problem and I've got a working solution that uses watchr and watch to automatically rebuild each time I make a change to a source file. If you are running a "web" version of your app you can make a change to a source file and go directly to your browser and see the effect of your changes fairly quickly depending on how long the build takes.
Prerequisites: Ruby, watchr, Unix 'watch', and a terminal.
gem install watchr.
create a new ruby file for watchr to know what files to monitor and what to do when it sees a change. I named my file 'my_watch.rb': https://gist.github.com/3153167
open two terminals. Terminal 1 will run watchr and Terminal two will run 'forge build ...'.
In terminal 1 run 'watchr my_watch.rb' making sure the path to my_watch.rb is correct and make sure you've edited my_watch.rb according to your setup so that the path inside watch(...) reflects the files to be watched. My example watches all files in the same directory (and beneath) as the my_watch.rb script. You can place my_watch.rb in the 'src' folder of your Trigger.io app if you want to match my example and run watchr my_watch.rb directly from the src folder. Also not the shell command and path in the block need to be updated to reflect your environment. Again, in my example 'my_watch.rb' is inside 'src/' so when a change is detected we go up one directory and call 'forge build'.
I tend to develop actively with the 'web' version of my app so I can just open terminal 2 to my forge project directory and 'forge run web'. When I am testing in simulators and on devices, yes I have to run forge build every time I want to see a change. However, I typically don't have to wait for forge build to finish because watchr kicked off the build as soon as I made a change and it happens pretty quickly.
I know this is not an ideal solution but so far developing new features in the 'web' version first and then implementing in mobile versions has been very smooth for me. I've never needed to kill the 'web' version after a build but I maybe just lucky. As for running build each time you want to test the mobile versions if you are good with your keyboard shortcuts it really isn't bad at all. XCode makes you build and run after changes are made to source code when creating native iOS apps so I don't think Trigger is unique in requiring this build step.
I hope this helps and that my answer isn't too specific to me and my setup.
The build phase makes some changes to your source to enable the forge.* APIs - therefore, trying to just use the raw files in your src directory won't work.
You may be tempted to change files directly in the development directory, but this is a pretty bad idea: we delete those files with impunity when we need to!
We have plans on our medium-term roadmap to add a file-system watcher to start builds automatically when changes have occurred.
In the meantime, I just use forge build && forge run PLATFORM which tends to only take a few seconds...
while not perfect... this works for me.
go into development/web
rm src
link to your root src, ie ln -s ../../src src
copy the all.js from the web/forge and add to your index.html
ie
start nodemon web.js
open in browser.
note you will need to comment out the all.js script tag for non web builds.

Resources