Skip to content

Commit 147e091

Browse files
committed
refine README
1 parent 1e7c452 commit 147e091

File tree

1 file changed

+16
-32
lines changed

1 file changed

+16
-32
lines changed

README.md

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![npm next channel](https://img.shields.io/npm/v/vite-plugin-elm/next?style=for-the-badge&color=yellow)](https://www.npmjs.com/package/vite-plugin-elm/v/next)
55
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/hmsk/vite-plugin-elm/main.yml?branch=main&style=for-the-badge)](https://github.com/hmsk/vite-plugin-elm/actions/workflows/main.yml)
66

7-
A plugin enables you to compile an Elm [application](https://package.elm-lang.org/packages/elm/browser/latest/Browser#application)/[document](https://package.elm-lang.org/packages/elm/browser/latest/Browser#document)/[element](https://package.elm-lang.org/packages/elm/browser/latest/Browser#element) on your [Vite](https://github.com/vitejs/vite) project. [Hot module replacement](https://vitejs.dev/guide/features.html#hot-module-replacement) works roughly in development.
7+
A plugin that enables us to compile an Elm [application](https://package.elm-lang.org/packages/elm/browser/latest/Browser#application), [document](https://package.elm-lang.org/packages/elm/browser/latest/Browser#document), or [element](https://package.elm-lang.org/packages/elm/browser/latest/Browser#element) within your [Vite](https://github.com/vitejs/vite) project. In development, [hot module replacement](https://vitejs.dev/guide/features.html#hot-module-replacement) works to some extent.
88

99
```ts
1010
import { Elm } from './MyApplication.elm'
@@ -18,7 +18,7 @@ Elm.MyApplication.init()
1818
npm i -D vite-plugin-elm
1919
```
2020

21-
Update `vite.config.(js|ts)`
21+
In `vite.config.(js|ts)`:
2222

2323
```ts
2424
import { defineConfig } from 'vite'
@@ -29,73 +29,57 @@ export default defineConfig({
2929
})
3030
```
3131

32-
Then you can import `.elm` file like:
32+
Then you can import a `.elm` file and run it like:
3333

3434
```ts
3535
import { Elm } from './Hello.elm'
36-
```
37-
38-
then
3936

40-
```ts
4137
// Mount "Hello" Browser.{element,document} on #root
4238
Elm.Hello.init({
4339
node: document.getElementById('root'),
4440
flags: "Initial Message"
4541
})
4642
```
4743

48-
See [`/example`](/example) dir to play with an actual Vite project. And [this working website](https://github.com/hmsk/hmsk.me) may help you to learn how to use.
44+
You can explore the [`/example`](/example) directory to experiment with an actual Vite project. Additionally, [this functional website](https://github.com/hmsk/hmsk.me) can serve as a helpful resource to learn how to use it effectively.
4945

50-
## Plugin Options
46+
## Options
5147

5248
### `debug` (Default: `process.env.NODE_ENV !== 'production'`)
5349

54-
By giving a boolean, can control debug mode of Elm (means toggle Elm Debugger)
50+
You can control the debug mode of Elm, which toggles the Elm Debugger, by providing a boolean value.
5551

5652
![image](https://user-images.githubusercontent.com/85887/120060168-fd7d8600-c00a-11eb-86cd-4125fe06dc59.png)
5753

5854
```ts
59-
import { defineConfig } from 'vite'
60-
import elmPlugin from 'vite-plugin-elm'
61-
62-
export default defineConfig({
63-
plugins: [elmPlugin({ debug: false })]
64-
})
55+
elmPlugin({ debug: false })
6556
```
6657

67-
When it's `false`, disables debug mode in both development and production. Conversely, enables debug mode even in production by `true`. **When production build gets debug mode, Elm's compile optimization doesn't happen**.
58+
When set to `false`, it disables debug mode in both development and production. Conversely, setting it to `true` enables debug mode even in production. It's important to note that **when the production build has debug mode enabled, Elm's compiler optimizations do not take place**.
6859

6960
### `optimize` (Default: `!debug && process.env.NODE_ENV === 'production'`)
7061

71-
By giving a boolean, can control build optimization, useful to use `Debug` [elm functions](https://package.elm-lang.org/packages/elm/core/latest/Debug)
62+
You can control build optimization by providing a boolean value, which can be useful for using [`Debug`](https://package.elm-lang.org/packages/elm/core/latest/Debug) functions in your Elm code.
7263

7364
```ts
74-
import { defineConfig } from 'vite'
75-
import elmPlugin from 'vite-plugin-elm'
76-
77-
export default defineConfig({
78-
plugins: [elmPlugin({ debug: false, optimize: false })]
79-
})
65+
elmPlugin({ debug: false, optimize: false })
8066
```
8167

82-
When true, optimize build and forbid usage of `Debug` elm functions.
83-
When specify optimize attribute, had to tell if need to debug or not. It's not why you want to make debug traces you want to see all actions.
68+
When set to `true`, it optimizes the build and prohibits the usage of Debug Elm functions. If you specify the optimize attribute, you must indicate whether debugging is needed. This is because you might want to have debug traces for the purpose of observing all actions, not necessarily for debugging specific issues.
8469

8570
## Static Assets Handling
8671

87-
This plugin supports importing assets by giving a particular tag `[VITE_PLUGIN_ELM_ASSET:<path to asset>]` to leverage [Vite's asset handling](https://vitejs.dev/guide/assets.html#importing-asset-as-url).
88-
When Elm code has a string, this plugin replaces it with an imported asset. That string should be just a string without any concatenation.
72+
This plugin supports importing assets by using a specific tag `[VITE_PLUGIN_ELM_ASSET:<path to asset>]` to leverage [Vite's asset handling](https://vitejs.dev/guide/assets.html#importing-asset-as-ur). When your Elm code contains a tag, this plugin replaces that string with the imported asset. It's important to note that the string should be a standalone string without any concatenation.
8973

9074
```elm
9175
Html.img [ Html.Attributes.src "[VITE_PLUGIN_ELM_ASSET:/assets/logo.jpg]" ] []
9276
```
9377

9478
### Helper package
9579

96-
By using a Elm package `elm-vite-plugin-helper`, you can shorten such the tagging:
80+
We can simplify the tagging process by using the Elm package `elm-vite-plugin-helper`:
9781

98-
```
82+
```sh
9983
elm install hmsk/elm-vite-plugin-helper
10084
```
10185

@@ -105,9 +89,9 @@ import VitePluginHelper
10589
Html.img [ Html.Attributes.src <| VitePluginHelper.asset "/assets/logo.png?inline" ] []
10690
```
10791

108-
## Combine multiple main files (Experimental from `2.7.0-beta.1`)
92+
## Combine multiple main files (Experimental)
10993

110-
By passing importing path via `with` URL-ish parameter(s), the plugin compiles multiple main files in a single compilation process. That generates a single `Elm` export which has multiple properties for each given main files. This way reduces bundle size comparing to a total size of importing each file separately since common modules/Elm core codes are not repeated.
94+
By passing importing paths via the `with` URL-ish parameter(s), the plugin compiles multiple main files in a single compilation process. This results in a single Elm export that contains multiple properties, each corresponding to a given main file. This feature helps reduce the bundle size when compared to importing each file separately because common modules and Elm core code are not repeated.
11195

11296
```ts
11397
// `Elm.App` and `Elm.Another`, both can work as like importing individually.

0 commit comments

Comments
 (0)