Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build-config): allow to custom modules by process.env.SWIPER_BUILD_MODULES #6043

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion scripts/build-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export const modules = [
import { parseSwiperBuildModulesEnv } from './utils/helper.js';

const envBuildModules = parseSwiperBuildModulesEnv();

export const modules = envBuildModules || [
'virtual',
'keyboard',
'mousewheel',
Expand Down
15 changes: 2 additions & 13 deletions scripts/build-js-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { modules as configModules } from './build-config.js';
import { outputDir } from './utils/output-dir.js';
import { banner } from './utils/banner.js';
import isProd from './utils/isProd.js';
import { capitalizeString } from './utils/helper.js';

async function buildEntry(modules, format, browser = false) {
const isUMD = format === 'umd';
Expand Down Expand Up @@ -83,19 +84,7 @@ export default async function buildJsBundle() {
elapsed.start('bundle');
const modules = [];
configModules.forEach((name) => {
// eslint-disable-next-line
const capitalized = name
.split('-')
.map((word) => {
return word
.split('')
.map((char, index) => {
if (index === 0) return char.toUpperCase();
return char;
})
.join('');
})
.join('');
const capitalized = capitalizeString(name);
const jsFilePath = `./src/modules/${name}/${name}.js`;
if (fs.existsSync(jsFilePath)) {
modules.push({ name, capitalized });
Expand Down
15 changes: 2 additions & 13 deletions scripts/build-js-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import elapsed from 'elapsed-time-logger';
import { modules as configModules } from './build-config.js';
import { outputDir } from './utils/output-dir.js';
import { banner } from './utils/banner.js';
import { capitalizeString } from './utils/helper.js';
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
/* eslint no-console: "off" */
const exec = execSh.promise;
Expand All @@ -31,19 +32,7 @@ export default async function build() {
elapsed.start('core');
const modules = [];
configModules.forEach((name) => {
// eslint-disable-next-line
const capitalized = name
.split('-')
.map((word) => {
return word
.split('')
.map((char, index) => {
if (index === 0) return char.toUpperCase();
return char;
})
.join('');
})
.join('');
const capitalized = capitalizeString(name);
const jsFilePath = `./src/modules/${name}/${name}.js`;
if (fs.existsSync(jsFilePath)) {
modules.push({ name, capitalized });
Expand Down
18 changes: 18 additions & 0 deletions scripts/utils/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function capitalizeString(str) {
return str.replace(/(?:^|-)([a-z])/g, (m, char) => char.toUpperCase());
}

/**
* Parse build modules from env `SWIPER_BUILD_MODULES`.<br>
* Will return null if env is not set or empty
* @returns {string[]|null}
*/
export function parseSwiperBuildModulesEnv() {
if (process.env.SWIPER_BUILD_MODULES) {
const buildModules = process.env.SWIPER_BUILD_MODULES.split(/[,\s]+/).filter(
(moduleName) => moduleName, // ensure to empty will be removed
);
if (buildModules.length) return buildModules;
}
return null;
}