Gulp, which can extract <script> (or <style>) tags into a new separate file
Is there a gulp module that can extract tags <script>
(or <style>
) into a separate file?
For example:
Original HTML file
<html>
<body>
<style>
.my-style{
background:red;
}
</style>
<div class="my-style">
hello
</div>
<script>
var MyScript = function(){
console.log("hello");
}
</script>
</body>
</html>
new HTML file
<html>
<body>
<div class="my-style">
hello
</div>
</body>
</html>
new CSS file
.my-style{
background:red;
}
new JS file
var MyScript = function(){
console.log("hello");
};
+3
source to share
2 answers
To extract inline scripts to an external .js file, you can use Cripser - https://www.npmjs.com/package/gulp-crisper
.pipe(crisper({
scriptInHead: true,
onlySplit: false
}))
So far I couldn't find anything that extracts the inline CSS for the external file, you can at least minify the inline CSS using 'gulp -minify-inline' which is an alternative option - https://www.npmjs.com/package/gulp -minify-inline
+1
source to share
Try gulp-html-extract https://www.npmjs.com/package/gulp-html-extract although it looks unflappable and maybe you can use concat or rename to generate the final file.
0
source to share