vue_cli-rails 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/.rspec +0 -0
- data/.rubocop.yml +20 -0
- data/.travis.yml +13 -0
- data/Gemfile +2 -4
- data/Gemfile.lock +0 -0
- data/LICENSE +0 -0
- data/README.md +482 -14
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/lib/helpers/lib/cmd.rb +6 -0
- data/lib/helpers/lib/common.rb +7 -0
- data/lib/helpers/lib/input_loop.rb +41 -0
- data/lib/helpers/lib.rb +3 -0
- data/lib/helpers/scripts/install_rails.rb +48 -0
- data/lib/helpers/scripts/vue_command.rb +74 -0
- data/lib/helpers/scripts/vue_create.rb +153 -0
- data/lib/source/app/assets/vue/components/layouts/App.vue +0 -0
- data/lib/source/app/assets/vue/components/layouts/index.js +0 -0
- data/lib/source/app/assets/vue/components/views/Bar.vue +0 -0
- data/lib/source/app/assets/vue/components/views/Foo.vue +1 -1
- data/lib/source/app/assets/vue/views/bar.js +0 -0
- data/lib/source/app/assets/vue/views/foo.js +0 -0
- data/lib/source/app/controllers/vue_controller.rb +2 -4
- data/lib/source/app/views/layouts/vue.html.erb +0 -0
- data/lib/source/app/views/vue/bar.html.erb +0 -0
- data/lib/source/app/views/vue/foo.html.erb +0 -0
- data/lib/source/vue.config.js +37 -33
- data/lib/source/vue.rails.js +64 -28
- data/lib/source/vue.yml +14 -8
- data/lib/tasks/vue.rake +23 -120
- data/lib/views/layouts/vue.erb +0 -0
- data/lib/vue_cli/rails/configuration.rb +58 -21
- data/lib/vue_cli/rails/dev_server_proxy.rb +3 -3
- data/lib/vue_cli/rails/engine.rb +16 -7
- data/lib/vue_cli/rails/helper.rb +0 -0
- data/lib/vue_cli/rails/node_env.rb +31 -23
- data/lib/vue_cli/rails/version.rb +1 -1
- data/lib/vue_cli/rails.rb +1 -1
- data/tmp/.keep +0 -0
- data/vue_cli-rails.gemspec +18 -18
- metadata +32 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 193e3f266fe5df04d06da5ba07e6811bcb95dcff
|
4
|
+
data.tar.gz: a62e9dbd576de83ab3a41130263b1379c2fbed1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e61eb0f58518561a57cf3d3602d9eed052460f142b9d4b6f3847827d6d2a15a0503c7ee966c30a5ca9dee2dd58d530571e1f47a8565da7ea40b07470ba156cd
|
7
|
+
data.tar.gz: b8a32249e7be88fa8eb0c11c351126078d998c77cecd306c322bb4955cbefb3a6290a850db28b2b11094b6226664f6f5b647058732e3f974df7c8ee5a8d74ba0
|
data/.gitignore
CHANGED
File without changes
|
data/.rspec
CHANGED
File without changes
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
|
4
|
+
Metrics/LineLength:
|
5
|
+
Max: 99
|
6
|
+
|
7
|
+
Style/FrozenStringLiteralComment:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Style/TrailingCommaInArguments:
|
11
|
+
EnforcedStyleForMultiline: comma
|
12
|
+
|
13
|
+
Style/TrailingCommaInArrayLiteral:
|
14
|
+
EnforcedStyleForMultiline: comma
|
15
|
+
|
16
|
+
Style/TrailingCommaInHashLiteral:
|
17
|
+
EnforcedStyleForMultiline: comma
|
18
|
+
|
19
|
+
Style/Documentation:
|
20
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -3,5 +3,18 @@ sudo: false
|
|
3
3
|
language: ruby
|
4
4
|
cache: bundler
|
5
5
|
rvm:
|
6
|
+
- 2.3.8
|
6
7
|
- 2.4.5
|
8
|
+
- 2.5.2
|
9
|
+
- 2.6.1
|
10
|
+
env:
|
11
|
+
- RAILS_VERSION=4 NODE_VERSION=8
|
12
|
+
- RAILS_VERSION=4 NODE_VERSION=lts
|
13
|
+
- RAILS_VERSION=5 NODE_VERSION=lts
|
14
|
+
- RAILS_VERSION=5 NODE_VERSION=latest
|
15
|
+
matrix:
|
16
|
+
fast_finish: true
|
17
|
+
include:
|
18
|
+
- rvm: ruby-head
|
19
|
+
env: RAILS_VERSION=beta NODE_VERSION=latest
|
7
20
|
before_install: gem install bundler -v 1.17.3
|
data/Gemfile
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in vue_cli-rails.gemspec
|
6
6
|
gemspec
|
7
|
-
|
8
|
-
gem 'pry-byebug'
|
data/Gemfile.lock
CHANGED
File without changes
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# VueCli::Rails
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Currently, I am still actively developing this gem. It's usable but lacks of documentation. I will update it once the main features are ready and well-tested.
|
3
|
+
Let's make cool boy Vue even cooler on Rails!
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -15,25 +13,495 @@ gem 'vue_cli-rails'
|
|
15
13
|
And then execute:
|
16
14
|
|
17
15
|
$ bundle install
|
18
|
-
$ bundle exec rake vue:create
|
19
16
|
|
20
|
-
|
17
|
+
## Requirements
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
- Ruby >= 2.3
|
20
|
+
- Rails >= 4.2
|
21
|
+
- Node >= [8.9+](https://cli.vuejs.org/guide/installation.html)
|
22
|
+
- Optional: `yarn`
|
23
|
+
|
24
|
+
> The auto-testing for CI still WIP. Sorry I can't guarantee it works for now.
|
25
|
+
|
26
|
+
## Features
|
27
|
+
|
28
|
+
- Feel free to use `yarn` or `npm`.
|
29
|
+
- Single `vue_entry` rather than confusing `stylesheet_pack_tag`, `javascript_packs_tag` and `javascript_packs_with_chunks_tag`.
|
30
|
+
- Get all benefits of [@vue/cli](https://cli.vuejs.org/).
|
31
|
+
- Powered by `webpack` 4
|
32
|
+
- DRY: all-in-one configuration file rather than repeating for `webpack`, `eslint` and etc.
|
33
|
+
- Out-of-box tooling: Babel, TypeScript, PWA, `vue-router`, `vuex`, CSS pre-processors, linter and testing tools.
|
34
|
+
- Run `webpack-dev-server` together with Rails server with development mode.
|
35
|
+
- Just single `RAILS_ENV`, no more `NODE_ENV`.
|
36
|
+
- Rails way configurations in `config/vue.yml`.
|
37
|
+
|
38
|
+
## Getting started
|
39
|
+
|
40
|
+
Out-of-box workflow:
|
41
|
+
|
42
|
+
1. `bundle exec rake vue:create` and follow the steps.
|
43
|
+
2. Put your entry point files under `app/assets/vue/views`.
|
44
|
+
3. `webpack-dev-server` auto starts alongside `rails server` in dev mode.
|
45
|
+
4. Invoke `bundle exec rake vue:compile` to compile assets (you still have to set `RAILS_ENV=production` manually).
|
46
|
+
|
47
|
+
> More settings are available in `config/vue.yml`
|
26
48
|
|
27
49
|
## Usage
|
28
50
|
|
29
|
-
|
51
|
+
### Core
|
52
|
+
|
53
|
+
#### Concept: Entry Point and File structure
|
54
|
+
|
55
|
+
Webpack sees JavaScript files as the center of page rather than HTML. Thus all styles, images, fonts and other assets are related to a JS files. Any `.js` files under `app/assets/vue/views` will be treated as entry-point files.
|
56
|
+
|
57
|
+
Please ONLY puts your entry-point files under `app/assets/vue/views` folder with `.js` extension name.
|
58
|
+
|
59
|
+
> Be aware, `.js.erb` and `.vue.erb` are NOT supported. I will explain the reason in [Q&A section](#difference-from-webpacker).
|
60
|
+
|
61
|
+
If you are new to modern front-end development, or more specifically with `webpack` in this case, please read [Q&A section](#Q&A) for more information.
|
62
|
+
|
63
|
+
#### Helper `vue_entry`
|
64
|
+
|
65
|
+
`vue_entry` is like `javascript_include_tag` and `stylesheet_link_tag` which generates relative assets links for your entry point. (It's like a combination of `stylesheet_pack_tag` and `javascript_packs_with_chunks_tag` in Webpacker 4. I will explain why it's different in [Q&A](#Q&A).)
|
66
|
+
|
67
|
+
> You may have interest of path alias in `config/vue.yml`.
|
68
|
+
|
69
|
+
<details><summary>For example</summary>
|
70
|
+
|
71
|
+
- File structure:
|
72
|
+
|
73
|
+
```text
|
74
|
+
[+] app
|
75
|
+
[+] assets
|
76
|
+
[+] vue
|
77
|
+
[+] components
|
78
|
+
[+] views - alias `~views`
|
79
|
+
[-] FooBar.vue - Vue component for `foo/bar`
|
80
|
+
[+] views - Folder for entry points
|
81
|
+
[+] foo
|
82
|
+
[-] bar.js - entry point: import '~views/FooBar.vue'
|
83
|
+
[+] controllers
|
84
|
+
[+] foo_controller.rb - controller
|
85
|
+
[+] views
|
86
|
+
[+] layout
|
87
|
+
[-] vue.html.erb - Vue layout
|
88
|
+
[+] foo
|
89
|
+
[-] bar.html.erb - View render: `vue_entry('foo/bar')`
|
90
|
+
```
|
91
|
+
|
92
|
+
- `alias` in `config/vue.yml`:
|
93
|
+
|
94
|
+
```yaml
|
95
|
+
# default
|
96
|
+
alias:
|
97
|
+
~views: app/assets/vue/components/views
|
98
|
+
```
|
99
|
+
|
100
|
+
- Your controller:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
# app/controllers/foo_controller.rb
|
104
|
+
|
105
|
+
class FooController < ApplicationController
|
106
|
+
layout 'vue'
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
- Your view:
|
111
|
+
|
112
|
+
```html
|
113
|
+
<!-- file - app/views/foo/bar.html.erb -->
|
114
|
+
<%= vue_entry('foo/bar') %>
|
115
|
+
```
|
116
|
+
|
117
|
+
- Entry point JS:
|
118
|
+
|
119
|
+
```js
|
120
|
+
// file - app/assets/vue/views/foo/bar.js
|
121
|
+
import Vue from 'vue';
|
122
|
+
|
123
|
+
import Foo from '~views/FooBar.vue';
|
124
|
+
|
125
|
+
new Vue({
|
126
|
+
render: h => h(Foo),
|
127
|
+
}).$mount('#app');
|
128
|
+
```
|
129
|
+
|
130
|
+
- Your Vue component for your entry point:
|
131
|
+
|
132
|
+
```vue
|
133
|
+
// file - app/assets/vue/components/views/FooBar.vue
|
134
|
+
<template>
|
135
|
+
<div id="foo-bar">
|
136
|
+
<h1>Foo/bar</h1>
|
137
|
+
</div>
|
138
|
+
</template>
|
139
|
+
|
140
|
+
<script>
|
141
|
+
export default {
|
142
|
+
name: 'FooBar',
|
143
|
+
};
|
144
|
+
</script>
|
145
|
+
|
146
|
+
<style scoped>
|
147
|
+
#foo-bar {
|
148
|
+
color: green;
|
149
|
+
}
|
150
|
+
</style>
|
151
|
+
```
|
152
|
+
|
153
|
+
- Layout:
|
154
|
+
|
155
|
+
```html
|
156
|
+
<!-- file - app/views/layout/vue.html.erb -->
|
157
|
+
<!DOCTYPE html>
|
158
|
+
<html>
|
159
|
+
<head>
|
160
|
+
<title>Vue</title>
|
161
|
+
<%= csrf_meta_tags %>
|
162
|
+
</head>
|
163
|
+
<body>
|
164
|
+
<div id="app"></div><%= yield %>
|
165
|
+
</body>
|
166
|
+
</html>
|
167
|
+
```
|
168
|
+
|
169
|
+
</details>
|
170
|
+
|
171
|
+
#### Public Output Path
|
172
|
+
|
173
|
+
If the default setting `vue_assets` does not bother you at all, you can ignore this section.
|
174
|
+
|
175
|
+
Actually `public_output_path` in `config/vue.yml` is very simple - just a sub path under `public` directory. You might suffer some problems by changing it without understanding how it works:
|
176
|
+
|
177
|
+
- My regular assets no longer work in dev mode server.
|
178
|
+
- I lost all my files in `public` folder. (Using a VCS would get your ass saved.)
|
179
|
+
- Where are my compiled assets for prod under `public/assets` directory?
|
180
|
+
|
181
|
+
<details><summary>TL, DR - DO NOT name it as any path used by anything else</summary>
|
182
|
+
|
183
|
+
- It's being used in:
|
184
|
+
|
185
|
+
- Rails dev server will forward all request under `/#{public_output_path}` to `webpack-dev-server`;
|
186
|
+
- Webpack will put all compiled assets under `public/#{public_output_path}`. Unfortunately, it always remove the entire folder before compiling.
|
187
|
+
|
188
|
+
- Alternative ways
|
189
|
+
|
190
|
+
- For dev proxy problem: to set different values for `development` and `production` mode in `config/vue.yml`.
|
191
|
+
- For deleting folder when set it to `assets` for prod: run `rake vue:compile[with_rails_assets]` to invoke `rake compile:assets` as well.
|
192
|
+
|
193
|
+
</details>
|
194
|
+
|
195
|
+
### Available Settings
|
196
|
+
|
197
|
+
#### General settings file is `config/vue.yml`
|
198
|
+
|
199
|
+
- `manifest_output`
|
200
|
+
|
201
|
+
Where to put `manifest.json` which required by Rails.
|
202
|
+
|
203
|
+
All entry-points will be compiled into assets files. Rails needs `manifest.json` to know what are the files and will serve all its JS/CSS tags.
|
204
|
+
|
205
|
+
- `package_manager`
|
206
|
+
|
207
|
+
Pretty straightforward, which package manager will be used. Valid value: `npm` or `yarn`. It does NOT support `pnpm` or other package managers. You can find the reason in [Q&A](#Q&A).
|
208
|
+
|
209
|
+
- `public_output_path`
|
210
|
+
|
211
|
+
Because it is very important I put it in core [section](#public-output-path).
|
212
|
+
|
213
|
+
- `launch_dev_service` (NOT available for `production` mode)
|
214
|
+
|
215
|
+
`rails server` will launch it when starting by default `vue-cli-service serve`. It will be invoked by `npx vue-cli-service serve` or `yarn exec vue-cli-service serve` depends on your `package_manager`.
|
216
|
+
|
217
|
+
- `camelCase` settings will be used in `vue.config.js`
|
218
|
+
|
219
|
+
Please see [available options](#valid-vue-cli-config-options).
|
220
|
+
|
221
|
+
#### Customize your webpack configurations in `vue.config.js`
|
222
|
+
|
223
|
+
Feel free update `vue.config.js` by yourself. There are some lines of boiler-plate code to adapt `compression-webpack-plugin` and `webpack-bundle-analyzer`.
|
224
|
+
|
225
|
+
### Rake Tasks
|
226
|
+
|
227
|
+
- `vue:create`
|
228
|
+
|
229
|
+
Install required packages and configurations. You should run this task to get `@vue/cli` initializing your project.
|
230
|
+
|
231
|
+
<details><summary>What it does for you</summary>
|
232
|
+
|
233
|
+
1. Select package manager: Y=`yarn`, N=`npm`
|
234
|
+
|
235
|
+
- Directly use npm if yarn has not been installed.
|
236
|
+
- Prefer yarn by default unless detect `package-lock.json`
|
237
|
+
|
238
|
+
2. Auto install `@vue/cli` globally with your package manager.
|
239
|
+
3. Invoke `vue create` to initialize Vue project.
|
240
|
+
|
241
|
+
When detected existing `package.json`
|
242
|
+
- `Y` - Yes: Fully overwrite
|
243
|
+
- `N` - No: Skip
|
244
|
+
- `A` - Auto: You won't loss anything (`old_config.merge(new_config)`)
|
245
|
+
- `K` - Keep: Keep all your settings already have (`new_config.merge(old_config)`)
|
246
|
+
|
247
|
+
4. Install `js-yaml` and `webpack-assets-manifest`
|
248
|
+
5. Deleting Vue demo code under `src` folder
|
249
|
+
6. Copy demo code to under `app` folder and update `config/routes.rb`
|
250
|
+
7. Copy `vue.rails.js` and `vue.config.js`
|
251
|
+
|
252
|
+
- Do not change `vue.rails.js`! This rake task will always restore `vue.rails.js` back.
|
253
|
+
- Yes you can update `vue.config.js`. Just make sure you know what are you won't break the configuration. You can chance `config/vue.yml` instead.
|
254
|
+
|
255
|
+
8. Generate `config/vue.yml`
|
256
|
+
|
257
|
+
- The convention is: `camelCase` for regular `vue.config.js`, `snake_case` for special usage.
|
258
|
+
- You can find a full list of [Vue CLI config options below](#valid-vue-cli-config-options).
|
259
|
+
- All available options [here](#available-options)
|
260
|
+
|
261
|
+
> BE AWARE: the default option for `config/vue.yml` is `Y` (to replace existing file), otherwise your package manager change won't be saved. All your files won't be overwritten silently except `vue.rails.js`.
|
262
|
+
|
263
|
+
</details>
|
264
|
+
|
265
|
+
- `vue:compile`
|
30
266
|
|
31
|
-
|
267
|
+
Compile Vue assets. Please specify `RAILS_ENV=production` to compile assets for production.
|
32
268
|
|
33
|
-
|
269
|
+
Optional argument: `[with_rails_assets]` to invoke `rake compile:assets` after it finished.
|
34
270
|
|
35
|
-
|
271
|
+
However, you can invoke `vue-cli-service build` (if `vue-cli-service` installed globally, or you can use `npx vue-cli-service build` or `yarn exec vue-cli-service build`) with `RAILS_ENV=production` to build assets.
|
36
272
|
|
37
|
-
|
273
|
+
> A good practice is to use [`cross-env`](https://www.npmjs.com/package/cross-env) to pass `RAILS_ENV=production`. So `cross-env RAILS_ENV=production vue-cli-service build` will work on any platform and shell.
|
274
|
+
|
275
|
+
- `vue:json_config`
|
276
|
+
|
277
|
+
Converts `config/vue.yml` to JSON to be used by `vue.rails.js`.
|
278
|
+
|
279
|
+
`vue.rails.js` prefers parsing `config/vue.yml` with `js-yaml`. So this is just in case. You may suffer performance issue when your Rails app grow big.
|
280
|
+
|
281
|
+
- `vue:support[formats]`
|
282
|
+
|
283
|
+
Adds template or style language support. Vue ships with supporting `pug`, `sass`, `less` and `stylus` out-of-box. How ever, you still have to install some loaders manually if you did not select that language with `vue:create`.
|
284
|
+
|
285
|
+
You can add multiple languages at the same time: `rake vue:support[pug,stylus]`
|
286
|
+
|
287
|
+
- `vue:node_env`
|
288
|
+
|
289
|
+
Adds `cross-env` and `npm-run-all` to your `devDependencies` in `package.json`, and adds `dev`, `prod`, `serve` and `rails-s` to `scripts` as well.
|
290
|
+
|
291
|
+
It enables you to start rails dev server alongside `webpack-dev-server` without pain, and compile production assets.
|
292
|
+
|
293
|
+
```bash
|
294
|
+
# to start `rails s` and `webpack-dev-server` together
|
295
|
+
npm run dev
|
296
|
+
# or
|
297
|
+
yarn dev
|
298
|
+
|
299
|
+
# same as `/usr/bin/env RAILS_ENV=production bundle exec vue:compile`
|
300
|
+
npm run prod
|
301
|
+
# or
|
302
|
+
yarn prod
|
303
|
+
```
|
304
|
+
|
305
|
+
You can update `scripts/rails-s` and/or `scripts/prod` if you need to more stuff:
|
306
|
+
|
307
|
+
```json
|
308
|
+
{
|
309
|
+
"scripts": {
|
310
|
+
"rails-s": "cross-env NO_WEBPACK_DEV_SERVER=1 rails s -b 0.0.0.0",
|
311
|
+
"prod": "cross-env RAILS_ENV=production bundle exec rake vue:compile[with_rails_assets]"
|
312
|
+
}
|
313
|
+
}
|
314
|
+
```
|
315
|
+
|
316
|
+
> You may need to invoke with `bundle exec`. Rails 5 and above supports new `rails rake:task` flavor.
|
317
|
+
|
318
|
+
## Valid Vue CLI config Options
|
319
|
+
|
320
|
+
You can check the full list on [Vue CLI official website](https://cli.vuejs.org/config/).
|
321
|
+
|
322
|
+
- Special
|
323
|
+
|
324
|
+
- publicPath - see [`public_output_path`](#public-output-path)
|
325
|
+
- outputDir - see [`public_output_path`](#public-output-path)
|
326
|
+
- configureWebpack - `vue.rails.js` will generate it. `entry`, `output` and `resolve/alias` are heavily required by this gem. So you must manually update it in `vue.config.js` very carefully.
|
327
|
+
<details><summary>Demo</summary>
|
328
|
+
|
329
|
+
Changes to `vue.config.js`
|
330
|
+
|
331
|
+
```diff
|
332
|
+
const {
|
333
|
+
manifest,
|
334
|
+
pickUpSettings,
|
335
|
+
// isProd,
|
336
|
+
- // getSettings,
|
337
|
+
+ getSettings,
|
338
|
+
} = railsConfig;
|
339
|
+
|
340
|
+
+ const { configureWebpack: { entry, output, resolve } } = getSettings('configureWebpack');
|
341
|
+
|
342
|
+
module.exports = {
|
343
|
+
...pickUpSettings`
|
344
|
+
outputDir
|
345
|
+
publicPath
|
346
|
+
devServer
|
347
|
+
- configureWebpack
|
348
|
+
|
349
|
+
filenameHashing
|
350
|
+
lintOnSave
|
351
|
+
runtimeCompiler
|
352
|
+
transpileDependencies
|
353
|
+
productionSourceMap
|
354
|
+
crossorigin
|
355
|
+
css
|
356
|
+
parallel
|
357
|
+
pwa
|
358
|
+
pluginOptions
|
359
|
+
`,
|
360
|
+
+ configureWebpack: {
|
361
|
+
+ entry,
|
362
|
+
+ output,
|
363
|
+
+ resolve,
|
364
|
+
+ },
|
365
|
+
chainWebpack: (config) => {
|
366
|
+
```
|
367
|
+
|
368
|
+
</details>
|
369
|
+
|
370
|
+
- Supported
|
371
|
+
|
372
|
+
- [x] filenameHashing
|
373
|
+
- [x] lintOnSave
|
374
|
+
- [x] runtimeCompiler
|
375
|
+
- [x] transpileDependencies
|
376
|
+
- [x] productionSourceMap
|
377
|
+
- [x] crossorigin
|
378
|
+
- [x] css
|
379
|
+
- [x] devServer
|
380
|
+
- [x] parallel
|
381
|
+
- [x] pwa
|
382
|
+
- [x] pluginOptions
|
383
|
+
|
384
|
+
- Unsupported
|
385
|
+
|
386
|
+
- [ ] baseUrl - Deprecated
|
387
|
+
- [ ] assetsDir - ignored
|
388
|
+
- [ ] indexPath - N/A
|
389
|
+
- [ ] pages - N/A
|
390
|
+
- [ ] integrity - N/A
|
391
|
+
- [ ] chainWebpack - directly edit `vue.config.js`
|
392
|
+
|
393
|
+
## Trouble-shooting
|
394
|
+
|
395
|
+
- My dev server can't find assets
|
396
|
+
|
397
|
+
Sometimes your `webpack-dev-server` might still be running while Rails dev server had terminated. For example, you had executed `exit!` in `pry`.
|
398
|
+
|
399
|
+
Usually `webpack-dev-server` should be killed when next time you start `rails server`. However, for some reason it could fail and the new `webpack-dev-server` will listen to another port. Then you must manually kill them:
|
400
|
+
|
401
|
+
```bash
|
402
|
+
lsof -i:3080 -sTCP:LISTEN -Pn
|
403
|
+
kill -9 <pid>
|
404
|
+
```
|
405
|
+
|
406
|
+
Alternatively, you can run `rake vue:node_dev` and always start your dev server with:
|
407
|
+
|
408
|
+
```bash
|
409
|
+
npm run dev
|
410
|
+
# or
|
411
|
+
yarn dev
|
412
|
+
```
|
413
|
+
|
414
|
+
> I know it is not Rails-way at all. I don't want to waste time to just get it worked properly in Rails way - you are already using Node, why it bothers you?
|
415
|
+
|
416
|
+
<details><summary>Q & A</summary>
|
417
|
+
|
418
|
+
## Q&A
|
419
|
+
|
420
|
+
### Difference from Webpacker
|
421
|
+
|
422
|
+
1. Webpacker is designed more generic. `vue_cli-rails` is opinionated to just get `@vue/cli` worked.
|
423
|
+
2. Due to the ease of use of `@vue/cli` this gem is much easier to configure.
|
424
|
+
3. This gem does not support `.erb` files at all
|
425
|
+
|
426
|
+
It does not make any sense to me. What's the benefit? What if someone wants to pass dynamic data in production, which the way `erb` supposed to work for? Should it launch webpack and spend maybe 10s to compiled it on-the-fly?
|
427
|
+
|
428
|
+
If you want some dynamic data, you should fetch it via some API. That's my opinion and why I don't even think it should have this feature.
|
429
|
+
|
430
|
+
4. This gem only provides 1 helper `vue_entry` rather than `stylesheet_pack_tag`, `javascript_pack_tag`, `javascript_packs_with_chunks_tag`, `image_pack_tag` and etc. in Webpacker
|
431
|
+
|
432
|
+
- First of all, JS files are the center of modern front-end world.
|
433
|
+
- Modern front-end bundlers like webpack offer lots of fancy features with tools like Babel, TypeScript, eslint and etc. They can take care of all your assets, and always give you correct set of assets.
|
434
|
+
- Webpack 4 is even smarter to split common code into chunks.
|
435
|
+
- Vue also provides some awesome features like scoped styles, async components.
|
436
|
+
|
437
|
+
All those functionalities are just working out-of-box. You should not even touch them. There is no point of managing assets by yourself. You will eventually shot on your foot:
|
438
|
+
|
439
|
+
- Why my component does not look right? Because you forgot to change your `stylesheet_pack_tag` after renaming the file.
|
440
|
+
- Why my styles from another component aren't working? Because your component uses scoped styles, which designed to only work for that component.
|
441
|
+
- Why my component does not work anymore? Because there is a new asset and you never write a `_tag` for it.
|
442
|
+
|
443
|
+
Trust me, you are not smarter than webpack. This design will save your time.
|
444
|
+
|
445
|
+
5. This gem supports both `npm` and `yarn`. Webpacker requires `yarn` to be installed.
|
446
|
+
|
447
|
+
`npm` and `yarn` are not much different nowadays. I myself prefer `yarn`. But you should be able to use `npm` which ships with node itself to reduce the complexity of deployment.
|
448
|
+
|
449
|
+
Unfortunately it does not support [`pnpm`](#does-it-support-pnpm)
|
450
|
+
|
451
|
+
6. Webpacker ships with plenty of node dependencies in `dependencies` section rather than `devDependencies`.
|
452
|
+
|
453
|
+
I'd say this is another thing does not make sense to me. Even there is no real difference for front-end projects, I'd expect a project follows common pattern: the packages will be used in your front-end code should be in `dependencies`.
|
454
|
+
|
455
|
+
7. `productionSourceMap` is off by default for production
|
456
|
+
|
457
|
+
You may or may not know [Rails turn this flag on by default](https://github.com/rails/webpacker/issues/769#issuecomment-458216151).
|
458
|
+
|
459
|
+
I just don't buy it. It could be a security issue, especially for a startup or small company where Rails is widely being adapted. It's not fair enough to your customers.
|
460
|
+
|
461
|
+
You can manually turn it on in `config/vue.yml`. It would be totally on your own risk because you intended to do that.
|
462
|
+
|
463
|
+
8. It does not put `manifest.json` under `public` folder.
|
464
|
+
|
465
|
+
Again, I have no idea why doing that.
|
466
|
+
|
467
|
+
9. `webpack-dev-server` automatically starts with `rails server` in dev mode.
|
468
|
+
|
469
|
+
I don't understand why not to start the killing feature of webpack. Stop wasting your life on stupidly refreshing and waiting the whole page being reloaded while debugging front-end code.
|
470
|
+
|
471
|
+
If your computer is too slow, ask your boss to buy a good one. You deserve it.
|
472
|
+
|
473
|
+
10. Less configurations and easier to understand.
|
474
|
+
|
475
|
+
Only a few platform-specific settings available. All others are very standard.
|
476
|
+
|
477
|
+
### Can I get rid of `js-yaml` and `webpack-assets-manifest`
|
478
|
+
|
479
|
+
Only `webpack-assets-manifest` is a required dependency. It will be used to generate `manifest.json` which required for both dev and prod.
|
480
|
+
|
481
|
+
`vue.rails.js` uses `js-yaml` for parsing `config/vue.yml`. It will fallback to `rake vue:json_config` if `js-yaml` not been installed. However, when your Rails app grow bigger, you will very likely find rake tasks start slower and slower.
|
482
|
+
|
483
|
+
### Does it support pnpm
|
484
|
+
|
485
|
+
No.
|
486
|
+
|
487
|
+
The reason is `@vue/cli` does not support `pnpm` very well, or `npm` does not support `@vue/cli`. Who knows.
|
488
|
+
|
489
|
+
You still have a chance to get it worked by giving `pnpm --shamefully-flatten` flag, which makes [no difference from `npm` or `yarn`](https://pnpm.js.org/docs/en/faq.html#solution-3).
|
490
|
+
|
491
|
+
If someday they support each other, I'd like to support `pnpm` as well.
|
492
|
+
|
493
|
+
### Your demo code seems awful
|
494
|
+
|
495
|
+
Yes I admit it. Personally I'd like to directly write SPA with webpack tooling for front-end. Back-end will be a separated project, and it will be a Rails-API or Sinatra project if I want to use ActiveRecord.
|
496
|
+
|
497
|
+
`webpack-dev-server` can simply be configured with a proxy and I can use something like `npm-run-all` to start 2 services at the same time. I had to write some not-so-good code to get those things done in Rails.
|
498
|
+
|
499
|
+
The demo is more Rails way - separated layouts and views. SPA world uses client routers like `vue-router`.
|
500
|
+
|
501
|
+
### It does not work on Windows
|
502
|
+
|
503
|
+
Sorry, I don't think many gems work on Windows. Please install a virtual machine and run Linux on it. This gem is very likely working with `WSL`, however you may suffer performance issues due to [slow file system](https://github.com/Microsoft/WSL/issues/873#issuecomment-425272829)
|
38
504
|
|
39
505
|
Currently `vue.config.js` is reading configurations from `vue.rails.js` which depends on `js-yaml`. It will fallback to `bundle exec rake vue:json_config` without `js-yaml` installed. You may suffer performance issue if your rake tasks are slow.
|
506
|
+
|
507
|
+
</details>
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'vue_cli/rails'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "vue_cli/rails"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'pry'
|
14
14
|
Pry.start(__FILE__)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class InputLoop
|
2
|
+
DEFAULT_HINT = { 'y' => 'Yes', 'n' => 'No' }.freeze
|
3
|
+
|
4
|
+
def gets(message, list = 'Yn', **hint)
|
5
|
+
default, list = build_list(list)
|
6
|
+
keys_hint, hint = build_hint(list, hint)
|
7
|
+
|
8
|
+
print "#{message} (#{hint}) #{keys_hint}"
|
9
|
+
wait_valid_input(keys_hint, Set.new(list.map(&:downcase)), default)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def wait_valid_input(keys_hint, keys, default)
|
15
|
+
loop do
|
16
|
+
r = STDIN.gets.chop.downcase
|
17
|
+
break default if r == ''
|
18
|
+
break r if keys.include?(r)
|
19
|
+
|
20
|
+
print " [INVALID!] Please retry: #{keys_hint}:"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_list(list)
|
25
|
+
list = list.chars
|
26
|
+
default = list.find { |c| c.upcase == c }
|
27
|
+
[default.downcase, list.map { |c| c == default ? c : c.downcase }.uniq]
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_hint(list, hint)
|
31
|
+
valid = "[#{list.join('')}]"
|
32
|
+
hint = DEFAULT_HINT.merge(hint.map { |k, v| [k.to_s.downcase, v] }.to_h)
|
33
|
+
hint = list.map do |c|
|
34
|
+
h = hint[c.downcase]
|
35
|
+
next if h.blank?
|
36
|
+
|
37
|
+
"#{c.upcase}=#{h}"
|
38
|
+
end
|
39
|
+
[valid, hint.join(', ')]
|
40
|
+
end
|
41
|
+
end
|
data/lib/helpers/lib.rb
ADDED