Remember that using vue jsx has some caveats. Most importantly that most vue builtin directives are not supported (for example, v-for
, v-model
, etc.), expect for v-show
. Some of them can be implemented manually, but v-model
for example is kind of a pain in the ass.
https://vuejs.org/v2/guide/render-function.html#Replacing-Template-Features-with-Plain-JavaScript
https://github.com/vuejs/babel-plugin-transform-vue-jsx#vue-directives
There's this though:
https://github.com/nickmessing/babel-plugin-jsx-v-model
Also the sourcemap result is kind of crappy, things like @
are not mapped correctly, I resorted to just using 'eval'
as webpack config.devtool
, it's good enough for what I'm doing.
(From now on, if you are on rails version < 5.0, and you see bundle exec rails
anywhere below, replace it with bundle exec rake
)
On an existing rails project:
- Run these commands:
bundle add webpacker
bundle exec rails webpacker:install
bundle exec rails webpacker:install:coffee
# current coffee version is now 1.x, we need to update to 2.x to enable saiyan es6 power
yarn upgrade coffeescript --latest
yarn add vue vuex
# let's add vue jsx support
yarn add babel-plugin-syntax-jsx babel-plugin-transform-vue-jsx \
babel-helper-vue-jsx-merge-props babel-preset-env
- Remove the
app/javascript/pack/hello_coffee.coffee
file - Update/Add the files shown below. (These files have comments inside about the changes done, except for
.babelrc
which is ajson
, and you can't put comments in ajson
file; I only added"transform-vue-jsx"
to"plugins"
to have jsx support) - (These files you added defined a component
Todo
). Add the component<todo/>
in a view of your choice. - Restart your rails server
- Run
./bin/webpack-dev-server
. (I wished I could make it work with justrails server
but I can't) - Browse that view and you should see this: