-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathesbuild.options.js
More file actions
92 lines (88 loc) · 2.52 KB
/
esbuild.options.js
File metadata and controls
92 lines (88 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { typecheckPlugin } from "@jgoz/esbuild-plugin-typecheck";
import copyLicensesPlugin from "esbuild-plugin-copy-licenses";
import { postcssModules, sassPlugin } from "esbuild-sass-plugin";
import stdlibBrowser from "node-stdlib-browser";
import stdlibPlugin from "node-stdlib-browser/helpers/esbuild/plugin";
import path from "path";
import { fileURLToPath } from "url";
/**
* This file defines the esbuild options for building the WordPress plugin.
* See its driving script ./build.js for more details.
*/
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const nodeEnv = process.env.NODE_ENV || "production";
const watch = process.env.HOT_RELOAD || false;
const minify = !Boolean(process.env.NO_MINIFY);
const withLicenses = Boolean(process.env.WITH_LICENSES);
const withMetaFile = Boolean(process.env.METAFILE);
const outdir = path.resolve(__dirname, process.env.OUTDIR || ".");
const stdlib = {
...stdlibBrowser,
net: fileURLToPath(import.meta.resolve("node-stdlib-browser/mock/net")),
};
export const WORDPRESS_PLUGIN_BUILD_OPTIONS = {
entryNames: `[name].min`,
entryPoints: {
post: path.resolve(__dirname, "src/post-shorthand-story.entry.js"),
},
platform: "browser",
target: "es2015",
sourcemap: nodeEnv !== "production",
outdir: path.join(outdir, "public/scripts"),
bundle: true,
metafile: withMetaFile,
inject: [
fileURLToPath(
import.meta.resolve("node-stdlib-browser/helpers/esbuild/shim"),
),
],
tsconfig: path.resolve(__dirname, "tsconfig.json"),
minify: minify,
define: {
"process.env.NODE_ENV": JSON.stringify(nodeEnv || "production"),
define: "undefined",
},
external: [
"*.png",
"*.svg",
"*.jpg",
"*.woff",
"*.eot",
"*.woff2",
"*.ttf",
"*.eot?#iefix",
"canvas",
],
plugins: [
...(withLicenses
? [
copyLicensesPlugin({
copyLicenseFiles: {
enabled: true,
directoryPath: path.join(outdir, "third-party"),
},
summaryFile: {
enabled: true,
filePath: path.join(outdir, "third-party", "summary.txt"),
},
}),
]
: []),
sassPlugin({
filter: /\.module\.scss$/,
transform: postcssModules({
basedir: "cwd",
localsConvention: "camelCase",
}),
}),
sassPlugin({
quietDeps: true,
cssImports: true,
}),
stdlibPlugin(stdlib),
typecheckPlugin({
configFile: path.resolve(__dirname, "tsconfig.json"),
watch,
}),
],
};