ecomfe / edp-build

Package for edp build.
Other
10 stars 32 forks source link

inline processor 需求 #70

Open junmer opened 9 years ago

junmer commented 9 years ago

在某些场景下(如移动端),需要 把一些 js or css 放到 <head>

所以期望有个 processor 可以做以下 工作

edp-build-config.js

var inlinePorcessor = new InlinePorcessor({
    extnames: 'html,tpl'
});

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script>
        {edp-inline:'src/common/meta.js'}
    </script>
    <style>
        {edp-inline:'src/common/head.css'}
    </style>
</head>
<body>
    hello
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script>
        /* meta.js content */
    </script>
    <style>
        /* head.css content */
    </style>
</head>
<body>
    hello
</body>
</html>
leeight commented 9 years ago

使用 StringReplace 这个大杀器?

junmer commented 9 years ago

StringReplace 实现build当然没啥问题, 开发阶段ws还需要 一个 inline-handler,来干这个事 所以希望这个 配置写在html里,这样handler也从这里读文件

junmer commented 9 years ago

@leeight @firede @treelite 请看下,这个接口设计是否合理,合理的话,我就开撸啦?

treelite commented 9 years ago

:ok_hand: 倾向使用注释的方式,另外可以考虑提供配置支持嵌入代码的压缩与否,方便调试

junmer commented 9 years ago

etpl 节奏么

<!-- include: xxx.xxx -->
firede commented 9 years ago

https://github.com/ecomfe/edp/wiki/Package-Management#%E5%AF%BC%E5%85%A5%E5%B9%B6%E4%BD%BF%E7%94%A8%E5%8C%85

这个链接再往下翻一点,记得有使用注释风格的先例。

zengjialuo commented 9 years ago

是不是可以借鉴 fis 的做法,在 html 里加 __inline 标志,这样就不用在 webServer 里再处理了 (逃

junmer commented 9 years ago

今天 实现了一个

<!-- edp-inline: xxx.xxx -->

build 没问题,但是 实现 webserver 发现个坑,因为 搞不定.less这类预编译的文件

删掉 重来 ( ╯-_-)╯┴—┴

这次,参考 @zengjialuo 的建议,这样搞的

<link data-inline rel="stylesheet" href="./src/css/path-mapper.css">
<script data-inline src="./src/foo.js"></script>

并且提供 自定义配置 data-inline 属性