Skip to content

Commit

Permalink
build!: separate entry point for bundled themes
Browse files Browse the repository at this point in the history
  • Loading branch information
HusamElbashir committed Mar 25, 2022
1 parent f734123 commit 27ff148
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 15 deletions.
45 changes: 39 additions & 6 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const moduleConfig = (moduleSystem, file, emitDeclaration) => {
const declarationDir = pkg.typings
? // @ts-ignore
inferDirectory(pkg.typings)
: `dist/types`;
: "dist/types";
console.log(`- the source's entrypoint is "${input}" and output will be put in "${outDir}" folder`);
if (emitDeclaration) {
console.log(`- the typings will also be generated and placed in the "${declarationDir}" directory`);
Expand All @@ -106,7 +106,7 @@ const moduleConfig = (moduleSystem, file, emitDeclaration) => {
outDir,
module: "esnext",
},
exclude: ["test", "tests", "node_modules", "docs"],
exclude: ["test", "tests", "node_modules", "docs", "src/themes"],
};

return {
Expand Down Expand Up @@ -157,12 +157,12 @@ async function buildModule(m, emitDeclaration) {
try {
console.log(`- 📦 starting bundling of ${m.toUpperCase()} module ${switches.has("min") ? "(minimized)" : ""}`);
if (switches.has("closure")) {
console.log(`- using closure compiler to minimize file size`);
console.log("- using closure compiler to minimize file size");
}
// @ts-ignore
if (getModuleShortname(m) === "es" && !pkg.module) {
console.log(
`- 🤨 while you are building for the ES module system your package.json doesn't specify a "module" entrypoint.`
"- 🤨 while you are building for the ES module system your package.json doesn't specify a \"module\" entrypoint."
);
}
const file = getFilenameByModule(m);
Expand All @@ -185,7 +185,7 @@ async function buildModule(m, emitDeclaration) {
const output = statSync(file);
console.log(`- 🚀 bundling saved to the "${file}" file [ ${Math.floor(output.size / 100) / 10} kb ].\n`);
} catch (error) {
console.warn(`- 👎 the build failed during Rollup bundling`);
console.warn("- 👎 the build failed during Rollup bundling");
console.log(`\n${error.stack}\n`);
process.exit(1);
}
Expand Down Expand Up @@ -225,9 +225,42 @@ const usesGlobalVars = (mod) => {
console.log();

for (const m of moduleSystems) {
const emitDeclaration = moduleSystems.length === 1 || getModuleShortname(m) === "es";
const moduleShortname = getModuleShortname(m);
const emitDeclaration = moduleSystems.length === 1 || moduleShortname === "es";
await buildModule(m, emitDeclaration);
}

// Bundle themes
const bundle = await rollup.rollup({
input: "src/themes/index.ts",
plugins: [
typescript({
tsconfig: "tsconfig.json",
typescript: ttypescript,
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
declaration: true,
declarationDir: "dist/themes/types",
outDir: "dist/themes",
module: "esnext",
},
include: ["src/themes"],
exclude: ["test", "tests", "node_modules", "docs"],
},
}),
...(process.env.ANALYZE || switches.analyze ? [analyze()] : []),
...(switches.has("closure") ? [closure()] : []),
...(switches.has("min") ? [terser()] : []),
],
});

await bundle.write({
file: "dist/themes/es/index.js",
format: "es",
exports: "auto",
sourcemap: false,
});

console.log("\n- Build completed!\n");
})();
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@
"jsdelivr": "dist/cjs/index.js",
"main": "dist/cjs/index.js",
"module": "dist/es/index.js",
"typings": "dist/types/index.d.ts",
"files": [
"dist"
],
"exports": {
".": {
"import": "./dist/es/index.js",
"require": "./dist/cjs/index.js"
},
"./themes": "./dist/themes/es/index.js",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"*": ["dist/types/index.d.ts"],
"themes": [ "dist/themes/types/index.d.ts"]
}
},
"scripts": {
"dev": "vite",
"autoindex": "yarn do autoindex --sfc",
Expand Down
11 changes: 5 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
//#autoindex, exclude: shims-vue.d, composables, shared
//#autoindex, exclude: shims-vue.d, composables, shared, themes

// #region autoindexed files

// index last changed at: 4th Apr, 2021, 05:18 AM ( GMT+2 )
// export: named; exclusions: shims-vue.d, composables, shared, index, private.
// directories: @types, components, themes.
// index last changed at: 3rd Mar, 2022, 02:52 AM ( GMT+2 )
// export: named; exclusions: shims-vue.d, composables, shared, themes, index, private.
// directories: @types, components.

// directory exports
export * from "./@types/index";
export * from "./components/index";
export * from "./themes/index";

// Note:
// -----
// This file was created by running: "do devops autoindex"; it assumes you have
// This file was created by running: "dd devops autoindex"; it assumes you have
// the 'do-devops' pkg installed as a dev dep.
//
// By default it assumes that exports are named exports but this can be changed by
Expand Down
4 changes: 2 additions & 2 deletions src/themes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #region autoindexed files

// index last changed at: 10th Oct, 2020, 02:23 AM ( GMT+2 )
// index last changed at: 25th Mar, 2022, 04:04 AM ( GMT+2 )
// export: named; exclusions: index, private.
// files: aubergine, dark, grey, minimal, retro, roadways, roadwaysMinimal, ultraLight.

Expand All @@ -18,7 +18,7 @@ export * from "./ultraLight";

// Note:
// -----
// This file was created by running: "do devops autoindex"; it assumes you have
// This file was created by running: "dd devops autoindex"; it assumes you have
// the 'do-devops' pkg installed as a dev dep.
//
// By default it assumes that exports are named exports but this can be changed by
Expand Down

0 comments on commit 27ff148

Please sign in to comment.