vue_cli-rails 0.3.1 → 0.4.0

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: 6f26555b1ff91f8ef6e62534d9d8b9e901a402193e39704c14d4500692382507
4
- data.tar.gz: d5c23a4261c2fe607cf070e1155d62efdaea332343dd1383fb72da6a30d8977a
3
+ metadata.gz: 106196baec28c9e822399c81c0aaa74e3ebc975ed6058ab4526bbd7afed75a9f
4
+ data.tar.gz: 3759ecd67ae31aac6c0cba11c779e7b2c2b43a3c4a1faa27b751d54b5b7066d3
5
5
  SHA512:
6
- metadata.gz: e33edb9aa638005ae5261d6860cfc49425e752cdf44ab7473ad50ad46816283bc1f4c26aa0d735b33cc99a77ed90c0d39d3b2b2013dd2d74f40a0c3a1eb99103
7
- data.tar.gz: 8eb5140657d70b049d1c53e0467f33b16856486a50bd8305fc8778d4fe156d58b3bdba6f9ac054a47e7a501877964a6c993384e4679ccaf29077ddc03c9c9ca7
6
+ metadata.gz: 1f96e3c8b417e714682deda2cfea327658326d1030ead03cc724b3e7d4544ba9813dcc6652196252cdebceb9a3cf90e1130f004770b9b8a3d8c0c76d97e93cb2
7
+ data.tar.gz: 9a161f5257422c9a07b8a86430bcc2d0c3860e43a39925cb100e7fb7f5eb03df85d7e607324efe00fdc02de1b39c96bbc10ff1006e65de65d9a6a2e21ba23450
data/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ # Change Log
2
+
3
+ ## [0.4.0] - Released on 2019-03-17
4
+
5
+ - Breaking change: changed `render_vue(entry_point)` to `render(vue: entry_point)`
6
+ - Fixed some bugs cause incorrect configs when rerun `rake vue:create`
7
+ - Adjusted Jest `transformIgnorePatterns` order
8
+ - Added Change Log
9
+ - Finished README
10
+
11
+ ## [0.3.1] - Released on 2019-03-16
12
+
13
+ - Added [`slm`](https://github.com/slm-lang/slm) template support, which is a lite version of [Slim](http://slim-lang.com/) implementation in JS.
14
+ - Fixed a bug of `rake vue:support[]`
15
+
16
+ ## [0.3.0] - Released on 2019-03-13
17
+
18
+ - Breaking change: Moved entry point folder to `app/assets/vue/entry_points`
19
+ - Added controller method `render_vue`
20
+ - Some bug fixes
21
+
22
+ ## [0.2.0] - Released on 2019-03-03
23
+
24
+ - Added Jest support
25
+
26
+ ## [0.1.6] - Released on 2019-03-03
27
+
28
+ - Bug fixes
29
+
30
+ ## [0.1.2] - Released on 2019-02-24
31
+
32
+ - First release.
33
+
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vue_cli-rails (0.3.1)
4
+ vue_cli-rails (0.4.0)
5
5
  activesupport (>= 4.2)
6
6
  rack-proxy (>= 0.6)
7
7
  railties (>= 4.2)
@@ -96,4 +96,4 @@ DEPENDENCIES
96
96
  vue_cli-rails!
97
97
 
98
98
  BUNDLED WITH
99
- 1.17.2
99
+ 1.17.3
data/README.md CHANGED
@@ -47,7 +47,7 @@ Out-of-box workflow:
47
47
  > Don NOT select `In package.json` for "Where do you prefer placing config for Babel, PostCSS, ESLint, etc.?". Some functionalities like alias of jest may not work.
48
48
 
49
49
  2. Put your JavaScript files under `app/assets/vue/entry_points`.
50
- 3. Insert your entry point by `vue_entry 'entry_point'` in views or `render_vue 'entry_point'` in controllers.
50
+ 3. Insert your entry point by `vue_entry 'entry_point'` in views or `render vue: 'entry_point'` in controllers.
51
51
  4. `webpack-dev-server` auto starts alongside `rails server` in dev mode.
52
52
  5. Invoke `env RAILS_ENV=production bundle exec rake vue:compile` to compile assets (you still must manually set `RAILS_ENV` to `production`).
53
53
 
@@ -75,110 +75,9 @@ If you are new to modern front-end development, or more specifically with `webpa
75
75
 
76
76
  > You may have interest of path alias in `config/vue.yml`.
77
77
 
78
- <details><summary>For example</summary>
79
-
80
- - File structure:
81
-
82
- ```text
83
- [+] app
84
- [+] assets
85
- [+] vue
86
- [+] entry_points - Folder for entry points
87
- [+] foo
88
- [-] bar.js - entry point: import '~views/FooBar.vue'
89
- [+] views - alias `~views`
90
- [-] FooBar.vue - Vue component for `foo/bar`
91
- [+] controllers
92
- [+] foo_controller.rb - controller
93
- [+] views
94
- [+] layout
95
- [-] vue.html.erb - Vue layout
96
- [+] foo
97
- [-] bar.html.erb - View render: `vue_entry('foo/bar')`
98
- ```
99
-
100
- - `alias` in `config/vue.yml`:
101
-
102
- ```yaml
103
- # default
104
- alias:
105
- ~views: app/assets/vue/views
106
- ```
107
-
108
- - Your controller:
109
-
110
- ```ruby
111
- # app/controllers/foo_controller.rb
112
-
113
- class FooController < ApplicationController
114
- layout 'vue'
115
- end
116
- ```
117
-
118
- - Your view:
119
-
120
- ```html
121
- <!-- file - app/views/foo/bar.html.erb -->
122
- <%= vue_entry('foo/bar') %>
123
- ```
124
-
125
- - Entry point JS:
126
-
127
- ```js
128
- // file - app/assets/vue/entry_points/foo/bar.js
129
- import Vue from 'vue';
130
-
131
- import Foo from '~views/FooBar.vue';
132
-
133
- new Vue({
134
- render: h => h(Foo),
135
- }).$mount('#app');
136
- ```
137
-
138
- - Your Vue component for your entry point:
139
-
140
- ```vue
141
- // file - app/assets/vue/views/FooBar.vue
142
- <template>
143
- <div id="foo-bar">
144
- <h1>Foo/bar</h1>
145
- </div>
146
- </template>
147
-
148
- <script>
149
- export default {
150
- name: 'FooBar',
151
- };
152
- </script>
153
-
154
- <style scoped>
155
- #foo-bar {
156
- color: green;
157
- }
158
- </style>
159
- ```
160
-
161
- - Layout:
162
-
163
- ```html
164
- <!-- file - app/views/layout/vue.html.erb -->
165
- <!DOCTYPE html>
166
- <html>
167
- <head>
168
- <title>Vue</title>
169
- <%= csrf_meta_tags %>
170
- </head>
171
- <body>
172
- <div id="app"></div><%= yield %>
173
- </body>
174
- </html>
175
- ```
176
-
177
- </details>
178
-
179
- #### Use `render_vue` in controllers
78
+ #### Use `render vue: <entry_point>` in controllers
180
79
 
181
- Usually you only need `<div id="app"></div>` and `vue_entry 'entry/point'` to render a Vue page. You can use `render_vue 'entry/point'` inside your controller.
80
+ Usually you only need `<div id="app"></div>` and `vue_entry 'entry/point'` to render a Vue page. You can use `render vue: 'entry/point'` inside your controller.
182
81
 
183
82
  This method is simply a wrap of `render html: vue_entry('entry_point'), layout: true`. So you can pass any arguments supported by `render` including `layout`.
184
83
 
@@ -190,7 +89,7 @@ class MyVueController < ApplicationController
190
89
  layout 'vue_base'
191
90
 
192
91
  def foo
193
- render_vue 'foo/bar'
92
+ render vue: 'foo/bar'
194
93
  end
195
94
  end
196
95
  ```
@@ -347,7 +246,7 @@ Feel free to update `vue.config.js` by yourself. There are some lines of boiler-
347
246
 
348
247
  - `vue:support[formats]`
349
248
 
350
- 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`.
249
+ Adds template or style language support. Vue ships with supporting `pug`, `slm`, `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`.
351
250
 
352
251
  You can add multiple languages at the same time: `rake vue:support[pug,stylus]`
353
252
 
@@ -404,7 +303,7 @@ You can check the full list on [Vue CLI official website](https://cli.vuejs.org/
404
303
  + getSettings,
405
304
  } = railsConfig;
406
305
 
407
- + const { configureWebpack: { entry, output, resolve } } = getSettings('configureWebpack');
306
+ + const { configureWebpack: { entry, output, resolve, module: cwModule } } = getSettings('configureWebpack');
408
307
 
409
308
  module.exports = {
410
309
  ...pickUpSettings`
@@ -428,6 +327,7 @@ You can check the full list on [Vue CLI official website](https://cli.vuejs.org/
428
327
  + entry,
429
328
  + output,
430
329
  + resolve,
330
+ + module: cwModule,
431
331
  + },
432
332
  chainWebpack: (config) => {
433
333
  ```
@@ -480,10 +380,85 @@ You can check the full list on [Vue CLI official website](https://cli.vuejs.org/
480
380
 
481
381
  > 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?
482
382
 
383
+ - My API does not work with CSRF token
384
+
385
+ Because Vue does not have opinion of Ajax (or JSON API) preference, you must implement what `jquery-ujs` does by yourself. There is an example code in vanilla JS with [querySelector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) whish should work for IE8+:
386
+
387
+ ```JS
388
+ // fetch API
389
+ async (url, data) => {
390
+ const $csrfParam = document.querySelector('meta[name="csrf-param"]');
391
+ const $csrfToken = document.querySelector('meta[name="csrf-token"]');
392
+ const csrfParam = ($csrfParam && $csrfParam.getAttribute('content')) || undefined;
393
+ const csrfToken = ($csrfToken && $csrfToken.getAttribute('content')) || undefined;
394
+
395
+ try {
396
+ const response = await fetch(url, {
397
+ method: 'POST',
398
+ headers: {
399
+ 'Content-type': 'application/json',
400
+ 'X-CSRF-Token': csrfToken,
401
+ },
402
+ body: JSON.stringify({
403
+ ...data,
404
+ [csrfParam]: csrfToken,
405
+ }),
406
+ });
407
+ return response.json();
408
+ } catch (e) {
409
+ // handle failed case
410
+ }
411
+ }
412
+ ```
413
+
414
+ Alternatively you can turn off CSRF token and set [SameSite cookie](https://gist.github.com/will/05cb64dc343296dec4d58b1abbab7aaf) if all your clients no longer use IE. [Modern browsers](https://caniuse.com/#feat=same-site-cookie-attribute) can handle `SameSite` flag to [prevent CSRF attacks](http://www.sjoerdlangkemper.nl/2016/04/14/preventing-csrf-with-samesite-cookie-attribute/).
415
+
483
416
  <details><summary>Q & A</summary>
484
417
 
485
418
  ## Q&A
486
419
 
420
+ ### Can I get rid of `js-yaml` and `webpack-assets-manifest`
421
+
422
+ Only `webpack-assets-manifest` is a required dependency. It will be used to generate `manifest.json` which required for both dev and prod.
423
+
424
+ `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.
425
+
426
+ ### Can I use YAML for template inside .vue
427
+
428
+ Short answer I don't know and I don't recommend. There are several HAML packages but all are too old. JS world suggests [pug](https://pugjs.org). You can also use [slm](https://github.com/slm-lang/slm) if you prefer [Slim](http://slim-lang.com/). Both are quite similar to CSS selector syntax, which means you don't really need to spend time to learn.
429
+
430
+ Just `rake vue:support[pug,slm]` and try them out: `<template lang="pug">` or `<template lang="slm">`.
431
+
432
+ ### Does it support pnpm
433
+
434
+ No.
435
+
436
+ The reason is `@vue/cli` does not support `pnpm` very well, or `npm` does not support `@vue/cli`. Who knows.
437
+
438
+ 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).
439
+
440
+ If someday they support each other, I'd like to support `pnpm` as well.
441
+
442
+ ### Your demo code seems awful
443
+
444
+ 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.
445
+
446
+ `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.
447
+
448
+ The demo is more Rails way - separated layouts and views. SPA world uses client routers like `vue-router`.
449
+
450
+ ### It does not work on Windows
451
+
452
+ 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)
453
+
454
+ 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.
455
+
456
+ ### Will you support SSR
457
+
458
+ I do want to support SSR. However, the way [Vue officially provided](https://ssr.vuejs.org/) requires you to write separated code for client and server then compile with Webpack, which is quite complicated.[ `prerender-spa-plugin`](https://github.com/chrisvfritz/prerender-spa-plugin) might be easier to achieve it.
459
+
460
+ I will do more investigation like how [Nuxt.js](https://nuxtjs.org/) does SSR. But I can't guarantee anything now.
461
+
487
462
  ### Difference from Webpacker
488
463
 
489
464
  1. Webpacker is designed more generic. `vue_cli-rails` is opinionated to just get `@vue/cli` worked.
@@ -541,41 +516,11 @@ You can check the full list on [Vue CLI official website](https://cli.vuejs.org/
541
516
 
542
517
  Only a few platform-specific settings available. All others are very standard.
543
518
 
544
- ### Can I get rid of `js-yaml` and `webpack-assets-manifest`
545
-
546
- Only `webpack-assets-manifest` is a required dependency. It will be used to generate `manifest.json` which required for both dev and prod.
547
-
548
- `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.
549
-
550
- ### Does it support pnpm
551
-
552
- No.
553
-
554
- The reason is `@vue/cli` does not support `pnpm` very well, or `npm` does not support `@vue/cli`. Who knows.
555
-
556
- 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).
557
-
558
- If someday they support each other, I'd like to support `pnpm` as well.
559
-
560
- ### Your demo code seems awful
561
-
562
- 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.
563
-
564
- `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.
565
-
566
- The demo is more Rails way - separated layouts and views. SPA world uses client routers like `vue-router`.
567
-
568
- ### It does not work on Windows
569
-
570
- 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)
571
-
572
- 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.
573
-
574
519
  </details>
575
520
 
576
521
  ## Explanation by Demo
577
522
 
578
- <details><summary>Not finished yet</summary>
523
+ <details><summary>Copy Demo Code</summary>
579
524
 
580
525
  ### Install
581
526
 
@@ -663,11 +608,11 @@ This functionality is called [HMR (Hot Module Replacement)](https://webpack.js.o
663
608
 
664
609
  You can run ESLint by
665
610
 
666
- $ yarn lint
611
+ $ yarn lint # npm run lint
667
612
 
668
613
  Run Jest
669
614
 
670
- $ yarn test:unit
615
+ $ yarn test:unit # npm run test:unit
671
616
 
672
617
  ### Compile Assets
673
618
 
@@ -690,7 +635,7 @@ run: yarn exec vue-cli-service build
690
635
  ...
691
636
  ```
692
637
 
693
- Your file names could be different from mine. Don't worry, we won't look those files. There are the files you got:
638
+ Your file names could be different from mine. Don't worry, we won't look those files. There are the files you will get:
694
639
 
695
640
  ```
696
641
  .
@@ -709,7 +654,9 @@ Your file names could be different from mine. Don't worry, we won't look those f
709
654
      └── foo.dcbad15e.js
710
655
  ```
711
656
 
712
- Let have a look at `app/assets/vue/manifest.json`:
657
+ ### How Entry Point works
658
+
659
+ Let's take a look at `app/assets/vue/manifest.json`:
713
660
 
714
661
  ```json
715
662
  {
@@ -741,4 +688,8 @@ Let have a look at `app/assets/vue/manifest.json`:
741
688
  }
742
689
  ```
743
690
 
691
+ As mentioned above, there are 2 files under `app/assets/vue/entry_points` folder: `foo.js` and `bar.js`. They will become entry points in `manifest.json`. When you call `render vue: 'bar'` in `VueDemoController` or `<%= vue_entry('foo') %>` in `app/views/vue_demo/foo.html.erb`, `vue_entry` will look for them in `entrypoints` of `manifest.json`, then generate `<link href="<path>" rel="stylesheet">` and `<script src="<path>"></script>` for each asset.
692
+
693
+ It's slightly different on dev server. This gem will send requests to webpack-dev-server and fetch the paths on-the-fly. The request will be GET `http://localhost:3080/__manifest/?<entry_point>` for each `vue_entry`. You can also send GET request to `http://localhost:3080/__manifest/?!!INSPECT!!` to get the full manifest.
694
+
744
695
  </details>
@@ -121,13 +121,13 @@ class VueCreate
121
121
 
122
122
  # merge gitignore
123
123
  if gi_input == 'm'
124
- old_gi_line_count = gi_lines.size
125
124
  old_gi = Set.new(gi_lines.map(&:strip))
125
+ new_lines = gi.read.split("\n")
126
126
 
127
- gi.read.split("\n").map(&:strip).find_all(&:present?).each do |ln|
127
+ new_lines.map(&:strip).find_all(&:present?).each do |ln|
128
128
  gi_lines << ln unless old_gi.include?(ln)
129
129
  end
130
- gi.write(gi_lines.map { |ln| "#{ln}\n" }.join('')) if gi_lines.size > old_gi_line_count
130
+ gi.write(gi_lines.map { |ln| "#{ln}\n" }.join('')) if gi_lines.size != new_lines.size
131
131
  elsif gi_input == 'k'
132
132
  gi.write(gi_lines.join(''))
133
133
  end
@@ -233,7 +233,7 @@ class VueCreate
233
233
  jest_config = JSON.parse(jest_config)
234
234
  if jest_config['transformIgnorePatterns'] &&
235
235
  !jest_config['transformIgnorePatterns'].include?('<rootDir>/node_modules/')
236
- jest_config['transformIgnorePatterns'] << '<rootDir>/node_modules/'
236
+ jest_config['transformIgnorePatterns'].unshift('<rootDir>/node_modules/')
237
237
  end
238
238
  jest_config.delete('moduleNameMapper')
239
239
  jest = <<~JS
@@ -2,10 +2,10 @@ class VueDemoController < ApplicationController
2
2
  layout 'vue_demo'
3
3
 
4
4
  def bar
5
- render_vue 'bar'
5
+ render vue: 'bar' # same as `render html: vue_entry('bar'), layout: true`
6
6
  end
7
7
 
8
8
  def baz
9
- render html: vue_entry('foo')
9
+ render html: vue_entry('foo') # same as `render vue: 'foo', layout: false`
10
10
  end
11
11
  end
@@ -21,14 +21,14 @@ module VueCli
21
21
  Configuration.instance unless is_dev
22
22
  end
23
23
 
24
+ ::ActionController::Renderers.add(:vue) do |entry, options|
25
+ render({ html: vue_entry(entry), layout: true }.merge(options))
26
+ end
27
+
24
28
  ::ActiveSupport.on_load(:action_controller) do
25
29
  ::ActionController::Base.class_eval do
26
30
  helper(Helper)
27
31
  include(Helper)
28
-
29
- define_method(:render_vue) do |entry, **args|
30
- render({ html: vue_entry(entry), layout: true }.merge(args))
31
- end
32
32
  end
33
33
  end
34
34
 
@@ -60,7 +60,7 @@ module VueCli
60
60
  npm: 'npm i -g',
61
61
  },
62
62
  install: {
63
- yarn: '',
63
+ yarn: 'yarn',
64
64
  npm: 'npm i',
65
65
  },
66
66
  }.freeze
@@ -1,5 +1,5 @@
1
1
  module VueCli
2
2
  module Rails
3
- VERSION = '0.3.1'.freeze
3
+ VERSION = '0.4.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vue_cli-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Chen
@@ -119,6 +119,7 @@ files:
119
119
  - ".rspec"
120
120
  - ".rubocop.yml"
121
121
  - ".travis.yml"
122
+ - CHANGELOG.md
122
123
  - Gemfile
123
124
  - Gemfile.lock
124
125
  - LICENSE