question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I only compile changed/new files?

See original GitHub issue

This script compiles all .js files from the ./src js folder to es6. These are saved individually! The path remains the same, only ./src/js becomes ./build/js. This is important! I do not want to have bundle.js.

When I call this task, every time all .js files are compiled. However, only currently changed files should be compiled. But how? How can I add this into my task?

package.json (part of it):

"paths": {
  "src": {
    "base": "./src/",
    "css": "./src/css/",
    "json": "./src/json/",
    "js": "./src/js/",
    "scss": "./src/scss/"
  },
  "dist": {
    "base": "./public/",
    "css": "./public/css/",
    "js": "./public/js/",
    "material": "./public/js/@material/"
  },
  "build": {
    "base": "./build/",
    "css": "./build/css/",
    "js": "./build/js/",
    "html": "./build/html/"
  }
},
"globs": {
  "babelJs": [
    "./src/js/**/*.js"
  ] 
}

gulpfile.js:

gulp.task('js-babel', function() {
  console.log($.chalk.yellow.bold('--> Transpiling Javascript via Browserify & Babelify...'));
  let files = $.glob.sync(''+pkg.globs.babelJs+'');
  // map them to  streams
  let tasks = files.map(function(entry) {
      return $.browserify({ entries: [entry] })
          .transform('babelify')
          .bundle()
          .pipe($.vinylSourceStream(entry))
          .pipe($.flatten()) // Important!!!!
          .pipe(gulp.dest(pkg.paths.build.js))
          .pipe($.size({gzip: true, showFiles: true}));
    });
    // merge
    return $.eventStream.merge.apply(null, tasks);
});

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
goto-bus-stopcommented, Sep 25, 2018

browserify looks like the wrong tool to use from that code snippet. You should not use browserify on every source file. You should only call it on your entry point(s) and generate a single bundle (or multiple bundles if they get too big). If you want to compile files with babel, and not create browser bundles that include all dependencies, use gulp-babel instead of browserify. Then use gulp-newer to only compile changed files.

watchify can be used during development to automatically and quickly rebuild the bundle when files change.

0reactions
ronakrathod18commented, Sep 25, 2018

@goto-bus-stop - thanks a lot! I will give this a try 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I make Makefile to recompile only changed files?
I have been struggling a bit to get make to compile only the files that have been edited. However I didn't have much...
Read more >
how to build with make so that only the changed files get build
First, you have to remove the clean dependency from your JYOTI target. Otherwise, everything is always built from scratch.
Read more >
Avoiding Compilation (GNU make)
Recompile the source files that need compilation for reasons independent of the particular header file, with ' make -o headerfile '. If several...
Read more >
How to create a Makefile that will build only the files that have ...
How can I create a Makefile to recompile only the changed .cpp files? The easiest way is to skip the header files in...
Read more >
compiling only the changed files in the project - Keil forum
Press the 'Build Target' button instead of the 'Rebuild all Target files' button. Note that using the SRC directive forces files to be ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found