1
0
Fork 0
This repository has been archived on 2026-03-24. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
  • JavaScript 42.8%
  • Dart 29.2%
  • HTML 22.8%
  • SCSS 5.2%
Find a file
Image renovate[bot] d097a2541c
chore(deps): update dependency vite to v4.1.1 (#152)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-02-02 18:48:49 +02:00
example chore(deps): update dependency vite to v4.1.1 (#152) 2023-02-02 18:48:49 +02:00
src feat: initial 2021-09-28 02:45:31 +03:00
.gitignore fix(example): invisible icons 2022-03-06 21:22:49 +02:00
.npmignore feat(docs): document CI workflow 2021-09-28 17:04:11 +03:00
CODE_OF_CONDUCT.md feat(docs): document CI workflow 2021-09-28 17:04:11 +03:00
index.d.ts feat: add type defination for typescript (#58) 2022-03-06 21:11:01 +02:00
package.json chore(deps): update dependency vite to v4.1.1 (#152) 2023-02-02 18:48:49 +02:00
README.md chore: vite.config.js -> mjs 2021-09-28 17:39:07 +03:00
renovate.json feat: initial 2021-09-28 02:45:31 +03:00

vite plugin dart logo

vite-plugin-dart

Import .dart files effortlessly.


Code Of Conduct

Install

  • Install the plugin:
pnpm i -D vite-plugin-dart # npm, yarn
  • Install Dart

  • Add vite-plugin-dart to your vite.config.mjs:

// vite.config.mjs (or .ts)
import Dart from "vite-plugin-dart";

export default {
  plugins: [Dart()],
};

Importing

It's as simple as:

import "./index.dart";

All your Pub packages should work as expected! For an example take a look at the example folder.

Options

Here's the default options:

const defaultConfig = {
  dart: "dart",
  minify: false,
  "enable-asserts": false,
  verbose: false,
  define: [],
  packages: "",
  "suppress-warnings": false,
  "fatal-warnings": false,
  "suppress-hints": false,
  "enable-diagnostic-colors": false,
  terse: false,
  "show-package-warnings": false,
  csp: false,
  "no-source-maps": false,
  "omit-late-names": false,
  O: 1,
  "omit-implicit-checks": false,
  "trust-primitives": false,
  "lax-runtime-type-to-string": false,
  verbosity: "warning",
  stdio: true,
};

For most, you can read their description by running dart compile js -h -v.

The ones that are not there are:

dart: Dart binary location
verbosity: Verbosity level (all, info, warning, error)
stdio: Whether or not to pass the dart stdio to parent

It uses JSDoc, so make sure to follow your IDE's annotations.

Example

See the example folder.

All tools used there are Dart packages!

How does it work?

Dart can compile to JS using dart2js. This plugin compiles your Dart files using that at your OS' tmp folder and then after cleaning the generated sourcemaps, returns it to Vite which imports it.

Deploying

Most platforms do not provide dart pre-installed so you need to install it.

The general workflow is: Install Dart => npm i => dart pub get => npm run build.

For example, here's the Vercel config for this repo:

Build Command: cd example && npm run build

Output Dir: ./example/dist

Install Command: yum install unzip -y && cd example && if [ ! -d "./dart-sdk/" ]; then curl -L  https://storage.googleapis.com/dart-archive/channels/be/raw/latest/sdk/dartsdk-linux-x64-release.zip > dart.zip; fi && unzip -qq dart.zip && npm i && ./dart-sdk/bin/dart pub get

At the same time, vite.config.mjs has some options for this plugin based on the current environment:

Dart({
  // Optimizations set to 2 on prod
  O: mode === "development" ? 1 : 2,
  // Dart location when on Vercel (This is a custom env var on Vercel, set to true)
  dart: process.env.VERCEL ? "./dart-sdk/bin/dart" : "dart",
}),

Contributing

  1. Read the Code of Conduct
  2. Fork it ( https://github.com/GeopJr/vite-plugin-dart/fork )
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request

Dart and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.