gulpfile.js
var gulp = require("gulp");
var rjs = require("requirejs");
gulp.task('build', function(cb){
rjs.optimize({
//文件输出路径
dir: './vajoy',
//定义入口文件路径
baseUrl: "./rjs",
//单入口
//mainConfigFile:"./rjs/main.js",
//name:'main',
//输出路径
//out:'./rjs/dist/build-main.js',
modules: [ //要优化的模块
{ name:'main'} //说白了就是各页面的入口文件,相对baseUrl的路径,也是省略后缀“.js”
],
optimize: "uglify",
//相对baseUrl的路径,定义依赖模块的路径
paths: {
a: './js/a',
jquery: './js/jquery',
}
}, function(buildResponse){
// console.log('build response', buildResponse);
cb();
}, cb);
//运行 gulp build
main.js
// JavaScript Document
require.config({
baseUrl: "js",
paths: {
"jquery":"jquery",
"a":"a"
}
});
require(['jquery','a'],function($,a){
$("#btn").on("click",function(){
a();
})
})
html
requireJS