Skip to content

Commit

Permalink
Automatic handling of Bootstrap's internal imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrammatiko committed Dec 1, 2021
1 parent 2d8cef3 commit c524cfd
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions build/build-modules-js/javascript/build-bootstrap-js.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ const { nodeResolve } = require('@rollup/plugin-node-resolve');
const replace = require('@rollup/plugin-replace');
const { babel } = require('@rollup/plugin-babel');
const commonjs = require('@rollup/plugin-commonjs');

const bsVersion = require('../../../package.json').dependencies.bootstrap.replace(/^\^|~/, '');
const tasks = [];
const inputFolder = 'build/media_source/vendor/bootstrap/js';
const outputFolder = 'media/vendor/bootstrap/js';

// eslint-disable-next-line import/no-dynamic-require
const bsVersion = require(`${process.cwd()}/package.json`).dependencies.bootstrap.replace(/^\^|~/, '');

const createMinified = async (file) => {
const initial = await readFile(resolve(outputFolder, file), { encoding: 'utf8' });
const mini = await minify(initial.replace('./popper.js', `./popper.min.js?${bsVersion}`).replace('./dom.js', `./dom.min.js?${bsVersion}`).replace('./alert.js', `./alert.min.js?${bsVersion}`).replace('./modal.js', `./modal.min.js?${bsVersion}`), { sourceMap: false, format: { comments: false } });
const mini = await minify(initial.replace('./popper.js', `./popper.min.js?${bsVersion}`).replace('./dom.js', `./dom.min.js?${bsVersion}`), { sourceMap: false, format: { comments: false } });
await writeFile(resolve(outputFolder, file), initial.replace('./popper.js', `./popper.js?${bsVersion}`).replace('./dom.js', `./dom.js?${bsVersion}`), { encoding: 'utf8', mode: 0o644 });
await writeFile(resolve(outputFolder, file.replace('.js', '.min.js')), mini.code, { encoding: 'utf8', mode: 0o644 });
};
Expand All @@ -28,6 +25,9 @@ const build = async () => {
// eslint-disable-next-line no-console
console.log('Building ES6 Components...');

const domImports = await readdir(resolve('node_modules/bootstrap', 'js/src/dom'));
const utilImports = await readdir(resolve('node_modules/bootstrap', 'js/src/util'));

const bundle = await rollup.rollup({
input: resolve(inputFolder, 'index.es6.js'),
plugins: [
Expand Down Expand Up @@ -58,11 +58,9 @@ const build = async () => {
],
external: [
'./base-component.js',
'./dom/data.js',
'./event-handler.js',
'./dom/manipulator.js',
'./selector-engine.js',
'./util/index.js',
...domImports.map((file) => `./dom/${file}`),
...domImports.map((file) => `./${file}`),
...utilImports.map((file) => `./util/${file}`),
],
manualChunks: {
alert: ['build/media_source/vendor/bootstrap/js/alert.es6.js'],
Expand All @@ -79,11 +77,8 @@ const build = async () => {
popper: ['@popperjs/core'],
dom: [
'node_modules/bootstrap/js/src/base-component.js',
'node_modules/bootstrap/js/src/dom/data.js',
'node_modules/bootstrap/js/src/dom/event-handler.js',
'node_modules/bootstrap/js/src/dom/manipulator.js',
'node_modules/bootstrap/js/src/dom/selector-engine.js',
'node_modules/bootstrap/js/src/util/index.js',
...domImports.map((file) => `node_modules/bootstrap/js/src/dom/${file}`),
...utilImports.map((file) => `node_modules/bootstrap/js/src/util/${file}`),
],
},
});
Expand Down

0 comments on commit c524cfd

Please sign in to comment.