my-notes-viewer/esbuild.config.js

75 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-03-22 15:59:05 +01:00
const resolvePlugin = {
name: "resolvePlugin",
setup(build) {
let path = require("path")
// url in css does not resolve via esbuild-svelte correctly
build.onResolve({ filter: /.*/, namespace: "fakecss" }, (args) => {
// console.log(args)
if (args.path.match(/^\./))
return { path: path.dirname(args.importer) + "/" + args.path }
// return { path: path.join(args.resolveDir, "public", args.path) }
})
},
}
////////////////////////// esbuild-svelte
2021-09-13 18:12:40 +02:00
const sveltePlugin = require("./esbuild-svelte.plugin")
2021-03-22 15:59:05 +01:00
const distDir = "dist"
console.log("copy public dir...")
const copydir = require("copy-dir")
copydir.sync(__dirname + "/public", __dirname + "/" + distDir)
/*copydir.sync(
__dirname + "/public/index.html",
__dirname + "/" + distDir + "/template.html"
)*/
const svelteConfig = require("./svelte.config")
const esbuildSvelte = sveltePlugin({
compileOptions: {
css: false,
hydratable: true,
dev: (process.argv?.length > 2 ? process.argv[2] : "build") !== "build",
},
preprocess: svelteConfig.preprocess,
cache: true,
})
const options = {
2021-09-13 18:12:40 +02:00
logLevel: "info",
2021-03-22 15:59:05 +01:00
color: true,
entryPoints: ["./src/index.ts"],
outfile: "./" + distDir + "/_dist_/index.mjs",
2021-09-13 18:12:40 +02:00
metafile: true, //"./" + distDir + "/_dist_/meta.json",
2021-03-22 15:59:05 +01:00
format: "esm",
minify: true,
bundle: true,
splitting: false,
plugins: [esbuildSvelte, resolvePlugin],
loader: {
".woff2": "file",
2021-09-13 18:12:40 +02:00
".woff": "file",
".eot": "file",
".svg": "file",
".ttf": "file",
2021-03-22 15:59:05 +01:00
},
sourcemap: true,
2021-09-13 18:12:40 +02:00
target: ["es2020", "chrome61", "firefox60", "safari11", "edge18"],
2021-03-22 15:59:05 +01:00
}
module.exports = {
sveltePlugin: sveltePlugin,
resolvePlugin: resolvePlugin,
options: options,
watch: {
path: [__dirname + "/src/**/*"],
},
serve: {
onRequest(args) {
console.log(args)
},
},
}