Search code examples
javascriptwebpackvue.jsassetsphotoeditorsdk

How do you include an assets folder in a Vue file?


I tried this (I'm using Vue's official Webpack template):

data () {
  photoEditorAssets: require('../assets/img/photoeditorsdk/assets'),
}

mounted () {
   var editor = new PhotoEditorSDK.UI.DesktopUI({ //eslint-disable-line
      container: container,
      assets: {
        baseUrl: this.photoEditorAssets // <-- This should be the absolute path to your `assets` directory
      }
    })
  }
}

However, I get this error:

Module build failed: Error: ENOENT: no such file or directory, open 'E:\alex\vreditor\src\assets\img\photoeditorsdk\assets'

Maybe the code is searching for a file called assets?

How to properly import a folder in a Vue file?

Note: Here's the structure of my project:

enter image description here


Solution

  • That's not how require() works. What you want is only the absolute path.

    Simply something like this should work for you.

    data () {
      photoEditorAssets: '../assets/img/photoeditorsdk/assets',
    }