Skip to content

Commit

Permalink
limits sourcemaps to dev; also uglifies the js for prod
Browse files Browse the repository at this point in the history
  • Loading branch information
btylerburton committed Oct 16, 2024
1 parent cdbd235 commit 9775b36
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 3 deletions.
12 changes: 9 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ const uswds = require("@uswds/compile");

var browserify = require('browserify');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify')
var gulpif = require('gulp-if');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');

const isProd = process.env.NODE_ENV == 'production';

console.log(process.env.NODE_ENV)
// file path vars
const paths = {
js: {
Expand All @@ -15,16 +20,17 @@ const paths = {
}

function jsTask() {
return browserify(`${paths.js.src}`, { debug: true })
return browserify(`${paths.js.src}`)
.transform('babelify', {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-runtime']
})
.bundle()
.pipe(source(paths.js.dest))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('.'))
.pipe(gulpif(isProd, uglify()))
.pipe(gulpif(!isProd, sourcemaps.init({ loadMaps: true })))
.pipe(gulpif(!isProd, sourcemaps.write('.')))
.pipe(dest("_site"));
};

Expand Down
197 changes: 197 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
"babelify": "^10.0.0",
"browserify": "^17.0.1",
"gulp": "^5.0.0",
"gulp-if": "^3.0.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-terser-js": "^5.2.2",
"gulp-uglify": "^3.0.2",
"vinyl-buffer": "^1.0.1",
"vinyl-source-stream": "^2.0.0"
}
Expand Down

0 comments on commit 9775b36

Please sign in to comment.