什么是构建工具?前端最常用的构建工具是啥?
前端构建,这里要推荐下 coolie 了,示意如下:
<!doctype html>
<link rel="stylesheet" href="path/to/style.css">
<style>
body {
background: url('path/to/abc.png');
}
</style>
<img src="path/to/abc.png">
<div style="backrgound: url('path/to/abc.png')"></div>
<!--coolie-->
<script src="path/to/a.js"></script>
<script src="path/to/b.js"></script>
<!--/coolie-->
<script coolie src="path/to/coolie.js"
data-config="coolie-config.js"
data-main="main.js"></script>
+
// main.js
alert('Hello' + require('world'));
coolie 构建之后:
<!doctype html>
<link rel="stylesheet" href="/static/css/xxxxxxx.css">
<style>
body {
background: url('/static/res/xxxxxxxx.png');
}
</style>
<img src="/static/res/xxxxxxxx.png">
<div style="backrgound: url('/static/res/xxxxxxxx.png')"></div>
<script src="/static/js/xxxxxxxx.js"></script>
<script coolie src="/static/js/yyyyyyyyy.js"
data-config="/static/js/zzzzzzzzz.js"
data-main="aaaaaaaaa.js"></script>
// aaaaaaaaa.js
define("0",["1"],function(r,e,m){alert("Hello"+r("1"));});
define("1",[],function(r,e,m){m.exports="world"});
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
就是把你写的前端代码,做一定的自动化处理变成易于发布的代码。
早期grunt比较流行,之后流行gulp,再到后来的webpack。这些工具都可以自定义构建流程。