AntoineMary / grunt-angular-file-loader

Automatically sort and inject AngularJS app files depending on module definitions and usage
MIT License
5 stars 8 forks source link

Txt feature #17

Closed DougReynolds closed 6 years ago

DougReynolds commented 6 years ago

Adds plain txt file output. This was added due to need for sorted globbing prior to minification. A raw glob is split into an array of path strings and is passed to the scripts of angularFileLoader task:

var myApp_pattern = "src/main/webapp/myApp/components/**/*.js";
var myApp_files = glob.sync(myApp_pattern);

...

angularFileLoader: {
                options: {
                    scripts: myApp_files,
                    relative: false
                },
                your_target: {
                    src: ['src/main/webapp/myApp/components/myApp_imports.txt']
                }
            },

The txt file is used as a minification src, e.g:

function sortPathsToArray() {
            var buffer = grunt.file.read('src/main/webapp/myApp/components/myApp_imports.txt');
            var pathString = buffer.toString();
            var myApp_files_sorted = pathString.split('\n');
            // remove the start/end tags
            myApp_files_sorted.pop();
            myApp_files_sorted.shift();

            return myApp_files_sorted;
        }

Then, in uglify:

uglify: {
                options: {
                    banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
                    mangle: false,
                    compress: false,
                    verbose: true
                },
                dist: {
                    files: {
                       'src/main/webapp/myApp/components/myApp.min.js': sortPathsToArray()
                    }
                }
            },
DougReynolds commented 6 years ago

Hello, will you accept? Best regards