Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/geopjr/vite-plugin-dart
⚡ + 🎯 = 💖
https://github.com/geopjr/vite-plugin-dart
dart plugin vite vitejs
Last synced: about 2 months ago
JSON representation
⚡ + 🎯 = 💖
- Host: GitHub
- URL: https://github.com/geopjr/vite-plugin-dart
- Owner: GeopJr
- Created: 2021-09-27T21:37:57.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-14T04:15:32.000Z (over 1 year ago)
- Last Synced: 2024-11-08T07:04:15.737Z (about 2 months ago)
- Topics: dart, plugin, vite, vitejs
- Language: JavaScript
- Homepage: https://vite-plugin-dart.vercel.app
- Size: 196 KB
- Stars: 30
- Watchers: 3
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
vite-plugin-dart
Import .dart files effortlessly.
#
## Install
- Install the plugin:
```bash
pnpm i -D vite-plugin-dart # npm, yarn
```- Install [Dart](https://dart.dev/get-dart)
- Add `vite-plugin-dart` to your `vite.config.mjs`:
```js
// vite.config.mjs (or .ts)
import Dart from "vite-plugin-dart";export default {
plugins: [Dart()],
};
```#
## Importing
It's as simple as:
```js
import "./index.dart";
```All your Pub packages should work as expected! For an example take a look at the [example](./example) folder.
#
## Options
Here's the default options:
```js
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](./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:
```bash
Build Command: cd example && npm run buildOutput 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](./example/vite.config.mjs) has some options for this plugin based on the current environment:
```js
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](https://github.com/GeopJr/vite-plugin-dart/blob/main/CODE_OF_CONDUCT.md)
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.