@ohos-ports/vite-plugin-rails 0.6.0-beta.1
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.
- package/LICENSE.txt +21 -0
- package/README.md +132 -0
- package/dist/index.d.mts +78 -0
- package/dist/index.mjs +72 -0
- package/package.json +60 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Maximo Mussini
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<h2 align='center'><samp>vite-plugin-rails</samp></h2>
|
|
2
|
+
|
|
3
|
+
<p align='center'>Convention over configuration for Rails projects using Vite</p>
|
|
4
|
+
|
|
5
|
+
<p align='center'>
|
|
6
|
+
<a href='https://www.npmjs.com/package/vite-plugin-rails'>
|
|
7
|
+
<img src='https://img.shields.io/npm/v/vite-plugin-rails?color=222&style=flat-square'>
|
|
8
|
+
</a>
|
|
9
|
+
<a href='https://github.com/ElMassimo/vite_ruby/blob/master/LICENSE.txt'>
|
|
10
|
+
<img src='https://img.shields.io/badge/license-MIT-blue.svg'>
|
|
11
|
+
</a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<br>
|
|
15
|
+
|
|
16
|
+
[vite_rails]: https://github.com/ElMassimo/vite_ruby/tree/main/vite_rails
|
|
17
|
+
[vite-plugin-ruby]: https://github.com/ElMassimo/vite_ruby/tree/main/vite-plugin-ruby
|
|
18
|
+
[configuration options]: https://github.com/ElMassimo/vite_ruby/tree/main/vite-plugin-rails/src/index.ts#L12-L84
|
|
19
|
+
[rollup-plugin-gzip]: https://github.com/kryops/rollup-plugin-gzip
|
|
20
|
+
[vite-plugin-environment]: https://github.com/ElMassimo/vite-plugin-environment
|
|
21
|
+
[vite-plugin-full-reload]: https://github.com/ElMassimo/vite-plugin-full-reload
|
|
22
|
+
[vite-plugin-stimulus-hmr]: https://github.com/ElMassimo/vite-plugin-stimulus-hmr
|
|
23
|
+
[vite-plugin-manifest-sri]: https://github.com/ElMassimo/vite-plugin-manifest-sri
|
|
24
|
+
|
|
25
|
+
## Installation 💿
|
|
26
|
+
|
|
27
|
+
In the future, [<kbd>vite_rails</kbd>][vite_rails] might install this plugin by default.
|
|
28
|
+
|
|
29
|
+
You can install it manually by running:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm i vite-plugin-rails # yarn add vite-plugin-rails
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage 🚀
|
|
36
|
+
|
|
37
|
+
Add it to your plugins in `vite.config.ts`
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// vite.config.ts
|
|
41
|
+
import Vue from '@vitejs/plugin-vue' // Example, could be using other plugins.
|
|
42
|
+
import ViteRails from 'vite-plugin-rails'
|
|
43
|
+
|
|
44
|
+
export default {
|
|
45
|
+
plugins: [
|
|
46
|
+
Vue(),
|
|
47
|
+
ViteRails(),
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Batteries Included 🔋
|
|
53
|
+
|
|
54
|
+
Unlike [`vite-plugin-ruby`][vite-plugin-ruby], which provides the minimum amount of configuration necessary to get started, this plugin takes a Rails-approach of including plugins you would normally add.
|
|
55
|
+
|
|
56
|
+
You can configure each plugin by passing options, which are fully typed. See the [configuration options] for reference.
|
|
57
|
+
|
|
58
|
+
If you need finer-grained control, you can opt-out and use `vite-plugin-ruby` instead, manually adding only the plugins you need.
|
|
59
|
+
|
|
60
|
+
### [Ruby][vite-plugin-ruby]
|
|
61
|
+
|
|
62
|
+
[`vite-plugin-ruby`][vite-plugin-ruby] is added by default.
|
|
63
|
+
|
|
64
|
+
### Compression
|
|
65
|
+
|
|
66
|
+
This plugin uses [`rollup-plugin-gzip`][rollup-plugin-gzip] to create `gzip` and `brotli` compressed copies of your assets after build.
|
|
67
|
+
|
|
68
|
+
You can disable each manually:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
ViteRails({
|
|
72
|
+
compress: { brotli: false }
|
|
73
|
+
}),
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
ViteRails({
|
|
78
|
+
compress: false
|
|
79
|
+
}),
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### [Environment](https://github.com/ElMassimo/vite-plugin-environment)
|
|
84
|
+
|
|
85
|
+
[`vite-plugin-environment`][vite-plugin-environment] is used to expose environment variables to your
|
|
86
|
+
client code, using the [`import.meta.env`](https://vitejs.dev/guide/env-and-mode.html#env-files) convention from Vite.
|
|
87
|
+
|
|
88
|
+
This plugin allows you to conveniently provide defaults, or fail on required env variables:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
ViteRails({
|
|
92
|
+
envVars: {
|
|
93
|
+
API_KEY: null,
|
|
94
|
+
OPTIONAL_KEY: '<opt-value>',
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### [Full Reload](https://github.com/ElMassimo/vite-plugin-full-reload)
|
|
100
|
+
|
|
101
|
+
[`vite-plugin-full-reload`][vite-plugin-full-reload] comes pre-configured to automatically reload the page
|
|
102
|
+
when making changes to server-rendered layouts and templates, improving the
|
|
103
|
+
feedback cycle.
|
|
104
|
+
|
|
105
|
+
You can override the default paths, or pass additional ones:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
ViteRails({
|
|
109
|
+
fullReload: {
|
|
110
|
+
additionalPaths: ['app/serializers/**/*']
|
|
111
|
+
},
|
|
112
|
+
}),
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### [Stimulus HMR](https://github.com/ElMassimo/vite-plugin-stimulus-hmr)
|
|
116
|
+
|
|
117
|
+
[`vite-plugin-stimulus-hmr`][vite-plugin-stimulus-hmr] is included by default,
|
|
118
|
+
allowing you to see changes to your Stimulus controllers instantly without refreshing the page.
|
|
119
|
+
|
|
120
|
+
You can use the `stimulus` option if you need to configure it.
|
|
121
|
+
|
|
122
|
+
### [Subresource Integrity](https://github.com/ElMassimo/vite-plugin-manifest-sri)
|
|
123
|
+
|
|
124
|
+
[`vite-plugin-manifest-sri`][vite-plugin-manifest-sri] is included by default,
|
|
125
|
+
calculating a cryptographic hash for JavaScript and CSS assets, so that the browser
|
|
126
|
+
can verify the resources it fetches.
|
|
127
|
+
|
|
128
|
+
You can use the `sri` option if you need to configure it.
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
This library is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Config } from "vite-plugin-full-reload";
|
|
2
|
+
import { Options as Options$1 } from "vite-plugin-manifest-sri";
|
|
3
|
+
import { EnvOptions, EnvVars } from "vite-plugin-environment";
|
|
4
|
+
import { Options as Options$2 } from "vite-plugin-stimulus-hmr";
|
|
5
|
+
import { GzipPluginOptions } from "rollup-plugin-gzip";
|
|
6
|
+
import { PluginOption } from "vite";
|
|
7
|
+
|
|
8
|
+
//#region src/index.d.ts
|
|
9
|
+
interface Options {
|
|
10
|
+
/**
|
|
11
|
+
* Whether to create compressed copies of relevant assets.
|
|
12
|
+
*
|
|
13
|
+
* Can use it to turn off `gzip` and `brotli` at once.
|
|
14
|
+
*
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
compress?: boolean | {
|
|
18
|
+
/**
|
|
19
|
+
* Whether to create gzip copies of relevant assets.
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
gzip?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether to create brotli copies of relevant assets.
|
|
25
|
+
* @default true
|
|
26
|
+
*/
|
|
27
|
+
brotli?: boolean;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Options for rollup-plugin-gzip, will be used both for brotli and gzip.
|
|
31
|
+
*
|
|
32
|
+
* https://github.com/kryops/rollup-plugin-gzip
|
|
33
|
+
*/
|
|
34
|
+
compression?: GzipPluginOptions;
|
|
35
|
+
/**
|
|
36
|
+
* Environment variables that should be exposed to the client build.
|
|
37
|
+
*
|
|
38
|
+
* By default, they are exposed under `import.meta.env`.
|
|
39
|
+
*
|
|
40
|
+
* https://github.com/ElMassimo/vite-plugin-environment
|
|
41
|
+
*/
|
|
42
|
+
envVars?: EnvVars;
|
|
43
|
+
/**
|
|
44
|
+
* Options for vite-plugin-environment.
|
|
45
|
+
*
|
|
46
|
+
* By default, they are exposed under `import.meta.env`.
|
|
47
|
+
*
|
|
48
|
+
* https://github.com/ElMassimo/vite-plugin-environment
|
|
49
|
+
*/
|
|
50
|
+
envOptions?: EnvOptions;
|
|
51
|
+
/**
|
|
52
|
+
* Options for vite-plugin-manifest-sri.
|
|
53
|
+
*
|
|
54
|
+
* https://github.com/ElMassimo/vite-plugin-manifest-sri
|
|
55
|
+
*/
|
|
56
|
+
sri?: false | Options$1;
|
|
57
|
+
/**
|
|
58
|
+
* Options for vite-plugin-stimulus-hmr.
|
|
59
|
+
*
|
|
60
|
+
* https://github.com/ElMassimo/vite-plugin-stimulus-hmr
|
|
61
|
+
*/
|
|
62
|
+
stimulus?: false | Options$2;
|
|
63
|
+
/**
|
|
64
|
+
* Options for vite-plugin-full-reload.
|
|
65
|
+
*
|
|
66
|
+
* By default it's configured for a standard Rails structure, assuming you
|
|
67
|
+
* would want to automatically reload when modifying views or routes.
|
|
68
|
+
*
|
|
69
|
+
* https://github.com/ElMassimo/vite-plugin-full-reload
|
|
70
|
+
*/
|
|
71
|
+
fullReload?: false | Config & {
|
|
72
|
+
additionalPaths?: string | string[];
|
|
73
|
+
overridePaths?: string | string[];
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
declare function ViteRubyPlugin(options?: Options): PluginOption[];
|
|
77
|
+
//#endregion
|
|
78
|
+
export { Options, ViteRubyPlugin as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { brotliCompressSync } from "zlib";
|
|
2
|
+
import fullReloadPlugin from "vite-plugin-full-reload";
|
|
3
|
+
import manifestSRI from "vite-plugin-manifest-sri";
|
|
4
|
+
import ruby from "vite-plugin-ruby";
|
|
5
|
+
import environment from "vite-plugin-environment";
|
|
6
|
+
import stimulusHMRPlugin from "vite-plugin-stimulus-hmr";
|
|
7
|
+
import gzipPlugin from "rollup-plugin-gzip";
|
|
8
|
+
//#region src/index.ts
|
|
9
|
+
/**
|
|
10
|
+
* [defaultReloadPaths description]
|
|
11
|
+
* @type {Array}
|
|
12
|
+
*/
|
|
13
|
+
const defaultReloadPaths = [
|
|
14
|
+
"config/routes.rb",
|
|
15
|
+
"config/routes/*.rb",
|
|
16
|
+
"app/views/**/*"
|
|
17
|
+
];
|
|
18
|
+
function ViteRubyPlugin(options = {}) {
|
|
19
|
+
let { compress = true } = options;
|
|
20
|
+
if (compress !== false) compress = {
|
|
21
|
+
gzip: true,
|
|
22
|
+
brotli: true,
|
|
23
|
+
...compress === true ? {} : compress
|
|
24
|
+
};
|
|
25
|
+
const envOptions = {
|
|
26
|
+
defineOn: "import.meta.env",
|
|
27
|
+
...options.envOptions
|
|
28
|
+
};
|
|
29
|
+
const { overridePaths, additionalPaths = [], ...reloadOptions } = options.fullReload || {};
|
|
30
|
+
const reloadPaths = overridePaths || [...defaultReloadPaths, ...wrapArray(additionalPaths)];
|
|
31
|
+
const plugins = [
|
|
32
|
+
ruby(),
|
|
33
|
+
options.envVars && environment(options.envVars, envOptions),
|
|
34
|
+
options.sri !== false && manifestSRI(options.sri),
|
|
35
|
+
options.stimulus !== false && stimulusHMRPlugin(options.stimulus),
|
|
36
|
+
options.fullReload !== false && fullReloadPlugin(reloadPaths, reloadOptions),
|
|
37
|
+
compress && compress.gzip && gzipPlugin(options.compression),
|
|
38
|
+
compress && compress.brotli && gzipPlugin({
|
|
39
|
+
...options.compression,
|
|
40
|
+
customCompression: (content) => brotliCompressSync(Buffer.from(content)),
|
|
41
|
+
fileName: ".br"
|
|
42
|
+
})
|
|
43
|
+
].flat(Infinity).filter((plugin) => plugin);
|
|
44
|
+
return [...plugins, dupDetector(plugins.map((plugin) => plugin.name))];
|
|
45
|
+
}
|
|
46
|
+
function wrapArray(array) {
|
|
47
|
+
return Array.isArray(array) ? array : [array];
|
|
48
|
+
}
|
|
49
|
+
function dupDetector(originalPluginNames) {
|
|
50
|
+
return {
|
|
51
|
+
name: "vite-plugin-rails:dup-detector",
|
|
52
|
+
configResolved(config) {
|
|
53
|
+
if (config.plugins) {
|
|
54
|
+
const pluginNames = new Set(originalPluginNames);
|
|
55
|
+
pluginNames.delete("gzip");
|
|
56
|
+
const pluginCounts = Object.create(null);
|
|
57
|
+
config.plugins.filter((plugin) => pluginNames.has(plugin.name)).forEach((plugin) => {
|
|
58
|
+
pluginCounts[plugin.name] = (pluginCounts[plugin.name] || 0) + 1;
|
|
59
|
+
});
|
|
60
|
+
const duplicates = Object.entries(pluginCounts).filter(([name, count]) => count > 1).map(([name, count]) => name);
|
|
61
|
+
if (duplicates.length) throw new Error(`
|
|
62
|
+
[vite-plugin-rails] Duplicate plugins detected: ${duplicates.join(", ")}.
|
|
63
|
+
|
|
64
|
+
If migrating from vite-plugin-ruby, make sure to remove these manually added
|
|
65
|
+
plugins, and instead pass the options to vite-plugin-rails.
|
|
66
|
+
`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { ViteRubyPlugin as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ohos-ports/vite-plugin-rails",
|
|
3
|
+
"description": "Convention over configuration for using Vite in Rails apps",
|
|
4
|
+
"version": "0.6.0-beta.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./dist/index.d.mts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/index.mjs",
|
|
9
|
+
"./package.json": "./package.json"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "Máximo Mussini <maximomussini@gmail.com> (https://maximomussini.com)",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
16
|
+
"directory": "ports/vite-plugin-rails/0.6.0"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"plugin",
|
|
20
|
+
"rails",
|
|
21
|
+
"ruby",
|
|
22
|
+
"vite",
|
|
23
|
+
"vite-plugin",
|
|
24
|
+
"vitejs"
|
|
25
|
+
],
|
|
26
|
+
"homepage": "https://github.com/ohos-ports/ohos-ports/tree/main/ports/vite-plugin-rails/0.6.0",
|
|
27
|
+
"bugs": "https://github.com/ohos-ports/ohos-ports/issues",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"rollup-plugin-gzip": "^4.2.0",
|
|
33
|
+
"vite-plugin-environment": "^1.1.3",
|
|
34
|
+
"vite-plugin-full-reload": "^1.1.0",
|
|
35
|
+
"vite-plugin-manifest-sri": "^0.2.0",
|
|
36
|
+
"vite-plugin-ruby": "^5.0.0",
|
|
37
|
+
"vite-plugin-stimulus-hmr": "^3.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"vite": ">=5.0.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/debug": "^4.1.12",
|
|
44
|
+
"@types/node": "^22.0.0",
|
|
45
|
+
"standard-version": "^9.5.0",
|
|
46
|
+
"typescript": "^5.0.0",
|
|
47
|
+
"@ohos-ports/rollup": "^4.62.2-beta.2",
|
|
48
|
+
"vite": "^8.0.0",
|
|
49
|
+
"vitest": "^0.34.6",
|
|
50
|
+
"@ohos-ports/tsdown": "^0.23.0-beta.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"lint": "eslint .",
|
|
54
|
+
"dev": "npm run build -- --watch",
|
|
55
|
+
"example:dev": "npm -C example run dev",
|
|
56
|
+
"example:build": "npm -C example run build",
|
|
57
|
+
"build": "tsdown",
|
|
58
|
+
"test": "vitest"
|
|
59
|
+
}
|
|
60
|
+
}
|