vite_rails 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a21a899a4c8bb0f107bdb5947e73654aa4ff4f5c8096655fca6afbf3230bca07
4
- data.tar.gz: c58dac4d02a4d63b65e0b520b5b124b2b6e4e0d02324fe1a99f6d76b24639778
3
+ metadata.gz: b4596570b8e1f1df1839336f50463239af3bb3c251769b7bfa7be112d245a0f3
4
+ data.tar.gz: 226884d61c9e133381b025e14dbbd1c9cca922cac7bf52cd9fe5ae77ec2d6550
5
5
  SHA512:
6
- metadata.gz: 3c15259b8704298bdf8ac0a63d93960c75d1f977de62645e9e855d644cb29d1de270e0e1a1357edfe468c816264c9136af3cab1226b13eb3ef2e9aea83f89b8e
7
- data.tar.gz: 1ba34b6164b4d0321f402fb3a96df166fa36f98539f3403aa1add892bdc1c056e836456970758349dc8db0189f13e96413bbbf1dd7f88fa6d116b232efe18710
6
+ metadata.gz: 405f84061588ece09e3f52d4137c27421d80f74826c5e6c7fe82ec7691abf703236a1cc13a265006c6f99673511f6ab0ae236028aa9a225c41a7595dde4218fb
7
+ data.tar.gz: cc212a87a1b4a5f678866d3e42d1c751465544badff3ecb58d462b59a6dbedc339e89d6e3b9b1fc43f14d4171d4a4115bc580f7493f992ad03a0cae086a9bb8f
data/README.md CHANGED
@@ -22,6 +22,7 @@
22
22
  [vite_rails]: https://github.com/ElMassimo/vite_rails
23
23
  [webpacker]: https://github.com/rails/webpacker
24
24
  [vite]: http://vitejs.dev/
25
+ [config file]: https://github.com/ElMassimo/vite_rails/blob/main/package/default.vite.json
25
26
 
26
27
  [__Vite Rails__][vite_rails] allows you to use [Vite] to power the frontend.
27
28
 
@@ -33,10 +34,11 @@
33
34
  - ⚡️ Hot Reload
34
35
  - ⚙️ Rake Tasks
35
36
  - 🪝 Hooks to <kbd>assets:precompile</kbd> and friends
37
+ - And more! (detects changes, and builds automatically if Vite is not running)
36
38
 
37
39
  ## Documentation 📖
38
40
 
39
- Coming Soon!
41
+ A documentation website is coming soon!
40
42
 
41
43
  ## Installation 💿
42
44
 
@@ -55,6 +57,71 @@ bin/rake vite:install
55
57
 
56
58
  This will generate configuration files and a sample setup.
57
59
 
60
+ ## Usage 🚀
61
+
62
+ Drawing inspiration from [webpacker], any files in `app/javascript/entrypoints`
63
+ will be considered entries to your application (SPAs or pages).
64
+
65
+ These files will be detected, and passed on to Vite, all configuration is done
66
+ for you.
67
+
68
+ ### Imports ⤵️
69
+
70
+ For convenience, a `~/` import alias is configured to `app/javascript`, allowing
71
+ you to use absolute paths:
72
+
73
+ ```js
74
+ import { createApp } from 'vue'
75
+ import App from '~/App.vue'
76
+ import '~/channels'
77
+
78
+ createApp(App).mount('#app')
79
+ ```
80
+
81
+ ### Tags 🏷
82
+
83
+ `vite_typescript_tag`, `vite_javascript_tag`, and `vite_stylesheet_tag` can be
84
+ used to output `<script>` and `<link>` tags in your Rails layouts or templates.
85
+
86
+ ```html
87
+ <head>
88
+ <title>Joie</title>
89
+ <%= csrf_meta_tags %>
90
+ <%= csp_meta_tag %>
91
+
92
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
93
+ <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
94
+
95
+ <%= vite_stylesheet_tag 'strange' %>
96
+ <%= vite_typescript_tag 'application' %>
97
+ </head>
98
+ ```
99
+
100
+ For other types of assets, you can use `vite_asset_path` and pass that to the appropriate tag helper.
101
+
102
+ ## Configuration ⚙️
103
+
104
+ This is what your `config/vite.json` might look like:
105
+
106
+ ```json
107
+ {
108
+ "all": {
109
+ "watchAdditionalPaths": []
110
+ },
111
+ "development": {
112
+ "autoBuild": true,
113
+ "publicOutputDir": "vite-dev",
114
+ "port": 3036
115
+ },
116
+ "test": {
117
+ "autoBuild": true,
118
+ "publicOutputDir": "vite-test"
119
+ }
120
+ }
121
+ ```
122
+
123
+ Check [this file][config file] to see all config options, documentation is coming soon.
124
+
58
125
  ## Inspiration 💡
59
126
 
60
127
  - [webpacker]
@@ -1,10 +1,8 @@
1
1
  import { defineConfig } from 'vite'
2
- import VuePlugin from '@vitejs/plugin-vue'
3
2
  import RubyPlugin from 'vite-plugin-ruby'
4
3
 
5
4
  export default defineConfig({
6
5
  plugins: [
7
- VuePlugin(),
8
6
  RubyPlugin(),
9
7
  ],
10
8
  optimizeDeps: {
@@ -1,16 +1,18 @@
1
- import '@rails/ujs'
2
- import Turbolinks from 'turbolinks'
3
- import ActiveStorage from '@rails/activestorage'
4
- import { createApp } from 'vue'
1
+ // Example: Load Rails libraries in Vite.
2
+ //
3
+ // import '@rails/ujs'
4
+ //
5
+ // import Turbolinks from 'turbolinks'
6
+ // import ActiveStorage from '@rails/activestorage'
7
+ //
8
+ // // Import all channels.
9
+ // import.meta.globEager('./**/*_channel.js')
10
+ //
11
+ // Turbolinks.start()
12
+ // ActiveStorage.start()
5
13
 
6
- import App from '~/App.vue'
7
- import '~/channels'
8
- import '../../stylesheets/index.css'
9
-
10
- Turbolinks.start()
11
- ActiveStorage.start()
14
+ // Example: Import a stylesheet in app/javascript/index.css
15
+ // import '~/index.css'
12
16
 
13
17
  console.log('Vite ⚡️ Rails')
14
18
 
15
- createApp(App).mount('#app')
16
-
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Install ViteRails
3
+ # Install Vite Rails
4
+ say 'Creating configuration files'
4
5
  copy_file "#{ __dir__ }/config/vite.json", ViteRails.config.config_path
6
+ copy_file "#{ __dir__ }/config/vite.config.ts", Rails.root
5
7
 
6
- if Dir.exist?(ViteRails.config.source_code_dir)
7
- say 'The JavaScript app source directory already exists. Move it and try again to see a basic setup.'
8
- else
9
- say 'Creating JavaScript app source directory'
10
- directory "#{ __dir__ }/javascript", ViteRails.config.source_code_dir
11
- end
8
+ say 'Creating entrypoints directory'
9
+ directory "#{ __dir__ }/javascript/entrypoints", ViteRails.config.source_code_dir.join(ViteRails.config.entrypoints_dir)
12
10
 
13
11
  apply "#{ __dir__ }/binstubs.rb"
14
12
 
@@ -66,8 +66,6 @@ private
66
66
  # Internal: Used to load a JSON file from the specified path.
67
67
  def load_json(path)
68
68
  JSON.parse(File.read(File.expand_path(path))).deep_transform_keys(&:underscore)
69
- rescue => error
70
- (require 'pry-byebug';binding.pry;);
71
69
  end
72
70
 
73
71
  # Internal: Retrieves a configuration option from environment variables.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRails
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vite_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Máximo Mussini
@@ -123,13 +123,7 @@ files:
123
123
  - lib/install/binstubs.rb
124
124
  - lib/install/config/vite.config.ts
125
125
  - lib/install/config/vite.json
126
- - lib/install/javascript/App.vue
127
- - lib/install/javascript/assets/logo.png
128
- - lib/install/javascript/channels/consumer.js
129
- - lib/install/javascript/channels/index.js
130
- - lib/install/javascript/components/HelloWorld.vue
131
126
  - lib/install/javascript/entrypoints/application.js
132
- - lib/install/javascript/stylesheets/index.css
133
127
  - lib/install/template.rb
134
128
  - lib/tasks/vite/binstubs.rake
135
129
  - lib/tasks/vite/build.rake
@@ -192,8 +186,8 @@ homepage: https://github.com/ElMassimo/vite_rails
192
186
  licenses:
193
187
  - MIT
194
188
  metadata:
195
- source_code_uri: https://github.com/ElMassimo/vite_rails/tree/v1.0.2
196
- changelog_uri: https://github.com/ElMassimo/vite_rails/blob/v1.0.2/CHANGELOG.md
189
+ source_code_uri: https://github.com/ElMassimo/vite_rails/tree/v1.0.3
190
+ changelog_uri: https://github.com/ElMassimo/vite_rails/blob/v1.0.3/CHANGELOG.md
197
191
  post_install_message:
198
192
  rdoc_options: []
199
193
  require_paths:
@@ -1,27 +0,0 @@
1
- <script>
2
- import { defineComponent } from 'vue'
3
- import HelloWorld from '~/components/HelloWorld.vue'
4
-
5
- export default defineComponent({
6
- name: 'App',
7
- components: {
8
- HelloWorld
9
- }
10
- })
11
- </script>
12
-
13
- <style>
14
- #app {
15
- font-family: Avenir, Helvetica, Arial, sans-serif;
16
- -webkit-font-smoothing: antialiased;
17
- -moz-osx-font-smoothing: grayscale;
18
- text-align: center;
19
- color: #2c3e50;
20
- margin-top: 60px;
21
- }
22
- </style>
23
-
24
- <template>
25
- <img alt="Vue logo" src="../assets/logo.png" />
26
- <HelloWorld class="strange" msg="Hello Vue 3 + Vite" />
27
- </template>
@@ -1,4 +0,0 @@
1
- // Action Cable provides the framework to deal with WebSockets in Rails.
2
- // You can generate new channels where WebSocket features live using the `rails generate channel` command.
3
- import { createConsumer } from "@rails/actioncable"
4
- export default createConsumer()
@@ -1,3 +0,0 @@
1
- // Load all the channels within this directory and all subdirectories.
2
- // Channel files must be named *_channel.js.
3
- import.meta.globEager('./**/*_channel.js')
@@ -1,53 +0,0 @@
1
- <script>
2
- import { ref, defineComponent } from 'vue'
3
-
4
- export default defineComponent({
5
- name: 'HelloWorld',
6
- props: {
7
- msg: { type: String, required: true }
8
- },
9
- setup: () => {
10
- const count = ref(0)
11
- return { count }
12
- }
13
- })
14
- </script>
15
-
16
- <style scoped>
17
- a {
18
- color: #42b983;
19
- }
20
- </style>
21
-
22
- <template>
23
- <h1 v-bind="$attrs">{{ msg }}</h1>
24
- <p>
25
- <a href="https://vitejs.dev/guide/features.html" target="_blank">Vite Documentation</a> |
26
- <a href="https://v3.vuejs.org/" target="_blank">Vue 3 Documentation</a>
27
- </p>
28
-
29
- <p>
30
- Recommended setup:
31
- <a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
32
- +
33
- <a
34
- href="https://marketplace.visualstudio.com/items?itemName=octref.vetur"
35
- target="_blank"
36
- >Vetur</a>
37
- +
38
- <a
39
- href="https://marketplace.visualstudio.com/items?itemName=znck.vue-language-features"
40
- target="_blank"
41
- >Vue DX</a>
42
- </p>
43
- <p>
44
- Make sure to use workspace version of TypeScript to get improved support via
45
- <a
46
- href="https://github.com/znck/vue-developer-experience"
47
- target="_blank"
48
- >@vuedx</a>.
49
- <br />Note @vuedx is still experimental and this setup is provided for early feedback.
50
- </p>
51
- <button name="Counter" @click="count++">count is: {{ count }}</button>
52
- <p>Edit <code>components/HelloWorld.vue</code> to test hot module replacement.</p>
53
- </template>
@@ -1,3 +0,0 @@
1
- body {
2
- background: red;
3
- }