Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Gulp.js Tutorial to Bundle All CSS,JS Files inside React App into a Single HTML File For Production

Posted on January 23, 2023

 

 

Welcome folks today in this blog post we will be using the gulp.js library to bundle all css and js files inside react.js app into a single html file. All the full steps are given below.

 

 

Get Started

 

 

In order to get started you need to create the new react.js app as shown below

 

 

npx create-react-app sampleapp

 

 

cd sampleapp

 

 

Now we need to install the below libraries using the npm command as shown below

 

 

npm i --save-dev gulp gulp-inline-source gulp-replace

 

 

Now you will see the below directory structure of the react.js app as shown below

 

 

 

 

Now we need to create the .env file and .gulpfile.js file as you can see in the above figure.

 

 

.env

 

 

1
2
3
INLINE_RUNTIME_CHUNK=false
GENERATE_SOURCEMAP=false
SKIP_PREFLIGHT_CHECK=true

 

 

.gulpfile.js

 

 

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const gulp = require('gulp');
const inlinesource = require('gulp-inline-source');
const replace = require('gulp-replace');
 
gulp.task('default', () => {
  return gulp
    .src('./build/*.html')
    .pipe(replace('.js"></script>', '.js" inline></script>'))
    .pipe(replace('rel="stylesheet">', 'rel="stylesheet" inline>'))
    .pipe(
      inlinesource({
        compress: false,
        ignore: ['png'],
      })
    )
    .pipe(gulp.dest('./build'));
});

 

 

Now we need to build the react.js app by executing the below command as shown below

 

 

npm run build

 

 

 

Recent Posts

  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Android Java Project to Download Youtube Video Thumbnail From URL & Save it inside SD Card
  • Android Java Project to Embed Google Maps & Add Markers Using Maps SDK
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme