Skip to content

Commit

Permalink
docs: update install and usage documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
redfox-mx committed Sep 8, 2024
1 parent 2522b6a commit 4cc9191
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
54 changes: 32 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
# unplugin-starter
# unplugin-fluent [![npm](https://img.shields.io/npm/v/unplugin-fluent.svg)](https://npmjs.com/package/unplugin-fluent)

[![NPM version](https://img.shields.io/npm/v/unplugin-starter?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-starter)
> Use all the power of the fluent project with your favorite bundler/compiler 🌊
Starter template for [unplugin](https://github.com/unjs/unplugin).
[![ci](https://github.com/redfox-mx/unplugin-fluent/actions/workflows/ci.yml/badge.svg)](https://github.com/redfox-mx/unplugin-fluent/actions/workflows/ci.yml)
![test](https://img.shields.io/badge/test-vite-orange)
![test](https://img.shields.io/badge/test-webpack-blue)
![test](https://img.shields.io/badge/test-rollup-yellow)
![test](https://img.shields.io/badge/test-esbuild-red)

## Template Usage
Transform your fluent files into compiled fluent resources

To use this template, clone it down using:
## Usage

```bash
npx degit unplugin/unplugin-starter my-unplugin
```
Import your .ftl files, that's all!!!

And do a global replacement of `unplugin-starter` with your plugin name.
```ts
import enUs from './locales/en-us.ftl'
import esMx from './locales/es-mx.ftl'

Then you can start developing your unplugin 🔥
// create your bundles
const bundle = new FluentBundle('en-US', { useIsolating: false })
const bundle = new FluentBundle('es-MX', { useIsolating: false })

```

To test your plugin, run: `pnpm run dev`
To release a new version, run: `pnpm run release`

## Install

```bash
npm i unplugin-starter
npm i -D @fluent/bundle unplugin-fluent

pnpm add -D @fluent/bundle unplugin-fluent
```

<details>
<summary>Vite</summary><br>

```ts
// vite.config.ts
import Starter from 'unplugin-starter/vite'
import fluent from 'unplugin-fluent/vite'

export default defineConfig({
plugins: [
Starter({ /* options */ }),
fluent({ /* options */ }),
],
})
```
Expand All @@ -48,11 +56,11 @@ Example: [`playground/`](./playground/)

```ts
// rollup.config.js
import Starter from 'unplugin-starter/rollup'
import fluent from 'unplugin-fluent/rollup'

export default {
plugins: [
Starter({ /* options */ }),
fluent({ /* options */ }),
],
}
```
Expand All @@ -67,7 +75,7 @@ export default {
module.exports = {
/* ... */
plugins: [
require('unplugin-starter/webpack')({ /* options */ })
require('unplugin-fluent/webpack')({ /* options */ })
]
}
```
Expand All @@ -81,7 +89,7 @@ module.exports = {
// nuxt.config.js
export default defineNuxtConfig({
modules: [
['unplugin-starter/nuxt', { /* options */ }],
['unplugin-fluent/nuxt', { /* options */ }],
],
})
```
Expand All @@ -98,7 +106,7 @@ export default defineNuxtConfig({
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-starter/webpack')({ /* options */ }),
require('unplugin-fluent/webpack')({ /* options */ }),
],
},
}
Expand All @@ -112,11 +120,13 @@ module.exports = {
```ts
// esbuild.config.js
import { build } from 'esbuild'
import Starter from 'unplugin-starter/esbuild'
import fluent from 'unplugin-fluent/esbuild'

build({
plugins: [Starter()],
plugins: [fluent()],
})
```

<br></details>

> Note: Unplugin fluent compiles your fluent files into FluentResources, sometimes this behavior can increase ypur bundle size in favor of performance
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"type": "module",
"version": "0.1.0",
"packageManager": "[email protected]",
"description": "",
"description": "Use all the power of the fluent project with your favorite bundler/compiler",
"license": "MIT",
"homepage": "https://github.com/antfu/unplugin-starter#readme",
"homepage": "https://github.com/redfox-mx/unplugin-fluent#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/antfu/unplugin-starter.git"
"url": "git+https://github.com/redfox-mx/unplugin-fluent.git"
},
"bugs": {
"url": "https://github.com/antfu/unplugin-starter/issues"
"url": "https://github.com/redfox-mx/unplugin-fluent/issues"
},
"keywords": [
"fluent",
Expand Down
1 change: 1 addition & 0 deletions playground/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import locale from './locale.ftl'
const bundle = new FluentBundle('en-US', { useIsolating: false })
bundle.addResource(locale)
const msg = bundle.getMessage('hello')

if (msg?.value) {
bundle.formatPattern(msg.value)
const element = document.getElementById('app')
Expand Down
2 changes: 1 addition & 1 deletion src/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Options } from './types'
import fluent from '.'

export default (options: Options): any => ({
name: 'unplugin-starter',
name: 'unplugin-fluent',
hooks: {
'astro:config:setup': async (astro: any) => {
astro.config.vite.plugins ||= []
Expand Down

0 comments on commit 4cc9191

Please sign in to comment.