module.exports = function(grunt){
grunt.initConfig({
uglify: {
'minify-each':{
options : {
beautify: false,
mangle: false,
sourceMap: true,
compress: {
drop_console: true
}
},
files: [{
cwd: 'src/private/assets/js/',
src: '**/*.js',
dest: 'src/public/assets/js/',
expand: true,
flatten: false,
ext: '.min.js' //Extension not used in ES6 import statements
}]
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('run', ['uglify']);
};
In each *.js file, there are ES6 import statements, for example:
in file1.js, I have…
import { getConstants, getUtils } from ‘../assets/js/utils.js’;
import { WidgetClass } from ‘../assets/js/classes.js’;
class ProcessMain {}
The issue is when performing minification on file1.js in Gruntfile.js, those import statements are maintained, but do want to be able to replace each import statement as follows:
import { getConstants, getUtils } from ‘../assets/js/utils.min.js’;
import { WidgetClass } from ‘../assets/js/classes.min.js’;
Are there ways to capture each line in file1.js to update the import statements?
Within uglify object in Gruntfile.js, I have replaced:
ext: ‘.min.js’ //Extension not used in ES6 import statements
–with–
ext: ‘.js’ //Extension used in ES6 import statements
and that seems to do the trick, perhaps, resolves the issue. However, it is not standard since the minified file1.js does not have a *.min.js extension.