PabloDK
PabloDK

Reputation: 2499

Simple call to method inside Browserified js file

I have this HTML file

<body>
    <div id="demodiv" style="width: 100%; height: 100%;"></div>
    <script src="chart.js"></script>
    <script>
        draw_chart();
    </script>
</body> </html>

Chart.js file (THIS WORKS!)

function draw_chart() {

var g = new Dygraph(
        document.getElementById("demodiv"),
        "chart.csv", // path to CSV file
        {}          // options
    );

g.ready(function() {

}); }

Then - i tried to install browerify, so i installed it and ran the cmd with

"browserify chart.js -o bundle.js"

and of course i also changed the script src in the HTML file from

chart.js to bundle.js

But is just doesn't work --> Uncaught ReferenceError: draw_chart is not defined

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o

function draw_chart() {

g.ready(function() {

...custom code... }); } },{}]},{},[1]);

Why can't the HTML page find the JS method draw_chart after i browerified it?

I guess i'm simply missing some thing really obvious!? Its the first time i'm using Browerify...

Upvotes: 0

Views: 262

Answers (1)

PabloDK
PabloDK

Reputation: 2499

I just realized - that Browerify don't work the way i expected...

Solution: I removed the call to the Draw_Chart from the HTML file and inserted the call in the bundle.js file instead... Thats all... :-)

Upvotes: 0

Related Questions