Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Aug 17, 2015
1 parent acabd3e commit e7fded1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function autowrap(info, conf) {
var content = info.content;
var shim = shims[file.subpath];

if (!file.isMod || amd.hasDefine(content)) {
if (!file.isMod || file.isPartial || amd.hasDefine(content)) {
return;
}

Expand Down
23 changes: 22 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ var entry = module.exports = function(fis, opts) {
fis.on('lookup:file', lookup);
fis.on('standard:js', function(info) {
var file = info.file;
var shimed = opts.shim && opts.shim[file.subpath];

if (file.isMod) {
if (file.isMod || shimed) {
// 用户主动配置了 shim 那么说明目标文件一定是模块化 js
shimed && (file.isMod = true);
amd(info, opts);
} else {

Expand All @@ -49,6 +52,24 @@ var entry = module.exports = function(fis, opts) {
}
}
});

// 支持 data-main 的用法。
var rScript = /<!--([\s\S]*?)(?:-->|$)|(<script[^>]*>[\s\S]*?<\/script>)/ig;
var rDataMain = /\bdata-main=('|")(.*?)\1/;
var lang = fis.compile.lang;

// 解析 data-main
fis.on('standard:html', function(info) {
info.content = info.content.replace(rScript, function(all, comment, script) {
if (!comment && script) {
all = all.replace(rDataMain, function(_, quote, value) {
return lang.info.wrap(lang.jsRequire.wrap(quote + value + quote));
});
}

return all;
});
});
};

entry.defaultOptions = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fis3-hook-amd",
"version": "0.0.1",
"version": "0.0.2",
"description": "fis3 amd",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit e7fded1

Please sign in to comment.