導航:首頁 > 編程語言 > helloseajs

helloseajs

發布時間:2023-04-21 19:22:09

A. 加速包js怎麼實現

基於 AngularJS 的拖拽指令
支持 GPU 加速
支持邊界限制
支持設置拖拽把柄
移動端與 PC 端通用
使用
支持使用 script 標簽或者 webpack、requirejs、seajs 調用:
script
調用

script src="lib/angular.js"></script>
<script src="dist/angular-drag.js"></script>
<script>
var app = angular.mole('app', ['angular-drag']);
</script>

webpack
安裝
npm install angular-drag

調用
require('angular-drag');
var app = angular.mole('app', ['angular-drag']);

angular-drag 依賴 angular 與 jquery 兩個全局模塊
指令
drag 被拖拽的元素
drag-handle 觸發拖拽的把柄(可選)
示例
簡單的可拖拽元素
<遲睜侍早橘div drag class="example">

hello world
</div>
自定義拖拽的把柄
<div drag class="example">

<碼吵div drag-handle></div>
<p>hello world</p>
</div>

B. seajs和requiejs的區別,和用gulp打包方法

從demo.html 引入一個入口c.js, c.js require-b.js , b.js require - a.js

代碼如下:

c mole

[html] view plain print?
define(function(require, exports, mole) {

console.log("hello mole c");

require('b');

console.log("c finished");

});

b mole
[html] view plain print?
define(function(require, exports, mole) {
console.log("hello mole b")
var a = require('a');
console.log("b finished")
});
a mole
[html] view plain print?
define(function() {
console.log("hello mole a")
});

requriejs 的 html代碼:

[html] view plain print?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>seajs和requirejs的區別</title>
<script src="require.min.js" data-main="c.js"></script>
</head>
<body>

</body>
</html>

執行結果:

ello mole aa.js:2

hello mole bb.js:2

b finishedb.js:4

hello mole cc.js:3

c finishedc.js:7

seajs的html代碼:

[html] view plain print?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>seajs和requirejs的區別</title>
<script src="sea.2.3.js"></script>
<script>
seajs.use('./c');
</script>
</head>
<body>

</body>
</html>
執行結果:
hello mole cc.js:3

hello mole bb.js:2

hello mole aa.js:2

b finishedb.js:4

c finishedc.js:7

所以總結:
seajs是從上到下執行,
requriejs是把其中require的js全部載入完了,再往下執行。·

2、依賴的載入有所不同

在define中 requriejs載入了依賴就執行;而seajs在define中只是載入不會執行(如果要執行,需要用require()方法)

案例代碼:

c.js模塊

[html] view plain print?
define(['b'],function(require,exports,mole){
console.log("hello mole c");

console.log("c finished");
});
b.js模塊
[html] view plain print?
define(['a'],function(require,exports,mole) {
console.log("hello mole b")

console.log("b finished")
});

a.js模塊

[html] view plain print?
define(['b'],function(require,exports,mole) {
console.log("hello mole a")
});

seajs和requirejs的 html代碼 和 1 中一樣
執行結果:

seajs執行結果:

hello mole cc.js:2

c finishedc.js:4

requiresj的執行結果:

ello mole aa.js:2

hello mole bb.js:2

b finishedb.js:4

hello mole cc.js:2

c finishedc.js:4

總結: 在define書寫中A:requirejs 載入了就執行,所以requirejs是預執行(在define中預先執行所有require依賴的js),RequireJS的做法是並行載入所有依賴的模塊, 並完成解析後, 再開始執行其他代碼, 因此執行結果只會"停頓"1次, 完成整個過程是會比SeaJS要快. 預執行

B:seajs只是純粹的載入依賴的文件,不執行就連console都不執行就是純粹的「載入」,SeaJS一樣是並行載入所有依賴的模塊, 但不會立即執行模塊, 等到真正需要(require)的時候才開始解析,
這里耗費了時間, 因為這個特例中的模塊巨大, 因此造成"停頓"2次的現象, 這就是我所說的SeaJS中的"懶執行".

在2的基礎上 c.js代碼為

[html] view plain print?
define(function(require,exports,mole){
require('b');
require('a');
console.log("hello mole c");

console.log("c finished");
});
執行結果都是一樣

hello mole bb.js:2

b finishedb.js:4

hello mole aa.js:2

hello mole cc.js:4

c finishedc.js:6

3、取別名時requirejs默認舍掉.js的後綴

4、 打包方法

gulp 打包seajs

requirejs 打包

C. 請教seajs 的define參數 的問題

開發階段不推薦define的參數傳入三個,只需給定後面的factory即可,發布時通過構建工版具提取壓權縮模塊,會自動加上idhe依賴數組(即第二個參數),這樣seajs能夠更快的定位本身這個模塊和它依賴的模塊。
順便提一下,第二個參數,如果顯示傳入了,那麼seajs就不會再通過正則去掃描factory.toString(),直接根據這個參數去載入依賴模塊,如果為[]即表示無依賴。

D. requirejs和seajs的區別

SeaJS對模塊的態度是懶執行, 而RequireJS對模塊的態度是預執行



如下模塊通過SeaJS/RequireJS來載入, 執行結果會是怎樣?
define(function(require, exports, mole) {
console.log('require mole: main');

var mod1 = require('./mod1');
mod1.hello();
var mod2 = require('./mod2');
mod2.hello();

return {
hello: function() {
console.log('hello main');
}
};
});

先試試SeaJS的執行結果
require mole: main
require mole: mod1
hello mod1
require mole: mod2
hello mod2
hello main

E. angularJS關於依賴和模塊與amd/cmd的區別,分享下結合使用示例

雙向綁定,可測試性的代碼結構,模型視圖分離的一個前端MV*框架

其中angular也提供了模型的概念和依賴管理,不過這個依賴都是要在js對象都已經定義的前提下,沒有像amd/cmd提供按需載入。

我個人比較喜歡cmd(seajs),它對頂級作用域window的使用約束較多,全局對象和方法少,缺點就是很多原生庫,都需要手工wrap下。

angular定義的controller一般都是全局的,我想用seajs來管理angular的代碼和依賴,下面是一起使用的示例,有類似需求的童鞋可以參考下:

java">//fileng_mole2.js
define(function(require){
varLog=require('log');
return{
init:function(){
Log.w('Loadangularmole:m2');

varag=window.angular;
if(!ag){
Log.w('Errorwhenloadangularmole:m2:noangular');
return;
}

varm2=ag.mole('m2',[]);
m2.filter('greet',function(){
returnfunction(name){
return'Hello,'+name+'!';
};
});
}
};
});
//fileng_mole1.js
define(function(require){
require('mole/demo/ng_mole2').init();
varLog=require('log');

return{
init:function(){
Log.w('Loadangularmole:m1');

varag=window.angular;
if(!ag){
Log.w('Errorwhenloadangularmole:m1:noangular');
return;
}

varm1=ag.mole('m1',['m2']);
m1.directive('testDateFormat',function(){
returnfunction(scope,el,attrs,ctrl){
varformat='yyyy-MM-dd';
varupdateTime=function(){
el.text(newDate().format(format));
};

//watchscope.formatinctrl
scope.$watch('format',function(value){
format=value;
updateTime();
});

updateTime();
}
});
}
};
});
//filedemo/ng1.js
//初始化頁面
define(function(require){
varLog=require('log');

require('mole/demo/ng_mole1').init();
varagAdaptor=require('x/x.ex.angular');

return{
initPage:function(from,pageInfo,params){
varTestCtrl=function($scope){
$scope.format='yyyy/MM/dd';
};
window.TestCtrl=TestCtrl;

agAdaptor.init(['m1'],'TestCtrl','ngContext');
},

mp:''
};
});
//filex/x.ex.angular.js
//angularbootstrap適配——在bootstrap之前動態修改下dom
define(function(require){
var$=require('jquery');
varLog=require('log');

return{
init:function(moles,ctrlName,contextId){
if(!window.angular){
Log.w('Noangluardefined!','WARN');
return;
}

var_context=$('#'+contextId);
this.initCtrl(_context,ctrlName);
this.initModel(_context);
this.bootstrapAngular(moles);
},

//把ng-controller補上
initCtrl:function(_context,ctrlName){
if(ctrlName)
_context.attr('ng-controller',ctrlName);
},

//根據name把ng-model補上
initModel:function(_context){
_context.find('[name^=f_]').each(function(){
var_el=$(this);
varname=_el.attr('name');
varmodelName=name.split('_').remove(0).join('.');
_el.attr('ng-model',modelName);
});
},

bootstrapAngular:function(moles){
window.angular.bootstrap(document,moles);
}
};
});
	<divclass="m_10">
<h3>Angular——WorkwithSeaJS</h3>

<divid="ngContext">
Dateformat:<inputng-model="format">
<br/>
Currenttimeis:<spantest-date-format=""></span>
</div>
</div>

seajs.use('mole/demo/ng1',function(IPage){
IPage.initPage();
});

F. GitHub 上有哪些值得推薦的開源電子書

語言無關類
操作系統

G. 請大神幫我解答一下這個函數。。。包括function中的兩個參數


jQuery插件開發的五種形態

面對這種情況,通常我們會通過定義function的方式來實現。


復制代碼代碼如下:


function pluginName($selector){
$.each($selector, function () {
$(this).css("background-color", "#ccc");
// to do something...
});
}
// pluginName(document.getElementsByClassName("demo"));


因為我談的是jQuery插件開發,那麼我現在把這段代碼擴展到jQuery上,代碼如下:


復制代碼代碼如下:


// IIFE(立即調用函數表達式); [參考http://suqing.iteye.com/blog/1981591/]
;(function ($) {
// 擴展這個方法到jQuery.
// $.extend() 是吧方法擴展到 $ 對象上,和 $.fn.extend 不同。 擴展到 $.fn.xxx 上後,
// 調用的時候就可以是 $(selector).xxx()
$.fn.extend({
// 插件名字
pluginName: function () {
// 遍歷匹配元素的集合
// 注意這里有個"return",作用是把處理後的對象返回,實現鏈式操作
return this.each(function () {
// 在這里編寫相應的代碼進行處理
});
}
});
// 傳遞jQuery到內層作用域去, 如果window,document用的多的話, 也可以在這里傳進去.
// })(jQuery, window, document, undefined);
})(jQuery, undefined);
// 調用方式 $(".selector").pluginName().otherMethod();


但是還差的遠,目前只解決了兩個問題

代碼相對獨立
鏈式操作
插件可配置
有可操作的方法,插件的生命周期可控制
配置可被緩存
可擴展
無沖突處理
事件代理,動態初始化

現在來給插件添加參數支持。代碼如下


復制代碼代碼如下:


;(function($){
$.fn.pluginName = function(options) {
// 合並參數,通過「extend」合並默認參數和自定義參數
var args = $.extend({}, $.fn.pluginName.defaults, options);
return this.each(function() {
console.log(args.text);
// to do something...
});
};
// 默認參數
$.fn.pluginName.defaults = {
text : "hello"
};
})(jQuery);
// $(".selector").pluginName({
// text : "hello world!"
// });


添加參數支持還比較容易些,又解決一問題

代碼相對獨立
鏈式操作
插件可配置
有可操作的方法,插件的生命周期可控制
配置可被緩存
可擴展
無沖突處理
事件代理,動態初始化

現在來添加方法的支持,我前面所提到的生命周期可控制,意思差不多,例如添加reInit,destory等方法來控制插件。


復制代碼代碼如下:


;(function($){
$.fn.pluginName = function (method) {
// 如果第一個參數是字元串, 就查找是否存在該方法, 找到就調用; 如果是object對象, 就調用init方法;.
if (methods[method]) {
// 如果存在該方法就調用該方法
// apply 是吧 obj.method(arg1, arg2, arg3) 轉換成 method(obj, [arg1, arg2, arg3]) 的過程.
// Array.prototype.slice.call(arguments, 1) 是把方法的參數轉換成數組.
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
// 如果傳進來的參數是"{...}", 就認為是初始化操作.
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.pluginName');
}
};
// 不把方法擴展在 $.fn.pluginName 上. 在閉包內建個"methods"來保存方法, 類似共有方法.
var methods = {
/**
* 初始化方法
* @param _options
* @return {*}
*/
init : function (_options) {
return this.each(function () {
var $this = $(this);
var args = $.extend({}, $.fn.pluginName.defaults, _options);
// ...
})
},
publicMethod : function(){
private_methods.demoMethod();
}
};
// 私有方法
function private_methods = {
demoMethod : function(){}
}
// 默認參數
$.fn.pluginName.defaults = {
};
})(jQuery);
// 調用方式
// $("div").pluginName({...}); // 初始化
// $("div").pluginName("publicMethod"); // 調用方法


又解決一問題

代碼相對獨立
鏈式操作
插件可配置
有可操作的方法,插件的生命周期可控制
配置可被緩存
可擴展
無沖突處理
事件代理,動態初始化

第三形態的插件修改就已經可以應對大多數插件的需求了。精益求精嘛,繼續升級
第四形態的插件是照幫司徒正美的《javascript框架設計》的代碼。加了點面向對象的知識。


復制代碼代碼如下:


(function ($) {
var Plugin = function (element, options) {
this.element = element;
this.options = options;
};
Plugin.prototype = {
create: function () {
console.log(this.element);
console.log(this.options);
}
};
$.fn.pluginName = function (options) {
// 合並參數
return this.each(function () {
// 在這里編寫相應的代碼進行處理
var ui = $._data(this, "pluginName");
// 如果該元素沒有初始化過(可能是新添加的元素), 就初始化它.
if (!ui) {
var opts = $.extend(true, {}, $.fn.pluginName.defaults, typeof options === "object" ? options : {});
ui = new Plugin(this, opts);
// 緩存插件
$._data(this, "pluginName", ui);
}
// 調用方法
if (typeof options === "string" && typeof ui[options] == "function") {
// 執行插件的方法
ui[options].apply(ui, args);
}
});
};
$.fn.pluginName.defaults = {};
})(jQuery);
// 調用的方式和之前一樣。


這里特別要提下緩存這個東西,插件用多了,覺的這個真的是好東西。
在傳統面向對象的插件開發中,至少會聲明個變數保存它,但是我到目前寫的jQuery插件中都沒有,用起來很麻煩。自從把初始化後的插件緩存起來後,方便了許多。通過代碼$("#target").data("pluginName")就可以取到對象了。 來看看還有什麼問題沒有解決

代碼相對獨立
鏈式操作
插件可配置
有可操作的方法,插件的生命周期可控制
配置可被緩存
可擴展
無沖突處理
事件代理,動態初始化

看了上面的代碼是否腦子有點暈了,如果是,休息片刻,稍後回來,下面的代碼更精彩。 最後一個方案算是比較全面的了。方案來自Bootstrap,下面代碼以 Bootstrap 的 button 插件為例.


復制代碼代碼如下:


!function ($) {
// ecma262v5 的新東西, 強制使用嚴謹的代碼編寫.
"use strict";
// BUTTON PUBLIC CLASS DEFINITION
// ==============================
var Button = function (element, options) {
this.$element = $(element);
this.options = $.extend({}, Button.DEFAULTS, options);
};
Button.DEFAULTS = {
loadingText: 'loading...'
};
Button.prototype.setState = function (state) {
// ...
};
Button.prototype.toggle = function () {
// ...
};
// BUTTON PLUGIN DEFINITION
// ========================
var old = $.fn.button; // 這里的 $.fn.button 有可能是之前已經有定義過的插件,在這里做無沖突處理使用。
$.fn.button = function (option) {
return this.each(function () {
var $this = $(this);
// 判斷是否初始化過的依據
var data = $this.data('bs.button');
var options = typeof option == 'object' && option;
// 如果沒有初始化過, 就初始化它
if (!data) $this.data('bs.button', (data = new Button(this, options)));
if (option == 'toggle') data.toggle();
else if (option) data.setState(option)
})
};
// ① 暴露類名, 可以通過這個為插件做自定義擴展
$.fn.button.Constructor = Button;
// 擴展的方式
// 設置 : $.fn.button.Constructor.newMethod = function(){}
// 使用 : $btn.button("newMethod");
// ② 無沖突處理
$.fn.button.noConflict = function () {
$.fn.button = old;
return this
};
// ③ 事件代理, 智能初始化
$(document).on('click.bs.button.data-api', '[data-toggle^=button]', function (e) {
var $btn = $(e.target);
// 查找要初始化的對象
if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn');
// 直接調用方法, 如果沒有初始化, 內部會先進行初始化
$btn.button('toggle');
e.preventDefault();
});
}(jQuery);


來看看還有什麼問題沒有解決

代碼相對獨立
鏈式操作
插件可配置
有可操作的方法,插件的生命周期可控制
配置可被緩存
可擴展
無沖突處理
事件代理,動態初始化

補充

現在的插件都要求靈活性要高,比如希望插件可以同時適配jQuery和Zepto,又或者需要支持AMD或者CMD規范。

支持jQuery和Zepto


復制代碼代碼如下:


if (window.jQuery || window.Zepto) {
(function ($) {
// plugin code...
})(window.jQuery || window.Zepto);
}


中間件支持,node


復制代碼代碼如下:


if (typeof(mole) !== 'undefined')
{
mole.exports = pluginName;
}
requirejs(AMD) support
if (typeof define === 'function' && define.amd) {
define([], function () {
'use strict';
return pluginName;
});
}
seajs(CMD) support
if (typeof define === 'function') {
define([], function () {
'use strict';
return pluginName;
});
}

H. seajs和requiejs的區別,和用gulp打包方法

1、執爛返行順序不同

從demo.html 引入一個入口c.js, c.js require-b.js , b.js require - a.js

代碼如下:

c mole

[html] view plain print?
define(function(require, exports, mole) {

console.log("hello mole c");

require('b');

console.log("c finished");

});

b mole
[html] view plain print?
define(function(require, exports, mole) {
console.log("hello mole b")
var a = require('a');
console.log("b finished")
});
a mole
[html] view plain print?
define(function() {
console.log("hello mole a")
});

requriejs 的 html代碼:

[html] view plain print?
<!doctype html>
<html lang="仔晌en">
<head>
<meta charset="UTF-8">
<title>seajs和requirejs的區別</title>
<script src="require.min.js" data-main="c.js"></script>
</head>
<body>

</body>
</html>

執行結果:

ello mole aa.js:2

hello mole bb.js:2

b finishedb.js:4

hello mole cc.js:3

c finishedc.js:7

==============================================

seajs的html代碼:

[html] view plain print?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>seajs和requirejs的區別</title>
<script src="sea.2.3.js"></script>
<script>
seajs.use('./c'飢戚飢);
</script>
</head>
<body>

</body>
</html>
執行結果:
hello mole cc.js:3

hello mole bb.js:2

hello mole aa.js:2

b finishedb.js:4

c finishedc.js:7

所以總結:
seajs是從上到下執行,
requriejs是把其中require的js全部載入完了,再往下執行。·

2、依賴的載入有所不同

在define中 requriejs載入了依賴就執行;而seajs在define中只是載入不會執行(如果要執行,需要用require()方法)

案例代碼:

c.js模塊

[html] view plain print?
define(['b'],function(require,exports,mole){
console.log("hello mole c");

console.log("c finished");
});
b.js模塊
[html] view plain print?
define(['a'],function(require,exports,mole) {
console.log("hello mole b")

console.log("b finished")
});

a.js模塊

[html] view plain print?
define(['b'],function(require,exports,mole) {
console.log("hello mole a")
});

seajs和requirejs的 html代碼 和 1 中一樣
執行結果:

seajs執行結果:

hello mole cc.js:2

c finishedc.js:4

requiresj的執行結果:

ello mole aa.js:2

hello mole bb.js:2

b finishedb.js:4

hello mole cc.js:2

c finishedc.js:4

總結: 在define書寫中A:requirejs 載入了就執行,所以requirejs是預執行(在define中預先執行所有require依賴的js),RequireJS的做法是並行載入所有依賴的模塊, 並完成解析後, 再開始執行其他代碼, 因此執行結果只會"停頓"1次, 完成整個過程是會比SeaJS要快. 預執行

B:seajs只是純粹的載入依賴的文件,不執行就連console都不執行就是純粹的「載入」,SeaJS一樣是並行載入所有依賴的模塊, 但不會立即執行模塊, 等到真正需要(require)的時候才開始解析,
這里耗費了時間, 因為這個特例中的模塊巨大, 因此造成"停頓"2次的現象, 這就是我所說的SeaJS中的"懶執行".

在2的基礎上 c.js代碼為

[html] view plain print?
define(function(require,exports,mole){
require('b');
require('a');
console.log("hello mole c");

console.log("c finished");
});
執行結果都是一樣

hello mole bb.js:2

b finishedb.js:4

hello mole aa.js:2

hello mole cc.js:4

c finishedc.js:6

3、取別名時requirejs默認舍掉.js的後綴

4、 打包方法

gulp 打包seajs

requirejs 打包
http://blog.csdn.net/kongjiea/article/details/48316049

I. seajs和requiejs的區別,和用gulp打包方法

1、執行順序不同

從demo.html 引入一個入口c.js, c.js require-b.js , b.js require - a.js

代碼如下:

c mole

[html] view plain print?
define(function(require, exports, mole) {

console.log("hello mole c");

require('b');

console.log("c finished");

});

b mole
[html] view plain print?
define(function(require, exports, mole) {
console.log("hello mole b")
var a = require('a');
console.log("b finished")
});
a mole
[html] view plain print?
define(function() {
console.log("hello mole a")
});

requriejs 的 html代碼:

[html] view plain print?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>seajs和requirejs的區別</title>
<script src="require.min.js" data-main="c.js"></script>
</head>
<body>

</body>
</html>

執行結果:

ello mole aa.js:2

hello mole bb.js:2

b finishedb.js:4

hello mole cc.js:3

c finishedc.js:7

==============================================

seajs的html代碼:

[html] view plain print?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>seajs和requirejs的區別</title>
<script src="sea.2.3.js"></script>
<script>
seajs.use('./c');
</script>
</head>
<body>

</body>
</html>
執行結果:
hello mole cc.js:3

hello mole bb.js:2

hello mole aa.js:2

b finishedb.js:4

c finishedc.js:7

所以總結:
seajs是從上到下執行,
requriejs是把其中require的js全部載入完了,再往下執行。·

2、依賴的載入有所不同

在define中 requriejs載入了依賴就執行;而seajs在define中只是載入不會執行(如果要執行,需要用require()方法)

案例代碼:

c.js模塊

[html] view plain print?
define(['b'],function(require,exports,mole){
console.log("hello mole c");

console.log("c finished");
});
b.js模塊
[html] view plain print?
define(['a'],function(require,exports,mole) {
console.log("hello mole b")

console.log("b finished")
});

a.js模塊

[html] view plain print?
define(['b'],function(require,exports,mole) {
console.log("hello mole a")
});

seajs和requirejs的 html代碼 和 1 中一樣
執行結果:

seajs執行結果:

hello mole cc.js:2

c finishedc.js:4

requiresj的執行結果:

ello mole aa.js:2

hello mole bb.js:2

b finishedb.js:4

hello mole cc.js:2

c finishedc.js:4

總結: 在define書寫中A:requirejs 載入了就執行,所以requirejs是預執行(在define中預先執行所有require依賴的js),RequireJS的做法是並行載入所有依賴的模塊, 並完成解析後, 再開始執行其他代碼, 因此執行結果只會"停頓"1次, 完成整個過程是會比SeaJS要快. 預執行

B:seajs只是純粹的載入依賴的文件,不執行就連console都不執行就是純粹的「載入」,SeaJS一樣是並行載入所有依賴的模塊, 但不會立即執行模塊, 等到真正需要(require)的時候才開始解析,
這里耗費了時間, 因為這個特例中的模塊巨大, 因此造成"停頓"2次的現象, 這就是我所說的SeaJS中的"懶執行".

在2的基礎上 c.js代碼為

[html] view plain print?
define(function(require,exports,mole){
require('b');
require('a');
console.log("hello mole c");

console.log("c finished");
});
執行結果都是一樣

hello mole bb.js:2

b finishedb.js:4

hello mole aa.js:2

hello mole cc.js:4

c finishedc.js:6

3、取別名時requirejs默認舍掉.js的後綴

4、 打包方法

gulp 打包seajs

requirejs 打包
http://blog.csdn.net/kongjiea/article/details/48316049

J. seajs2.3.0和spm3怎麼配合打包

開發一個組件的流程: 初始化組件 在本地磁碟新建文件夾,文件夾名稱為組件名稱,名稱要符合 [a-z\d-.],並以英文字母開頭,首選合適的英文單詞, 禁止使用駝峰 。避免組件名稱產生沖突。 下面以epay-mole1為例,說明組件初始化過程。 $ mkdir epay-mole1 $ cd epay-mole1 $ spm init Creating a spm package: [?] Package name: epay-mole1 [?] Version: 0.0.0 [?] Description: [?] Author: Initialize a spm package Succeccfully! 初始化完成後會生成一個骨架,在這個基礎上進行開發更方便。 epay-mole1 ├── examples 組件演示 │ └── index.md ├── HISTORY.md 版本更新說明 ├── index.js 組件的主要入口文件 ├── package.json 版本等元信息 ├── README.md 組件總體說明,包括功能描述、api文檔 └── tests 單元測試 └── index-spec.js 4.首先分析組件的依賴,比如需要 jquery。 可以使用 spm install 下載依賴。 $ spm install jquery --save 這樣 spm 會自動在 package.json 中添加依賴,你也可以手動添加並 install 。 "spm": { "dependencies": { "jquery": "1.7.2" } } 並且,所有依賴的模塊都會被下載到 spm_moles 下。 修改 index.js 進行開發 var $ = require('jquery') var epayMole1 = function(){ this.info = 'hello mole1' }; mole.exports = epayMole1 啟動本地服務進行調試。 $ spm doc 通過瀏覽器訪問 http://127.0.0.1:8000/ 本地調試 examples 也使用 md 編寫,這樣寫起來非常方便。 在 examples/index.md 添加實例化代碼,可以直接 use。 seajs.use('../index', function(Mole1) { var mole1 = new Mole1() console.log(mole1.info) }); 也可以用 require 來調用模塊。 var Mole1 = require('index'); 通過四個 "````" 所包裹的代碼不僅會顯示成代碼片段,也會插入 HTML 中進行實際運行,這樣你調試好代碼後,演示頁面的文檔也同時生成好了。 spm doc 支持 livereload,只要通過 spm doc 啟動服務,修改文件後都會自動構建。 修改組件元信息 修改 package.json 配置打包方式 "spm": { "main": "index.js" } 這樣 spm build 將打包 index.js 文件,並將這個文件中的本地依賴文件也打包進來。 接下來就可以開始打包,build 後會在 dist 目錄生成打包的文件和 -debug 文件。 $ spm build 發布組件 你的組件發布後可以很方便的被其他組件調用。通過 spm publish 命令將會把你的組件發布到伺服器上。 $ spm publish 發布組件文檔 $ spm doc publish

閱讀全文

與helloseajs相關的資料

熱點內容
手機怎麼在word製作作業文件 瀏覽:489
工行銀行卡安全升級 瀏覽:807
桌面放的文件找不到 瀏覽:922
買學生票用什麼app 瀏覽:590
共建共享網路平台 瀏覽:39
js傳值到超鏈接裡面 瀏覽:608
編程中的w和h是什麼 瀏覽:313
資料庫切了什麼意思 瀏覽:213
如何登錄極路由器設置密碼 瀏覽:522
jsp用戶登陸密碼加密源代碼 瀏覽:629
everfilter使用教程 瀏覽:768
作業票文件名稱是什麼 瀏覽:463
私密文件忘記密碼 瀏覽:686
藏文軟體app怎麼可以下載 瀏覽:960
鍵盤文件名 瀏覽:538
電腦自帶驅動在那個文件夾 瀏覽:531
c窗體讀取文件夾 瀏覽:965
asp婚紗攝影網站 瀏覽:684
文件恢復的原理 瀏覽:828
移動硬碟清空怎麼恢復數據 瀏覽:433

友情鏈接