Does not work with multiple outputs or standard output format
Closed this issue · 5 comments
I've been using grunt-rollup happily with a single output file, like so:
rollup : {
options : {
format : 'iife',
sourceMap : true,
// external : function() { return false; },
plugins : function() {
return [
replace({
'process.env.NODE_ENV': JSON.stringify( 'development' )
}),
babel({
presets : [ 'es2015-rollup', 'react', ],
exclude : './node_modules/**',
}),
nodeResolve({
module: true,
jsnext : true,
main : true,
browser: true,
}),
commonjs({
include : 'node_modules/**',
exclude : [ './node_modules/lodash-es/**' ],
}),
];
},
},
files : {
dest : 'built/dist.js',
src : 'js/init.js',
},
},
However, I now need to output two files, and grunt-rollup can't handle this. When I switch files to this format:
files : {
'built/dist.js' : 'js/init.js',
},
as the docs suggest, rollup simply builds nothing. (Putting the source in an array doesn't help.) Adding in my second build command
files : {
'built/dist.js' : 'js/init.js',
'built/social.js' : 'js/social.js',
},
similarly builds nothing. Any other syntax, like:
files : [{
dest: 'built/dist.js',
src: 'js/init.js',
}],
causes Grunt to error out completely.
Any solution? Is this a dead project?
It's not a dead project per se, I'm happy to support it if it breaks for my projects or to merge in PRs when I get a chance. However, I've not experienced the problem you're describing with my build's configuration so I'm unable to offer you any suggestions.
@futuraprime I just stumbled with this problem. Here's how I solved it:
rollup: {
options: {
format: 'iife'
},
'dist/preload.js': 'src/preload.js',
'dist/config/config.js': 'src/config/*'
},
I am able to use the files directive after placing it in a subcommand.
For example:
rollup: {
options: {
format: 'iife',
plugins: () => {
return [
babel({
exclude: './node_modules/**'
})
];
}
},
main: {
files: {
'dest1.js': 'src1.js',
'dest2.js': 'src2.js'
}
}
}
And since I'm not a huge fan of the 'dest': 'src' syntax, I'm returning an object dynamically:
let outputDir = 'public/assets/admin/pages/scripts/',
srcDir = 'public/assets/admin/pages/src/',
srcFiles = [
'main.js',
'client_registration.js',
'another_file_etc.js'
];
// ...
rollup: {
options: {
format: 'iife',
plugins: () => {
return [
babel({
exclude: './node_modules/**'
})
];
}
},
main: {
files: (() => {
let fileMap = {};
for (var srcFile of srcFiles) {
fileMap[outputDir + srcFile] = srcDir + srcFile;
}
return fileMap;
})()
}
}
So now I can just edit the srcFiles array whenever I want to add a file to rollup.