This repository was archived by the owner on Aug 15, 2018. It is now read-only.

Description
Action
源文件
// a.css
body {background: none;}
// a.js
require('./a.css');
现在的方案
编译后
define('a.js', ['./a.css'], function(require) {
require('./a.css');
});
define('a.css', [], function() {
seajs.importStyle('body {background: none;}');
});
优点
- importStyle 方法可单独维护,所有模块可用一套
- 构建工具的约定只是 seajs.importStyle
缺点
- 使用该模块的时候需要引入 seajs-style 插件,对开发者不透明
最早的方案
编译后
define('a.js', ['./a.css'], function(require) {
require('./a.css');
});
define('a.css', [], function() {
function importStyle() {
return ...
}
importStyle('body {background: none;}');
});
优缺点与上面相反,但这种做法对 importStyle 的维护成本更高,代码维护在构建工具中,需要升级构建工具重新编译。
待讨论的方案
importStyle 为单独模块,编译后
define('a.js', ['./a.css'], function(require) {
require('./a.css');
});
define('a.css', ['import-style'], function() {
require('import-style')('body {background: none;}');
});
这种方式和 handlebars 一样
优点
- import-style 单独维护
- 构建工具的约定为“当有 css2js 编译时,添加一个 import-style 的模块”
- 每个模块可依赖不同的 import-style 版本
- 开发者不需要单独引入插件
缺点
- 构建工具需要添加一个新的规则