Giter VIP home page Giter VIP logo

dart3_node_interop's Introduction

dart3-node-interop

Experiments with node.js interoperability using the latest Dart 3 features.

How to Run

  1. Run webdev build --output bin:build/gen to generate the js. Files should be generated in the build/gen directory.
  2. Modify the import in build/main_with_preamble.js with the name of the new entrypoint generated in step 1.
  3. Run node build/main_with_preamble.js to test the compiled js.
  • Alternatively, you can also run it in the browser by using webdev serve build:8080.

NOTE: For some reason, webdev serve isnt regenerating the js files on change, so this implementation currently requires use of webdev build first.

  • webdev build --output bin:build/gen
  • webdev serve build:8080

TODO

  • basic node.js interop script using 0 dependencies
  • create a JS interop type that represents the (built-in) console log
  • verify platform agnostic type (e.g. console) can be run from browser.
  • create a Node.JS interop type that only exists via an import (e.g. fs)
  • create a Browser JS interop type, and verify it doesn't work using node

Enhancements

End-to-End use cases

Some use cases to validate full functionality with.

  • VSCode extension interop
  • ReactJS interop

Additional Notes

Dynamic Imports

Dart currently doesn't have a way to declare modules that can automatically be imported into the global scope. There are two options (but possibly more) for dealing with module imports:

  • only use static imports (e.g. <script> in index.html)
  • explicitly import a module using js_interop.importModule('fs')

note: unsure why static imports cant be used, e.g:

import { foo } from "foo";

Relevant:

Required Preamble

The generated dart code requires some preamble in order to interop with node.js (e.g. adding require to the global scope for future import statements).

An issue has been opened against buid_web_compilers to allow custom premable scripts to be added to the compiler output.

Note: digging around build_modules may give some insight on how to customize the build pipeline.

NodeJS Hot Reload

Dart hot reload cannot work together to hot reload NodeJS. Unlocking this feature would likely require interop with a JS reloader, e.g. Webpack HMR.

Auto-generate Dart extension types

TODO: description

see:

dart3_node_interop's People

Contributors

pattobrien avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.