makepack 1.3.0 → 1.3.2
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/README.md +8 -2
- package/package.json +3 -2
- package/src/actions/{pack.js → pack/index.js} +6 -13
- package/src/actions/serve/index.js +9 -4
- package/src/helpers.js +13 -0
- package/src/index.js +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,12 @@ npm install -g makepack
|
|
|
16
16
|
|
|
17
17
|
This will allow you to use the `makepack` command anywhere in your terminal.
|
|
18
18
|
|
|
19
|
+
## Configuration Files
|
|
20
|
+
|
|
21
|
+
**MakePack** supports loading configuration files for Vite and esbuild. If `vite.config.js` and `esbuild.config.js` exist in the root of the project, they will be automatically loaded when running the respective commands.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
19
25
|
## Commands
|
|
20
26
|
|
|
21
27
|
### `create`
|
|
@@ -38,7 +44,7 @@ This command will guide you through the initial setup for your library.
|
|
|
38
44
|
|
|
39
45
|
### `serve`
|
|
40
46
|
|
|
41
|
-
The `serve` command starts a development server for your library, providing you with a live-reload environment where you can test and iterate on your library in real-time.
|
|
47
|
+
The `serve` command starts a development server for your library, providing you with a live-reload environment where you can test and iterate on your library in real-time. It will load `vite.config.js` if it exists in the root of the project.
|
|
42
48
|
|
|
43
49
|
#### Usage
|
|
44
50
|
|
|
@@ -68,7 +74,7 @@ makepack serve --port 4000 --root src/index.ts
|
|
|
68
74
|
|
|
69
75
|
### `pack`
|
|
70
76
|
|
|
71
|
-
The `pack` command is used to build your library and optionally publish it to the npm repository. This command compiles your code into a distributable format and prepares it for sharing with others.
|
|
77
|
+
The `pack` command is used to build your library and optionally publish it to the npm repository. This command compiles your code into a distributable format and prepares it for sharing with others. It will load `esbuild.config.js` if it exists in the root of the project.
|
|
72
78
|
|
|
73
79
|
#### Usage
|
|
74
80
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "makepack",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A CLI tool to create, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for npm projects.",
|
|
6
6
|
"files": [
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"glob": "^11.0.0",
|
|
37
37
|
"inquirer": "^12.1.0",
|
|
38
38
|
"typescript": "^5.7.2",
|
|
39
|
-
"vite": "^6.0.2"
|
|
39
|
+
"vite": "^6.0.2",
|
|
40
|
+
"@vitejs/plugin-react": "^4.3.4"
|
|
40
41
|
},
|
|
41
42
|
"keywords": [
|
|
42
43
|
"CLI",
|
|
@@ -3,7 +3,7 @@ import fs from 'fs-extra';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { glob } from 'glob'
|
|
5
5
|
import ts from 'typescript'
|
|
6
|
-
import { execSync, logLoader } from '
|
|
6
|
+
import { execSync, logLoader, loadConfig } from '../../helpers.js';
|
|
7
7
|
|
|
8
8
|
const pack = async (args) => {
|
|
9
9
|
args.outdir = 'pack'
|
|
@@ -14,24 +14,17 @@ const pack = async (args) => {
|
|
|
14
14
|
const files = await glob('src/**/*.{tsx,ts,js,jsx}') || []
|
|
15
15
|
const entries = files.map(entry => path.join(process.cwd(), entry))
|
|
16
16
|
let loader = logLoader("Generating a production build for the package...")
|
|
17
|
-
|
|
17
|
+
const esbuildConfig = await loadConfig('esbuild.config.js') || {}
|
|
18
18
|
esbuild.buildSync({
|
|
19
|
-
entryPoints: entries,
|
|
20
|
-
outdir: path.join(process.cwd(), args.outdir),
|
|
21
19
|
// minify: true,
|
|
22
20
|
sourcemap: true,
|
|
23
21
|
format: "esm",
|
|
24
22
|
platform: 'node',
|
|
25
23
|
loader: { '.ts': 'ts' },
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// "emitDeclarationOnly": true,
|
|
31
|
-
// "jsx": "react",
|
|
32
|
-
// "module": "esnext",
|
|
33
|
-
// }
|
|
34
|
-
// }`
|
|
24
|
+
tsconfig: path.join(process.cwd(), 'tsconfig.json'),
|
|
25
|
+
...esbuildConfig,
|
|
26
|
+
entryPoints: entries,
|
|
27
|
+
outdir: path.join(process.cwd(), args.outdir),
|
|
35
28
|
})
|
|
36
29
|
loader.stop()
|
|
37
30
|
loader = logLoader("🔄 Generating TypeScript declarations...")
|
|
@@ -4,14 +4,16 @@ import path from 'path'
|
|
|
4
4
|
import { createServer as createViteServer } from 'vite';
|
|
5
5
|
import express from 'express';
|
|
6
6
|
import { glob } from 'glob'
|
|
7
|
-
import { logger } from '../../helpers.js'
|
|
7
|
+
import { logger, loadConfig } from '../../helpers.js'
|
|
8
8
|
import chalk from 'chalk';
|
|
9
9
|
import figlet from 'figlet';
|
|
10
|
+
import react from '@vitejs/plugin-react'
|
|
10
11
|
|
|
11
12
|
const app = express();
|
|
12
13
|
|
|
13
|
-
const serve = async (args) => {
|
|
14
14
|
|
|
15
|
+
|
|
16
|
+
const serve = async (args) => {
|
|
15
17
|
if (args.root === undefined) {
|
|
16
18
|
const serveFile = await glob('serve.{ts,js,tsx,jsx}', {
|
|
17
19
|
cwd: process.cwd()
|
|
@@ -46,13 +48,15 @@ const serve = async (args) => {
|
|
|
46
48
|
</html>
|
|
47
49
|
`;
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
let viteConfig = await loadConfig('vite.config.js') || {}
|
|
50
52
|
|
|
51
53
|
const vite = await createViteServer({
|
|
54
|
+
...viteConfig,
|
|
52
55
|
root: process.cwd(),
|
|
53
|
-
|
|
56
|
+
plugins: [react(), ...(viteConfig.plugins || [])],
|
|
54
57
|
server: {
|
|
55
58
|
middlewareMode: true,
|
|
59
|
+
...(viteConfig.server || {})
|
|
56
60
|
},
|
|
57
61
|
customLogger: {
|
|
58
62
|
info: (msg) => {
|
|
@@ -60,6 +64,7 @@ const serve = async (args) => {
|
|
|
60
64
|
},
|
|
61
65
|
warn: (msg) => logger.warning(msg),
|
|
62
66
|
error: (msg) => logger.error(msg),
|
|
67
|
+
...(viteConfig.customLogger || {})
|
|
63
68
|
},
|
|
64
69
|
appType: 'custom'
|
|
65
70
|
});
|
package/src/helpers.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import child_process from 'child_process'
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import figures from 'figures';
|
|
4
|
+
import { pathToFileURL } from 'url';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
4
7
|
|
|
5
8
|
export const logLoader = (message = "") => {
|
|
6
9
|
const spinner = ['|', '/', '-', '\\'];
|
|
@@ -53,3 +56,13 @@ export const logger = {
|
|
|
53
56
|
},
|
|
54
57
|
};
|
|
55
58
|
|
|
59
|
+
|
|
60
|
+
export const loadConfig = async (file) => {
|
|
61
|
+
const viteConfigPath = path.resolve(process.cwd(), file);
|
|
62
|
+
if (fs.existsSync(viteConfigPath)) {
|
|
63
|
+
try {
|
|
64
|
+
return await import(pathToFileURL(viteConfigPath).href);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/index.js
CHANGED