Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp module that can extract <script> (or <style>) tags into a new separate file

Is there a gulp module that can extract <script> (or <style>) tags 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");
};
like image 971
Jammer Avatar asked Oct 19 '25 05:10

Jammer


1 Answers

To extract inline scripts to external .js file you can use can use Cripser - https://www.npmjs.com/package/gulp-crisper

.pipe(crisper({
      scriptInHead: true,
      onlySplit: false
    }))

While I couldn't find anything that extracts inline CSS to external file, you can at least minify the inline CSS using 'gulp-minify-inline' which is alternative option - https://www.npmjs.com/package/gulp-minify-inline

like image 172
David Douglas Avatar answered Oct 21 '25 18:10

David Douglas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!