diff options
-rw-r--r-- | package-lock.json | 20 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/build.gleam | 26 | ||||
-rw-r--r-- | src/build_ffi.mjs | 40 |
4 files changed, 79 insertions, 8 deletions
diff --git a/package-lock.json b/package-lock.json index 1562962..838488f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "esbuild": "^0.23.0", + "esbuild-plugin-less": "^1.3.8", "less": "^4.2.0" } }, @@ -397,6 +398,12 @@ "node": ">=18" } }, + "node_modules/@types/less": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/@types/less/-/less-3.0.6.tgz", + "integrity": "sha512-PecSzorDGdabF57OBeQO/xFbAkYWo88g4Xvnsx7LRwqLC17I7OoKtA3bQB9uXkY6UkMWCOsA8HSVpaoitscdXw==", + "license": "MIT" + }, "node_modules/copy-anything": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/copy-anything/-/copy-anything-2.0.6.tgz", @@ -461,6 +468,19 @@ "@esbuild/win32-x64": "0.23.0" } }, + "node_modules/esbuild-plugin-less": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/esbuild-plugin-less/-/esbuild-plugin-less-1.3.8.tgz", + "integrity": "sha512-Gnx9BfcrFQKhp+w16LZn2hfYTDJcZ4hvEX+CuHQl+EEgV85tdnBGdNOZAzaoz3X5ONTvaXb7R3o8DvqT2wT8tw==", + "license": "WTFPL", + "dependencies": { + "@types/less": "^3.0.6", + "less": "^4.2.0" + }, + "peerDependencies": { + "esbuild": ">=0.14.0 <0.23.1" + } + }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", diff --git a/package.json b/package.json index 917d689..56aebeb 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "license": "MIT", "dependencies": { "esbuild": "^0.23.0", + "esbuild-plugin-less": "^1.3.8", "less": "^4.2.0" } } diff --git a/src/build.gleam b/src/build.gleam index 0aba25d..a35e8aa 100644 --- a/src/build.gleam +++ b/src/build.gleam @@ -1,5 +1,31 @@ +// import gleam/string +import gleam/javascript/promise.{type Promise} // import bundle +// const entry = "./build/dev/javascript/wechat_dev_tools/bundle.mjs" +// const app_content = "import { app } from './bundle.mjs'; app()" +// const dist = "./dist/" +// const src = "./src/" +// +// fn page_content(p: String) -> String { +// "improt { pages, page } from './bundle.mjs'; page(pages(), \"" <> p <> "\")" +// } + +@external(javascript, "./build_ffi.mjs", "bundle_build") +pub fn bundle_build(entry f: String, outfile o: String) -> Promise(Result(Nil, String)) + +@external(javascript, "./build_ffi.mjs", "js_build") +pub fn js_build(content c: String, outfile o: String) -> Promise(Result(Nil, String)) + +@external(javascript, "./build_ffi.mjs", "json_build") +pub fn json_build(json f: String, outfile o: String) -> Promise(Result(Nil, String)) + +@external(javascript, "./build_ffi.mjs", "wxml_build") +pub fn wxml_build(wxml f: String, outfile o: String) -> Promise(Result(Nil, String)) + +@external(javascript, "./build_ffi.mjs", "less_build") +pub fn less_build(less f: String, outfile o: String) -> Promise(Result(Nil, String)) + pub fn main() { Nil } diff --git a/src/build_ffi.mjs b/src/build_ffi.mjs index d9d2671..d60f1dd 100644 --- a/src/build_ffi.mjs +++ b/src/build_ffi.mjs @@ -1,13 +1,13 @@ -import {build} from 'esbuild' +import { build } from 'esbuild' +import { lessLoader } from 'esbuild-plugin-less'; -export async function bundle_build(es, out, min) { +export async function bundle_build(entry, out) { await build({ - entryPoints: es, + entryPoints: [entry], bundle: true, - minify: min, + minify: true, format: 'esm', - outdir: out, - allowOverwrite: true, + outfile: out, }) } @@ -16,11 +16,35 @@ export async function js_build(js, out) { stdin: { contents: js, loader: 'js', - } + }, bundle: false, minify: false, format: 'esm', outfile: out, - allowOverwrite: true, + }) +} + +export async function wxml_build(wxml, out) { + await build({ + entryPoints: [wxml], + loader: 'txt', + outfile: out, + }) +} + +export async function json_build(json, out) { + await build({ + entryPoints: [json], + loader: 'json', + outfile: out, + }) +} + +export async function less_build(css, out) { + await build({ + entryPoints: [css], + plugins: [lessLoader()], + loader: 'css', + outfile: out, }) } |