Skip to content

using-npm-on-the-client-side #16

@malutanpetronel

Description

@malutanpetronel

Hi Kyle

I was tried to use guidelines you provided in http://dontkry.com/posts/code/using-npm-on-the-client-side.html article on a Laravel website.
I am trying to use node_modules inside my web site, and by chance I did thought to ask you maybe you'll clarify me a bit:
I did created index.js with:

var strip_js = require('./public/stripjs.js');
var parsed = strip_js('<h1 onclick="whatever();">Start</h1><script src="http://laravel-petro.dev/bundle.js"></script><h1>End</h1>');
console.log(parsed);

I did also

browserify index.js > public/bundle.js    

and in my view

<script src="{{ asset('bundle.js') }}"></script>

In the web page I see first log inside the index.js correctly stripped js tags

<h1>Start</h1><h1>End</h1>

but second log from inside a script loaded inside the same above view which is saying:

$(document).ready(function () {
    console.log(strip_js);

the output is:

index.js:15 Uncaught ReferenceError: strip_js is not defined
    at HTMLDocument.<anonymous> (index.js:15)
    at i (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at Function.ready (jquery.min.js:2)
    at HTMLDocument.J (jquery.min.js:2)

Any ideea what I do wrong ? Or strip_js should not be visible in my own js ? The order is bundle.js called first and only after my.js file

With kind regard
Petronel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions