Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load asset_pack_path images into .vue #1256

Closed
alexandesigner opened this issue Feb 8, 2018 · 3 comments
Closed

How to load asset_pack_path images into .vue #1256

alexandesigner opened this issue Feb 8, 2018 · 3 comments

Comments

@alexandesigner
Copy link

I'm trying to use images inside the .vue file

<img src="<%= asset_pack_path 'images/logo.svg' %>" />

How to use the tag asset_pack_path

NOTE: I know that using the relative path is possible, I'm just wondering if it's possible to use the tag inside .vue.erb

@ytbryan
Copy link
Contributor

ytbryan commented Feb 22, 2018

Setup: yarn add rails-erb-loader

At .vue

    <% helpers = ActionController::Base.helpers %>
    <%= helpers.image_tag "logo.svg" %>
    <img src="<%= helpers. asset_pack_path 'images/logo.svg' %>" />

At app/config/webpack/loaders/vue.js

const { dev_server: devServer } = require('@rails/webpacker').config

const isProduction = process.env.NODE_ENV === 'production'
const inDevServer = process.argv.find(v => v.includes('webpack-dev-server'))
const extractCSS = !(inDevServer && (devServer && devServer.hmr)) || isProduction

module.exports = {
  test: /\.vue(\.erb)?$/,
  use: [{
    loader: 'vue-loader',
    options: { extractCSS }
  },
  {
    loader: 'rails-erb-loader', 
    options: {
      runner: 'bin/rails runner',
      dependenciesRoot: '../app'
    }
  }
]
}

Cc usabilityhub/rails-erb-loader#53

@gauravtiwari this can be closed.

@ytbryan ytbryan mentioned this issue Feb 22, 2018
@rhys-vdw
Copy link

Suggest closing this issue in preference for usabilityhub/rails-erb-loader#33.

@gauravtiwari
Copy link
Member

Thanks @ytbryan and @rhys-vdw for looking into this 🍰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants