Compare commits
5 Commits
v0.1.0-dev
...
v0.1.0-dev
Author | SHA1 | Date |
---|---|---|
semantic-release-bot | a3e87b4a44 | |
Derrick Hammer | 9bb629d441 | |
Derrick Hammer | f6a5bc27b6 | |
Derrick Hammer | 40580f793f | |
Derrick Hammer | 398be8fede |
|
@ -0,0 +1 @@
|
|||
src/templates/vite.config.js
|
|
@ -1,3 +1,11 @@
|
|||
# [0.1.0-develop.30](https://git.lumeweb.com/LumeWeb/presetter-kernel-module-preset/compare/v0.1.0-develop.29...v0.1.0-develop.30) (2023-07-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* change node-resolve config to assume it is an object entry since we rewrite it in the rollup plugin in browser mode ([398be8f](https://git.lumeweb.com/LumeWeb/presetter-kernel-module-preset/commit/398be8fede84167282c3252ab24e6149bf095f32))
|
||||
* passing browser mode does not work here ([40580f7](https://git.lumeweb.com/LumeWeb/presetter-kernel-module-preset/commit/40580f793f7c4b94f37cf62961bd062b4bb24c55))
|
||||
|
||||
# [0.1.0-develop.29](https://git.lumeweb.com/LumeWeb/presetter-kernel-module-preset/compare/v0.1.0-develop.28...v0.1.0-develop.29) (2023-07-03)
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
|
@ -1,15 +1,12 @@
|
|||
{
|
||||
"name": "@lumeweb/presetter-kernel-module-preset",
|
||||
"version": "0.1.0-develop.29",
|
||||
"version": "0.1.0-develop.30",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "gitea@git.lumeweb.com:LumeWeb/presetter-kernel-module-preset.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"presetter": "*"
|
||||
},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"scripts": {
|
||||
"prepare": "presetter bootstrap",
|
||||
|
@ -18,7 +15,10 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@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": {
|
||||
"access": "public"
|
||||
|
|
91
src/index.ts
91
src/index.ts
|
@ -1,6 +1,50 @@
|
|||
import type { PresetAsset } 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
|
||||
* @returns list of preset templates
|
||||
|
@ -11,35 +55,42 @@ export default async function (context: PresetContext): Promise<PresetAsset> {
|
|||
: [];
|
||||
|
||||
return {
|
||||
extends: [
|
||||
"@lumeweb/node-library-preset",
|
||||
"@lumeweb/presetter-preset-rollup",
|
||||
],
|
||||
extends: ["@lumeweb/node-library-preset"],
|
||||
template: {
|
||||
/* 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,
|
||||
supplementaryConfig: {
|
||||
// @ts-ignore
|
||||
browser: true,
|
||||
release: {
|
||||
plugins: {
|
||||
"3": ["@semantic-release/npm", { npmPublish: false }],
|
||||
},
|
||||
},
|
||||
rollup: {
|
||||
plugins: {
|
||||
"1": [
|
||||
"@apply @rollup/plugin-node-resolve[default]",
|
||||
[
|
||||
{
|
||||
dedupe: [
|
||||
"@lumeweb/libkernel",
|
||||
"@lumeweb/libweb",
|
||||
"@lumeweb/libportal",
|
||||
],
|
||||
},
|
||||
],
|
||||
],
|
||||
vite: {
|
||||
build: {
|
||||
outDir: "{output}",
|
||||
lib: {
|
||||
// Could also be a dictionary or array of multiple entry points
|
||||
entry: "{source}/index.js",
|
||||
name: "main",
|
||||
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