gulp js import other files in one file

I have this files and I want to compile with gulp

./src/app.js

console.log("app root functions");

./src/add.js

console.log("add functions");

./src/main.js

var path = location.pathname;

if (path == "/app") {
    import './app.js';
} else if(path == "add") {
    import './add.js';
}

Expected Output:

./dist/main.js

var path = location.pathname;

if (path == "/app") {
    console.log("app root functions");
} else if(path == "add") {
    console.log("add functions");
}

But it not output like this.

gulpfile.js

const gulp = require("gulp");

gulp.task("js", () => {
    return gulp.src("./src/main.js")
    .pipe(gulp.dest('./dist/'));
});

4 thoughts on “gulp js import other files in one file”

Leave a Comment