Combining js files into one with phpStorm

Using phpStorm, I would like to merge several JavaScript files into one. I installed a closure compiler and configured a file watcher to minimize every JavaScript file.

Now I would like to merge all my JavaScript files into one.

Here is the architecture of my project (test project for combining js files):

index.php
js(folder) >
    first.js (+first.min.js),
    second.js (+second.min.js),
    third.js (+third.min.js)
cache (folder)
    main.js

I would like to combine (first.min.js, second.min.js, third.min.js) into a folder cache > main.js.

Ideally, all files will merge automatically; I do not want to specify each js file manually.

Can someone explain the arguments I should use to set up my file manager?

+4
1

npm concat, minifier walk.

script :

var walk = require('walk'),
    concat = require('concat'),
    minifier = require('minifier'),
    files = [];

var JS_SOURCES_DIR = 'app/components',
    JS_LAST_FILE = 'app/app.module.js',
    JS_DIR = 'app/',
    JS_FULL_FILE = JS_DIR + 'app.js',
    JS_MINIFIED_FILE = 'app.min.js',
    JS_MINIFIED_FILE_PATH = JS_DIR + JS_MINIFIED_FILE;

var walker = walk.walk(JS_SOURCES_DIR, {followLinks: false});

walker.on('file', (root, stat, next) => {
    var fullpath = root.replace(/\\/g, '/');
    var regex = new RegExp(/.+\.js$/);
    if (stat.name.match(regex)) {
        files.push(fullpath + '/' + stat.name);
    }
    next();
});

walker.on('end', function () {
    files.push(JS_LAST_FILE);
    files.forEach(function (item) {
        console.log(item);
    })
    concat(files, JS_FULL_FILE).then((result) => {
        minifier.minify(JS_FULL_FILE, {output: JS_MINIFIED_FILE_PATH});
        console.log('\n[OK] ' + JS_MINIFIED_FILE + ' sucessfully updated');
    }, function (error) {
        console.log('[ERROR] JS concat failure: ' + error.message);
    });
});

minifier.on('error', function (error) {
    console.log('\n[ERROR] JS minify error: ' + error);
});

walker var . JS_LAST_FILE angularjs, . JS_FULL_FILE. , JS_FULL_FILE JS_MINIFIED_FILE.

concat script . , , , head , php scandir().

0

All Articles