feat: move to vite from rollup
This commit is contained in:
parent
f6a5bc27b6
commit
9bb629d441
|
@ -0,0 +1 @@
|
||||||
|
src/templates/vite.config.js
|
File diff suppressed because it is too large
Load Diff
|
@ -7,9 +7,6 @@
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "gitea@git.lumeweb.com:LumeWeb/presetter-kernel-module-preset.git"
|
"url": "gitea@git.lumeweb.com:LumeWeb/presetter-kernel-module-preset.git"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
|
||||||
"presetter": "*"
|
|
||||||
},
|
|
||||||
"readme": "ERROR: No README data found!",
|
"readme": "ERROR: No README data found!",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "presetter bootstrap",
|
"prepare": "presetter bootstrap",
|
||||||
|
@ -18,7 +15,10 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/node-library-preset": "0.2.7",
|
"@lumeweb/node-library-preset": "0.2.7",
|
||||||
"@lumeweb/presetter-preset-rollup": "4.1.0-develop.5"
|
"presetter": "^4.0.1",
|
||||||
|
"vite": "^4.4.2",
|
||||||
|
"vite-plugin-node-polyfills": "^0.9.0",
|
||||||
|
"vite-plugin-optimizer": "^1.4.2"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
|
|
88
src/index.ts
88
src/index.ts
|
@ -1,6 +1,50 @@
|
||||||
import type { PresetAsset } from "presetter-types";
|
import type { PresetAsset } from "presetter-types";
|
||||||
import { PresetContext } from "presetter-types";
|
import { PresetContext } from "presetter-types";
|
||||||
|
|
||||||
|
import { dirname, resolve } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
import { loadFile, resolveDirective, template } from "presetter";
|
||||||
|
|
||||||
|
const DIR = fileURLToPath(dirname(import.meta.url));
|
||||||
|
|
||||||
|
// paths to the template directory
|
||||||
|
const TEMPLATES = resolve(DIR, "..", "templates");
|
||||||
|
|
||||||
|
/** List of configurable variables */
|
||||||
|
export type Variable = {
|
||||||
|
/** the directory containing all source code (default: source) */
|
||||||
|
source: string;
|
||||||
|
/** the directory containing all the compiled files (default: lib) */
|
||||||
|
output: string;
|
||||||
|
buildSource: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DEFAULT_VARIABLE: Variable = {
|
||||||
|
source: "build",
|
||||||
|
output: "lib",
|
||||||
|
buildSource: "src",
|
||||||
|
};
|
||||||
|
|
||||||
|
function buildOptions(context: PresetContext) {
|
||||||
|
const opts = context.custom.config?.vite as any;
|
||||||
|
if (!opts) {
|
||||||
|
throw new Error("vite options missing!");
|
||||||
|
}
|
||||||
|
|
||||||
|
const build = opts.build;
|
||||||
|
const resolve = opts.resolve;
|
||||||
|
const optimize = opts.optimize;
|
||||||
|
const polyfill = opts.polyfill;
|
||||||
|
|
||||||
|
return {
|
||||||
|
viteBuild: resolveDirective(build, context).stringifiedConfig,
|
||||||
|
viteResolve: resolveDirective(resolve, context).stringifiedConfig,
|
||||||
|
viteOptimize: resolveDirective(optimize, context).stringifiedConfig,
|
||||||
|
vitePolyfill: resolveDirective(polyfill, context).stringifiedConfig,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the list of templates provided by this preset
|
* get the list of templates provided by this preset
|
||||||
* @returns list of preset templates
|
* @returns list of preset templates
|
||||||
|
@ -11,10 +55,17 @@ export default async function (context: PresetContext): Promise<PresetAsset> {
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
extends: [
|
extends: ["@lumeweb/node-library-preset"],
|
||||||
"@lumeweb/node-library-preset",
|
template: {
|
||||||
"@lumeweb/presetter-preset-rollup",
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
],
|
"vite.config.js": (context) => {
|
||||||
|
const content = loadFile(resolve(TEMPLATES, "vite.config.js"), "text");
|
||||||
|
const variable = buildOptions(context);
|
||||||
|
|
||||||
|
return template(content, variable);
|
||||||
|
/* eslint-enable @typescript-eslint/naming-convention */
|
||||||
|
},
|
||||||
|
},
|
||||||
supplementaryIgnores: ignores,
|
supplementaryIgnores: ignores,
|
||||||
supplementaryConfig: {
|
supplementaryConfig: {
|
||||||
release: {
|
release: {
|
||||||
|
@ -22,19 +73,24 @@ export default async function (context: PresetContext): Promise<PresetAsset> {
|
||||||
"3": ["@semantic-release/npm", { npmPublish: false }],
|
"3": ["@semantic-release/npm", { npmPublish: false }],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
rollup: {
|
vite: {
|
||||||
plugins: {
|
build: {
|
||||||
"1": {
|
outDir: "{output}",
|
||||||
"1": {
|
lib: {
|
||||||
dedupe: [
|
// Could also be a dictionary or array of multiple entry points
|
||||||
"@lumeweb/libkernel",
|
entry: "{source}/index.js",
|
||||||
"@lumeweb/libweb",
|
name: "main",
|
||||||
"@lumeweb/libportal",
|
formats: ["cjs"],
|
||||||
],
|
fileName: "index",
|
||||||
},
|
},
|
||||||
},
|
minify: false,
|
||||||
},
|
},
|
||||||
|
resolve: {},
|
||||||
|
optimize: {},
|
||||||
|
polyfill: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
scripts: resolve(TEMPLATES, "scripts.yaml"),
|
||||||
|
variable: DEFAULT_VARIABLE,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
# replace the `prepare` template from presetter-preset
|
||||||
|
# so that the build procedure will not be triggered upon package installation
|
||||||
|
build: cross-env NODE_ENV=production run-s clean build:typescript:* build:vite
|
||||||
|
build:vite: vite build && mv lib/*.cjs lib/index.js
|
||||||
|
develop: cross-env NODE_ENV=development run-s "vite:rollup -- --watch {@}" --
|
||||||
|
clean:buildOutput: shx rm -rf {source}
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { defineConfig } from "vite";
|
||||||
|
import path from "path";
|
||||||
|
import optimizer from "vite-plugin-optimizer";
|
||||||
|
import { nodePolyfills } from "vite-plugin-node-polyfills";
|
||||||
|
export default defineConfig({
|
||||||
|
build: {viteBuild},
|
||||||
|
resolve: {viteResolve},
|
||||||
|
plugins: [
|
||||||
|
optimizer({viteOptimize}),
|
||||||
|
nodePolyfills({vitePolyfill}),
|
||||||
|
],
|
||||||
|
});
|
Loading…
Reference in New Issue