Including JQuery Mobile in a Node JS project with Browserify

后端 未结 4 640
面向向阳花
面向向阳花 2021-01-12 14:59

I\'m writing a Node JS application where I need both jQuery UI and jQuery Mobile. I\'m using Browserify to pack the modules in a single js file.

I have the following

4条回答
  •  误落风尘
    2021-01-12 15:17

    You need to specify the path to jquery-mobile.

    In packadge.json

    "devDependencies": {
        "gulp": "3.8.7",
        "browserify": "9.0.3",
        "browserify-shim": "3.8.3",
        // [...] many more hidden
        "jquery": "1.11.0",
        "jquery-mobile": "1.4.1"
    },
    "browser": {
        "jquery-mobile": "./node_modules/jquery-mobile/dist/jquery.mobile.js"
    },
    "browserify": {
        "transform": [ "browserify-shim" ]
    },
    "browserify-shim": {
        "jquery": "$",
        "jquery-mobile" : { "exports": "$.mobile", "depends": [ "jquery:$" ] },
        "three": "global:THREE"
    }
    

    in you js file:

    var $ = require('jquery');
    $.mobile = require('jquery-mobile');
    

    You can see more of this here

    I am also using gulp. In gulpfile.js:

    gulp.task('browserify', ['jshint'], function () {
        return browserify('./src/js/app.js')
        .bundle()
        .pipe(source('myjs.js'))
        .pipe(gulp.dest('./js/'));
    });
    

提交回复
热议问题