有没有可以提取<script>
的gulp模块(或 <style>
)标记到单独的文件中?
例如:
原始 HTML 文件
<html>
<body>
<style>
.my-style{
background:red;
}
</style>
<div class="my-style">
hello
</div>
<script>
var MyScript = function(){
console.log("hello");
}
</script>
</body>
</html>
新建 HTML 文件
<html>
<body>
<div class="my-style">
hello
</div>
</body>
</html>
新建CSS文件
.my-style{
background:red;
}
新建JS文件
var MyScript = function(){
console.log("hello");
};
最佳答案
要将内联脚本提取到外部 .js 文件,您可以使用 Cripser - https://www.npmjs.com/package/gulp-crisper
.pipe(crisper({
scriptInHead: true,
onlySplit: false
}))
虽然我找不到任何可以将内联 CSS 提取到外部文件的东西,但您至少可以使用“gulp-minify-inline”来缩小内联 CSS,这是替代选项 - https://www.npmjs.com/package/gulp-minify-inline
关于javascript - 可以将 <script>(或 <style>)标签提取到新的单独文件中的 Gulp 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31501877/