Search code examples
javascriptwebpackpaperjs

How load paper.js in webpack?


I use paper.js in my frontent application. I use gulp. This is my gulp code:

gulp.src([
    // .... other vendor js scripts
    'node_modules/paper/dist/paper-full.js'
])
    .pipe(uglify())
    .pipe(concat('vendor.js'))
    .pipe(gulp.dest(target))

but now I need use paper.js in webpack. I try use code like this:

 import paper from 'paper'

but after this, when I try call paper methods (for example const path = new paper.Path() ) I got error

Cannot read property 'Path' of undefined"

UPDATE:

I use vuejs webpack template for my application, my webpack.base.conf.js here


Solution

  • try using

    import * as paper from 'paper'
    

    or And there is a loader for paper.js https://github.com/aprowe/paper-loader

    module.exports = {
      ...
      module: {
        loaders: [
          {
            test: /\.paper.js$/,
            loader: "paper-loader"
          }
        ]
      }
    };