@utoo/pack 1.1.21 → 1.1.23-rc.1
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 +34 -26
- package/cjs/commands/build.js +9 -55
- package/cjs/commands/dev.js +4 -4
- package/cjs/core/hmr.js +6 -26
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/utils/getInitialAssets.d.ts +5 -0
- package/cjs/utils/getInitialAssets.js +35 -0
- package/cjs/utils/{html-entry.js → htmlEntry.js} +5 -1
- package/esm/commands/build.js +7 -20
- package/esm/commands/dev.js +2 -2
- package/esm/core/hmr.js +5 -25
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/utils/getInitialAssets.d.ts +5 -0
- package/esm/utils/getInitialAssets.js +29 -0
- package/esm/utils/{html-entry.js → htmlEntry.js} +5 -1
- package/package.json +9 -9
- /package/cjs/utils/{find-root.d.ts → findRoot.d.ts} +0 -0
- /package/cjs/utils/{find-root.js → findRoot.js} +0 -0
- /package/cjs/utils/{html-entry.d.ts → htmlEntry.d.ts} +0 -0
- /package/cjs/utils/{print-server-info.d.ts → printServerInfo.d.ts} +0 -0
- /package/cjs/utils/{print-server-info.js → printServerInfo.js} +0 -0
- /package/esm/utils/{find-root.d.ts → findRoot.d.ts} +0 -0
- /package/esm/utils/{find-root.js → findRoot.js} +0 -0
- /package/esm/utils/{html-entry.d.ts → htmlEntry.d.ts} +0 -0
- /package/esm/utils/{print-server-info.d.ts → printServerInfo.d.ts} +0 -0
- /package/esm/utils/{print-server-info.js → printServerInfo.js} +0 -0
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
## 📦 Installation
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
|
-
|
|
34
|
+
ut install @utoo/pack --save-dev
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
## 🚀 Quick Start
|
|
@@ -46,50 +46,58 @@ const { build, dev } = require('@utoo/pack');
|
|
|
46
46
|
// Production build
|
|
47
47
|
async function runBuild() {
|
|
48
48
|
await build({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
mode: "production",
|
|
50
|
+
entry: [
|
|
51
|
+
{
|
|
52
|
+
import: "./src/index.ts",
|
|
53
|
+
html: {
|
|
54
|
+
template: "./index.html"
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
output: {
|
|
59
|
+
path: "./dist",
|
|
60
|
+
filename: "[name].[contenthash:8].js",
|
|
61
|
+
chunkFilename: "[name].[contenthash:8].js",
|
|
62
|
+
clean: true
|
|
63
|
+
},
|
|
64
|
+
sourceMaps: true
|
|
59
65
|
});
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
// Development mode with HMR
|
|
63
69
|
async function startDev() {
|
|
64
70
|
const server = await dev({
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
mode: "development",
|
|
72
|
+
entry: [
|
|
73
|
+
{
|
|
74
|
+
import: "./src/index.ts",
|
|
75
|
+
html: {
|
|
76
|
+
template: "./index.html"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
output: {
|
|
81
|
+
path: "./dist",
|
|
82
|
+
filename: "[name].[contenthash:8].js",
|
|
83
|
+
chunkFilename: "[name].[contenthash:8].js",
|
|
84
|
+
clean: true
|
|
85
|
+
},
|
|
86
|
+
sourceMaps: true
|
|
69
87
|
});
|
|
70
88
|
}
|
|
71
89
|
```
|
|
72
90
|
|
|
73
91
|
## 🔌 Webpack Compatibility Mode
|
|
74
92
|
|
|
75
|
-
`@utoo/pack` provides a partial compatibility layer for Webpack.
|
|
76
|
-
|
|
77
|
-
### Usage via CLI
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
up build --webpack
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Programmatic Usage
|
|
93
|
+
`@utoo/pack` provides a partial compatibility layer for Webpack.
|
|
84
94
|
|
|
85
95
|
```javascript
|
|
86
96
|
const { build } = require('@utoo/pack');
|
|
87
|
-
const { compatOptionsFromWebpack } = require('@utoo/pack/webpack-compat');
|
|
88
97
|
const webpackConfig = require('./webpack.config.js');
|
|
89
98
|
|
|
90
99
|
async function run() {
|
|
91
|
-
|
|
92
|
-
await build(options);
|
|
100
|
+
await build({ ...webpackConfig, webpackMode: true });
|
|
93
101
|
}
|
|
94
102
|
```
|
|
95
103
|
|
package/cjs/commands/build.js
CHANGED
|
@@ -1,56 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.build = build;
|
|
37
4
|
const pack_shared_1 = require("@utoo/pack-shared");
|
|
38
5
|
const child_process_1 = require("child_process");
|
|
39
|
-
const fs_1 =
|
|
6
|
+
const fs_1 = require("fs");
|
|
40
7
|
const nanoid_1 = require("nanoid");
|
|
41
8
|
const path_1 = require("path");
|
|
42
9
|
const webpackCompat_1 = require("../config/webpackCompat");
|
|
43
10
|
const project_1 = require("../core/project");
|
|
44
11
|
const HtmlPlugin_1 = require("../plugins/HtmlPlugin");
|
|
45
12
|
const common_1 = require("../utils/common");
|
|
46
|
-
const
|
|
47
|
-
const
|
|
13
|
+
const findRoot_1 = require("../utils/findRoot");
|
|
14
|
+
const getInitialAssets_1 = require("../utils/getInitialAssets");
|
|
15
|
+
const htmlEntry_1 = require("../utils/htmlEntry");
|
|
48
16
|
const xcodeProfile_1 = require("../utils/xcodeProfile");
|
|
49
17
|
function build(options, projectPath, rootPath) {
|
|
50
18
|
const bundleOptions = (0, webpackCompat_1.resolveBundleOptions)(options, projectPath, rootPath);
|
|
51
19
|
if (!rootPath) {
|
|
52
20
|
// help user to find the rootDir automatically.
|
|
53
|
-
rootPath = (0,
|
|
21
|
+
rootPath = (0, findRoot_1.findRootDir)(projectPath || process.cwd());
|
|
54
22
|
}
|
|
55
23
|
return buildInternal(bundleOptions, projectPath, rootPath);
|
|
56
24
|
}
|
|
@@ -60,7 +28,7 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
60
28
|
if (process.env.XCODE_PROFILE) {
|
|
61
29
|
await (0, xcodeProfile_1.xcodeProfilingReady)();
|
|
62
30
|
}
|
|
63
|
-
(0,
|
|
31
|
+
(0, htmlEntry_1.processHtmlEntry)(bundleOptions.config, projectPath || process.cwd());
|
|
64
32
|
const createProject = (0, project_1.projectFactory)();
|
|
65
33
|
const project = await createProject({
|
|
66
34
|
processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
|
|
@@ -100,23 +68,9 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
100
68
|
const assets = { js: [], css: [] };
|
|
101
69
|
const outputDir = ((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || (0, path_1.join)(process.cwd(), "dist");
|
|
102
70
|
if (assets.js.length === 0 && assets.css.length === 0) {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const stats = JSON.parse(fs_1.default.readFileSync(statsPath, "utf-8"));
|
|
107
|
-
if (stats.assets) {
|
|
108
|
-
stats.assets.forEach((asset) => {
|
|
109
|
-
if (asset.name.endsWith(".js"))
|
|
110
|
-
assets.js.push(asset.name);
|
|
111
|
-
if (asset.name.endsWith(".css"))
|
|
112
|
-
assets.css.push(asset.name);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
catch (e) {
|
|
117
|
-
console.warn("Failed to read stats.json for assets discovery", e);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
71
|
+
const discovered = (0, getInitialAssets_1.getInitialAssetsFromStats)(outputDir);
|
|
72
|
+
assets.js.push(...discovered.js);
|
|
73
|
+
assets.css.push(...discovered.css);
|
|
120
74
|
}
|
|
121
75
|
const publicPath = (_e = bundleOptions.config.output) === null || _e === void 0 ? void 0 : _e.publicPath;
|
|
122
76
|
for (const config of htmlConfigs) {
|
package/cjs/commands/dev.js
CHANGED
|
@@ -22,9 +22,9 @@ const url_1 = __importDefault(require("url"));
|
|
|
22
22
|
const webpackCompat_1 = require("../config/webpackCompat");
|
|
23
23
|
const hmr_1 = require("../core/hmr");
|
|
24
24
|
const common_1 = require("../utils/common");
|
|
25
|
-
const
|
|
25
|
+
const findRoot_1 = require("../utils/findRoot");
|
|
26
26
|
const mkcert_1 = require("../utils/mkcert");
|
|
27
|
-
const
|
|
27
|
+
const printServerInfo_1 = require("../utils/printServerInfo");
|
|
28
28
|
const xcodeProfile_1 = require("../utils/xcodeProfile");
|
|
29
29
|
function parsePath(pathStr) {
|
|
30
30
|
const hashIndex = pathStr.indexOf("#");
|
|
@@ -80,7 +80,7 @@ function normalizedPublicPath(publicPath) {
|
|
|
80
80
|
function serve(options, projectPath, rootPath, serverOptions) {
|
|
81
81
|
const bundleOptions = (0, webpackCompat_1.resolveBundleOptions)(options, projectPath, rootPath);
|
|
82
82
|
if (!rootPath) {
|
|
83
|
-
rootPath = (0,
|
|
83
|
+
rootPath = (0, findRoot_1.findRootDir)(projectPath || process.cwd());
|
|
84
84
|
}
|
|
85
85
|
return serveInternal(bundleOptions, projectPath, rootPath, serverOptions);
|
|
86
86
|
}
|
|
@@ -211,7 +211,7 @@ async function startServer(serverOptions, bundleOptions, projectPath, rootPath)
|
|
|
211
211
|
console.warn(`Port ${originalPort} is in use, using available port ${port} instead.`);
|
|
212
212
|
}
|
|
213
213
|
if (serverOptions.logServerInfo !== false) {
|
|
214
|
-
(0,
|
|
214
|
+
(0, printServerInfo_1.printServerInfo)(serverOptions.https ? "https" : "http", formattedHostname, port);
|
|
215
215
|
}
|
|
216
216
|
try {
|
|
217
217
|
let cleanupStarted = false;
|
package/cjs/core/hmr.js
CHANGED
|
@@ -5,20 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.FAST_REFRESH_RUNTIME_RELOAD = void 0;
|
|
7
7
|
exports.createHotReloader = createHotReloader;
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
8
|
const nanoid_1 = require("nanoid");
|
|
10
9
|
const path_1 = require("path");
|
|
11
10
|
const ws_1 = __importDefault(require("ws"));
|
|
12
11
|
const HtmlPlugin_1 = require("../plugins/HtmlPlugin");
|
|
13
12
|
const common_1 = require("../utils/common");
|
|
14
|
-
const
|
|
13
|
+
const getInitialAssets_1 = require("../utils/getInitialAssets");
|
|
14
|
+
const htmlEntry_1 = require("../utils/htmlEntry");
|
|
15
15
|
const project_1 = require("./project");
|
|
16
16
|
const wsServer = new ws_1.default.Server({ noServer: true });
|
|
17
17
|
const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random());
|
|
18
18
|
exports.FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
|
|
19
19
|
async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
20
20
|
var _a;
|
|
21
|
-
(0,
|
|
21
|
+
(0, htmlEntry_1.processHtmlEntry)(bundleOptions.config, projectPath || process.cwd());
|
|
22
22
|
const createProject = (0, project_1.projectFactory)();
|
|
23
23
|
const project = await createProject({
|
|
24
24
|
processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
|
|
@@ -141,12 +141,6 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
141
141
|
const assets = { js: [], css: [] };
|
|
142
142
|
await Promise.all(entrypoints.apps.map((l) => l.writeToDisk().then((res) => {
|
|
143
143
|
(0, common_1.processIssues)(res, true, true);
|
|
144
|
-
res.clientPaths.forEach((p) => {
|
|
145
|
-
if (p.endsWith(".js"))
|
|
146
|
-
assets.js.push(p);
|
|
147
|
-
if (p.endsWith(".css"))
|
|
148
|
-
assets.css.push(p);
|
|
149
|
-
});
|
|
150
144
|
})));
|
|
151
145
|
const htmlConfigs = [
|
|
152
146
|
...(Array.isArray(bundleOptions.config.html)
|
|
@@ -162,23 +156,9 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
162
156
|
const outputDir = ((_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.path) || (0, path_1.join)(process.cwd(), "dist");
|
|
163
157
|
const publicPath = (_b = bundleOptions.config.output) === null || _b === void 0 ? void 0 : _b.publicPath;
|
|
164
158
|
if (assets.js.length === 0 && assets.css.length === 0) {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const stats = JSON.parse(fs_1.default.readFileSync(statsPath, "utf-8"));
|
|
169
|
-
if (stats.assets) {
|
|
170
|
-
stats.assets.forEach((asset) => {
|
|
171
|
-
if (asset.name.endsWith(".js"))
|
|
172
|
-
assets.js.push(asset.name);
|
|
173
|
-
if (asset.name.endsWith(".css"))
|
|
174
|
-
assets.css.push(asset.name);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
catch (e) {
|
|
179
|
-
console.warn("Failed to read stats.json for assets discovery", e);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
159
|
+
const discovered = (0, getInitialAssets_1.getInitialAssetsFromStats)(outputDir);
|
|
160
|
+
assets.js.push(...discovered.js);
|
|
161
|
+
assets.css.push(...discovered.css);
|
|
182
162
|
}
|
|
183
163
|
for (const config of htmlConfigs) {
|
|
184
164
|
const plugin = new HtmlPlugin_1.HtmlPlugin(config);
|
package/cjs/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export default utoopack;
|
|
|
11
11
|
export * from "./config/types";
|
|
12
12
|
export * from "./config/webpackCompat";
|
|
13
13
|
export * from "./core/types";
|
|
14
|
-
export * from "./utils/
|
|
14
|
+
export * from "./utils/findRoot";
|
|
15
15
|
export type WebpackConfig = webpackCompat.WebpackConfig;
|
|
16
16
|
declare namespace utoopack {
|
|
17
17
|
type WebpackConfig = webpackCompat.WebpackConfig;
|
package/cjs/index.js
CHANGED
|
@@ -24,4 +24,4 @@ exports.default = utoopack;
|
|
|
24
24
|
__exportStar(require("./config/types"), exports);
|
|
25
25
|
__exportStar(require("./config/webpackCompat"), exports);
|
|
26
26
|
__exportStar(require("./core/types"), exports);
|
|
27
|
-
__exportStar(require("./utils/
|
|
27
|
+
__exportStar(require("./utils/findRoot"), exports);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getInitialAssetsFromStats = getInitialAssetsFromStats;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
function getInitialAssetsFromStats(outputDir) {
|
|
10
|
+
const assets = { js: [], css: [] };
|
|
11
|
+
const statsPath = (0, path_1.join)(outputDir, "stats.json");
|
|
12
|
+
if (fs_1.default.existsSync(statsPath)) {
|
|
13
|
+
try {
|
|
14
|
+
const stats = JSON.parse(fs_1.default.readFileSync(statsPath, "utf-8"));
|
|
15
|
+
if (stats.entrypoints) {
|
|
16
|
+
Object.values(stats.entrypoints).forEach((entrypoint) => {
|
|
17
|
+
var _a;
|
|
18
|
+
(_a = entrypoint.assets) === null || _a === void 0 ? void 0 : _a.forEach((asset) => {
|
|
19
|
+
if (asset.name.endsWith(".js") && !assets.js.includes(asset.name)) {
|
|
20
|
+
assets.js.push(asset.name);
|
|
21
|
+
}
|
|
22
|
+
if (asset.name.endsWith(".css") &&
|
|
23
|
+
!assets.css.includes(asset.name)) {
|
|
24
|
+
assets.css.push(asset.name);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.warn("Failed to read stats.json for assets discovery", e);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return assets;
|
|
35
|
+
}
|
|
@@ -21,7 +21,11 @@ function processHtmlEntry(config, projectPath) {
|
|
|
21
21
|
const scripts = doc.querySelectorAll("script");
|
|
22
22
|
scripts.forEach((script) => {
|
|
23
23
|
const src = script.getAttribute("src");
|
|
24
|
-
|
|
24
|
+
const type = script.getAttribute("type");
|
|
25
|
+
if (src &&
|
|
26
|
+
!src.startsWith("http") &&
|
|
27
|
+
!src.startsWith("//") &&
|
|
28
|
+
type === "module") {
|
|
25
29
|
const scriptPath = path_1.default.join(path_1.default.dirname(entry.import), src);
|
|
26
30
|
// Remove the origin script tag from the DOM
|
|
27
31
|
if (script.parentNode) {
|
package/esm/commands/build.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { handleIssues } from "@utoo/pack-shared";
|
|
2
2
|
import { spawn } from "child_process";
|
|
3
|
-
import
|
|
3
|
+
import { existsSync } from "fs";
|
|
4
4
|
import { nanoid } from "nanoid";
|
|
5
5
|
import { join } from "path";
|
|
6
6
|
import { resolveBundleOptions } from "../config/webpackCompat";
|
|
7
7
|
import { projectFactory } from "../core/project";
|
|
8
8
|
import { HtmlPlugin } from "../plugins/HtmlPlugin";
|
|
9
9
|
import { blockStdout, createDefineEnv, getPackPath } from "../utils/common";
|
|
10
|
-
import { findRootDir } from "../utils/
|
|
11
|
-
import {
|
|
10
|
+
import { findRootDir } from "../utils/findRoot";
|
|
11
|
+
import { getInitialAssetsFromStats } from "../utils/getInitialAssets";
|
|
12
|
+
import { processHtmlEntry } from "../utils/htmlEntry";
|
|
12
13
|
import { xcodeProfilingReady } from "../utils/xcodeProfile";
|
|
13
14
|
export function build(options, projectPath, rootPath) {
|
|
14
15
|
const bundleOptions = resolveBundleOptions(options, projectPath, rootPath);
|
|
@@ -64,23 +65,9 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
64
65
|
const assets = { js: [], css: [] };
|
|
65
66
|
const outputDir = ((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || join(process.cwd(), "dist");
|
|
66
67
|
if (assets.js.length === 0 && assets.css.length === 0) {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const stats = JSON.parse(fs.readFileSync(statsPath, "utf-8"));
|
|
71
|
-
if (stats.assets) {
|
|
72
|
-
stats.assets.forEach((asset) => {
|
|
73
|
-
if (asset.name.endsWith(".js"))
|
|
74
|
-
assets.js.push(asset.name);
|
|
75
|
-
if (asset.name.endsWith(".css"))
|
|
76
|
-
assets.css.push(asset.name);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
console.warn("Failed to read stats.json for assets discovery", e);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
68
|
+
const discovered = getInitialAssetsFromStats(outputDir);
|
|
69
|
+
assets.js.push(...discovered.js);
|
|
70
|
+
assets.css.push(...discovered.css);
|
|
84
71
|
}
|
|
85
72
|
const publicPath = (_e = bundleOptions.config.output) === null || _e === void 0 ? void 0 : _e.publicPath;
|
|
86
73
|
for (const config of htmlConfigs) {
|
package/esm/commands/dev.js
CHANGED
|
@@ -8,9 +8,9 @@ import url from "url";
|
|
|
8
8
|
import { resolveBundleOptions } from "../config/webpackCompat";
|
|
9
9
|
import { createHotReloader } from "../core/hmr";
|
|
10
10
|
import { blockStdout, getPackPath } from "../utils/common";
|
|
11
|
-
import { findRootDir } from "../utils/
|
|
11
|
+
import { findRootDir } from "../utils/findRoot";
|
|
12
12
|
import { createSelfSignedCertificate } from "../utils/mkcert";
|
|
13
|
-
import { printServerInfo } from "../utils/
|
|
13
|
+
import { printServerInfo } from "../utils/printServerInfo";
|
|
14
14
|
import { xcodeProfilingReady } from "../utils/xcodeProfile";
|
|
15
15
|
function parsePath(pathStr) {
|
|
16
16
|
const hashIndex = pathStr.indexOf("#");
|
package/esm/core/hmr.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
1
|
import { nanoid } from "nanoid";
|
|
3
2
|
import { join } from "path";
|
|
4
3
|
import ws from "ws";
|
|
5
4
|
import { HtmlPlugin } from "../plugins/HtmlPlugin";
|
|
6
5
|
import { createDefineEnv, debounce, getPackPath, processIssues, } from "../utils/common";
|
|
7
|
-
import {
|
|
6
|
+
import { getInitialAssetsFromStats } from "../utils/getInitialAssets";
|
|
7
|
+
import { processHtmlEntry } from "../utils/htmlEntry";
|
|
8
8
|
import { projectFactory } from "./project";
|
|
9
9
|
const wsServer = new ws.Server({ noServer: true });
|
|
10
10
|
const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random());
|
|
@@ -134,12 +134,6 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
134
134
|
const assets = { js: [], css: [] };
|
|
135
135
|
await Promise.all(entrypoints.apps.map((l) => l.writeToDisk().then((res) => {
|
|
136
136
|
processIssues(res, true, true);
|
|
137
|
-
res.clientPaths.forEach((p) => {
|
|
138
|
-
if (p.endsWith(".js"))
|
|
139
|
-
assets.js.push(p);
|
|
140
|
-
if (p.endsWith(".css"))
|
|
141
|
-
assets.css.push(p);
|
|
142
|
-
});
|
|
143
137
|
})));
|
|
144
138
|
const htmlConfigs = [
|
|
145
139
|
...(Array.isArray(bundleOptions.config.html)
|
|
@@ -155,23 +149,9 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
155
149
|
const outputDir = ((_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.path) || join(process.cwd(), "dist");
|
|
156
150
|
const publicPath = (_b = bundleOptions.config.output) === null || _b === void 0 ? void 0 : _b.publicPath;
|
|
157
151
|
if (assets.js.length === 0 && assets.css.length === 0) {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const stats = JSON.parse(fs.readFileSync(statsPath, "utf-8"));
|
|
162
|
-
if (stats.assets) {
|
|
163
|
-
stats.assets.forEach((asset) => {
|
|
164
|
-
if (asset.name.endsWith(".js"))
|
|
165
|
-
assets.js.push(asset.name);
|
|
166
|
-
if (asset.name.endsWith(".css"))
|
|
167
|
-
assets.css.push(asset.name);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
catch (e) {
|
|
172
|
-
console.warn("Failed to read stats.json for assets discovery", e);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
152
|
+
const discovered = getInitialAssetsFromStats(outputDir);
|
|
153
|
+
assets.js.push(...discovered.js);
|
|
154
|
+
assets.css.push(...discovered.css);
|
|
175
155
|
}
|
|
176
156
|
for (const config of htmlConfigs) {
|
|
177
157
|
const plugin = new HtmlPlugin(config);
|
package/esm/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export default utoopack;
|
|
|
11
11
|
export * from "./config/types";
|
|
12
12
|
export * from "./config/webpackCompat";
|
|
13
13
|
export * from "./core/types";
|
|
14
|
-
export * from "./utils/
|
|
14
|
+
export * from "./utils/findRoot";
|
|
15
15
|
export type WebpackConfig = webpackCompat.WebpackConfig;
|
|
16
16
|
declare namespace utoopack {
|
|
17
17
|
type WebpackConfig = webpackCompat.WebpackConfig;
|
package/esm/index.js
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
export function getInitialAssetsFromStats(outputDir) {
|
|
4
|
+
const assets = { js: [], css: [] };
|
|
5
|
+
const statsPath = join(outputDir, "stats.json");
|
|
6
|
+
if (fs.existsSync(statsPath)) {
|
|
7
|
+
try {
|
|
8
|
+
const stats = JSON.parse(fs.readFileSync(statsPath, "utf-8"));
|
|
9
|
+
if (stats.entrypoints) {
|
|
10
|
+
Object.values(stats.entrypoints).forEach((entrypoint) => {
|
|
11
|
+
var _a;
|
|
12
|
+
(_a = entrypoint.assets) === null || _a === void 0 ? void 0 : _a.forEach((asset) => {
|
|
13
|
+
if (asset.name.endsWith(".js") && !assets.js.includes(asset.name)) {
|
|
14
|
+
assets.js.push(asset.name);
|
|
15
|
+
}
|
|
16
|
+
if (asset.name.endsWith(".css") &&
|
|
17
|
+
!assets.css.includes(asset.name)) {
|
|
18
|
+
assets.css.push(asset.name);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
console.warn("Failed to read stats.json for assets discovery", e);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return assets;
|
|
29
|
+
}
|
|
@@ -15,7 +15,11 @@ export function processHtmlEntry(config, projectPath) {
|
|
|
15
15
|
const scripts = doc.querySelectorAll("script");
|
|
16
16
|
scripts.forEach((script) => {
|
|
17
17
|
const src = script.getAttribute("src");
|
|
18
|
-
|
|
18
|
+
const type = script.getAttribute("type");
|
|
19
|
+
if (src &&
|
|
20
|
+
!src.startsWith("http") &&
|
|
21
|
+
!src.startsWith("//") &&
|
|
22
|
+
type === "module") {
|
|
19
23
|
const scriptPath = path.join(path.dirname(entry.import), src);
|
|
20
24
|
// Remove the origin script tag from the DOM
|
|
21
25
|
if (script.parentNode) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/pack",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.23-rc.1",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"types": "esm/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@babel/code-frame": "7.22.5",
|
|
41
41
|
"@swc/helpers": "0.5.15",
|
|
42
|
-
"@utoo/pack-shared": "1.1.
|
|
42
|
+
"@utoo/pack-shared": "1.1.23-rc.1",
|
|
43
43
|
"@utoo/style-loader": "^1.0.0",
|
|
44
44
|
"domparser-rs": "^0.0.5",
|
|
45
45
|
"find-up": "4.1.0",
|
|
@@ -86,12 +86,12 @@
|
|
|
86
86
|
},
|
|
87
87
|
"repository": "git@github.com:utooland/utoo.git",
|
|
88
88
|
"optionalDependencies": {
|
|
89
|
-
"@utoo/pack-darwin-arm64": "1.1.
|
|
90
|
-
"@utoo/pack-darwin-x64": "1.1.
|
|
91
|
-
"@utoo/pack-linux-arm64-gnu": "1.1.
|
|
92
|
-
"@utoo/pack-linux-arm64-musl": "1.1.
|
|
93
|
-
"@utoo/pack-linux-x64-gnu": "1.1.
|
|
94
|
-
"@utoo/pack-linux-x64-musl": "1.1.
|
|
95
|
-
"@utoo/pack-win32-x64-msvc": "1.1.
|
|
89
|
+
"@utoo/pack-darwin-arm64": "1.1.23-rc.1",
|
|
90
|
+
"@utoo/pack-darwin-x64": "1.1.23-rc.1",
|
|
91
|
+
"@utoo/pack-linux-arm64-gnu": "1.1.23-rc.1",
|
|
92
|
+
"@utoo/pack-linux-arm64-musl": "1.1.23-rc.1",
|
|
93
|
+
"@utoo/pack-linux-x64-gnu": "1.1.23-rc.1",
|
|
94
|
+
"@utoo/pack-linux-x64-musl": "1.1.23-rc.1",
|
|
95
|
+
"@utoo/pack-win32-x64-msvc": "1.1.23-rc.1"
|
|
96
96
|
}
|
|
97
97
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|