Skip to content

Rules for Writting Cross Plattform ESM Code

Frank Lemanschik edited this page Dec 1, 2018 · 5 revisions

Do not do

  • use NPM resolve Algo
  • use CJS
  • Create ESM via Babel or any programatic way out of CJS ESM needs Rethinking!

Suggestions

  • use the Stealify esm patch for node https://github.com/standard-things/esm @std/esm
  • don't use package managers create your own package self install able
  • Simply paste this line sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share} before first command and remove sudo when using npm i -g

Do

  • use Always .mjs extension for ESM and .js for CJS
  • If using package.json NPM use main without file ext and module with relativ path and file extension aka URL
  • use Always Relative Paths and keep them intact or rewrite them when bundling or packaging.
  • use ESM Versions where possible even fork and create them!

Project structure should look like

  • src/*
  • src/frontend (cli,interface, app)
    • Should Contain also if needed SSR Code
    • Should Contain Asset Managment
  • src/backend (Data Storage,Api, access point, optional can serve)
  • dist/
  • should publish individual packages to get consumed directly
    • repo tools and packaging as also documentation

Special Notes what this Structure Enables

  • Guide Stealify Modules and CJS code.

Build for Android

  • install gradle sudo apt-get install gradle
  • Download https://developer.android.com/studio/#command-tools
  • JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee' sdkmanager "platform-tools" "platforms;android-26" "build-tools;27.0.3"
  • android list sdk --all
  • android update sdk -u -a -t android-27
  • JAVA_OPTS="" ANDROID_HOME="/home/frank/android-sdk" PATH="${PATH}:/home/frank/android-sdk/tools/bin:/home/frank/android-sdk/platform-tools" cordovabuild android --verbose
  • avdmanager create avd -n test -k "system-images;android-25;google_apis;x86"