Skip to content

Commit c3b266c

Browse files
authored
Merge pull request #2 from eGust/release
Release
2 parents 8030cfa + 92b3c50 commit c3b266c

File tree

16 files changed

+220
-45
lines changed

16 files changed

+220
-45
lines changed

.travis.yml

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@ cache:
55
bundler: true
66
yarn: true
77

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-
178
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
1922
- 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
2126

2227
gemfile:
2328
- test/Gemfile-rails.$RAILS_VERSION
@@ -28,19 +33,17 @@ before_install:
2833
install:
2934
- nvm install --lts
3035
- node -v
31-
- yarn global add @vue/cli
3236
- gem install rspec
3337

34-
before_script:
35-
- sh -c 'cd test && ./install.rb'
36-
3738
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'
3941

4042
jobs:
4143
include:
4244
- stage: gem release
4345
rvm: 2.3
46+
env: RAILS_VERSION=4.2 PACKAGE_MANAGER=yarn
4447
script: echo "Deploying to rubygems.org ..."
4548
deploy:
4649
provider: rubygems

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

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+
310
## [0.4.1] - Released on 2019-03-18
411

512
- Better hint than crashing when run Rails server with `vue_cli-rails` but `rake vue:create` have not been called
@@ -37,4 +44,3 @@
3744
## [0.1.2] - Released on 2019-02-24
3845

3946
- First release.
40-

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
vue_cli-rails (0.4.1)
4+
vue_cli-rails (0.5.0)
55
activesupport (>= 4.2)
66
rack-proxy (>= 0.6)
77
railties (>= 4.2)

README.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
Let's make cool boy Vue even cooler on Rails!
66

7+
[Change Log](./CHANGELOG.md)
8+
79
## Installation
810

911
Add this line to your Rails application's `Gemfile`:
@@ -42,14 +44,15 @@ And then execute:
4244

4345
Out-of-box workflow:
4446

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.
4649

4750
> 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.
4851
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`).
5356

5457
> More settings are available in `config/vue.yml`
5558
@@ -279,8 +282,38 @@ Feel free to update `vue.config.js` by yourself. There are some lines of boiler-
279282
}
280283
```
281284

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+
282289
> You may need to invoke `rake` with `bundle exec`. Rails 5 and above supports new `rails rake:task` flavor.
283290
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+
284317
## Valid Vue CLI config Options
285318

286319
You can check the full list on [Vue CLI official website](https://cli.vuejs.org/config/).

lib/helpers/lib/common.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,13 @@ class Object
33
def blank?
44
respond_to?(:empty?) ? !!empty? : !self
55
end
6+
7+
def presence
8+
blank? ? nil : self
9+
end
10+
11+
def present?
12+
!blank?
13+
end
614
end
715
end

lib/helpers/scripts/vue_create.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def run_vue_create?
7474
if @pack.exist?
7575
puts 'Detected `package.json`!'
7676
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',
7878
'yAks',
7979
a: 'Auto', k: 'Keep', s: 'Skip vue create',
8080
)
@@ -86,7 +86,7 @@ def run_vue_create?
8686
if gi.exist?
8787
puts 'Detected `.gitignore`!'
8888
gi_input = @input.gets(
89-
' Do you want `vue create?` to overwrite your .gitignore',
89+
' Do you want vue-cli to overwrite your .gitignore',
9090
'yMk',
9191
m: 'Merge', k: 'Keep',
9292
)

lib/source/vue.rails.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ module.exports = (() => {
5757
const root = resolve(__dirname);
5858
const pop = (config.public_output_path || 'vue_assets').replace(/(^\/+|\/+$)/g, '');
5959
const {
60+
entry_path: ep = '',
61+
entryPath = resolve(root, ep.trim() || 'app/assets/vue/entry_points'),
6062
manifest_output: manifestOutput,
6163
js_output: output,
6264
alias = {},
@@ -78,21 +80,20 @@ module.exports = (() => {
7880
devServer.contentBase = resolve(root, devServer.contentBase);
7981
}
8082
const entry = {};
81-
const assetRoot = resolve(root, 'app/assets/vue/entry_points');
8283
const findAllJsFiles = (path) => {
8384
readdirSync(path).forEach((fn) => {
8485
const filename = resolve(path, fn);
8586
const stat = lstatSync(filename);
8687
if (stat.isDirectory()) {
8788
findAllJsFiles(filename);
8889
} 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;
9091
}
9192
});
9293
};
9394

9495
try {
95-
findAllJsFiles(assetRoot);
96+
findAllJsFiles(entryPath);
9697
} catch (_e) {
9798
//
9899
}

lib/source/vue.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
default: &default
22
package_manager: ${PACKAGE_MANAGER}
3+
4+
# entry_path: app/assets/vue/entry_points
5+
# # Migrate from Webpacker:
6+
# entry_path: app/javascript/packs
7+
38
public_output_path: vue_assets
9+
# # Migrate from Webpacker:
10+
# public_output_path: packs
11+
412
# js_output:
513
# filename: 'js/[name].[hash:8].js'
614
# chunkFilename: 'js/[name].[hash:8].js'
@@ -20,6 +28,7 @@ development:
2028
production:
2129
<<: *default
2230
manifest_output: app/assets/vue/manifest.json
31+
# Webpacker manifest_output (public/packs/manifest.json) is not suggested
2332
productionSourceMap: false
2433
css:
2534
extract: true

lib/tasks/vue.rake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ namespace :vue do
2525
desc 'Build assets: set [with_rails_assets] to invoke assets:precompile as well'
2626
task :compile, [:with_rails_assets] => :environment do |_t, args|
2727
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)
2930
::Rake::Task['assets:precompile'].invoke if args.with_rails_assets
3031
end
3132

@@ -48,4 +49,11 @@ namespace :vue do
4849
require_relative '../helpers/scripts/vue_command'
4950
VueCommand.new.install_node_dev
5051
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
5159
end

lib/vue_cli/rails/configuration.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ def node_env
3030

3131
def load_config(config)
3232
config = config[::Rails.env]
33+
entry_path = config['entry_path'].presence || 'app/assets/vue/entry_points'
3334
c = {
3435
'configureWebpack' => {
35-
'entry' => entry,
36+
'entry' => entry(entry_path),
3637
'resolve' => {},
3738
},
3839
}
@@ -137,8 +138,8 @@ def resolve(*path)
137138
@root.join(*path).to_s
138139
end
139140

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)
142143
start = base_dir.to_s.size + 1
143144
Dir[base_dir.join('**/*.js')].each_with_object({}) do |filename, h|
144145
h[filename[start...-3]] = filename

0 commit comments

Comments
 (0)