Tarion
Tarion

Reputation: 17164

How to use grunt-browoserify to access my module from the script tag

I have a simple browserify setup in my Gruntfile.js

browserify: {
    dist: {
        src: 'public/js/main.js',
        dest: 'public/js/bundle.js'
    }
}

But how can I access party of my code from the browser? It seems like the module is completely encapulated. But I need to access some methods from <script> tags in my output.

From the console this works browserify -s myExport public/js/main.js -o public/js/bundle.js But I can't get grunt-browserify to execute that.

Upvotes: 1

Views: 357

Answers (1)

Tarion
Tarion

Reputation: 17164

I ended up with this (working):

browserify: {
    options: {
        transform:  [ require('grunt-react').browserify ],
        browserifyOptions: {
            debug: true,
            standalone: 'myExport'
        }
    },
    dev: {
        src: 'public/js/main.js',
        dest: 'public/js/bundle.js'
    },
    dist: {
        src: 'public/js/main.js',
        dest: 'public/js/bundle.js'
    }
}

Upvotes: 2

Related Questions