mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-14 13:34:10 +02:00
infra for admin js
This commit is contained in:
parent
7d92949e46
commit
5cddb60f33
2 changed files with 38 additions and 30 deletions
|
@ -5,8 +5,11 @@ const webpack = require('webpack-stream');
|
||||||
const uswds = require('@uswds/compile');
|
const uswds = require('@uswds/compile');
|
||||||
|
|
||||||
const ASSETS_DIR = './registrar/assets/';
|
const ASSETS_DIR = './registrar/assets/';
|
||||||
const JS_MODULES_SRC = ASSETS_DIR + 'modules/*.js';
|
|
||||||
const JS_BUNDLE_DEST = ASSETS_DIR + 'js';
|
const JS_BUNDLE_DEST = ASSETS_DIR + 'js';
|
||||||
|
const JS_SOURCES = [
|
||||||
|
{ src: ASSETS_DIR + 'modules/*.js', output: 'get-gov.js' },
|
||||||
|
{ src: ASSETS_DIR + 'modules-admin/*.js', output: 'get-gov-admin.js' },
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* USWDS version
|
* USWDS version
|
||||||
|
@ -26,17 +29,16 @@ uswds.paths.dist.js = ASSETS_DIR + 'js';
|
||||||
uswds.paths.dist.img = ASSETS_DIR + 'img';
|
uswds.paths.dist.img = ASSETS_DIR + 'img';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task: Bundle JavaScript modules using Webpack
|
* Function: Create Bundling Task
|
||||||
*/
|
*/
|
||||||
gulp.task('bundle-js', () => {
|
function createBundleTask(source, output) {
|
||||||
return gulp
|
return () =>
|
||||||
.src(JS_MODULES_SRC)
|
gulp
|
||||||
|
.src(source)
|
||||||
.pipe(
|
.pipe(
|
||||||
webpack({
|
webpack({
|
||||||
mode: 'production', // Use 'development' for debugging
|
mode: 'production',
|
||||||
output: {
|
output: { filename: output },
|
||||||
filename: 'get-gov.js',
|
|
||||||
},
|
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
|
@ -44,9 +46,7 @@ gulp.task('bundle-js', () => {
|
||||||
exclude: /node_modules/,
|
exclude: /node_modules/,
|
||||||
use: {
|
use: {
|
||||||
loader: 'babel-loader',
|
loader: 'babel-loader',
|
||||||
options: {
|
options: { presets: ['@babel/preset-env'] },
|
||||||
presets: ['@babel/preset-env'],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -54,13 +54,21 @@ gulp.task('bundle-js', () => {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.pipe(gulp.dest(JS_BUNDLE_DEST));
|
.pipe(gulp.dest(JS_BUNDLE_DEST));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create tasks for JavaScript sources
|
||||||
|
JS_SOURCES.forEach(({ src, output }, index) => {
|
||||||
|
const taskName = `bundle-js-${index}`;
|
||||||
|
gulp.task(taskName, createBundleTask(src, output));
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task: Watch for changes in JavaScript modules
|
* Watch for changes in JavaScript modules
|
||||||
*/
|
*/
|
||||||
gulp.task('watch-js', () => {
|
gulp.task('watch-js', () => {
|
||||||
gulp.watch(JS_MODULES_SRC, gulp.series('bundle-js'));
|
JS_SOURCES.forEach(({ src }, index) => {
|
||||||
|
gulp.watch(src, gulp.series(`bundle-js-${index}`));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,9 +81,9 @@ gulp.task('watch', gulp.parallel('watch-js', uswds.watch));
|
||||||
* Add as many as you need
|
* Add as many as you need
|
||||||
* Some tasks combine USWDS compilation and JavaScript precompilation.
|
* Some tasks combine USWDS compilation and JavaScript precompilation.
|
||||||
*/
|
*/
|
||||||
exports.default = gulp.series(uswds.compile, 'bundle-js');
|
exports.default = gulp.series(uswds.compile, ...JS_SOURCES.map((_, i) => `bundle-js-${i}`));
|
||||||
exports.init = uswds.init;
|
exports.init = uswds.init;
|
||||||
exports.compile = gulp.series(uswds.compile, 'bundle-js');
|
exports.compile = gulp.series(uswds.compile, ...JS_SOURCES.map((_, i) => `bundle-js-${i}`));
|
||||||
exports.watch = uswds.watch;
|
exports.watch = uswds.watch;
|
||||||
exports.watchAll = gulp.parallel('watch');
|
exports.watchAll = gulp.parallel('watch');
|
||||||
exports.copyAssets = uswds.copyAssets
|
exports.copyAssets = uswds.copyAssets
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue