I've just started using Grunt, and I'm trying to get the concat task to concat my files in a specific order. Here's what I've got:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: ';'
},
dist: {
src: ['www/js/*.js','www/js/main.js','!**/*.{min,pack}.js','!<%= concat.dist.dest %>','!<%= uglify.dist %>'],
dest: 'www/js/<%= pkg.name %>.js'
}
},
I was hoping that by putting www/js/main.js
second, it would move the file down to the bottom of the list, but that doesn't appear to be the case.
How can I impose some order on the list of files it matches?
grunt. util. _ is deprecated and we highly encourage you to npm install lodash and var _ = require('lodash') to use lodash .
Grunt Configuration Task configuration is specified in your Gruntfile via the grunt. initConfig method. This configuration will mostly be under task-named properties, but may contain any arbitrary data.
The Grunt community is still going strong and both tools look like they're going to be around for a while yet. I should mention that another up and coming alternative to task runners like Grunt and Gulp is simply using npm scripts with command-line tools.
gulp, Webpack, npm, Yarn, and Gradle are the most popular alternatives and competitors to Grunt.
Your problem is that main.js
is matched by the first pattern so the second pattern is made redundant. This might seem like a hacky way of doing it but basically you have to exclude it from the first pattern before you include it in the second; like so:
concat: {
options: {
separator: ';'
},
dist: {
src: ['www/js/*.js', '!www/js/main.js', 'www/js/main.js','!**/*.{min,pack}.js','!<%= concat.dist.dest %>','!<%= uglify.dist %>'],
dest: 'www/js/<%= pkg.name %>.js'
}
}
Note that when using minimatch pattern order is important.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With