quickbundle 0.12.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +18 -1
- package/bin/bundler/bundler.d.ts +5 -8
- package/bin/bundler/bundler.js +88 -117
- package/bin/bundler/index.js +1 -6
- package/bin/bundler/package.d.ts +9 -9
- package/bin/bundler/package.js +20 -29
- package/bin/bundler/plugins.d.ts +1 -3
- package/bin/bundler/plugins.js +25 -56
- package/bin/bundler/typescript.d.ts +5 -9
- package/bin/bundler/typescript.js +65 -144
- package/bin/helpers.d.ts +3 -4
- package/bin/helpers.js +47 -9
- package/bin/program/commands/build.d.ts +1 -3
- package/bin/program/commands/build.js +69 -105
- package/bin/program/commands/watch.d.ts +1 -3
- package/bin/program/commands/watch.js +71 -95
- package/bin/program/index.js +10 -13
- package/bin/program/types.d.ts +1 -1
- package/bin/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Ayoub Adib
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -12,10 +12,11 @@ Quickbundle allows you to bundle a library in a **quick**, **fast** and **easy**
|
|
|
12
12
|
|
|
13
13
|
- Fast build and watch mode thanks to [esbuild](https://esbuild.github.io/)
|
|
14
14
|
- Zero configuration: define the build artifacts in your `package.json` and you're all set!
|
|
15
|
-
- JavaScript, TypeScript, JSX, CSS, JSON and Text support following [esbuild support](https://esbuild.github.io/content-types/)
|
|
15
|
+
- JavaScript, TypeScript, JSX, CSS, JSON, Image and Text support following [esbuild support](https://esbuild.github.io/content-types/)
|
|
16
16
|
- Support of multiple module formats including `cjs` & `esm`
|
|
17
17
|
- Bundling can be done for several platform targets including `browser` or `node`
|
|
18
18
|
- Optimized build such as `peerDependencies` not bundled in the final output
|
|
19
|
+
- Serve and live reload support for `html` entrypoint
|
|
19
20
|
|
|
20
21
|
<br>
|
|
21
22
|
|
|
@@ -43,6 +44,7 @@ yarn add quickbundle
|
|
|
43
44
|
"scripts": {
|
|
44
45
|
"build": "quickbundle build", // Production mode (optimizes bundle)
|
|
45
46
|
"watch": "quickbundle watch", // Development mode (watches each file change)
|
|
47
|
+
"serve": "quickbundle watch --serve public/index.html", // Serve an html entrypoint with live reload capabilities (for more details, check examples folder)
|
|
46
48
|
"build:fast": "quickbundle build --no-check", // Production mode with fast transpilation time. This mode disables TypeScript type checking (ie. not using `tsc`) and, consequently, the `types` asset is no more managed by the tool
|
|
47
49
|
"watch:fast": "quickbundle watch --no-check" // Development mode with fast transpilation time
|
|
48
50
|
}
|
|
@@ -62,4 +64,19 @@ yarn prod
|
|
|
62
64
|
|
|
63
65
|
## 🤩 Used by
|
|
64
66
|
|
|
67
|
+
- [@adbayb/scripts](https://github.com/adbayb/stack) My opinionated toolbox for JavaScript/TypeScript projects
|
|
68
|
+
|
|
65
69
|
Contribution welcomed! 🤗
|
|
70
|
+
|
|
71
|
+
<br>
|
|
72
|
+
|
|
73
|
+
## 💙 Acknowledgements
|
|
74
|
+
|
|
75
|
+
- The backend powered by [ESBuild](https://github.com/evanw/esbuild) to make blazing fast builds. A special shoutout to its author [Evan Wallace](https://github.com/evanw) and [all contributors](https://github.com/evanw/esbuild/graphs/contributors).
|
|
76
|
+
- The zero-configuration approach was inspired by [microbundle](https://github.com/developit/microbundle). A special shoutout to its author [Jason Miller](https://github.com/developit) and [all contributors](https://github.com/developit/microbundle/graphs/contributors).
|
|
77
|
+
|
|
78
|
+
<br>
|
|
79
|
+
|
|
80
|
+
## 📖 License
|
|
81
|
+
|
|
82
|
+
[MIT](./LICENSE "License MIT")
|
package/bin/bundler/bundler.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
declare type BundleParameters = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
isProduction: boolean;
|
|
3
|
+
isFast: boolean;
|
|
4
|
+
onWatch?: (error: Error | null) => void;
|
|
5
|
+
serveEntryPoint?: string;
|
|
5
6
|
};
|
|
6
|
-
export declare const bundle: ({
|
|
7
|
-
isProduction,
|
|
8
|
-
isFast,
|
|
9
|
-
onWatch,
|
|
10
|
-
}: BundleParameters) => Promise<(string | null)[]>;
|
|
7
|
+
export declare const bundle: ({ isProduction, isFast, onWatch, serveEntryPoint, }: BundleParameters) => Promise<(string | null)[]>;
|
|
11
8
|
export {};
|
package/bin/bundler/bundler.js
CHANGED
|
@@ -1,126 +1,97 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
-
function fulfilled(value) {
|
|
14
|
-
try {
|
|
15
|
-
step(generator.next(value));
|
|
16
|
-
} catch (e) {
|
|
17
|
-
reject(e);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function rejected(value) {
|
|
21
|
-
try {
|
|
22
|
-
step(generator["throw"](value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function step(result) {
|
|
28
|
-
result.done
|
|
29
|
-
? resolve(result.value)
|
|
30
|
-
: adopt(result.value).then(fulfilled, rejected);
|
|
31
|
-
}
|
|
32
|
-
step(
|
|
33
|
-
(generator = generator.apply(thisArg, _arguments || [])).next()
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
};
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
37
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
12
|
exports.bundle = void 0;
|
|
39
13
|
const esbuild_1 = require("esbuild");
|
|
14
|
+
const http_1 = require("http");
|
|
40
15
|
const constants_1 = require("../constants");
|
|
16
|
+
const helpers_1 = require("../helpers");
|
|
41
17
|
const package_1 = require("./package");
|
|
42
18
|
const plugins_1 = require("./plugins");
|
|
43
19
|
const typescript_1 = require("./typescript");
|
|
44
|
-
const bundle = ({ isProduction, isFast, onWatch }) =>
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
...(isWatching
|
|
120
|
-
? [getJavaScript(hasModule ? "esm" : "cjs")]
|
|
121
|
-
: [getJavaScript("cjs"), getJavaScript("esm")]),
|
|
122
|
-
...(isTypingRequested ? [getType()] : []),
|
|
123
|
-
];
|
|
124
|
-
return Promise.all(promises);
|
|
125
|
-
});
|
|
20
|
+
const bundle = ({ isProduction, isFast, onWatch, serveEntryPoint, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const { destination, externalDependencies, hasModule, platform, source, types, } = (0, package_1.getPackageMetadata)();
|
|
22
|
+
const isWatching = typeof onWatch === "function";
|
|
23
|
+
const isLiveReloadable = serveEntryPoint && isWatching;
|
|
24
|
+
const isTypingRequested = typeof types === "string" && !isFast;
|
|
25
|
+
const tsConfig = yield (0, typescript_1.getTypeScriptConfiguration)();
|
|
26
|
+
const getType = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const outfile = types;
|
|
28
|
+
if (!outfile)
|
|
29
|
+
return null;
|
|
30
|
+
yield (0, typescript_1.generateTypeScriptDeclaration)(outfile);
|
|
31
|
+
return outfile;
|
|
32
|
+
});
|
|
33
|
+
const getJavaScript = (format) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const outfile = destination[format];
|
|
35
|
+
if (!outfile)
|
|
36
|
+
return null;
|
|
37
|
+
yield (0, esbuild_1.build)(Object.assign(Object.assign({}, (isLiveReloadable && {
|
|
38
|
+
banner: {
|
|
39
|
+
js: `;new EventSource("http://0.0.0.0:${servePort}").onmessage = function() { location.reload(); }; console.log("Live reload ✅ (port: ${servePort})");`,
|
|
40
|
+
},
|
|
41
|
+
})), { absWorkingDir: constants_1.CWD, bundle: true, define: {
|
|
42
|
+
"process.env.NODE_ENV": isProduction
|
|
43
|
+
? '"production"'
|
|
44
|
+
: '"development"',
|
|
45
|
+
}, entryPoints: [source], external: externalDependencies, format, loader: {
|
|
46
|
+
".jpg": "file",
|
|
47
|
+
".jpeg": "file",
|
|
48
|
+
".png": "file",
|
|
49
|
+
".gif": "file",
|
|
50
|
+
".svg": "file",
|
|
51
|
+
".webp": "file",
|
|
52
|
+
}, logLevel: "silent", metafile: true, minify: isProduction, outfile, plugins: [(0, plugins_1.jsxPlugin)(tsConfig)], platform, sourcemap: true, target: (tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.target) || "esnext", treeShaking: true, watch: isWatching && {
|
|
53
|
+
onRebuild(bundleError) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
let error = bundleError;
|
|
56
|
+
if (isLiveReloadable) {
|
|
57
|
+
clients.forEach((client) => {
|
|
58
|
+
client.write("data: update\n\n");
|
|
59
|
+
});
|
|
60
|
+
clients = [];
|
|
61
|
+
}
|
|
62
|
+
if (!error && isTypingRequested) {
|
|
63
|
+
try {
|
|
64
|
+
yield getType();
|
|
65
|
+
}
|
|
66
|
+
catch (typingError) {
|
|
67
|
+
error = typingError;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
onWatch(error);
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
} }));
|
|
74
|
+
return outfile;
|
|
75
|
+
});
|
|
76
|
+
if (isLiveReloadable) {
|
|
77
|
+
servePort = yield (0, helpers_1.getAvailablePortFrom)(servePort);
|
|
78
|
+
(0, http_1.createServer)((_, res) => {
|
|
79
|
+
clients.push(res.writeHead(200, {
|
|
80
|
+
"Content-Type": "text/event-stream",
|
|
81
|
+
"Cache-Control": "no-cache",
|
|
82
|
+
"Access-Control-Allow-Origin": "*",
|
|
83
|
+
}));
|
|
84
|
+
}).listen(servePort);
|
|
85
|
+
(0, helpers_1.openBrowser)(serveEntryPoint);
|
|
86
|
+
}
|
|
87
|
+
const promises = [
|
|
88
|
+
...(isWatching
|
|
89
|
+
? [getJavaScript(hasModule ? "esm" : "cjs")]
|
|
90
|
+
: [getJavaScript("cjs"), getJavaScript("esm")]),
|
|
91
|
+
...(isTypingRequested ? [getType()] : []),
|
|
92
|
+
];
|
|
93
|
+
return Promise.all(promises);
|
|
94
|
+
});
|
|
126
95
|
exports.bundle = bundle;
|
|
96
|
+
let clients = [];
|
|
97
|
+
let servePort = 9000;
|
package/bin/bundler/index.js
CHANGED
|
@@ -2,9 +2,4 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.bundle = void 0;
|
|
4
4
|
var bundler_1 = require("./bundler");
|
|
5
|
-
Object.defineProperty(exports, "bundle", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function () {
|
|
8
|
-
return bundler_1.bundle;
|
|
9
|
-
},
|
|
10
|
-
});
|
|
5
|
+
Object.defineProperty(exports, "bundle", { enumerable: true, get: function () { return bundler_1.bundle; } });
|
package/bin/bundler/package.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export declare const getPackageMetadata: () => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
readonly destination: {
|
|
3
|
+
readonly esm?: string | undefined;
|
|
4
|
+
readonly cjs: string;
|
|
5
|
+
};
|
|
6
|
+
readonly externalDependencies: string[];
|
|
7
|
+
readonly hasModule: boolean;
|
|
8
|
+
readonly platform: "node" | "browser";
|
|
9
|
+
readonly source: string;
|
|
10
|
+
readonly types: string | undefined;
|
|
11
11
|
};
|
package/bin/bundler/package.js
CHANGED
|
@@ -5,34 +5,25 @@ const path_1 = require("path");
|
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
const helpers_1 = require("../helpers");
|
|
7
7
|
const getPackageMetadata = () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
29
|
-
return {
|
|
30
|
-
destination: Object.assign({ cjs: main }, module && { esm: module }),
|
|
31
|
-
externalDependencies,
|
|
32
|
-
hasModule: Boolean(module),
|
|
33
|
-
platform,
|
|
34
|
-
source,
|
|
35
|
-
types,
|
|
36
|
-
};
|
|
8
|
+
const { devDependencies = {}, peerDependencies = {}, dependencies = {}, main, module, platform = "browser", source, types, } = require((0, path_1.resolve)(constants_1.CWD, "package.json"));
|
|
9
|
+
(0, helpers_1.assert)(main, "A `main` field is required in `package.json`. Did you forget to add it?");
|
|
10
|
+
(0, helpers_1.assert)(source, "A `source` field is required in `package.json`. Did you forget to add it?");
|
|
11
|
+
(0, helpers_1.assert)(["browser", "node"].includes(platform), "The `platform` package field can only accept `browser` or `node` value.");
|
|
12
|
+
const peerDependencyNames = Object.keys(peerDependencies);
|
|
13
|
+
const externalDependencies = platform === "browser"
|
|
14
|
+
? peerDependencyNames
|
|
15
|
+
: [
|
|
16
|
+
...peerDependencyNames,
|
|
17
|
+
...Object.keys(dependencies),
|
|
18
|
+
...Object.keys(devDependencies),
|
|
19
|
+
];
|
|
20
|
+
return {
|
|
21
|
+
destination: Object.assign({ cjs: main }, (module && { esm: module })),
|
|
22
|
+
externalDependencies,
|
|
23
|
+
hasModule: Boolean(module),
|
|
24
|
+
platform,
|
|
25
|
+
source,
|
|
26
|
+
types,
|
|
27
|
+
};
|
|
37
28
|
};
|
|
38
29
|
exports.getPackageMetadata = getPackageMetadata;
|
package/bin/bundler/plugins.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { Plugin } from "esbuild";
|
|
2
2
|
import type { TypeScriptConfiguration } from "./typescript";
|
|
3
|
-
export declare const jsxPlugin: (
|
|
4
|
-
tsConfig: TypeScriptConfiguration | null
|
|
5
|
-
) => Plugin;
|
|
3
|
+
export declare const jsxPlugin: (tsConfig: TypeScriptConfiguration | null) => Plugin;
|
package/bin/bundler/plugins.js
CHANGED
|
@@ -1,63 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
-
function fulfilled(value) {
|
|
14
|
-
try {
|
|
15
|
-
step(generator.next(value));
|
|
16
|
-
} catch (e) {
|
|
17
|
-
reject(e);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function rejected(value) {
|
|
21
|
-
try {
|
|
22
|
-
step(generator["throw"](value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function step(result) {
|
|
28
|
-
result.done
|
|
29
|
-
? resolve(result.value)
|
|
30
|
-
: adopt(result.value).then(fulfilled, rejected);
|
|
31
|
-
}
|
|
32
|
-
step(
|
|
33
|
-
(generator = generator.apply(thisArg, _arguments || [])).next()
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
};
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
37
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
12
|
exports.jsxPlugin = void 0;
|
|
39
13
|
const helpers_1 = require("../helpers");
|
|
40
14
|
const jsxPlugin = (tsConfig) => ({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
loader: "tsx",
|
|
58
|
-
};
|
|
59
|
-
})
|
|
60
|
-
);
|
|
61
|
-
},
|
|
15
|
+
name: "jsx-runtime",
|
|
16
|
+
setup(build) {
|
|
17
|
+
build.onLoad({ filter: /\.(j|t)sx$/ }, ({ path }) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
if (!tsConfig || !tsConfig.hasJsxRuntime)
|
|
19
|
+
return;
|
|
20
|
+
const module = tsConfig.jsxImportSource || "react";
|
|
21
|
+
if (!(0, helpers_1.resolveModulePath)(`${module}/jsx-runtime`)) {
|
|
22
|
+
throw new Error("Unable to find the JSX runtime.\nPotential solutions:\n1. If you rely on a non React runtime, set a valid `jsxImportSource` in your tsconfig\n2. Make sure that you've installed your project dependencies");
|
|
23
|
+
}
|
|
24
|
+
const content = yield (0, helpers_1.readFile)(path, "utf8");
|
|
25
|
+
return {
|
|
26
|
+
contents: `import * as React from "${module}";${content}`,
|
|
27
|
+
loader: "tsx",
|
|
28
|
+
};
|
|
29
|
+
}));
|
|
30
|
+
},
|
|
62
31
|
});
|
|
63
32
|
exports.jsxPlugin = jsxPlugin;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
export declare type TypeScriptConfiguration = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
target?: string;
|
|
3
|
+
jsxImportSource?: string;
|
|
4
|
+
hasJsxRuntime?: boolean;
|
|
5
5
|
};
|
|
6
6
|
export declare const getTypeScriptConfiguration: () => Promise<TypeScriptConfiguration | null>;
|
|
7
|
-
export declare const generateTypeScriptDeclaration: (
|
|
8
|
-
|
|
9
|
-
) => Promise<string>;
|
|
10
|
-
export declare const hasTypeScript: (
|
|
11
|
-
tsConfig: TypeScriptConfiguration | null
|
|
12
|
-
) => tsConfig is TypeScriptConfiguration;
|
|
7
|
+
export declare const generateTypeScriptDeclaration: (outfile: string) => Promise<string>;
|
|
8
|
+
export declare const hasTypeScript: (tsConfig: TypeScriptConfiguration | null) => tsConfig is TypeScriptConfiguration;
|