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

css2js 编译再讨论 #793

@popomore

Description

@popomore

Action

  • spm-build 增加 install 步骤
  • 如果 package.json 不存在 handlebar 则添加默认版本,并 install

源文件

// 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;}');
});

优点

  1. importStyle 方法可单独维护,所有模块可用一套
  2. 构建工具的约定只是 seajs.importStyle

缺点

  1. 使用该模块的时候需要引入 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 一样

优点

  1. import-style 单独维护
  2. 构建工具的约定为“当有 css2js 编译时,添加一个 import-style 的模块”
  3. 每个模块可依赖不同的 import-style 版本
  4. 开发者不需要单独引入插件

缺点

  1. 构建工具需要添加一个新的规则

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions