Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does gulp have code splitting for javascript files?

I'm using gulp and I want to know if it has capabilities for code splitting. Something similar to what is mentioned here in the webpack site . Ive looked online but not seen anything dedicated to that.

like image 676
Suemayah Eldursi Avatar asked Sep 23 '16 16:09

Suemayah Eldursi


People also ask

How do I use gulp to compile a JS file?

Create a gulpfile.js file in your project root. Import your npm packages as modules in your gulpfile. Add your tasks to the gulpfile to compile your SCSS/JS files and run a watch task. Run the gulp command to run all your tasks. What is Gulp and what does it do? Gulp is a tool that will run various tasks for you in your web development workflow.

How to use gulp functions without gulp?

We’re exporting just the specific gulp functions that we will be using, like src, dest, watch, and others. This allows us to call those functions directly without the gulp, for example we can just type in src () instead of gulp.src (). gulp-sourcemaps — maps the CSS styles back to the original SCSS file in your browser dev tools

What is a gulpfile in JavaScript?

Although a few utilities are provided to simplify working with the filesystem and command line, everything else you write is pure JavaScript. A gulpfile is a file in your project directory titled gulpfile.js (or capitalized as Gulpfile.js, like Makefile), that automatically loads when you run the gulp command.

How to use gulp to concatenate JavaScript files?

Create a Gulp Task to Concatenate JavaScript Files Select the Source JavaScript Files Concatenate the Selected Files Write the Concatenated JavaScript File into Disk Run the Concatenation Task GitHub Repo Install Gulp Concat Plugin First, we will need to install gulp-concat, which we have installed in the previous article.


1 Answers

I found this on the internet gulp-split-files, I hope this answers your issue.

As you the author has said in the documentation.

In your gulpfile:

const gulp = require("gulp");
const splitFiles = require("gulp-split-files");

gulp.task("split", function () {
    return gulp.src("superMegaBigCss.css")
    .pipe(splitFiles())
    .pipe(gulp.dest("path/to/dest"));
});

This will produce three files:

superMegaBigCss-0.css
superMegaBigCss-1.css
superMegaBigCss-2.css

I don't think this package is very useful, as it split the code where we place the comment /*split*/.


Personally, I love using webpack so much, now I use it in most of my projects, I think it is like a butcher where it chops down the files and bundles it up in different ways.

like image 103
Yashu Mittal Avatar answered Oct 17 '22 14:10

Yashu Mittal