javascript - Exposing an api in a web page with browserify standalone - getting not defined error in Firefox -
i new node , javascript stuff. want access api in web page. followed this guide can't work. firefox tells me mylibrary not defined. tried around can't work. webstorm ide did recognize correctly in code editor. don't know why not work in ff.
i have file called readprotocoljson.js want expose in webpage, want acess contents
import {sequenceof, assequence, emptysequence, generatesequence} 'sequency'; module.exports = mylibrary; function mylibrary(){} mylibrary.prototype.readlogfile= function readlogfile() { loadjson(function(response) { // parse json string object var actual_json = json.parse(response); assequence(actual_json.frames); //just testing return actual_json.frames; }); };
i followed guide , created new file exportedmodules.js
module.exports = require('./readprotocoljson.js')
in html include lib
<script src="dist/exportedmodules.js"><script> <body> <script> var exportedmodules = new mylibrary(); var all_frames = exportedmodules.readlogfile(); </script> </body>
i execute via gulpfile.babel.js , run --standalone option gulpfile looks this:
import gulp 'gulp'; import browsersync 'browser-sync'; import browserify 'gulp-task-browserify'; gulp.task('scripts', browserify({ src: 'exportedmodules.js', dest: 'dist', uglify: false, sourcemaps: true, standalone: 'mylibrary', watch: { callback: browsersync.reload } }));
my package.json inlcudes following dependenices:
"dependencies": { "sequency": "latest", "browser-sync": "latest" }, "devdependencies": { "babel-node-modules": "0.0.1", "babel-preset-env": "^1.6.0", "babel-preset-es2015": "^6.24.1", "babel-preset-react": "^6.24.1", "babelify": "^7.3.0", "browserify": "latest", "gulp": "^3.9.1", "gulp-task-browserify": "latest" }
Comments
Post a Comment