dist/main.js
function inline(content, path) {
    var result = content;
    var ast = babylon.parse(content, {
        allowImportExportEverywhere: true
    });
    var statements = ast.program.body;
    var gap = 0;
    for (var _i = 0, statements_1 = statements; _i < statements_1.length; _i++) {
        var statement = statements_1[_i];
        if (statement.type === "ImportDeclaration") {
            if (statement.specifiers.length === 0) {
                var regexpLocalFile = /^\.\//;
                var subPath = "";
                if (regexpLocalFile.test(statement.source.value)) {
                    subPath =
                        path_1.dirname(path) +
                            "/" +
                            statement.source.value +
                            (statement.source.value.endsWith(".js") ? "" : ".js");
                }
                else {
                    subPath = require.resolve(statement.source.value);
                }
                if (fs_1.existsSync(subPath) === false) {
                    throw new Error("file \"" + path_1.resolve(__dirname, subPath) + "\" does not exist");
                }
                var stat = fs_1.lstatSync(subPath);
                if (stat.isFile() === false) {
                    throw new Error("path \"" + subPath + "\" should target a file");
                }
                var subContent = fs_1.readFileSync(subPath).toString();
                var subResult = inline(subContent, subPath);
                result =
                    result.substring(0, statement.start + gap) +
                        subResult +
                        result.substring(statement.end + gap);
                gap += subResult.length - (statement.end - statement.start);
            }
        }
    }
    return result;
}
function inline(content, path) {
    var result = content;
    var ast = babylon.parse(content, {
        allowImportExportEverywhere: true
    });
    var statements = ast.program.body;
    var gap = 0;
    for (var _i = 0, statements_1 = statements; _i < statements_1.length; _i++) {
        var statement = statements_1[_i];
        if (statement.type === "ImportDeclaration") {
            if (statement.specifiers.length === 0) {
                var regexpLocalFile = /^\.\//;
                var subPath = "";
                if (regexpLocalFile.test(statement.source.value)) {
                    subPath =
                        path_1.dirname(path) +
                            "/" +
                            statement.source.value +
                            (statement.source.value.endsWith(".js") ? "" : ".js");
                }
                else {
                    subPath = require.resolve(statement.source.value);
                }
                if (fs_1.existsSync(subPath) === false) {
                    throw new Error("file \"" + path_1.resolve(__dirname, subPath) + "\" does not exist");
                }
                var stat = fs_1.lstatSync(subPath);
                if (stat.isFile() === false) {
                    throw new Error("path \"" + subPath + "\" should target a file");
                }
                var subContent = fs_1.readFileSync(subPath).toString();
                var subResult = inline(subContent, subPath);
                result =
                    result.substring(0, statement.start + gap) +
                        subResult +
                        result.substring(statement.end + gap);
                gap += subResult.length - (statement.end - statement.start);
            }
        }
    }
    return result;
}
function inline ( content , path ) { var result = content ; var ast = babylon . parse ( content , { allowImportExportEverywhere : true } ) ; var statements = ast . program . body ; var gap = 0 ; for ( var _i = 0 , statements_1 = statements ; _i < statements_1 . length ; _i ++ ) { var statement = statements_1 [ _i ] ; if ( statement . type === "ImportDeclaration" ) { if ( statement . specifiers . length === 0 ) { var regexpLocalFile = / ^\.\/ / ; var subPath = "" ; if ( regexpLocalFile . test ( statement . source . value ) ) { subPath = path_1 . dirname ( path ) + "/" + statement . source . value + ( statement . source . value . endsWith ( ".js" ) ? "" : ".js" ) ; } else { subPath = require . resolve ( statement . source . value ) ; } if ( fs_1 . existsSync ( subPath ) === false ) { throw new Error ( "file \"" + path_1 . resolve ( __dirname , subPath ) + "\" does not exist" ) ; } var stat = fs_1 . lstatSync ( subPath ) ; if ( stat . isFile ( ) === false ) { throw new Error ( "path \"" + subPath + "\" should target a file" ) ; } var subContent = fs_1 . readFileSync ( subPath ) . toString ( ) ; var subResult = inline ( subContent , subPath ) ; result = result . substring ( 0 , statement . start + gap ) + subResult + result . substring ( statement . end + gap ) ; gap += subResult . length - ( statement . end - statement . start ) ; } } } return result ; }
Traverse a content and import recursively all the import statement contents into the content.

@param {String} content The file that could contain import statement.
@param {String} path The path to the file.
@return {String} The content with potential inlined import statements.
@throws {Error} If one of the sub import files target a non existing file in their imports.
@throws {Error} If one of the sub import files does not target a file.
Traverse a content and import recursively all the import statement contents into the content .