chenmnkken / gulp-seajs-combo Goto Github PK
View Code? Open in Web Editor NEWseajs(CMD) Module combo pulgin for gulp
License: MIT License
seajs(CMD) Module combo pulgin for gulp
License: MIT License
打包后生成的js包含,
var Overlay = require('overlay');
require('dialog.css');
但是css文件未加载
比如文件目录如下
src/
|-- a
| |-- a.js
| `-- b.js
`-- b
`-- bb.js
b.js 依赖 bb.js
gulp代码如下
var gulp = require( 'gulp' ),
seajsCombo = require( 'gulp-seajs-combo' );
gulp.task( 'seajscombo', function(){
return gulp.src( 'src/js/a/*.js' )
.pipe( seajsCombo() )
.pipe( gulp.task('build/js') );
});
结果是
合并后,
a.js 中只有自己的一个module,这个是正常的
但是b.js中不仅有依赖的bb.js的module,a.js的module也被合并进来了
a.js 和 b.js 没有任何依赖关系啊,为什么会这样
我的gulpfile.js是这样写的
gulp.task('seajscombo', function() {
gulp.src("static/module/*/.js")
.pipe(seajsCombo())
.pipe(gulp.dest('dist/static/module'));
});
生成的合并文件main.js是这样
define('main',['support','showanimation'],function(require,exports,moudle) {});
define('support',function(require, exports, moudule) {});
define('showanimation',['support'],function(require,exports,moudule) {});
但是执行不了,网上查貌似是id问题,请问怎么解决?
在使用过程中,发现存在一些特殊情况,combo对模块的依赖解析出错。
当标准的seajs模块中存在seajs.use
调用时,依赖解析会跳去解析seajs.use的模式
defind(function(require, exports, module) {
var $ = require('jQuery');
function doSomething() {
seajs.use('http://hm.baidu.com/h.js');
}
})
当源地址不是一个文件而是文件夹的时候,合并出来的结果有问题,会重复合并。原因是入口的o变量,被后面的闭包持久化了
/*
if (location.href.indexOf("?dev") > 0) {
seajs.use("./src/a", function () {
console.log(arguments);
});
}
*/
seajs.use("./src/a", function () {
console.log(arguments);
});
以上代码在执行gulp-seajs-combo/index.jspullDeps( options, rDeps, item )
会报错,去掉注释中的if条件就没问题,我想应是rDeps
正则匹配问题。origId
在被赋值成?dev
时代码粗bug了。
var gulp = require( 'gulp' ),
seajsCombo = require( 'gulp-seajs-combo' );
gulp.task('default', function() {
}) ;
gulp.task( 'seajs', function(){
return gulp.src( 'resources/assets/js/main.js' )
.pipe( seajsCombo({'ignore':['wx']}) )
.pipe( gulp.task('public/js') );
});
[15:19:18] Using gulpfile ~/www/vhost/wgjv2/gulpfile.js
[15:19:18] Starting 'seajs'...
[15:19:18] Finished 'seajs' after 8.85 ms
[15:19:18] gulp-seajs-cmobo error: undefined is not a function
TypeError: undefined is not a function
at write (/home/bluse/www/vhost/wgjv2/node_modules/gulp-seajs-combo/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
at flow (/home/bluse/www/vhost/wgjv2/node_modules/gulp-seajs-combo/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)
at DestroyableTransform.pipeOnReadable (/home/bluse/www/vhost/wgjv2/node_modules/gulp-seajs-combo/node_modules/through2/node_modules/readable-stream/lib/stream_readable.js:664:5)
at DestroyableTransform.emit (events.js:104:17)
at emitReadable (/home/bluse/www/vhost/wgjv2/node_modules/gulp-seajs-combo/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:448:10)
at emitReadable (/home/bluse/www/vhost/wgjv2/node_modules/gulp-seajs-combo/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:444:5)
at readableAddChunk (/home/bluse/www/vhost/wgjv2/node_modules/gulp-seajs-combo/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:187:9)
at DestroyableTransform.Readable.push (/home/bluse/www/vhost/wgjv2/node_modules/gulp-seajs-combo/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:149:10)
at DestroyableTransform.Transform.push (/home/bluse/www/vhost/wgjv2/node_modules/gulp-seajs-combo/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:145:32)
at afterTransform (/home/bluse/www/vhost/wgjv2/node_modules/gulp-seajs-combo/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:101:12)
在解析tpl模块上时报错。
gulp-seajs-cmobo Error: TypeError: Cannot read property 'forEach' of undefined
错误原因: options.plugins 为空。
不知道作者能否抽时间解决下?
谢谢您分享开发的插件,很好用,但是小弟有个问题,劳烦您给解答一下。
如题,有没有简便的方式,项目中不同的html用的js路径不同,不可能全部手动修改html吧。
我的想法是用压缩合并后,输出到和原来的文件相同目录结构的文件夹,比如原来是assets/a.js,合并压缩输出到,build/assets/a.js,这样我只需要在seajs-config中配置就可以实现不同的文件加载。请问如何实现输出时把原来的目录也输出过来?提前感谢您的回答。
你好,没有浏览器环境,seajscombo是如何找到seajs.config的?
能不能把seajs,也加载进来,像这样seajs.use("./static/seajs");
我试下 了下,可以加载进来,只是顺序不对
建议作者可以在seajscombo配置中,添加可以自己配置base和paths,而不是让程序去读取seajs.config,因为我在使用过程中总是因为路径匹配导致好多错误。希望可以以当前gulpfile.js目录为基础目录,然后所有的base、paths,以及其他js文件都是基于此路径,(当然,原先以相对路径require的js文件,相对路径配置),这样可以避免好多问题。感谢作者的付出,往采纳!
代码中是这样require一个模块:
Hogan.compile(require("./template"))
但是压缩后:
Hogan.compilerequire('template'))
压缩后直接报错。
然后改为:var template = require("./template")方式压缩即可。
如此看来,插件是不支持非变量方式的require。
对于命名模块,可以不用重命名
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.