https://github.com/hychen/flutter_js_asset
Packing NPM modules for Flutter.
https://github.com/hychen/flutter_js_asset
flutter
Last synced: about 1 month ago
JSON representation
Packing NPM modules for Flutter.
- Host: GitHub
- URL: https://github.com/hychen/flutter_js_asset
- Owner: hychen
- License: mit
- Created: 2021-11-19T13:51:48.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-24T22:45:08.000Z (over 4 years ago)
- Last Synced: 2024-12-31T08:45:41.614Z (over 1 year ago)
- Topics: flutter
- Language: Dart
- Homepage:
- Size: 130 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Inspired by [aspen](https://pub.dev/packages/aspen) but specified for using npm modules in
[flutter_js](https://pub.dev/packages/flutter_js)
## Features
- Creates a .dart file containing constants that included javascript code read from specified files
by using `@TextAsset` annotation.
## Getting started
```
flutter pub add -d build_runner
flutter pub add flutter_js_asset
```
To build, type
```
flutter pub run build_runner build
```
To test, type
```
flutter pub run build_runner test
```
## Usage
1. Create a npm module in `web` folder or any other folders are whitelisted because by default
`package:build` only allows you to use assets from a pre-defined whitelist of directories.
2. Installs packages you'd like to use and
3. Create a `index.js` and exports modules to global object like this:
```javascript
module.exports.lib = require('name/of/module');
```
4. Generates a `bundle.js` by using webpack.
5. Creates a dart file like this:
```dart
library example;
import 'package:flutter_js_asset/annotations.dart';
part 'example.g.dart';
@TextAsset('asset:example/web/dist/bundle.js')
const String jsCode = $jsCodeContent;
```
6. Generates $jsCodeContent by typing:
```sh
flutter pub run build_runner build
```
see `example` for more details.