oliverfindl / vue-svg-inline-loader

Webpack loader used for inline replacement of SVG images with actual content of SVG files in Vue projects.
MIT License
124 stars 18 forks source link

Failed to mount component: template or render function not defined. #7

Closed igorkurochka closed 6 years ago

igorkurochka commented 6 years ago

Hi (again), sorry to bother you, but after I added your loader and put this code in my template

<img svg-inline svg-sprite class="icon icon-arrow-bottom-icon" src="@/assets/images/sale.svg" alt="svgicons"/>

I've got this warning in devtools console and my app stopped working (just plain whitescreen) "vue.esm.js?efeb:591 [Vue warn]: Failed to mount component: template or render function not defined."

the loader was added right after vue-loader

  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: vueLoaderConfig
      },
      {
        test: /\.vue$/,
        use: [
          "vue-loader",
          {
            loader: "vue-svg-inline-loader"
          },
        ]
      },
....

and the vueLoaderConfig is:

{
  loaders: utils.cssLoaders({
    sourceMap: sourceMapEnabled,
    extract: isProduction
  }),
  cssSourceMap: sourceMapEnabled,
  cacheBusting: config.dev.cacheBusting,
  transformToRequire: {
    video: ['src', 'poster'],
    source: 'src',
    img: 'src',
    image: 'xlink:href'
  }
}
oliverfindl commented 6 years ago

Hello,

your webpack config should look like this:

module: {
    rules: [{
        test: /\.vue$/,
        use: [{
            loader: "vue-loader",
            options: vueLoaderConfig
        }, {
            loader: "vue-svg-inline-loader",
            options: { /* options */ }
        }]
    }, {
        /* another rule */
    }, {
        /* one more rule */
    }]
}

Try it and let me know if it works.

Thanks

igorkurochka commented 6 years ago

it works! thank you!

mark-reason commented 5 years ago

I'm having the same issue, my webpack config is:

module: { rules: [{ test: /\.vue$/, use: [ "vue-loader", { loader: "vue-svg-inline-loader", options: { svgo: { plugins: [{ removeDoctype: true }, { removeComments: true }, { cleanupIDs: false }] } } } ] }] }

oliverfindl commented 5 years ago

Hello,

I copied your rule into my project and it works without any errors. You have probably error somewhere else in webpack config.

Thanks

mark-reason commented 5 years ago

Hi Oliver

It's the only thing in my webpack config, the app was generated via the vue-cli and the code has been added to a vue.config.js file. Full file is here:

module.exports = { configureWebpack: { module: { rules: [{ test: /\.vue$/, use: [ "vue-loader", { loader: "vue-svg-inline-loader", options: { svgo: { plugins: [{ removeDoctype: true }, { removeComments: true }, { cleanupIDs: false }] } } } ] }] } } };

Cheers Mark

oliverfindl commented 5 years ago

Hello,

unfortunately I'm not using vue-cli. I'm using webpack instead. Please refer to vue-cli docs for webpack.

I'm sorry, I can't assist you with vue-cli issues, because it's out of my scope.

Thanks

oliverfindl commented 5 years ago

Hello guys,

finally got some spare time, so I updated readme file with usage snippets for webpack, vue-cli and nuxt based projects. Also I added examples for each one of those.

If you still have issues, please let me know.

Thanks

mark-reason commented 5 years ago

Thanks so much, works a treat!