Last active
May 23, 2016 18:42
-
-
Save BrandesEric/df0e1fd59cc658cb8267483d13176930 to your computer and use it in GitHub Desktop.
Webpack and TrackJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The easiest way to use TrackJS with webpack | |
// You can put the initial config in a different file if you wish, just make sure it's loaded before you require('trackjs') | |
window._trackJs = { | |
token: "" | |
} | |
require('trackjs'); // window.trackJs() will be a thing now in the browser. | |
// You can just treat as global if you wish: | |
trackJs.track("Test error"); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Must be first! | |
window._trackJs = { | |
token: "" | |
} | |
// Sometimes people want to be able to have something be returned from a require() call | |
// It's better semantics and it generally appeases linters (most do not care for magic globals) | |
var trackJsInstance = require('exports?trackJs!trackjs'); | |
// All the exports? declaration does is add a "module.exports = trackJs" to the end of the npm file. | |
// So now you have an instance | |
trackJsInstance.track("Test error"); | |
// But really | |
console.log(trackJsInstance === window.trackJs) // true | |
// Of course, writing require('exports?trackJs!trackjs') everywhere is cumbersome, that's why we stuff the export config in the webpack.config.js | |
// So you can do | |
var trackJs = require("trackJs"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment