vue_cli-rails 0.4.1 → 0.5.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: d94627f882ae1d49750c10af029d0198758192e2a1c48a28d3acb03d390191e9
4
- data.tar.gz: f91614fdaa017c41077bb29fc18990d6032d236ca815fa72bafacac16b8c86de
3
+ metadata.gz: 3d726378bf9cb84c5bb46d6c02f3945cd314723fd213b8b2c4d42a35c7942a2d
4
+ data.tar.gz: fb10a980c2ea4a44fb09361c900519600257223d9eb80ed959a76cedf35fcbf1
5
5
  SHA512:
6
- metadata.gz: 99c4c3dc1c9141ad7a58879b42a70ebefa9cd53e64c822bbfea7af4d270dc39bebf75065e5977c9e5d2e116042c2e4301c3666b19098a29f36112007cd895c07
7
- data.tar.gz: 9de90b5be774639d27c19753ffa2d4b0dd1a0dc9a7dd98752ce5700170a47bb8899a49d2525653261d3940cb507fd27e87e9ff12beb17724df561b844aabab66
6
+ metadata.gz: 58cf9af965c358d6cf0fbfda8023a9a44027048c00569e3bb60c07635932543f52f5850597219a19d3e3fbb9a1a95ebd1d68a540db455e03ae6f2199d06fc044
7
+ data.tar.gz: '01229ed4a7c5be6aa2da098c397570518f8ba256a2d36caeac8ae9400f03616f1f159e86e33988a7d72a533599b868408b44ec9aa4bb598b36ec4d472463d22c'
data/.travis.yml CHANGED
@@ -5,19 +5,24 @@ cache:
5
5
  bundler: true
6
6
  yarn: true
7
7
 
8
- rvm:
9
- - 2.3
10
- - 2.4
11
- - 2.5
12
-
13
- env:
14
- - RAILS_VERSION=4.2
15
- - RAILS_VERSION=5.2
16
-
17
8
  matrix:
18
- exclude:
9
+ allow_failures:
10
+ - env: RAILS_VERSION=pre
11
+ include:
12
+ - rvm: 2.3
13
+ env: RAILS_VERSION=4.2 PACKAGE_MANAGER=npm
14
+ - rvm: 2.3
15
+ env: RAILS_VERSION=5.2 PACKAGE_MANAGER=yarn
16
+ - rvm: 2.4
17
+ env: RAILS_VERSION=5.2 PACKAGE_MANAGER=npm
18
+ - rvm: 2.5
19
+ env: RAILS_VERSION=5.2 PACKAGE_MANAGER=yarn
20
+ - rvm: 2.6
21
+ env: RAILS_VERSION=5.2 PACKAGE_MANAGER=npm
19
22
  - rvm: 2.5
20
- env: RAILS_VERSION=4.2
23
+ env: RAILS_VERSION=pre PACKAGE_MANAGER=npm
24
+ - rvm: 2.6
25
+ env: RAILS_VERSION=pre PACKAGE_MANAGER=yarn
21
26
 
22
27
  gemfile:
23
28
  - test/Gemfile-rails.$RAILS_VERSION
@@ -28,19 +33,17 @@ before_install:
28
33
  install:
29
34
  - nvm install --lts
30
35
  - node -v
31
- - yarn global add @vue/cli
32
36
  - gem install rspec
33
37
 
34
- before_script:
35
- - sh -c 'cd test && ./install.rb'
36
-
37
38
  script:
38
- - sh -c 'cd test && rspec ./vcr_spec.rb'
39
+ - sh -c 'cd test && ./install.rb'
40
+ - sh -c 'cd test && rspec ./vcr_specs.rb'
39
41
 
40
42
  jobs:
41
43
  include:
42
44
  - stage: gem release
43
45
  rvm: 2.3
46
+ env: RAILS_VERSION=4.2 PACKAGE_MANAGER=yarn
44
47
  script: echo "Deploying to rubygems.org ..."
45
48
  deploy:
46
49
  provider: rubygems
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## [0.5.0] - Released on 2019-03-23
4
+
5
+ - Added option `entry_path` to simplify migration from `Webpacker`
6
+ - Added instructions for migration from `Webpacker`
7
+ - Added task `vue:inspect`
8
+ - Fixed ignoring `RAILS_ENV` for `rake vue:compile`
9
+
3
10
  ## [0.4.1] - Released on 2019-03-18
4
11
 
5
12
  - Better hint than crashing when run Rails server with `vue_cli-rails` but `rake vue:create` have not been called
@@ -37,4 +44,3 @@
37
44
  ## [0.1.2] - Released on 2019-02-24
38
45
 
39
46
  - First release.
40
-
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vue_cli-rails (0.4.1)
4
+ vue_cli-rails (0.5.0)
5
5
  activesupport (>= 4.2)
6
6
  rack-proxy (>= 0.6)
7
7
  railties (>= 4.2)
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  Let's make cool boy Vue even cooler on Rails!
6
6
 
7
+ [Change Log](./CHANGELOG.md)
8
+
7
9
  ## Installation
8
10
 
9
11
  Add this line to your Rails application's `Gemfile`:
@@ -42,14 +44,15 @@ And then execute:
42
44
 
43
45
  Out-of-box workflow:
44
46
 
45
- 1. `bundle exec rake vue:create` and follow the steps.
47
+ 1. Make sure you already installed `@vue/cli` globally via `npm` (`npm i -g @vue/cli`) or `yarn` (`yarn global add @vue/cli`)
48
+ 2. `bundle exec rake vue:create` and follow the steps.
46
49
 
47
50
  > 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
51
 
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.
51
- 4. `webpack-dev-server` auto starts alongside `rails server` in dev mode.
52
- 5. Invoke `env RAILS_ENV=production bundle exec rake vue:compile` to compile assets (you still must manually set `RAILS_ENV` to `production`).
52
+ 3. Put your JavaScript files under `app/assets/vue/entry_points`.
53
+ 4. Insert your entry point by `vue_entry 'entry_point'` in views or `render vue: 'entry_point'` in controllers.
54
+ 5. `webpack-dev-server` auto starts alongside `rails server` in dev mode.
55
+ 6. Invoke `env RAILS_ENV=production bundle exec rake vue:compile` to compile assets (you still must manually set `RAILS_ENV` to `production`).
53
56
 
54
57
  > More settings are available in `config/vue.yml`
55
58
 
@@ -279,8 +282,38 @@ Feel free to update `vue.config.js` by yourself. There are some lines of boiler-
279
282
  }
280
283
  ```
281
284
 
285
+ - `vue:inspect`
286
+
287
+ Alias of `vue inspect`, `npx vue-cli-service inspect` or `yarn exec vue-cli-service inspect`. Display the webpack configuration file.
288
+
282
289
  > You may need to invoke `rake` with `bundle exec`. Rails 5 and above supports new `rails rake:task` flavor.
283
290
 
291
+ ## Migrate from Webpacker
292
+
293
+ It's very easy to migrate from Webpacker.
294
+
295
+ 1. Install this gem and `bundle install`
296
+ 2. Install `@vue/cli` globally then follow the instructions of `rake vue:create`;
297
+ 3. Edit `config/vue.yml`, set `default/entry_path` to `source_path` (by default `app/javascript`) joins `source_entry_path` (by default `packs`);
298
+ 4. Change all `javascript_packs_with_chunks_tag` to `vue_entry`;
299
+ 5. Fix all nonsense `xxxx_packs_tag`;
300
+ 6. If you mind `public_output_path` and `manifest_output` you can change them to follow Webpacker values;
301
+ > I strongly not recommend to put `manifest_output.json` under `public` folder;
302
+ 7. Update `vue.config.js` if you have any customized webpack configurations;
303
+ > You can inspect how webpack settings at anytime
304
+ 8. Directly `rails s` to start dev server;
305
+ > You can get rid of `bin/webpack-dev-server` and `bin/webpack` now. However, still recommend `rake vue:node_dev` and run `yarn dev` so it will kill `webpack-dev-server` properly when your Rails dev server stopped.
306
+ 9. Call `env RAILS_ENV=production rake vue:compile[with_rails_assets]` instead of `env RAILS_ENV=production rake assets:precompile` to compile all assets for production.
307
+ 10. Delete unused Webpacker files
308
+ - `bin/webpack-dev-server`
309
+ - `bin/webpack`
310
+ - `config/webpack`
311
+ - `config/webpacker.yml`
312
+
313
+ > Strongly recommend to backup your codebase before the migration.
314
+
315
+ Enjoy Hot Module Replacement now!
316
+
284
317
  ## Valid Vue CLI config Options
285
318
 
286
319
  You can check the full list on [Vue CLI official website](https://cli.vuejs.org/config/).
@@ -3,5 +3,13 @@ unless Object.instance_methods.include?(:blank?)
3
3
  def blank?
4
4
  respond_to?(:empty?) ? !!empty? : !self
5
5
  end
6
+
7
+ def presence
8
+ blank? ? nil : self
9
+ end
10
+
11
+ def present?
12
+ !blank?
13
+ end
6
14
  end
7
15
  end
@@ -74,7 +74,7 @@ class VueCreate
74
74
  if @pack.exist?
75
75
  puts 'Detected `package.json`!'
76
76
  pack_input = @input.gets(
77
- ' Do you want `vue create?` to overwrite your package.json',
77
+ ' Do you want vue-cli to overwrite your package.json',
78
78
  'yAks',
79
79
  a: 'Auto', k: 'Keep', s: 'Skip vue create',
80
80
  )
@@ -86,7 +86,7 @@ class VueCreate
86
86
  if gi.exist?
87
87
  puts 'Detected `.gitignore`!'
88
88
  gi_input = @input.gets(
89
- ' Do you want `vue create?` to overwrite your .gitignore',
89
+ ' Do you want vue-cli to overwrite your .gitignore',
90
90
  'yMk',
91
91
  m: 'Merge', k: 'Keep',
92
92
  )
@@ -57,6 +57,8 @@ module.exports = (() => {
57
57
  const root = resolve(__dirname);
58
58
  const pop = (config.public_output_path || 'vue_assets').replace(/(^\/+|\/+$)/g, '');
59
59
  const {
60
+ entry_path: ep = '',
61
+ entryPath = resolve(root, ep.trim() || 'app/assets/vue/entry_points'),
60
62
  manifest_output: manifestOutput,
61
63
  js_output: output,
62
64
  alias = {},
@@ -78,7 +80,6 @@ module.exports = (() => {
78
80
  devServer.contentBase = resolve(root, devServer.contentBase);
79
81
  }
80
82
  const entry = {};
81
- const assetRoot = resolve(root, 'app/assets/vue/entry_points');
82
83
  const findAllJsFiles = (path) => {
83
84
  readdirSync(path).forEach((fn) => {
84
85
  const filename = resolve(path, fn);
@@ -86,13 +87,13 @@ module.exports = (() => {
86
87
  if (stat.isDirectory()) {
87
88
  findAllJsFiles(filename);
88
89
  } else if (stat.isFile() && fn.endsWith('.js')) {
89
- entry[filename.slice(assetRoot.length + 1, -3)] = filename;
90
+ entry[filename.slice(entryPath.length + 1, -3)] = filename;
90
91
  }
91
92
  });
92
93
  };
93
94
 
94
95
  try {
95
- findAllJsFiles(assetRoot);
96
+ findAllJsFiles(entryPath);
96
97
  } catch (_e) {
97
98
  //
98
99
  }
data/lib/source/vue.yml CHANGED
@@ -1,6 +1,14 @@
1
1
  default: &default
2
2
  package_manager: ${PACKAGE_MANAGER}
3
+
4
+ # entry_path: app/assets/vue/entry_points
5
+ # # Migrate from Webpacker:
6
+ # entry_path: app/javascript/packs
7
+
3
8
  public_output_path: vue_assets
9
+ # # Migrate from Webpacker:
10
+ # public_output_path: packs
11
+
4
12
  # js_output:
5
13
  # filename: 'js/[name].[hash:8].js'
6
14
  # chunkFilename: 'js/[name].[hash:8].js'
@@ -20,6 +28,7 @@ development:
20
28
  production:
21
29
  <<: *default
22
30
  manifest_output: app/assets/vue/manifest.json
31
+ # Webpacker manifest_output (public/packs/manifest.json) is not suggested
23
32
  productionSourceMap: false
24
33
  css:
25
34
  extract: true
data/lib/tasks/vue.rake CHANGED
@@ -25,7 +25,8 @@ namespace :vue do
25
25
  desc 'Build assets: set [with_rails_assets] to invoke assets:precompile as well'
26
26
  task :compile, [:with_rails_assets] => :environment do |_t, args|
27
27
  pm = VueCli::Rails::Configuration.instance.node_env
28
- pm.exec('vue-cli-service build', env: { 'RAILS_ENV' => ::Rails.env })
28
+ env = { 'RAILS_ENV' => ENV['RAILS_ENV'].presence || ::Rails.env }
29
+ pm.exec('vue-cli-service build', env: env)
29
30
  ::Rake::Task['assets:precompile'].invoke if args.with_rails_assets
30
31
  end
31
32
 
@@ -48,4 +49,11 @@ namespace :vue do
48
49
  require_relative '../helpers/scripts/vue_command'
49
50
  VueCommand.new.install_node_dev
50
51
  end
52
+
53
+ desc 'Inspect webpack settings' do
54
+ task inspect: :environment do
55
+ pm = VueCli::Rails::Configuration.instance.node_env
56
+ env = { 'RAILS_ENV' => ENV['RAILS_ENV'].presence || ::Rails.env }
57
+ pm.exec('vue-cli-service inspect', env: env)
58
+ end
51
59
  end
@@ -30,9 +30,10 @@ module VueCli
30
30
 
31
31
  def load_config(config)
32
32
  config = config[::Rails.env]
33
+ entry_path = config['entry_path'].presence || 'app/assets/vue/entry_points'
33
34
  c = {
34
35
  'configureWebpack' => {
35
- 'entry' => entry,
36
+ 'entry' => entry(entry_path),
36
37
  'resolve' => {},
37
38
  },
38
39
  }
@@ -137,8 +138,8 @@ module VueCli
137
138
  @root.join(*path).to_s
138
139
  end
139
140
 
140
- def entry
141
- base_dir = @root.join('app/assets/vue/entry_points')
141
+ def entry(entry_path)
142
+ base_dir = @root.join(entry_path)
142
143
  start = base_dir.to_s.size + 1
143
144
  Dir[base_dir.join('**/*.js')].each_with_object({}) do |filename, h|
144
145
  h[filename[start...-3]] = filename
@@ -1,5 +1,5 @@
1
1
  module VueCli
2
2
  module Rails
3
- VERSION = '0.4.1'.freeze
3
+ VERSION = '0.5.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vue_cli-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-18 00:00:00.000000000 Z
11
+ date: 2019-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport