@dcloudio/vite-plugin-uni 0.0.1-nvue3.3030820220125001
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 +202 -0
- package/bin/uni.js +22 -0
- package/dist/cli/action.d.ts +4 -0
- package/dist/cli/action.js +76 -0
- package/dist/cli/build.d.ts +5 -0
- package/dist/cli/build.js +147 -0
- package/dist/cli/index.d.ts +20 -0
- package/dist/cli/index.js +50 -0
- package/dist/cli/nvue.d.ts +1 -0
- package/dist/cli/nvue.js +24 -0
- package/dist/cli/server.d.ts +4 -0
- package/dist/cli/server.js +120 -0
- package/dist/cli/utils.d.ts +25 -0
- package/dist/cli/utils.js +189 -0
- package/dist/config/build.d.ts +3 -0
- package/dist/config/build.js +35 -0
- package/dist/config/css.d.ts +3 -0
- package/dist/config/css.js +28 -0
- package/dist/config/define.d.ts +3 -0
- package/dist/config/define.js +15 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +36 -0
- package/dist/config/optimizeDeps.d.ts +3 -0
- package/dist/config/optimizeDeps.js +18 -0
- package/dist/config/resolve.d.ts +4 -0
- package/dist/config/resolve.js +33 -0
- package/dist/configResolved/env.d.ts +2 -0
- package/dist/configResolved/env.js +28 -0
- package/dist/configResolved/index.d.ts +25 -0
- package/dist/configResolved/index.js +59 -0
- package/dist/configResolved/options.d.ts +3 -0
- package/dist/configResolved/options.js +19 -0
- package/dist/configResolved/plugins/index.d.ts +8 -0
- package/dist/configResolved/plugins/index.js +54 -0
- package/dist/configResolved/plugins/json.d.ts +3 -0
- package/dist/configResolved/plugins/json.js +33 -0
- package/dist/configResolved/plugins/pre.d.ts +3 -0
- package/dist/configResolved/plugins/pre.js +51 -0
- package/dist/configResolved/plugins/preCss.d.ts +7 -0
- package/dist/configResolved/plugins/preCss.js +41 -0
- package/dist/configResolved/plugins/preVue.d.ts +6 -0
- package/dist/configResolved/plugins/preVue.js +146 -0
- package/dist/configResolved/plugins/resolveId.d.ts +15 -0
- package/dist/configResolved/plugins/resolveId.js +37 -0
- package/dist/configResolved/plugins/ssr.d.ts +3 -0
- package/dist/configResolved/plugins/ssr.js +63 -0
- package/dist/configResolved/plugins/static.d.ts +9 -0
- package/dist/configResolved/plugins/static.js +44 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +81 -0
- package/dist/plugins/copy.d.ts +3 -0
- package/dist/plugins/copy.js +55 -0
- package/dist/resolveId/index.d.ts +3 -0
- package/dist/resolveId/index.js +16 -0
- package/dist/utils/easycom.d.ts +2 -0
- package/dist/utils/easycom.js +37 -0
- package/dist/utils/filter.d.ts +1 -0
- package/dist/utils/filter.js +15 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/plugin.d.ts +26 -0
- package/dist/utils/plugin.js +115 -0
- package/dist/utils/polyfill.d.ts +4 -0
- package/dist/utils/polyfill.js +28 -0
- package/dist/vue/index.d.ts +1 -0
- package/dist/vue/index.js +13 -0
- package/dist/vue/options.d.ts +10 -0
- package/dist/vue/options.js +117 -0
- package/package.json +62 -0
|
@@ -0,0 +1,120 @@
|
|
|
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.createSSRServer = exports.createServer = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
10
|
+
const vite_1 = require("vite");
|
|
11
|
+
const express_1 = __importDefault(require("express"));
|
|
12
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
async function createServer(options) {
|
|
15
|
+
const server = await (0, vite_1.createServer)((0, utils_1.addConfigFile)({
|
|
16
|
+
root: process.env.VITE_ROOT_DIR,
|
|
17
|
+
mode: options.mode,
|
|
18
|
+
logLevel: options.logLevel,
|
|
19
|
+
clearScreen: options.clearScreen,
|
|
20
|
+
server: (0, utils_1.cleanOptions)(options),
|
|
21
|
+
}));
|
|
22
|
+
await server.listen();
|
|
23
|
+
const logger = server.config.logger;
|
|
24
|
+
logger.info(picocolors_1.default.cyan(`\n vite v${require('vite/package.json').version}`) +
|
|
25
|
+
picocolors_1.default.green(` dev server running at:\n`), {
|
|
26
|
+
clear: !server.config.logger.hasWarned,
|
|
27
|
+
});
|
|
28
|
+
server.printUrls();
|
|
29
|
+
// printUrls 会在 nextTick 中输出
|
|
30
|
+
process.nextTick(() => (0, utils_1.printStartupDuration)(logger));
|
|
31
|
+
return server;
|
|
32
|
+
}
|
|
33
|
+
exports.createServer = createServer;
|
|
34
|
+
async function createSSRServer(options) {
|
|
35
|
+
const app = (0, express_1.default)();
|
|
36
|
+
/**
|
|
37
|
+
* @type {import('vite').ViteDevServer}
|
|
38
|
+
*/
|
|
39
|
+
const vite = await (0, vite_1.createServer)((0, utils_1.addConfigFile)({
|
|
40
|
+
root: process.env.VITE_ROOT_DIR,
|
|
41
|
+
mode: options.mode,
|
|
42
|
+
logLevel: options.logLevel,
|
|
43
|
+
clearScreen: options.clearScreen,
|
|
44
|
+
server: {
|
|
45
|
+
middlewareMode: true,
|
|
46
|
+
watch: {
|
|
47
|
+
// During tests we edit the files too fast and sometimes chokidar
|
|
48
|
+
// misses change events, so enforce polling for consistency
|
|
49
|
+
usePolling: true,
|
|
50
|
+
interval: 100,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
}));
|
|
54
|
+
// use vite's connect instance as middleware
|
|
55
|
+
app.use(vite.middlewares);
|
|
56
|
+
app.use('*', async (req, res) => {
|
|
57
|
+
try {
|
|
58
|
+
const { h5 } = (0, uni_cli_shared_1.parseManifestJson)(process.env.UNI_INPUT_DIR);
|
|
59
|
+
const base = (h5 && h5.router && h5.router.base) || '';
|
|
60
|
+
const url = req.originalUrl.replace(base, '');
|
|
61
|
+
const template = await vite.transformIndexHtml(url, fs_1.default.readFileSync(path_1.default.resolve(process.env.VITE_ROOT_DIR, 'index.html'), 'utf-8'));
|
|
62
|
+
const render = (await vite.ssrLoadModule(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'entry-server.js'))).render;
|
|
63
|
+
const { title, headMeta, preloadLinks, appHtml, appContext } = await render(url);
|
|
64
|
+
const icon = template.includes('rel="icon"')
|
|
65
|
+
? ''
|
|
66
|
+
: '<link rel="icon" href="data:," />\n';
|
|
67
|
+
const html = template
|
|
68
|
+
.replace(/<title>(.*?)<\/title>/, `${icon}<title>${title}</title>`)
|
|
69
|
+
.replace(`<!--head-meta-->`, headMeta)
|
|
70
|
+
.replace(`<!--preload-links-->`, preloadLinks)
|
|
71
|
+
.replace(`<!--app-html-->`, appHtml)
|
|
72
|
+
.replace(`<!--app-context-->`, appContext);
|
|
73
|
+
res.status(200).set({ 'Content-Type': 'text/html' }).end(html);
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
vite && vite.ssrFixStacktrace(e);
|
|
77
|
+
res.status(500).end(e.stack);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const logger = (0, vite_1.createLogger)(options.logLevel);
|
|
81
|
+
const serverOptions = vite.config.server || {};
|
|
82
|
+
let port = options.port || serverOptions.port || 3000;
|
|
83
|
+
let hostname;
|
|
84
|
+
if (options.host === 'localhost') {
|
|
85
|
+
// Use a secure default
|
|
86
|
+
hostname = '127.0.0.1';
|
|
87
|
+
}
|
|
88
|
+
else if (options.host === undefined || options.host === true) {
|
|
89
|
+
// probably passed --host in the CLI, without arguments
|
|
90
|
+
hostname = undefined; // undefined typically means 0.0.0.0 or :: (listen on all IPs)
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
hostname = options.host;
|
|
94
|
+
}
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
const onSuccess = () => {
|
|
97
|
+
(0, vite_1.printHttpServerUrls)(server, vite.config);
|
|
98
|
+
process.nextTick(() => (0, utils_1.printStartupDuration)(logger));
|
|
99
|
+
resolve(vite);
|
|
100
|
+
};
|
|
101
|
+
const onError = (e) => {
|
|
102
|
+
if (e.code === 'EADDRINUSE') {
|
|
103
|
+
if (options.strictPort) {
|
|
104
|
+
server.off('error', onError);
|
|
105
|
+
reject(new Error(`Port ${port} is already in use`));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
logger.info(`Port ${port} is in use, trying another one...`);
|
|
109
|
+
app.listen(++port, hostname, onSuccess).on('error', onError);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
server.off('error', onError);
|
|
114
|
+
reject(e);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const server = app.listen(port, hostname, onSuccess).on('error', onError);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
exports.createSSRServer = createSSRServer;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { InlineConfig, Logger } from 'vite';
|
|
2
|
+
import { CliOptions } from '.';
|
|
3
|
+
export declare const PLATFORMS: string[];
|
|
4
|
+
export declare function addConfigFile(inlineConfig: InlineConfig): InlineConfig;
|
|
5
|
+
export declare function initEnv(type: 'dev' | 'build', options: CliOptions): void;
|
|
6
|
+
export declare function cleanOptions(options: CliOptions): {
|
|
7
|
+
'--'?: string[] | undefined;
|
|
8
|
+
platform?: string | undefined;
|
|
9
|
+
p?: string | undefined;
|
|
10
|
+
ssr?: boolean | undefined;
|
|
11
|
+
debug?: string | boolean | undefined;
|
|
12
|
+
d?: string | boolean | undefined;
|
|
13
|
+
filter?: string | undefined;
|
|
14
|
+
f?: string | undefined;
|
|
15
|
+
logLevel?: import("vite").LogLevel | undefined;
|
|
16
|
+
l?: import("vite").LogLevel | undefined;
|
|
17
|
+
m?: string | undefined;
|
|
18
|
+
mode?: string | undefined;
|
|
19
|
+
clearScreen?: boolean | undefined;
|
|
20
|
+
autoHost?: string | undefined;
|
|
21
|
+
autoPort?: number | undefined;
|
|
22
|
+
subpackage?: string | undefined;
|
|
23
|
+
plugin?: boolean | undefined;
|
|
24
|
+
};
|
|
25
|
+
export declare function printStartupDuration(logger: Logger, whitespace?: boolean): void;
|
|
@@ -0,0 +1,189 @@
|
|
|
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.printStartupDuration = exports.cleanOptions = exports.initEnv = exports.addConfigFile = exports.PLATFORMS = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
11
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
12
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
13
|
+
const nvue_1 = require("./nvue");
|
|
14
|
+
exports.PLATFORMS = [
|
|
15
|
+
'app',
|
|
16
|
+
'h5',
|
|
17
|
+
'mp-alipay',
|
|
18
|
+
'mp-baidu',
|
|
19
|
+
'mp-qq',
|
|
20
|
+
'mp-lark',
|
|
21
|
+
'mp-toutiao',
|
|
22
|
+
'mp-weixin',
|
|
23
|
+
'quickapp-webview',
|
|
24
|
+
'quickapp-webview-huawei',
|
|
25
|
+
'quickapp-webview-union',
|
|
26
|
+
];
|
|
27
|
+
function resolveConfigFile() {
|
|
28
|
+
const viteConfigJs = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'vite.config.js');
|
|
29
|
+
const viteConfigTs = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'vite.config.ts');
|
|
30
|
+
if (fs_1.default.existsSync(viteConfigTs)) {
|
|
31
|
+
return viteConfigTs;
|
|
32
|
+
}
|
|
33
|
+
if (fs_1.default.existsSync(viteConfigJs)) {
|
|
34
|
+
return viteConfigJs;
|
|
35
|
+
}
|
|
36
|
+
return path_1.default.resolve(process.env.UNI_CLI_CONTEXT, 'vite.config.js');
|
|
37
|
+
}
|
|
38
|
+
function addConfigFile(inlineConfig) {
|
|
39
|
+
if ((0, uni_cli_shared_1.isInHBuilderX)()) {
|
|
40
|
+
inlineConfig.configFile = resolveConfigFile();
|
|
41
|
+
}
|
|
42
|
+
return inlineConfig;
|
|
43
|
+
}
|
|
44
|
+
exports.addConfigFile = addConfigFile;
|
|
45
|
+
function initEnv(type, options) {
|
|
46
|
+
if (options.platform === 'mp-360') {
|
|
47
|
+
console.error(uni_cli_shared_1.M['mp.360.unsupported']);
|
|
48
|
+
process.exit(0);
|
|
49
|
+
}
|
|
50
|
+
if (options.plugin) {
|
|
51
|
+
process.env.UNI_MP_PLUGIN = 'true';
|
|
52
|
+
}
|
|
53
|
+
if (type === 'dev') {
|
|
54
|
+
process.env.NODE_ENV = 'development';
|
|
55
|
+
}
|
|
56
|
+
else if (type === 'build') {
|
|
57
|
+
if (options.watch) {
|
|
58
|
+
process.env.NODE_ENV = 'development';
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
process.env.NODE_ENV = 'production';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!options.mode) {
|
|
65
|
+
options.mode = process.env.NODE_ENV;
|
|
66
|
+
}
|
|
67
|
+
// vite 会修改 NODE_ENV,存储在 UNI_NODE_ENV 中,稍后校正 NODE_ENV
|
|
68
|
+
process.env.UNI_NODE_ENV = process.env.VITE_USER_NODE_ENV =
|
|
69
|
+
process.env.NODE_ENV;
|
|
70
|
+
process.env.UNI_CLI_CONTEXT = (0, uni_cli_shared_1.isInHBuilderX)()
|
|
71
|
+
? path_1.default.resolve(process.env.UNI_HBUILDERX_PLUGINS, 'uniapp-cli-vite')
|
|
72
|
+
: process.cwd();
|
|
73
|
+
if (options.platform === 'app-plus') {
|
|
74
|
+
options.platform = 'app';
|
|
75
|
+
}
|
|
76
|
+
if (options.platform === 'quickapp-webview-huawei' ||
|
|
77
|
+
options.platform === 'quickapp-webview-union') {
|
|
78
|
+
process.env.UNI_SUB_PLATFORM = options.platform;
|
|
79
|
+
options.platform = 'quickapp-webview';
|
|
80
|
+
}
|
|
81
|
+
process.env.VITE_ROOT_DIR = process.env.UNI_INPUT_DIR || process.cwd();
|
|
82
|
+
process.env.UNI_INPUT_DIR =
|
|
83
|
+
process.env.UNI_INPUT_DIR || path_1.default.resolve(process.cwd(), 'src');
|
|
84
|
+
initCustomScripts(options);
|
|
85
|
+
process.env.UNI_PLATFORM = options.platform;
|
|
86
|
+
const hasOutputDir = !!process.env.UNI_OUTPUT_DIR;
|
|
87
|
+
if (hasOutputDir) {
|
|
88
|
+
;
|
|
89
|
+
options.outDir = process.env.UNI_OUTPUT_DIR;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (!options.outDir) {
|
|
93
|
+
;
|
|
94
|
+
options.outDir = path_1.default.resolve(process.cwd(), 'dist', process.env.NODE_ENV === 'production' ? 'build' : 'dev', process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM);
|
|
95
|
+
}
|
|
96
|
+
process.env.UNI_OUTPUT_DIR = options.outDir;
|
|
97
|
+
}
|
|
98
|
+
// 兼容 HBuilderX 旧参数
|
|
99
|
+
if (process.env.UNI_SUBPACKGE) {
|
|
100
|
+
options.subpackage = process.env.UNI_SUBPACKGE;
|
|
101
|
+
}
|
|
102
|
+
if (options.subpackage) {
|
|
103
|
+
process.env.UNI_SUBPACKAGE = options.subpackage;
|
|
104
|
+
if (!hasOutputDir) {
|
|
105
|
+
// 未指定,则自动补充
|
|
106
|
+
process.env.UNI_OUTPUT_DIR = options.outDir =
|
|
107
|
+
path_1.default.resolve(process.env.UNI_OUTPUT_DIR, options.subpackage);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
initAutomator(options);
|
|
111
|
+
if (process.env.UNI_PLATFORM === 'app') {
|
|
112
|
+
const pkg = require('../../package.json');
|
|
113
|
+
console.log(uni_cli_shared_1.M['app.compiler.version'].replace('{version}', pkg['uni-app']['compilerVersion'] + '(vue3)'));
|
|
114
|
+
(0, nvue_1.initNVueEnv)();
|
|
115
|
+
}
|
|
116
|
+
if (process.env.NODE_ENV === 'development') {
|
|
117
|
+
console.log(uni_cli_shared_1.M['dev.performance'] +
|
|
118
|
+
(process.env.UNI_PLATFORM.startsWith('mp-')
|
|
119
|
+
? uni_cli_shared_1.M['dev.performance.mp']
|
|
120
|
+
: ''));
|
|
121
|
+
}
|
|
122
|
+
(0, uni_cli_shared_1.initModulePaths)();
|
|
123
|
+
console.log(uni_cli_shared_1.M['compiling']);
|
|
124
|
+
}
|
|
125
|
+
exports.initEnv = initEnv;
|
|
126
|
+
function initAutomator({ autoHost, autoPort }) {
|
|
127
|
+
// 发行分包,插件也不需要自动化测试
|
|
128
|
+
if (!autoPort || process.env.UNI_SUBPACKAGE || process.env.UNI_MP_PLUGIN) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
process.env.UNI_AUTOMATOR_WS_ENDPOINT =
|
|
132
|
+
'ws://' + (autoHost || resolveHostname()) + ':' + autoPort;
|
|
133
|
+
}
|
|
134
|
+
function resolveHostname() {
|
|
135
|
+
const interfaces = os_1.default.networkInterfaces();
|
|
136
|
+
const keys = Object.keys(interfaces);
|
|
137
|
+
for (const key of keys) {
|
|
138
|
+
const interfaceInfos = interfaces[key];
|
|
139
|
+
if (!interfaceInfos) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
for (const info of interfaceInfos) {
|
|
143
|
+
if (info.family === 'IPv4' && !info.address.includes('127.0.0.1')) {
|
|
144
|
+
return info.address;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return 'localhost';
|
|
149
|
+
}
|
|
150
|
+
function cleanOptions(options) {
|
|
151
|
+
const ret = { ...options };
|
|
152
|
+
delete ret['--'];
|
|
153
|
+
delete ret.platform;
|
|
154
|
+
delete ret.p;
|
|
155
|
+
delete ret.ssr;
|
|
156
|
+
delete ret.debug;
|
|
157
|
+
delete ret.d;
|
|
158
|
+
delete ret.filter;
|
|
159
|
+
delete ret.f;
|
|
160
|
+
delete ret.logLevel;
|
|
161
|
+
delete ret.l;
|
|
162
|
+
delete ret.clearScreen;
|
|
163
|
+
delete ret.m;
|
|
164
|
+
delete ret.mode;
|
|
165
|
+
delete ret.autoHost;
|
|
166
|
+
delete ret.autoPort;
|
|
167
|
+
return ret;
|
|
168
|
+
}
|
|
169
|
+
exports.cleanOptions = cleanOptions;
|
|
170
|
+
function printStartupDuration(logger, whitespace = true) {
|
|
171
|
+
// @ts-ignore
|
|
172
|
+
if (global.__vite_start_time) {
|
|
173
|
+
// @ts-ignore
|
|
174
|
+
const startupDuration = perf_hooks_1.performance.now() - global.__vite_start_time;
|
|
175
|
+
logger.info(`${whitespace ? `\n ` : ''}${picocolors_1.default.cyan(`ready in ${Math.ceil(startupDuration)}ms.`)}\n`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.printStartupDuration = printStartupDuration;
|
|
179
|
+
function initCustomScripts(options) {
|
|
180
|
+
const custom = (0, uni_cli_shared_1.parseScripts)(process.env.UNI_SCRIPT || options.platform, // process.env.UNI_SCRIPT 是 HBuilderX 传递的
|
|
181
|
+
path_1.default.join(process.env.VITE_ROOT_DIR, 'package.json'));
|
|
182
|
+
if (!custom) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
options.platform = custom.platform;
|
|
186
|
+
process.env.UNI_CUSTOM_SCRIPT = custom.name;
|
|
187
|
+
process.env.UNI_CUSTOM_DEFINE = JSON.stringify(custom.define);
|
|
188
|
+
process.env.UNI_CUSTOM_CONTEXT = JSON.stringify(custom.context);
|
|
189
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBuild = void 0;
|
|
4
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
5
|
+
const shared_1 = require("@vue/shared");
|
|
6
|
+
function createBuild(options, config) {
|
|
7
|
+
(0, uni_cli_shared_1.initEasycomsOnce)(options.inputDir, {
|
|
8
|
+
dirs: [(0, uni_cli_shared_1.resolveComponentsLibPath)()],
|
|
9
|
+
platform: process.env.UNI_PLATFORM,
|
|
10
|
+
});
|
|
11
|
+
return {
|
|
12
|
+
cssTarget: uni_cli_shared_1.cssTarget,
|
|
13
|
+
chunkSizeWarningLimit: 100000000,
|
|
14
|
+
minify: config.build && (0, shared_1.hasOwn)(config.build, 'minify')
|
|
15
|
+
? config.build.minify
|
|
16
|
+
: process.env.NODE_ENV === 'production'
|
|
17
|
+
? 'terser'
|
|
18
|
+
: false,
|
|
19
|
+
rollupOptions: {
|
|
20
|
+
onwarn(warning, warn) {
|
|
21
|
+
if (warning.code === 'UNUSED_EXTERNAL_IMPORT') {
|
|
22
|
+
const { message } = warning;
|
|
23
|
+
// ignore
|
|
24
|
+
if (message.includes('"vue"') ||
|
|
25
|
+
message.includes('"resolveComponent"') ||
|
|
26
|
+
message.includes('"@dcloudio/uni-h5"')) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
warn(warning);
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.createBuild = createBuild;
|
|
@@ -0,0 +1,28 @@
|
|
|
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.createCss = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
function resolveAdditionalData(inputDir, config) {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
const uniScssFile = path_1.default.resolve(inputDir, 'uni.scss');
|
|
12
|
+
const userAdditionalData = ((_c = (_b = (_a = config.css) === null || _a === void 0 ? void 0 : _a.preprocessorOptions) === null || _b === void 0 ? void 0 : _b.scss) === null || _c === void 0 ? void 0 : _c.additionalData) || '';
|
|
13
|
+
if (!fs_extra_1.default.existsSync(uniScssFile)) {
|
|
14
|
+
return userAdditionalData;
|
|
15
|
+
}
|
|
16
|
+
return fs_extra_1.default.readFileSync(uniScssFile, 'utf8') + '\n' + userAdditionalData;
|
|
17
|
+
}
|
|
18
|
+
function createCss(options, config) {
|
|
19
|
+
return {
|
|
20
|
+
preprocessorOptions: {
|
|
21
|
+
scss: {
|
|
22
|
+
charset: false,
|
|
23
|
+
additionalData: resolveAdditionalData(options.inputDir, config),
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.createCss = createCss;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDefine = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
6
|
+
function createDefine(_) {
|
|
7
|
+
return (0, shared_1.extend)({
|
|
8
|
+
__VUE_PROD_DEVTOOLS__: false,
|
|
9
|
+
__VUE_I18N_FULL_INSTALL__: true,
|
|
10
|
+
__VUE_I18N_LEGACY_API__: true,
|
|
11
|
+
__VUE_I18N_PROD_DEVTOOLS__: false,
|
|
12
|
+
__INTLIFY_PROD_DEVTOOLS__: false,
|
|
13
|
+
}, (0, uni_cli_shared_1.initDefine)());
|
|
14
|
+
}
|
|
15
|
+
exports.createDefine = createDefine;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConfig = void 0;
|
|
4
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
5
|
+
const css_1 = require("./css");
|
|
6
|
+
const resolve_1 = require("./resolve");
|
|
7
|
+
const build_1 = require("./build");
|
|
8
|
+
const optimizeDeps_1 = require("./optimizeDeps");
|
|
9
|
+
const define_1 = require("./define");
|
|
10
|
+
function createConfig(options, _uniPlugins) {
|
|
11
|
+
return (config, env) => {
|
|
12
|
+
options.command = env.command;
|
|
13
|
+
let base = config.base;
|
|
14
|
+
if (!base) {
|
|
15
|
+
const { h5 } = (0, uni_cli_shared_1.parseManifestJsonOnce)(options.inputDir);
|
|
16
|
+
base = (h5 && h5.router && h5.router.base) || '';
|
|
17
|
+
}
|
|
18
|
+
if (!base) {
|
|
19
|
+
base = '/';
|
|
20
|
+
}
|
|
21
|
+
options.base = base;
|
|
22
|
+
return {
|
|
23
|
+
base: process.env.UNI_H5_BASE || base,
|
|
24
|
+
root: process.env.VITE_ROOT_DIR,
|
|
25
|
+
// TODO 临时设置为__static__,屏蔽警告:https://github.com/vitejs/vite/blob/824d042535033a5c3d7006978c0d05c201cd1c25/packages/vite/src/node/server/middlewares/transform.ts#L125
|
|
26
|
+
publicDir: config.publicDir || '__static__',
|
|
27
|
+
define: (0, define_1.createDefine)(options),
|
|
28
|
+
resolve: (0, resolve_1.createResolve)(options, config),
|
|
29
|
+
logLevel: config.logLevel || 'warn',
|
|
30
|
+
optimizeDeps: (0, optimizeDeps_1.createOptimizeDeps)(options),
|
|
31
|
+
build: (0, build_1.createBuild)(options, config),
|
|
32
|
+
css: (0, css_1.createCss)(options, config),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
exports.createConfig = createConfig;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createOptimizeDeps = void 0;
|
|
4
|
+
function createOptimizeDeps(_options) {
|
|
5
|
+
return {
|
|
6
|
+
exclude: [
|
|
7
|
+
'vue',
|
|
8
|
+
'vuex',
|
|
9
|
+
'vue-i18n',
|
|
10
|
+
'vue-router',
|
|
11
|
+
'@dcloudio/uni-app',
|
|
12
|
+
'@dcloudio/uni-components',
|
|
13
|
+
'@dcloudio/uni-i18n',
|
|
14
|
+
'@dcloudio/uni-shared',
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
exports.createOptimizeDeps = createOptimizeDeps;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { UserConfig } from 'vite';
|
|
2
|
+
import { VitePluginUniResolvedOptions } from '..';
|
|
3
|
+
export declare function customResolver(updatedId: string): string;
|
|
4
|
+
export declare function createResolve(options: VitePluginUniResolvedOptions, _config: UserConfig): UserConfig['resolve'];
|
|
@@ -0,0 +1,33 @@
|
|
|
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.createResolve = exports.customResolver = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
9
|
+
function customResolver(updatedId) {
|
|
10
|
+
if (uni_cli_shared_1.isWindows) {
|
|
11
|
+
return (0, uni_cli_shared_1.normalizePath)((0, uni_cli_shared_1.requireResolve)(updatedId, process.env.UNI_INPUT_DIR));
|
|
12
|
+
}
|
|
13
|
+
return updatedId;
|
|
14
|
+
}
|
|
15
|
+
exports.customResolver = customResolver;
|
|
16
|
+
function createResolve(options, _config) {
|
|
17
|
+
return {
|
|
18
|
+
// 必须使用alias解析,插件定制的resolveId,不会被应用到css等预处理器中
|
|
19
|
+
alias: [
|
|
20
|
+
// @ts-ignore because @rollup/plugin-alias' type doesn't allow function
|
|
21
|
+
// replacement, but its implementation does work with function values.
|
|
22
|
+
{
|
|
23
|
+
find: /^(~@|@)\/(.*)/,
|
|
24
|
+
replacement(_str, _$1, $2) {
|
|
25
|
+
return (0, uni_cli_shared_1.normalizePath)(path_1.default.resolve(options.inputDir, $2));
|
|
26
|
+
},
|
|
27
|
+
customResolver,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
extensions: uni_cli_shared_1.extensions,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.createResolve = createResolve;
|
|
@@ -0,0 +1,28 @@
|
|
|
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.initEnv = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
function initEnv(config) {
|
|
10
|
+
if (!process.env.UNI_PLATFORM) {
|
|
11
|
+
process.env.UNI_PLATFORM = 'h5';
|
|
12
|
+
}
|
|
13
|
+
if (!process.env.UNI_CLI_CONTEXT) {
|
|
14
|
+
process.env.UNI_CLI_CONTEXT = process.cwd();
|
|
15
|
+
}
|
|
16
|
+
if (!process.env.UNI_INPUT_DIR) {
|
|
17
|
+
process.env.UNI_INPUT_DIR = path_1.default.resolve(config.root, 'src');
|
|
18
|
+
}
|
|
19
|
+
if (!process.env.UNI_OUTPUT_DIR) {
|
|
20
|
+
process.env.UNI_OUTPUT_DIR = path_1.default.resolve(config.root, config.build.outDir);
|
|
21
|
+
}
|
|
22
|
+
process.env.BROWSERSLIST_CONFIG = [
|
|
23
|
+
path_1.default.resolve(process.env.UNI_INPUT_DIR, '.browserslistrc'),
|
|
24
|
+
path_1.default.resolve(process.env.UNI_CLI_CONTEXT, 'package.json'),
|
|
25
|
+
path_1.default.resolve(process.cwd(), 'package.json'),
|
|
26
|
+
].find((file) => fs_1.default.existsSync(file));
|
|
27
|
+
}
|
|
28
|
+
exports.initEnv = initEnv;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { VitePluginUniResolvedOptions } from '..';
|
|
3
|
+
export declare function createConfigResolved(options: VitePluginUniResolvedOptions): ((config: Readonly<Omit<import("vite").UserConfig, "alias" | "dedupe" | "optimizeDeps" | "plugins" | "assetsInclude"> & {
|
|
4
|
+
configFile: string | undefined;
|
|
5
|
+
configFileDependencies: string[];
|
|
6
|
+
inlineConfig: import("vite").InlineConfig;
|
|
7
|
+
root: string;
|
|
8
|
+
base: string;
|
|
9
|
+
publicDir: string;
|
|
10
|
+
command: "build" | "serve";
|
|
11
|
+
mode: string;
|
|
12
|
+
isProduction: boolean;
|
|
13
|
+
env: Record<string, any>;
|
|
14
|
+
resolve: import("vite").ResolveOptions & {
|
|
15
|
+
alias: import("vite").Alias[];
|
|
16
|
+
};
|
|
17
|
+
plugins: readonly Plugin[];
|
|
18
|
+
server: import("vite").ResolvedServerOptions;
|
|
19
|
+
build: Required<Omit<import("vite").BuildOptions, "base" | "cleanCssOptions" | "polyfillDynamicImport" | "brotliSize">>;
|
|
20
|
+
preview: import("vite").ResolvedPreviewOptions;
|
|
21
|
+
assetsInclude: (file: string) => boolean;
|
|
22
|
+
logger: import("vite").Logger;
|
|
23
|
+
createResolver: (options?: Partial<import("vite").InternalResolveOptions> | undefined) => import("vite").ResolveFn;
|
|
24
|
+
optimizeDeps: Omit<import("vite").DepOptimizationOptions, "keepNames">;
|
|
25
|
+
}>) => void | Promise<void>) | undefined;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConfigResolved = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
6
|
+
const env_1 = require("./env");
|
|
7
|
+
const options_1 = require("./options");
|
|
8
|
+
const plugins_1 = require("./plugins");
|
|
9
|
+
const resolve_1 = require("../config/resolve");
|
|
10
|
+
function createConfigResolved(options) {
|
|
11
|
+
return ((config) => {
|
|
12
|
+
// 如果是混合编译且是 nvue 时,部分逻辑无需执行
|
|
13
|
+
if (!(0, uni_cli_shared_1.isInHybridNVue)(config)) {
|
|
14
|
+
(0, env_1.initEnv)(config);
|
|
15
|
+
}
|
|
16
|
+
initLogger(config);
|
|
17
|
+
(0, options_1.initOptions)(options, config);
|
|
18
|
+
(0, plugins_1.initPlugins)(config, options);
|
|
19
|
+
if (!(0, uni_cli_shared_1.isInHybridNVue)(config)) {
|
|
20
|
+
initCheckUpdate();
|
|
21
|
+
}
|
|
22
|
+
if (uni_cli_shared_1.isWindows) {
|
|
23
|
+
// TODO 等 https://github.com/vitejs/vite/issues/3331 修复后,可以移除下列代码
|
|
24
|
+
const item = config.resolve.alias.find((item) => typeof item.find !== 'string' ? item.find.test('@/') : false);
|
|
25
|
+
if (item) {
|
|
26
|
+
item.customResolver = resolve_1.customResolver;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.createConfigResolved = createConfigResolved;
|
|
32
|
+
function initCheckUpdate() {
|
|
33
|
+
(0, uni_cli_shared_1.checkUpdate)({
|
|
34
|
+
inputDir: process.env.UNI_INPUT_DIR,
|
|
35
|
+
compilerVersion: process.env.UNI_COMPILER_VERSION,
|
|
36
|
+
versionType: process.env.UNI_COMPILER_VERSION_TYPE,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function initLogger({ logger, nvue }) {
|
|
40
|
+
const { info, warn, error } = logger;
|
|
41
|
+
logger.info = (msg, opts) => {
|
|
42
|
+
msg = (0, uni_cli_shared_1.formatInfoMsg)(msg, (0, shared_1.extend)({ nvue }, opts));
|
|
43
|
+
if (msg) {
|
|
44
|
+
return info(msg, opts);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
logger.warn = (msg, opts) => {
|
|
48
|
+
msg = (0, uni_cli_shared_1.formatWarnMsg)(msg, opts);
|
|
49
|
+
if (msg) {
|
|
50
|
+
return warn(msg, opts);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
logger.error = (msg, opts) => {
|
|
54
|
+
msg = (0, uni_cli_shared_1.formatErrMsg)(msg, opts);
|
|
55
|
+
if (msg) {
|
|
56
|
+
return error(msg, opts);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|