eduardolundgren / tracking.js

A modern approach for Computer Vision on the web
http://trackingjs.com
Other
9.43k stars 1.44k forks source link

Import tracking (ES6, webpack) #177

Closed nosy-b closed 6 years ago

nosy-b commented 7 years ago

Thanks for this great library.

I wanted to use it in a web project built using webpack. In the package.json i added

"tracking": "^1.1.2"

which works fine, it's built and goes into node_modules. But how do you use it in a class? import tracking from 'tracking'; doesn't work, nor the Require version (even with the build tracking.js placed into the sources) Thank you

SimoneS93 commented 7 years ago

I don't know about webpack, but I edited the tracking.js file to make it work on node with require('./tracking'). Here's it: https://github.com/SimoneS93/trackingjs

psigen commented 7 years ago

Having a similar problem here. I have installed the package via npm, but it is impossible to include directly using import or require syntax.

It would be great if this module followed any of the JS module standards, but the most useful would probably be ES6 modules.

As @SimoneS93 noted, this is as simple as adding a module.exports (CommonJS) or export (ES6) statement to the end of the library.

samburgers commented 7 years ago

Looks like they take pull requests ^^

geekplux commented 7 years ago

you can try to use webpack shimming(https://webpack.js.org/guides/shimming/):


rules: [{
  test: require.resolve('tracking'),
  use: 'imports-loader?this=>window'
}],

plugins: [
  new webpack.ProvidePlugin({
    tracking: 'tracking'
  })
]
joZephhh commented 6 years ago

is that currently supports ? :)

jsprow commented 6 years ago

Hopefully this'll help someone.

I was running into the same problem importing tracking.js, and went the Webpack shim route as suggested by @geekplux , copying the code exactly as written, after installing the files via npm install tracking --save.

When I imported tracking, I found I also needed to import the libraries for ObjectTracker. I thought I'd need to dive back into webpack.config.js, but it worked just fine using:

import tracking from 'tracking';
import 'tracking/build/data/face-min.js';
import 'tracking/build/data/eye-min.js';
import 'tracking/build/data/mouth-min.js';
mrmiguu commented 4 years ago

@jsprow Thank you for this!

Update for Parcel.js users:

import 'tracking'
import 'tracking/build/data/face-min.js'
import 'tracking/build/data/eye-min.js'
import 'tracking/build/data/mouth-min.js'