cis
Version:
春雨 fis 自动化编译工具
209 lines (185 loc) • 5.23 kB
JavaScript
/**
* Created by zongkelong on 2017/3/20.
*/
//vi foo/index.js
var fis = module.exports = require('fis3');
fis.require.prefixes.unshift('cis');
fis.cli.name = 'cis';
fis.cli.info = require('./package.json');
//设置项目命名空间
fis.set('namespace', 'medweb');
//忽略python文件
fis.match('*.py', {
// 设置 release 为 FALSE,不再产出此文件
release: false
});
// 构建忽略以下文件
fis.set('project.ignore', [
'output/**',
'node_modules/**',
'.git/**',
'.svn/**'
]);
// 配置按需编译:设置编译范围为 html 文件,
// 不过 html 文件中使用到的资源也会参与编译。
fis.set('project.files','*.{html,json}');
//使用commonJS
fis.hook('commonjs');
//启用CMD 加载雪碧图片
//启用资源按需加载
fis.match('::packager', {
spriter: fis.plugin('csssprites'),
packager: fis.plugin('map', {
'/static/pkg/common/common_pkg.js': [
'/static/js/libs/mod.js',
'/static/js/libs/zepto.js'
]
}),
postpackager: fis.plugin('loader', {
resourceType: 'commonJs',
useInlineMap: true, // 资源映射表内嵌
allInOne: {
js: function (file) {
//截取掉'/page'字符串,取文件路径剩余部分
var dirname = file.subdirname.slice(5);
return "/static/pkg" + dirname + '/' + file.filename + "_aio.js";
},
css: function (file) {
var dirname = file.subdirname.slice(5);
return "/static/pkg" + dirname + '/' + file.filename + "_aio.css";
}
}
})
});
// 关闭所有文件MD5
fis.match('*', {
useHash: false
});
//每个jango App里面的templates要有一个子目录
fis.match('/page/(**)', {
release: '/v2/$1'
});
//设置 widget 的输入目录
fis.match('/widget/**', {
isMod:true,
release: '/static/v2/$0'
});
// 每个jango App里面的static要有一个子目录
fis.match('/static/(**)', {
release: '/static/v2/$1'
});
//js 调用 jswrapper 进行自动化封装
fis.match('/static/js/**.js', {
postprocessor: fis.plugin('jswrapper',{
wrapAll:true
})
});
//不封装 libs 下面的 js 文件
fis.match('/static/js/libs/**.js', {
postprocessor: fis.plugin('jswrapper',{
wrapAll:false
})
});
//将 html 放入资源映射表
fis.match('*.html', {
useMap: true
});
//所有的 js css 加 hash
// 这里不添加 scss 的话会导致 css 文件没有 hash 值, fis 执行原理导致
fis.match('*.{js,css,scss}',{
useHash:true
});
//编译所有scss文件
fis.match('*.scss', {
rExt: '.css', // from .scss to .css
optimizer: fis.plugin('clean-css'),
parser: fis.plugin('node-sass')
});
//启用css雪碧图片和css压缩优化
fis.match('*.{css,scss}', {
useSprite: true
});
//自动补充css前缀
fis.match('*.{css,scss}', {
preprocessor: fis.plugin('autoprefixer', {
"browsers": ["Android >= 2.1", "iOS >= 4", "ie >= 8", "firefox >= 15"],
"cascade": true
})
});
//启用图片优化
fis.match('*.png', {
optimizer: fis.plugin('png-compressor')
});
//设置以下文件md5时间戳
fis.match('image', {
useHash: true
});
//开启组件同名依赖
fis.match('*.{html,css,js}', {
useSameNameRequire: true
});
//支持 js 中直接 require 文件.
// es6 的 import 也支持,但是先通过 es6 => es5 的转换
fis.match('*.{js,es,es6,jsx,ts,tsx}', {
preprocessor: [
fis.plugin('js-require-file',{
//默认 20K。即:当目标文件的体积小于 20k 时,自动用 base64 引入
// 大于 20K 时,用目标文件的 url
// 如果不想启用此功能,请设置为 0 或者 null, false 都可以
'useEmbedWhenSizeLessThan':0
}),
fis.plugin('js-require-css')]
});
//本地部署
fis.media('local')
.match('/page/**', {
deploy: fis.plugin('local-deliver', {
to: '../medweb/templates/'
})
})
.match('{/static/**,/widget/**}', {
deploy: fis.plugin('local-deliver', {
to: '../medweb/'
})
});
//部署测试
fis.media('test_server')
.match('/page/**', {
deploy: fis.plugin('local-deliver', {
to: './test_output/templates/'
})
})
.match('{/static/**,/widget/**}', {
deploy: fis.plugin('local-deliver', {
to: './test_output/'
})
});
// optimize
fis.media('server')
.match('/widget/**', {
domain:"http://media2.chunyuyisheng.com/@"
})
.match('/static/**', {
domain:"http://media2.chunyuyisheng.com/@"
})
.match('/static/pkg/**', {
domain:"http://media2.chunyuyisheng.com/@"
})
.match('*.js', {
parser: fis.plugin('jdists', {
remove: "debug,test"
}),
optimizer: fis.plugin('uglify-js', {
mangle: {
expect: ['require', 'define'] //不想被压的
}
})
})
.match('*.css', {
optimizer: fis.plugin('clean-css')
})
.match('*', {
deploy: fis.plugin('local-deliver', {
to: './output'
})
});