Open eduardolundgren opened 10 years ago
For testing #92 i started messing around with using trackingjs + node and it was really troubleless when 'requiring' from sandbox. Although it might not seem as the best way to do it, there are any cons?
Using the sandbox works well although it requires nodeunit, without it, tracking.js is unusable on node. I am not very familiar with UMD approach, seems a little overhead. What do you think in going with a naive strategy exporting the classes from each module, for example:
ColorTracker.js
...
if (module.exports) {
module.exports.ColorTracker = tracking.ColorTracker;
}
Then from node:
var ColorTracker = require('tracking.js').ColorTracker;
This should be enough and will remove nodeunit dependency for sandboxing. Let me know what do you think.
yeah, depending on nodeunit does not seems good.
Exposing if (module.exports) ..
is a good idea, but i think that dependency management is better done with UMD patterns.
I was thinking about UMD as it makes it clear whats going on with dependencies and how easy would be to expose the index.js
file for npm, as well as letting AMD users happy (not my case hahah). I created a gist with an example for tracking.js using UMD: https://gist.github.com/cirocosta/f41bcbea972002bf90de
In the example i'm not supporting AMD but adding 2 more lines would do it.
I think this also fits well with how tracking.js is structured, having always that tracking
object receiving methods and other stuff. It's very clear what's going on by seing something like:
(function (root, factory) {
// some amd/require/root things
}(this, function (tracking) {
tracking.newStuff = function () { };
return tracking;
}));
So I understand sandbox.js enables the tracking.js functionality to be used in a server-side node environment, but how does this change the implementation itself?
Do you need to feed pixel data directly to the tracker as opposed to the tracking.track() function handling it for you (since there's only a fake DOM within the sandbox)?
Currently tracking.js modules can work in Node via sandboxing, see https://github.com/eduardolundgren/tracking.js/blob/master/test/utils/sandbox.js.
Maybe adding
module.exports
into each file would allow to require them from node without a sandboxing? Once it's done we can publish it to NPM.