script-extractor

Extract script sources from a html file to use in uglify task

Usage no npm install needed!

<script type="module">
  import scriptExtractor from 'https://cdn.skypack.dev/script-extractor';
</script>

README

grunt-script-extractor

Extract the script sources from a html file and pass them to uglify task.

example Gruntfile.js:

module.exports = function (grunt) {
    'use strict';

    var scriptExtractor = require('grunt-script-extractor')(grunt);

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        uglify: {
            options: {
                banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
                report: 'min'
            },
            build: {
                files: {
                    'dist/app.min.js': scriptExtractor('index.html')
                }
            }
        }
    });
    grunt.loadNpmTask('grunt-contrib-uglify');
    grunt.loadNpmTask('grunt-script-extractor');

    grunt.registertask('default', ['uglify']);
};

scriptExtractor(htmlFile, [prefix])

Search through htmlFile for script tags and return an array of each script tags src value, prefixed by optional prefix.