requireJS,rjs,gulp简易实现
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
<!DOCTYPE HTML> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>requireJS</title> <script src="require.js" defer async data-main="./main.js" ></script> </head> <body> <input type="button" value="点击" id="btn"> </body> </html>
参考文章
http://www.tuicool.com/articl... r.js
http://www.cnblogs.com/2050/p... gulp
http://m.blog.csdn.net/articl... require.js文件合并
相关推荐
我有一只小松鼠 2020-02-29
MrLiar 2015-11-09
idnochinese 2019-07-01
UndefineOrNull 2019-07-01
星辰的笔记 2020-07-04
liangjielaoshi 2020-06-11
zhongweinan 2020-06-10
jiangfulai 2020-04-18
UndefineOrNull 2020-02-29
UndefineOrNull 2020-03-01
hlihaihong 2020-02-18
UndefineOrNull 2020-02-12
yinuoqingqin 2020-01-13
星辰的笔记 2020-01-13
UndefineOrNull 2020-01-13
hlihaihong 2020-01-13
kaosini 2020-01-12
hlihaihong 2020-01-12
kaosini 2020-01-12