Open wuyuedefeng opened 4 years ago
安装yarn
# ubuntu $ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - $ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list $ sudo apt install yarn
deploy.rb
append :linked_dirs, ..., "public/packs", "node_modules"
本地编译部署:https://zh-cn.dev4app.com/archives/43911610-deploy-rails-5-1-webpacker-app-with-capistrano.html
添加gem
gem 'vite_rails'
then
$ bundle install $ bundle exec vite install
cd app/frontend
$ yarn create @vitejs/app vue3
then 拷贝app/frontend/vue3/package.json
中的依赖 到 项目跟录下的 package.json
then 拷贝app/frontend/vue3/vite.config.js
中的功能 到 项目跟录下的 vite.config.ts
then 删除app/frontend/vue3中的除src目录的其他文件和文件夹,并将src的内容移到vue3
中
创建controller
$ rails g controller vue3 index # config/router.rb get '/vue3', to: 'vue3#index', format: false
创建
app/views/vue3/index.html.erb
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta content="Example on how to use Inertia.js to build the frontend with Vue.js within a Ruby on Rails application" name="description" /> <meta content="PingCRM" name="application-name" /> <meta content="#667eea" name="theme-color" /> <title>Vite App</title>
<%#= csrf_meta_tags %> <%#= csp_meta_tag %> <%= vite_client_tag %>
<%= vite_javascript_tag 'application' %>
初始化引入
手动引入
添加gem
bundle install
->rails webpacker:install
->rails webpacker:install:vue
设置模板
创建
controller
config/router.rb
app/views/vue/index.html.erb
package.json
run
npm start
then visithttp://localhost:3000/vue
完善vue路由
更改
app/javascript/packs/hello_vue.js
->app/javascript/packs/main.js
(等价于正常vue项目的src/main.js
文件)添加路由
将
vue-router
引入app/javascript/packs/main.js
的vue实例中引入
PxRem
支持postcss.config.js
append below codeapp/javascript/packs/main.js