openannotation / annotator

Annotation tools for the web. Select text, images, or (nearly) anything else, and add your notes.
http://annotatorjs.org
Other
2.69k stars 530 forks source link

Packaging annotator through webpack #684

Closed sonysujatha closed 6 years ago

sonysujatha commented 6 years ago

I was able to npm install annotator version 2.0.0-alpha.3. there are no error while bundling as well. But at runtime the below line throws error

const Annotator = require('annotator');

r: Cannot read property 'match' of undefined at Object.eval (rneedsContext.js:5) at eval (rneedsContext.js:6)

for webpack bundling is there any specific configuration required?

sonysujatha commented 6 years ago

Solved this , it was the way jQuery gets loaded through webpack. Had to add following in webpack.config.js

plugins: [
    new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery"
    })

and rules to have following module: { rules: [{ test: /jquery.aci/, loader: 'imports-loader?this=>window' },{ test: /jquery.aci/, loader: 'imports-loader?define=>false' }] }

Details on this stackoverflow answer