@sdeverywhere/plugin-vite 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +146 -1
  2. package/package.json +2 -3
package/README.md CHANGED
@@ -22,7 +22,152 @@ yarn add -D @sdeverywhere/plugin-vite
22
22
 
23
23
  ## Usage
24
24
 
25
- _TODO: This section needs to be fleshed out. In the meantime, you can refer to the API documentation below for the options used to configure this plugin._
25
+ _Note:_ If you followed the "Quick Start" instructions above and/or are using one of the standard project templates provided by SDEverywhere, the `sde.config.js` file should already be set up to use `plugin-vite`.
26
+ Reading these instructions can still be helpful if you are setting up a project manually or want to understand how `plugin-vite` can be integrated into your project.
27
+
28
+ ### Why use this plugin?
29
+
30
+ Most SDEverywhere projects include an application (or a library) that is built around the generated model.
31
+ Rather than running `sde bundle` and `vite build` as two separate steps, this plugin folds the Vite build into the `sde` build process, which means:
32
+
33
+ - your app is rebuilt automatically whenever the model is regenerated; and
34
+ - in development mode (`sde dev`), a single command starts a Vite dev server that reloads the app when either the model or your app sources change.
35
+
36
+ The plugin does not replace your Vite configuration; it simply runs Vite using the config you provide.
37
+
38
+ ### Steps
39
+
40
+ 1. Add `@sdeverywhere/plugin-vite` as a project "dev" dependency:
41
+
42
+ ```sh
43
+ cd your-model-project
44
+ npm install --save-dev @sdeverywhere/plugin-vite
45
+ ```
46
+
47
+ 2. Update your `sde.config.js` file to use `vitePlugin`. Both the `name` (used in log messages) and `config` (the Vite config) options are required:
48
+
49
+ ```js
50
+ import { dirname, join as joinPath } from 'path'
51
+ import { fileURLToPath } from 'url'
52
+
53
+ import { vitePlugin } from '@sdeverywhere/plugin-vite'
54
+
55
+ const __dirname = dirname(fileURLToPath(import.meta.url))
56
+ const appPath = (...parts) => joinPath(__dirname, 'packages', 'app', ...parts)
57
+
58
+ export async function config() {
59
+ return {
60
+ modelFiles: ['model/example.mdl'],
61
+
62
+ // ...
63
+
64
+ plugins: [
65
+ // ...
66
+
67
+ // Build or serve the model explorer app
68
+ vitePlugin({
69
+ name: 'app',
70
+ apply: {
71
+ // Run the Vite dev server when `sde dev` is used
72
+ development: 'serve'
73
+ },
74
+ config: {
75
+ configFile: appPath('vite.config.js')
76
+ }
77
+ })
78
+ ]
79
+ }
80
+ }
81
+ ```
82
+
83
+ 3. Run `sde bundle` to build your app, or `sde dev` to serve it locally with live reload.
84
+
85
+ ### Choosing the `apply` behavior
86
+
87
+ The `apply` option controls when (and how) Vite runs for each `sde` build mode.
88
+ Both `apply.development` and `apply.production` default to `'post-build'`.
89
+
90
+ For a **web application** that you want to view while you work on the model, use `'serve'` in development mode.
91
+ Vite starts a dev server and refreshes the browser when changes are detected:
92
+
93
+ ```js
94
+ vitePlugin({
95
+ name: 'app',
96
+ apply: {
97
+ development: 'serve'
98
+ },
99
+ config: {
100
+ configFile: appPath('vite.config.js')
101
+ }
102
+ })
103
+ ```
104
+
105
+ For a **library** that other packages depend on (for example, a `core` package that wraps the generated model), use `'watch'` in development mode so that Vite rebuilds the library whenever its sources change:
106
+
107
+ ```js
108
+ vitePlugin({
109
+ name: 'core',
110
+ apply: {
111
+ development: 'watch'
112
+ },
113
+ config: {
114
+ configFile: corePath('vite.config.js')
115
+ }
116
+ })
117
+ ```
118
+
119
+ The full set of values is:
120
+
121
+ | Value | Development | Production | Behavior |
122
+ | ----------------- | :---------: | :--------: | -------------------------------------------------------- |
123
+ | `'skip'` | ✓ | ✓ | Don't run the plugin. |
124
+ | `'post-generate'` | ✓ | ✓ | Run `vite build` in the `postGenerate` phase. |
125
+ | `'post-build'` | ✓ | ✓ | Run `vite build` in the `postBuild` phase (the default). |
126
+ | `'watch'` | ✓ | | Run `vite build` in watch mode; useful for libraries. |
127
+ | `'serve'` | ✓ | | Run the Vite dev server; useful for applications. |
128
+
129
+ Use `'post-generate'` when a later plugin needs the output of this Vite build; use `'post-build'` (the default) otherwise.
130
+
131
+ ### Using more than one instance
132
+
133
+ A project can include as many `vitePlugin` instances as it needs; give each one a distinct `name` so that log messages are easy to follow.
134
+ Because plugins run in order, list a library before the app that depends on it:
135
+
136
+ ```js
137
+ plugins: [
138
+ // Build the `core` library that wraps the generated model
139
+ vitePlugin({
140
+ name: 'core',
141
+ apply: { development: 'watch' },
142
+ config: { configFile: corePath('vite.config.js') }
143
+ }),
144
+
145
+ // Build or serve the app that depends on the `core` library
146
+ vitePlugin({
147
+ name: 'app',
148
+ apply: { development: 'serve' },
149
+ config: { configFile: appPath('vite.config.js') }
150
+ })
151
+ ]
152
+ ```
153
+
154
+ ### Providing the Vite config inline
155
+
156
+ The `config` option is a Vite [`InlineConfig`](https://vite.dev/config/), so you can define the configuration directly in `sde.config.js` instead of pointing at a separate config file:
157
+
158
+ ```js
159
+ vitePlugin({
160
+ name: 'app',
161
+ config: {
162
+ configFile: false,
163
+ root: appPath(),
164
+ build: {
165
+ outDir: appPath('dist'),
166
+ emptyOutDir: true
167
+ }
168
+ }
169
+ })
170
+ ```
26
171
 
27
172
  ## Documentation
28
173
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdeverywhere/plugin-vite",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "files": [
5
5
  "dist/**"
6
6
  ],
@@ -20,8 +20,7 @@
20
20
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@sdeverywhere/build": "*",
24
- "vite": "^7.1.12"
23
+ "vite": "^7.3.6"
25
24
  },
26
25
  "author": "Climate Interactive",
27
26
  "license": "MIT",