* move to esbuild & yarn * remove gulpfile * cleanup unused ref * updated gitignore
87 lines
2.2 KiB
JavaScript
87 lines
2.2 KiB
JavaScript
const esbuild = require('esbuild');
|
|
const { sassPlugin } = require('esbuild-sass-plugin');
|
|
|
|
const options = {
|
|
bundle: true,
|
|
minify: true,
|
|
sourcemap: 'external',
|
|
sourcesContent: false,
|
|
logLevel: 'error',
|
|
};
|
|
|
|
const ARGS = process.argv.slice(2);
|
|
|
|
|
|
async function bundleScripts() {
|
|
const entryPoints = {
|
|
'app': 'js/home.js'
|
|
};
|
|
try {
|
|
const result = await esbuild.build({
|
|
...options,
|
|
outdir: '../static/netbox_topology_views/js/',
|
|
entryPoints,
|
|
target: 'es2016',
|
|
});
|
|
if (result.errors.length === 0) {
|
|
for (const [targetName, sourceName] of Object.entries(entryPoints)) {
|
|
const source = sourceName.split('/')[1];
|
|
console.log(`✅ Bundled source file '${source}' to '${targetName}.js'`);
|
|
}
|
|
}
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
}
|
|
|
|
async function bundleStyles() {
|
|
try {
|
|
const entryPoints = {
|
|
'vendor': 'css/_external.scss',
|
|
'app': 'css/app.scss',
|
|
};
|
|
const pluginOptions = { outputStyle: 'compressed' };
|
|
// Allow cache disabling.
|
|
if (ARGS.includes('--no-cache')) {
|
|
pluginOptions.cache = false;
|
|
}
|
|
let result = await esbuild.build({
|
|
...options,
|
|
outdir: '../static/netbox_topology_views/css/',
|
|
// Disable sourcemaps for CSS/SCSS files, see #7068
|
|
sourcemap: false,
|
|
entryPoints,
|
|
plugins: [sassPlugin(pluginOptions)],
|
|
loader: {
|
|
'.eot': 'file',
|
|
'.woff': 'file',
|
|
'.woff2': 'file',
|
|
'.svg': 'file',
|
|
'.ttf': 'file',
|
|
},
|
|
});
|
|
if (result.errors.length === 0) {
|
|
for (const [targetName, sourceName] of Object.entries(entryPoints)) {
|
|
const source = sourceName.split('/')[1];
|
|
console.log(`✅ Bundled source file '${source}' to '${targetName}.css'`);
|
|
}
|
|
}
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
}
|
|
|
|
|
|
async function bundleAll() {
|
|
if (ARGS.includes('--styles')) {
|
|
// Only run style jobs.
|
|
return await bundleStyles();
|
|
} else if (ARGS.includes('--scripts')) {
|
|
// Only run script jobs.
|
|
return await bundleScripts();
|
|
}
|
|
await bundleStyles();
|
|
await bundleScripts();
|
|
}
|
|
|
|
bundleAll(); |