Skip to content

Commit 0859f89

Browse files
committed
v0.5.0
1 parent 8046066 commit 0859f89

File tree

8 files changed

+73
-18
lines changed

8 files changed

+73
-18
lines changed

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/source/vue.rails.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ module.exports = (() => {
5757
const root = resolve(__dirname);
5858
const pop = (config.public_output_path || 'vue_assets').replace(/(^\/+|\/+$)/g, '');
5959
const {
60-
package_manager: packageManager,
60+
entry_path: ep = '',
61+
entryPath = resolve(root, ep.trim() || 'app/assets/vue/entry_points'),
6162
manifest_output: manifestOutput,
6263
js_output: output,
6364
alias = {},
@@ -79,29 +80,27 @@ module.exports = (() => {
7980
devServer.contentBase = resolve(root, devServer.contentBase);
8081
}
8182
const entry = {};
82-
const assetRoot = resolve(root, 'app/assets/vue/entry_points');
8383
const findAllJsFiles = (path) => {
8484
readdirSync(path).forEach((fn) => {
8585
const filename = resolve(path, fn);
8686
const stat = lstatSync(filename);
8787
if (stat.isDirectory()) {
8888
findAllJsFiles(filename);
8989
} else if (stat.isFile() && fn.endsWith('.js')) {
90-
entry[filename.slice(assetRoot.length + 1, -3)] = filename;
90+
entry[filename.slice(entryPath.length + 1, -3)] = filename;
9191
}
9292
});
9393
};
9494

9595
try {
96-
findAllJsFiles(assetRoot);
96+
findAllJsFiles(entryPath);
9797
} catch (_e) {
9898
//
9999
}
100100

101101
settings = {
102102
env: mode,
103103
root,
104-
packageManager,
105104
manifestOutput: manifestOutput && resolve(root, manifestOutput),
106105

107106
outputDir: resolve(root, 'public', pop),

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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ 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
}
3940
@package_manager = config['package_manager']
40-
c['packageManger'] = @package_manager
4141
cw = c['configureWebpack']
4242

4343
c['env'] = ::Rails.env
@@ -138,8 +138,8 @@ def resolve(*path)
138138
@root.join(*path).to_s
139139
end
140140

141-
def entry
142-
base_dir = @root.join('app/assets/vue/entry_points')
141+
def entry(entry_path)
142+
base_dir = @root.join(entry_path)
143143
start = base_dir.to_s.size + 1
144144
Dir[base_dir.join('**/*.js')].each_with_object({}) do |filename, h|
145145
h[filename[start...-3]] = filename

lib/vue_cli/rails/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module VueCli
22
module Rails
3-
VERSION = '0.4.1'.freeze
3+
VERSION = '0.5.0'.freeze
44
end
55
end

0 commit comments

Comments
 (0)