@dcloudio/vite-plugin-uni 3.0.0-5000720260410001 → 3.0.0-5010520260709001

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.
@@ -48,8 +48,7 @@ async function runDev(options) {
48
48
  options.minify = true;
49
49
  }
50
50
  (0, utils_1.initEnv)('dev', options);
51
- if (process.env.UNI_APP_X === 'true' &&
52
- process.env.UNI_UTS_PLATFORM === 'app-android') {
51
+ if ((0, uni_cli_shared_1.isUniAppXAndroidNative)()) {
53
52
  return (0, uvue_1.runUVueAndroidDev)(options);
54
53
  }
55
54
  const createLogger = await Promise.resolve().then(() => __importStar(require('vite'))).then(({ createLogger }) => createLogger);
@@ -101,18 +100,30 @@ async function runDev(options) {
101
100
  }
102
101
  const utsChanged = process.env.UNI_APP_UTS_CHANGED === 'true';
103
102
  process.env.UNI_APP_UTS_CHANGED = '';
103
+ const pagesJsonChanged = process.env.UNI_APP_X_DOM2_PAGES_JSON_CHANGED === 'true';
104
+ process.env.UNI_APP_X_DOM2_PAGES_JSON_CHANGED = '';
105
+ let changedFiles = '';
106
+ let hasBinFiles = false;
104
107
  if (options.platform === 'app') {
105
108
  const files = process.env.UNI_APP_CHANGED_FILES;
106
109
  const pages = process.env.UNI_APP_CHANGED_PAGES;
107
110
  const dex = process.env.UNI_APP_UTS_CHANGED_FILES;
108
- const changedFiles = pages || files;
111
+ hasBinFiles = getHasBinFiles();
112
+ changedFiles = pages || files;
109
113
  process.env.UNI_APP_CHANGED_PAGES = '';
110
114
  process.env.UNI_APP_CHANGED_FILES = '';
111
115
  process.env.UNI_APP_UTS_CHANGED_FILES = '';
112
- if ((changedFiles &&
116
+ if (process.env.UNI_APP_X_DOM2_DYNAMIC === 'true') {
117
+ process.env.UNI_APP_X_DOM2_BIN_CHANGED_FILES = '';
118
+ }
119
+ const hasIncrementalFiles = changedFiles &&
113
120
  !changedFiles.includes(uni_cli_shared_1.APP_CONFIG_SERVICE) &&
114
- !changedFiles.includes(uni_cli_shared_1.APP_SERVICE_FILENAME)) ||
115
- dex) {
121
+ !changedFiles.includes(uni_cli_shared_1.APP_SERVICE_FILENAME);
122
+ if (
123
+ // 目前动态渲染下,只要bin有变更,就需要全量同步,后续可以优化成bin变更时输出bin变更文件列表
124
+ !hasBinFiles &&
125
+ !pagesJsonChanged &&
126
+ (hasIncrementalFiles || dex)) {
116
127
  if (pages) {
117
128
  return (0, uni_cli_shared_1.output)('log', uni_cli_shared_1.M['dev.watching.end.pages'].replace('{pages}', changedFiles));
118
129
  }
@@ -121,11 +132,39 @@ async function runDev(options) {
121
132
  }
122
133
  else if (options.platform === 'app-harmony' ||
123
134
  options.platform === 'mp-harmony') {
135
+ hasBinFiles = getHasBinFiles();
136
+ // 动态化且没有uts插件变更时,输出变更文件列表
137
+ if (process.env.UNI_APP_X_DOM2_DYNAMIC === 'true' &&
138
+ !utsChanged &&
139
+ !hasBinFiles) {
140
+ const changed = [];
141
+ const files = process.env.UNI_APP_CHANGED_FILES;
142
+ process.env.UNI_APP_CHANGED_PAGES = '';
143
+ if (files) {
144
+ try {
145
+ changed.push(...JSON.parse(files));
146
+ }
147
+ catch { }
148
+ }
149
+ // 鸿蒙平台暂不启用 bin 文件热更新,先不合并到 changes 中。
150
+ // const binFiles = process.env.UNI_APP_X_DOM2_BIN_CHANGED_FILES
151
+ process.env.UNI_APP_X_DOM2_BIN_CHANGED_FILES = '';
152
+ // if (binFiles) {
153
+ // try {
154
+ // changed.push(...JSON.parse(binFiles))
155
+ // } catch {}
156
+ // }
157
+ if (!pagesJsonChanged && changed.length) {
158
+ return (0, uni_cli_shared_1.output)('log', uni_cli_shared_1.M['dev.watching.end.files'].replace('{files}', JSON.stringify(changed)));
159
+ }
160
+ }
124
161
  // 鸿蒙平台cpp/uts插件变更需要整体编译
125
162
  if (process.env.UNI_APP_X_DOM2_CPP_CHANGED !== 'true' &&
126
- !utsChanged) {
163
+ !utsChanged &&
164
+ !hasBinFiles) {
127
165
  const files = process.env.UNI_APP_CHANGED_FILES;
128
- if (files) {
166
+ process.env.UNI_APP_CHANGED_FILES = '';
167
+ if (!pagesJsonChanged && files) {
129
168
  return (0, uni_cli_shared_1.output)('log', uni_cli_shared_1.M['dev.watching.end.files'].replace('{files}', files));
130
169
  }
131
170
  }
@@ -135,10 +174,14 @@ async function runDev(options) {
135
174
  // 之前之所以没有增量就全量同步,是为了兼容性,怕出意外。
136
175
  if (process.env.UNI_APP_X_DOM2 === 'true') {
137
176
  if (process.env.UNI_APP_X_DOM2_CPP_CHANGED === 'true' ||
138
- utsChanged) {
177
+ utsChanged ||
178
+ pagesJsonChanged) {
139
179
  return (0, uni_cli_shared_1.output)('log', uni_cli_shared_1.M['dev.watching.end']);
140
180
  }
141
- return (0, uni_cli_shared_1.output)('log', uni_cli_shared_1.M['uvue.dev.watching.end.empty']);
181
+ // 没有cpp/uts插件变更,且没有增量js/bin文件变更,就输出无变更
182
+ if (!changedFiles && !hasBinFiles) {
183
+ return (0, uni_cli_shared_1.output)('log', uni_cli_shared_1.M['uvue.dev.watching.end.empty']);
184
+ }
142
185
  }
143
186
  return (0, uni_cli_shared_1.output)('log', uni_cli_shared_1.M['dev.watching.end']);
144
187
  }
@@ -174,8 +217,7 @@ async function runDev(options) {
174
217
  exports.runDev = runDev;
175
218
  async function runBuild(options) {
176
219
  (0, utils_1.initEnv)('build', options);
177
- if (process.env.UNI_APP_X === 'true' &&
178
- process.env.UNI_UTS_PLATFORM === 'app-android') {
220
+ if ((0, uni_cli_shared_1.isUniAppXAndroidNative)()) {
179
221
  return (0, uvue_1.runUVueAndroidBuild)(options);
180
222
  }
181
223
  try {
@@ -230,3 +272,9 @@ const stopProfiler = (log) => {
230
272
  });
231
273
  };
232
274
  exports.stopProfiler = stopProfiler;
275
+ function getHasBinFiles() {
276
+ const binFiles = process.env.UNI_APP_X_DOM2_DYNAMIC === 'true'
277
+ ? process.env.UNI_APP_X_DOM2_BIN_CHANGED_FILES
278
+ : '';
279
+ return !!(binFiles && binFiles !== '[]');
280
+ }
package/dist/cli/utils.js CHANGED
@@ -176,7 +176,7 @@ function initEnv(type, options) {
176
176
  manifestJson['app-plus']?.['utsCompilerVersion'] === 'v1') {
177
177
  process.env.UNI_APP_X_TSC = 'false';
178
178
  }
179
- if (manifestJson['uni-app-x']?.['styleIsolationVersion'] === '2') {
179
+ if (manifestJson['uni-app-x']?.['styleIsolationVersion'] == 2) {
180
180
  process.env.UNI_APP_STYLE_ISOLATION_VERSION = '2';
181
181
  }
182
182
  }
@@ -226,14 +226,19 @@ function initEnv(type, options) {
226
226
  ? 'true'
227
227
  : 'false';
228
228
  (0, uni_cli_shared_1.initPreContext)(process.env.UNI_PLATFORM, process.env.UNI_CUSTOM_CONTEXT, process.env.UNI_UTS_PLATFORM, process.env.UNI_APP_X === 'true');
229
- // 应该全平台都显示吧,当初为啥只在部分平台显示?
230
- if (process.env.UNI_PLATFORM === 'app' ||
231
- process.env.UNI_PLATFORM === 'web' ||
232
- process.env.UNI_PLATFORM === 'h5' ||
233
- process.env.UNI_PLATFORM === 'app-harmony') {
234
- console.log(uni_cli_shared_1.M['app.compiler.version'].replace('{version}', process.env.UNI_COMPILER_VERSION +
235
- `(${process.env.UNI_APP_X === 'true' ? 'uni-app x' : 'vue3'})` +
236
- (process.env.UNI_APP_X_DOM2 === 'true' ? '蒸汽模式' : '')));
229
+ const isX = (0, uni_cli_shared_1.isUniAppX)();
230
+ console.log(uni_cli_shared_1.M['app.compiler.version'].replace('{version}', process.env.UNI_COMPILER_VERSION +
231
+ `(${isX ? 'uni-app x' : 'vue3'})` +
232
+ (process.env.UNI_APP_X_DOM2 === 'true' ? '蒸汽模式' : '')));
233
+ if ((0, uni_cli_shared_1.isUniAppXVapor)() &&
234
+ (process.env.UNI_PLATFORM === 'app' ||
235
+ process.env.UNI_PLATFORM === 'app-harmony')) {
236
+ console.log(uni_cli_shared_1.M['view.render.compiler.target'].replace('{target}', process.env.UNI_APP_X_DOM2_DYNAMIC === 'true'
237
+ ? uni_cli_shared_1.M['view.render.compiler.target.bytecode']
238
+ : uni_cli_shared_1.M['view.render.compiler.target.nativecode']));
239
+ }
240
+ if (isX && !(0, uni_cli_shared_1.isUniAppXVapor)()) {
241
+ console.log(uni_cli_shared_1.M['style.isolation.version'].replace('{version}', (process.env.UNI_APP_STYLE_ISOLATION_VERSION || '1') + '.0'));
237
242
  }
238
243
  console.log(uni_cli_shared_1.M['compiling']);
239
244
  }
package/dist/cli/uvue.js CHANGED
@@ -26,8 +26,8 @@ function initUVueEnv() {
26
26
  }
27
27
  if (process.env.UNI_PLATFORM === 'app') {
28
28
  process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE = 'native';
29
- // 如果是app-ios,目前强制使用js引擎
30
- if (process.env.UNI_UTS_PLATFORM === 'app-ios') {
29
+ // App X iOS 与 Android Vapor 统一使用 JS 引擎
30
+ if ((0, uni_cli_shared_1.isUniAppXIOS)() || (0, uni_cli_shared_1.isUniAppXAndroidVapor)()) {
31
31
  process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE = 'js';
32
32
  }
33
33
  }
@@ -17,7 +17,8 @@ function resolveUTSModuleProxyFile(id, importer) {
17
17
  }
18
18
  }
19
19
  const customResolver = (updatedId, importer) => {
20
- updatedId = updatedId.split('?')[0];
20
+ const independentRoot = (0, uni_cli_shared_1.resolveIndependentRoot)(updatedId, importer, process.env.UNI_INPUT_DIR, process.env.UNI_PLATFORM);
21
+ updatedId = (0, uni_cli_shared_1.withoutIndependentRoot)(updatedId).split('?')[0];
21
22
  const utsImporter = importer
22
23
  ? path_1.default.dirname(importer)
23
24
  : process.env.UNI_INPUT_DIR;
@@ -26,16 +27,14 @@ const customResolver = (updatedId, importer) => {
26
27
  ? resolveUTSModuleProxyFile(updatedId, utsImporter)
27
28
  : (0, uni_cli_shared_1.resolveUTSModule)(updatedId, utsImporter);
28
29
  if (utsModuleFile) {
29
- return uni_cli_shared_1.isWindows ? (0, uni_cli_shared_1.normalizePath)(utsModuleFile) : utsModuleFile;
30
+ return (0, uni_cli_shared_1.withIndependentRootIfNeeded)(uni_cli_shared_1.isWindows ? (0, uni_cli_shared_1.normalizePath)(utsModuleFile) : utsModuleFile, independentRoot, process.env.UNI_INPUT_DIR);
30
31
  }
31
32
  const resolveId = (0, uni_cli_shared_1.resolveEncryptUniModule)((0, uni_cli_shared_1.normalizePath)(updatedId), process.env.UNI_UTS_PLATFORM, process.env.UNI_APP_X === 'true');
32
33
  if (resolveId) {
33
- return resolveId;
34
+ return (0, uni_cli_shared_1.withIndependentRootIfNeeded)(resolveId, independentRoot, process.env.UNI_INPUT_DIR);
34
35
  }
35
- if (uni_cli_shared_1.isWindows) {
36
- return (0, uni_cli_shared_1.normalizePath)((0, uni_cli_shared_1.requireResolve)(updatedId, importer || process.env.UNI_INPUT_DIR));
37
- }
38
- return (0, uni_cli_shared_1.requireResolve)(updatedId, importer || process.env.UNI_INPUT_DIR);
36
+ const resolvedId = (0, uni_cli_shared_1.requireResolve)(updatedId, importer || process.env.UNI_INPUT_DIR);
37
+ return (0, uni_cli_shared_1.withIndependentRootIfNeeded)(uni_cli_shared_1.isWindows ? (0, uni_cli_shared_1.normalizePath)(resolvedId) : resolvedId, independentRoot, process.env.UNI_INPUT_DIR);
39
38
  };
40
39
  exports.customResolver = customResolver;
41
40
  function createResolve(options, _config) {
@@ -23,6 +23,13 @@ function uniPreVuePlugin() {
23
23
  }
24
24
  // 清空当前页面已缓存的 filter 信息
25
25
  (0, uni_cli_shared_1.clearMiniProgramTemplateFilter)((0, uni_cli_shared_1.removeExt)((0, uni_cli_shared_1.normalizeMiniProgramFilename)(id, process.env.UNI_INPUT_DIR)));
26
+ if (process.env.UNI_APP_X_DOM2 === 'true' &&
27
+ process.env.UNI_INPUT_DIR &&
28
+ (0, uni_cli_shared_1.isUniPageFile)(filename)) {
29
+ // dom2 页面模板编译会读取 pages.json 中的页面配置,
30
+ // 需要让 pages.json 变更时重新 transform 页面,避免复用旧模板产物。
31
+ this.addWatchFile(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'pages.json'));
32
+ }
26
33
  return {
27
34
  code: (0, uni_cli_shared_1.parseVueCode)(code, isNVue).code, // 暂不提供sourcemap,意义不大
28
35
  map: null,
package/dist/index.d.ts CHANGED
@@ -25,3 +25,4 @@ export interface VitePluginUniResolvedOptions extends VitePluginUniOptions {
25
25
  }
26
26
  export { runDev, runBuild } from './cli/action';
27
27
  export default function uniPlugin(rawOptions?: VitePluginUniOptions): Plugin[];
28
+ export declare function shouldMoveSourceMapFromCache(): boolean | "";
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.runBuild = exports.runDev = void 0;
6
+ exports.shouldMoveSourceMapFromCache = exports.runBuild = exports.runDev = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const vite_1 = __importDefault(require("unplugin-auto-import/vite"));
9
9
  const plugin_vue_jsx_1 = __importDefault(require("@vitejs/plugin-vue-jsx"));
@@ -18,6 +18,7 @@ const vue_1 = require("./vue");
18
18
  const utils_2 = require("./cli/utils");
19
19
  const plugins_1 = require("./uvue/plugins");
20
20
  const path_1 = __importDefault(require("path"));
21
+ const rewriteImportVue_1 = require("./uvue/plugins/rewriteImportVue");
21
22
  var action_1 = require("./cli/action");
22
23
  Object.defineProperty(exports, "runDev", { enumerable: true, get: function () { return action_1.runDev; } });
23
24
  Object.defineProperty(exports, "runBuild", { enumerable: true, get: function () { return action_1.runBuild; } });
@@ -41,16 +42,17 @@ function uniPlugin(rawOptions = {}) {
41
42
  };
42
43
  options.platform = process.env.UNI_PLATFORM || 'h5';
43
44
  options.inputDir = process.env.UNI_INPUT_DIR;
44
- const plugins = process.env.UNI_APP_X === 'true' &&
45
- process.env.UNI_UTS_PLATFORM === 'app-android'
45
+ const plugins = (0, uni_cli_shared_1.isUniAppXAndroidNative)()
46
46
  ? createUVueAndroidPlugins(options)
47
47
  : createPlugins(options);
48
48
  // x 提供 auto import(非android、android自行处理)
49
- if (process.env.UNI_APP_X === 'true' &&
50
- process.env.UNI_UTS_PLATFORM !== 'app-android') {
49
+ if (process.env.UNI_APP_X === 'true' && !(0, uni_cli_shared_1.isUniAppXAndroidNative)()) {
51
50
  plugins.unshift((0, vite_1.default)((0, uni_cli_shared_1.initAutoImportOptions)(process.env.UNI_UTS_PLATFORM, options.autoImportOptions || {})));
52
51
  }
53
52
  plugins.unshift((0, uni_cli_shared_1.uniJsonPlugin)());
53
+ if (process.env.UNI_APP_OUTPUT_FORMAT === 'esm') {
54
+ plugins.push((0, rewriteImportVue_1.rewriteImportVuePlugin)());
55
+ }
54
56
  return plugins;
55
57
  }
56
58
  exports.default = uniPlugin;
@@ -63,7 +65,9 @@ function createPlugins(options) {
63
65
  // iOS 暂不使用该机制
64
66
  process.env.UNI_UTS_PLATFORM !== 'app-ios' &&
65
67
  // harmony 同 iOS
66
- process.env.UNI_UTS_PLATFORM !== 'app-harmony') {
68
+ process.env.UNI_UTS_PLATFORM !== 'app-harmony' &&
69
+ // Android Vapor 暂不使用该机制(只有 Android Native 会进入该方法,不需要额外判断)
70
+ process.env.UNI_UTS_PLATFORM !== 'app-android') {
67
71
  plugins.push((0, uni_cli_shared_1.uniUTSExtApiReplace)());
68
72
  }
69
73
  else {
@@ -135,10 +139,7 @@ function createPlugins(options) {
135
139
  if (fs_1.default.existsSync(sourceMapPath)) {
136
140
  (0, uni_cli_shared_1.emptyDir)(sourceMapPath);
137
141
  }
138
- if (process.env.UNI_APP_X === 'true' &&
139
- process.env.UNI_UTS_PLATFORM === 'app-ios' &&
140
- process.env.UNI_APP_X_CACHE_DIR &&
141
- process.env.NODE_ENV !== 'development') {
142
+ if (shouldMoveSourceMapFromCache()) {
142
143
  plugins.push((0, move_1.uniMovePlugin)({
143
144
  apply: 'build',
144
145
  enforce: 'post',
@@ -190,3 +191,10 @@ function createUVueAndroidPlugins(options) {
190
191
  function resolveSourceMapDirByCacheDir() {
191
192
  return path_1.default.resolve(process.env.UNI_APP_X_CACHE_DIR, 'sourcemap');
192
193
  }
194
+ function shouldMoveSourceMapFromCache() {
195
+ return (process.env.UNI_APP_X === 'true' &&
196
+ process.env.UNI_APP_X_CACHE_DIR &&
197
+ process.env.NODE_ENV !== 'development' &&
198
+ ((0, uni_cli_shared_1.isUniAppXIOS)() || (0, uni_cli_shared_1.isUniAppXAndroidJsEngine)()));
199
+ }
200
+ exports.shouldMoveSourceMapFromCache = shouldMoveSourceMapFromCache;
@@ -12,9 +12,8 @@ const debugCopy = (0, debug_1.default)('uni:copy');
12
12
  function uniCopyPlugin({ outputDir, copyOptions, }) {
13
13
  const staticDir = uni_cli_shared_1.PUBLIC_DIR + '/**/*';
14
14
  const uniModulesStaticDir = 'uni_modules/*/' + uni_cli_shared_1.PUBLIC_DIR + '/**/*';
15
- const isDom2Harmony = process.env.UNI_APP_X_DOM2 === 'true' &&
16
- process.env.UNI_PLATFORM === 'app-harmony';
17
- const uniModulesCppDir = isDom2Harmony ? 'uni_modules/*/cppsdk/**/*' : '';
15
+ const isDom2 = process.env.UNI_APP_X_DOM2 === 'true';
16
+ const uniModulesCppDir = isDom2 ? 'uni_modules/*/cppsdk/**/*' : '';
18
17
  const assets = [staticDir, uniModulesStaticDir];
19
18
  const cppAssets = [];
20
19
  if (uniModulesCppDir) {
@@ -32,10 +31,17 @@ function uniCopyPlugin({ outputDir, copyOptions, }) {
32
31
  assets.push(asset);
33
32
  });
34
33
  const inputDir = (0, uni_cli_shared_1.normalizePath)(process.env.UNI_INPUT_DIR);
34
+ const normalizedInputDir = normalizePathForCompare(inputDir);
35
35
  const platform = process.env.UNI_PLATFORM;
36
36
  const utsPlatform = process.env.UNI_UTS_PLATFORM;
37
37
  // 非当前平台 static 目录
38
38
  const ignorePlatformStaticDirs = createIgnorePlatformDirs(uni_cli_shared_1.PUBLIC_DIR, platform, utsPlatform);
39
+ // app 资源包导出时,如果 uni_modules 的 utssdk 不支持当前原生平台,则连同 static 一起忽略
40
+ const ignoreUniModulesStaticDirs = createIgnoreUniModulesStaticDirs(inputDir, subpackages, utsPlatform);
41
+ const ignoreStaticDirs = [
42
+ ...ignorePlatformStaticDirs,
43
+ ...ignoreUniModulesStaticDirs,
44
+ ];
39
45
  // 非当前平台 cppsdk 目录
40
46
  const ignorePlatformCppDirs = uniModulesCppDir
41
47
  ? createIgnorePlatformDirs('cppsdk', platform, utsPlatform)
@@ -48,15 +54,17 @@ function uniCopyPlugin({ outputDir, copyOptions, }) {
48
54
  readyTimeout: getReadyTimeout(),
49
55
  ignored(path) {
50
56
  const normalizedPath = (0, uni_cli_shared_1.normalizePath)(path);
51
- if (ignorePlatformStaticDirs.find((dir) =>
52
- // dir都是以 / 结尾,所以这里也要以 / 结尾
53
- (normalizedPath + '/').includes(dir))) {
57
+ const comparablePath = normalizePathForCompare(normalizedPath);
58
+ if (ignoreUniModulesStaticDirs.find((dir) =>
59
+ // 忽略整个 static 目录及其子文件,避免无效资源进入资源包
60
+ (comparablePath + '/').includes(dir))) {
61
+ return true;
62
+ }
63
+ if (ignorePlatformStaticDirs.find((dir) => (comparablePath + '/').includes(dir))) {
54
64
  return fs_1.default.statSync(normalizedPath).isDirectory();
55
65
  }
56
- // 应该是软链
57
- if (!normalizedPath.startsWith(inputDir)) {
58
- // 目前仅简单处理static
59
- if (normalizedPath.includes('/static/')) {
66
+ if (!comparablePath.startsWith(normalizedInputDir)) {
67
+ if (comparablePath.includes('/static/')) {
60
68
  return false;
61
69
  }
62
70
  return true;
@@ -67,10 +75,10 @@ function uniCopyPlugin({ outputDir, copyOptions, }) {
67
75
  },
68
76
  ];
69
77
  targets.push(...copyOptions.targets);
70
- if (process.env.UNI_APP_HARMONY_DOM2_CPP_DIR && cppAssets.length) {
78
+ if (process.env.UNI_APP_X_DOM2_CPP_DIR && cppAssets.length) {
71
79
  targets.push({
72
80
  src: cppAssets,
73
- dest: process.env.UNI_APP_HARMONY_DOM2_CPP_DIR,
81
+ dest: process.env.UNI_APP_X_DOM2_CPP_DIR,
74
82
  watchOptions: {
75
83
  readyTimeout: getReadyTimeout(),
76
84
  ignored(path) {
@@ -86,7 +94,7 @@ function uniCopyPlugin({ outputDir, copyOptions, }) {
86
94
  });
87
95
  }
88
96
  debugCopy(targets);
89
- checkIgnoreStatic(ignorePlatformStaticDirs.map((dir) => dir.substring(1).split('/')));
97
+ checkIgnoreStatic(ignoreStaticDirs.map((dir) => dir.substring(1).split('/')));
90
98
  return (0, uni_cli_shared_1.uniViteCopyPlugin)({
91
99
  targets,
92
100
  });
@@ -143,5 +151,38 @@ function createIgnorePlatformDirs(dir, platform, utsPlatform) {
143
151
  return p !== platform;
144
152
  })
145
153
  // 在最后增加 / 是为了避免误判以 platform 开头的目录,比如 app-test
146
- .map((p) => '/' + dir + '/' + p + '/'));
154
+ .map((p) => normalizePathForCompare('/' + dir + '/' + p + '/')));
155
+ }
156
+ function createIgnoreUniModulesStaticDirs(inputDir, subpackages, utsPlatform) {
157
+ if (utsPlatform !== 'app-android' && utsPlatform !== 'app-ios') {
158
+ return [];
159
+ }
160
+ const ignoreDirs = [];
161
+ const roots = [
162
+ inputDir,
163
+ ...subpackages.map((root) => path_1.default.resolve(inputDir, root)),
164
+ ];
165
+ roots.forEach((rootDir) => {
166
+ const uniModulesDir = path_1.default.resolve(rootDir, 'uni_modules');
167
+ if (!fs_1.default.existsSync(uniModulesDir)) {
168
+ return;
169
+ }
170
+ fs_1.default.readdirSync(uniModulesDir).forEach((uniModuleDir) => {
171
+ const uniModuleRootDir = path_1.default.resolve(uniModulesDir, uniModuleDir);
172
+ const utssdkDir = path_1.default.resolve(uniModuleRootDir, 'utssdk');
173
+ const staticDir = path_1.default.resolve(uniModuleRootDir, uni_cli_shared_1.PUBLIC_DIR);
174
+ if (!fs_1.default.existsSync(utssdkDir) || !fs_1.default.existsSync(staticDir)) {
175
+ return;
176
+ }
177
+ if ((0, uni_cli_shared_1.hasUTSModulePlatformFile)(uniModuleRootDir, utsPlatform)) {
178
+ return;
179
+ }
180
+ ignoreDirs.push(normalizePathForCompare('/' + (0, uni_cli_shared_1.normalizePath)(path_1.default.relative(inputDir, staticDir)) + '/'));
181
+ });
182
+ });
183
+ return ignoreDirs;
184
+ }
185
+ function normalizePathForCompare(id) {
186
+ const normalizedPath = (0, uni_cli_shared_1.normalizePath)(id);
187
+ return uni_cli_shared_1.isWindows ? normalizedPath.toLowerCase() : normalizedPath;
147
188
  }
@@ -0,0 +1,19 @@
1
+ import { type ImportSpecifier } from 'es-module-lexer';
2
+ import MagicString from 'magic-string';
3
+ import type { Plugin } from 'vite';
4
+ /**
5
+ * 如下情况会生成import vue的代码:
6
+ * 1. uvue页面编译产物通过helpers方式导入的vue相关api,defineComponent、unref等
7
+ * 2. 用户代码script中的ref、reactive、computed等
8
+ * 3. onLoad等从@dcloudio/uni-app导入的api等
9
+ * 4. 用户代码script中import vue的api
10
+ *
11
+ * 如果在transform中处理,需要确保此插件在autoImport之后,否则此时2、3尚未生成import vue的代码。
12
+ * 如果在renderChunk中处理,能保证所有代码都已经生成import vue的代码,但是此时热更新会触发所有文件重新处理import vue。
13
+ */
14
+ export declare function rewriteImportVuePlugin(): Plugin;
15
+ /**
16
+ * import { xx as yy, zz } from 'vue' =>
17
+ * const { xx: yy, zz } = globalThis.Vue
18
+ */
19
+ export declare function rewriteImportVue(input: string, importRanges?: Pick<ImportSpecifier, 'ss' | 'se'>[]): MagicString;
@@ -0,0 +1,108 @@
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.rewriteImportVue = exports.rewriteImportVuePlugin = void 0;
7
+ const parser_1 = require("@babel/parser");
8
+ const es_module_lexer_1 = require("es-module-lexer");
9
+ const magic_string_1 = __importDefault(require("magic-string"));
10
+ /**
11
+ * 如下情况会生成import vue的代码:
12
+ * 1. uvue页面编译产物通过helpers方式导入的vue相关api,defineComponent、unref等
13
+ * 2. 用户代码script中的ref、reactive、computed等
14
+ * 3. onLoad等从@dcloudio/uni-app导入的api等
15
+ * 4. 用户代码script中import vue的api
16
+ *
17
+ * 如果在transform中处理,需要确保此插件在autoImport之后,否则此时2、3尚未生成import vue的代码。
18
+ * 如果在renderChunk中处理,能保证所有代码都已经生成import vue的代码,但是此时热更新会触发所有文件重新处理import vue。
19
+ */
20
+ function rewriteImportVuePlugin() {
21
+ return {
22
+ name: 'uni:rewrite-import-vue',
23
+ enforce: 'post',
24
+ async transform(source, id) {
25
+ await es_module_lexer_1.init;
26
+ const [imports] = (0, es_module_lexer_1.parse)(source);
27
+ const vueImportRanges = imports.filter((specifier) => specifier.n === 'vue' && specifier.d === -1);
28
+ if (!vueImportRanges.length) {
29
+ return;
30
+ }
31
+ const rewritten = rewriteImportVue(source, vueImportRanges);
32
+ if (rewritten.hasChanged()) {
33
+ return {
34
+ code: rewritten.toString(),
35
+ // 必须指定hires,不然部分情况可能会无法正确映射行号。
36
+ map: rewritten.generateMap({ hires: 'boundary' }),
37
+ };
38
+ }
39
+ },
40
+ };
41
+ }
42
+ exports.rewriteImportVuePlugin = rewriteImportVuePlugin;
43
+ /**
44
+ * import { xx as yy, zz } from 'vue' =>
45
+ * const { xx: yy, zz } = globalThis.Vue
46
+ */
47
+ function rewriteImportVue(input, importRanges) {
48
+ const s = new magic_string_1.default(input);
49
+ if (importRanges) {
50
+ importRanges.forEach(({ ss, se }) => {
51
+ const rewritten = rewriteImportVueStatement(input.slice(ss, se));
52
+ if (rewritten !== undefined) {
53
+ s.overwrite(ss, se, rewritten);
54
+ }
55
+ });
56
+ }
57
+ else {
58
+ const ast = (0, parser_1.parse)(input, {
59
+ sourceType: 'module',
60
+ }).program.body;
61
+ ast.forEach((node) => {
62
+ if (node.type === 'ImportDeclaration' && node.source.value === 'vue') {
63
+ const rewritten = createImportVueReplacement(node);
64
+ if (rewritten !== undefined) {
65
+ s.overwrite(node.start, node.end, rewritten);
66
+ }
67
+ }
68
+ });
69
+ }
70
+ return s;
71
+ }
72
+ exports.rewriteImportVue = rewriteImportVue;
73
+ function rewriteImportVueStatement(input) {
74
+ const node = (0, parser_1.parse)(input, {
75
+ sourceType: 'module',
76
+ }).program.body[0];
77
+ if (node?.type === 'ImportDeclaration' && node.source.value === 'vue') {
78
+ return createImportVueReplacement(node);
79
+ }
80
+ }
81
+ function createImportVueReplacement(node) {
82
+ const imports = [];
83
+ const declarations = [];
84
+ node.specifiers.forEach((specifier) => {
85
+ if (specifier.type === 'ImportSpecifier') {
86
+ const imported = specifier.imported.name;
87
+ const local = specifier.local.name;
88
+ if (imported === local) {
89
+ imports.push(imported);
90
+ }
91
+ else {
92
+ imports.push(`${imported}: ${local}`);
93
+ }
94
+ }
95
+ else if (specifier.type === 'ImportDefaultSpecifier') {
96
+ const local = specifier.local.name;
97
+ imports.push(`default: ${local}`);
98
+ }
99
+ else if (specifier.type === 'ImportNamespaceSpecifier') {
100
+ const local = specifier.local.name;
101
+ declarations.push(`const ${local} = globalThis.Vue`);
102
+ }
103
+ });
104
+ if (imports.length > 0) {
105
+ declarations.push(`const { ${imports.join(', ')} } = globalThis.Vue`);
106
+ }
107
+ return declarations.join(';');
108
+ }
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.initPluginViteLegacyOptions = exports.initPluginVueJsxOptions = exports.initPluginVueOptions = exports.createPluginVueInstance = void 0;
7
- const path_1 = __importDefault(require("path"));
8
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
8
  const shared_1 = require("@vue/shared");
10
9
  const uni_shared_1 = require("@dcloudio/uni-shared");
@@ -53,10 +52,9 @@ function initPluginVueOptions(options, UniVitePlugins, uniPluginOptions) {
53
52
  }
54
53
  const templateOptions = vueOptions.template || (vueOptions.template = {});
55
54
  const compilerOptions = templateOptions.compilerOptions || (templateOptions.compilerOptions = {});
56
- const isDom2Harmony = process.env.UNI_APP_X_DOM2 === 'true' &&
57
- process.env.UNI_PLATFORM === 'app-harmony';
55
+ const isDom2 = process.env.UNI_APP_X_DOM2 === 'true';
58
56
  compilerOptions.isX = process.env.UNI_APP_X === 'true';
59
- compilerOptions.dom2 = isDom2Harmony;
57
+ compilerOptions.dom2 = isDom2;
60
58
  // 默认就移除comments节点
61
59
  compilerOptions.comments = false;
62
60
  const { compiler, styleOptions: { postcssPlugins }, compilerOptions: { miniProgram, isNativeTag, isVoidTag, isCustomElement, nodeTransforms, directiveTransforms, whitespace, }, } = uniPluginOptions;
@@ -145,7 +143,7 @@ function initPluginVueOptions(options, UniVitePlugins, uniPluginOptions) {
145
143
  };
146
144
  }
147
145
  if (options.platform !== 'h5' && options.platform !== 'web') {
148
- compilerOptions.nodeTransforms.push(...(0, uni_cli_shared_1.getBaseNodeTransforms)(options.base, isDom2Harmony ? (0, uni_cli_shared_1.createResolveStaticAsset)(options.inputDir) : undefined));
146
+ compilerOptions.nodeTransforms.push(...(0, uni_cli_shared_1.getBaseNodeTransforms)(options.base, isDom2 ? (0, uni_cli_shared_1.createResolveStaticAsset)(options.inputDir) : undefined));
149
147
  }
150
148
  if (nodeTransforms) {
151
149
  compilerOptions.nodeTransforms.push(...nodeTransforms);
@@ -216,7 +214,7 @@ function initPluginVueOptions(options, UniVitePlugins, uniPluginOptions) {
216
214
  if (!vueOptions.script.babelParserPlugins.includes('decorators')) {
217
215
  vueOptions.script.babelParserPlugins.push('decorators');
218
216
  }
219
- if (isDom2Harmony) {
217
+ if (isDom2) {
220
218
  const appVue = (0, uni_cli_shared_1.resolveAppVue)(process.env.UNI_INPUT_DIR);
221
219
  function isAppVue(id) {
222
220
  return (0, uni_cli_shared_1.normalizePath)(id) === appVue;
@@ -231,6 +229,8 @@ function initPluginVueOptions(options, UniVitePlugins, uniPluginOptions) {
231
229
  vueOptions.script.extraOptions = (descriptor) => {
232
230
  return {
233
231
  isWatch: process.env.NODE_ENV === 'development',
232
+ // TODO 目前使用全局开关,后续可能是页面级别的开关?
233
+ dynamicSharedData: process.env.UNI_APP_X_DOM2_DYNAMIC === 'true',
234
234
  helper: (0, uni_cli_shared_1.requireUniHelpers)(),
235
235
  componentType: (0, uni_cli_shared_1.isUniPageFile)(descriptor.filename)
236
236
  ? 'page'
@@ -239,31 +239,8 @@ function initPluginVueOptions(options, UniVitePlugins, uniPluginOptions) {
239
239
  : 'component',
240
240
  };
241
241
  };
242
- let disableStaticStyle = false;
243
- if (isDevX && process.env.NODE_ENV === 'development') {
244
- if (process.env.UNI_UTS_PLATFORM === 'app-harmony') {
245
- // 开发版本、开发模式下,非鸿蒙release模式打包
246
- disableStaticStyle =
247
- process.env.UNI_APP_HARMONY_RUN_MODE !== 'release';
248
- }
249
- }
250
- ;
251
242
  vueOptions.template.compilerOptions.extraOptions = (descriptor) => {
252
- const filename = (0, uni_cli_shared_1.normalizePath)(descriptor.filename.split('?')[0]);
253
- const relativeFilename = (0, uni_cli_shared_1.normalizePath)(path_1.default.relative(process.env.UNI_INPUT_DIR, filename));
254
- return {
255
- root: (0, uni_cli_shared_1.normalizePath)(process.env.UNI_INPUT_DIR),
256
- platform: process.env.UNI_UTS_PLATFORM,
257
- componentType: (0, uni_cli_shared_1.isUniPageFile)(filename) ? 'page' : 'component',
258
- relativeFilename,
259
- helper: (0, uni_cli_shared_1.requireUniHelpers)(),
260
- scriptCppBlocks: descriptor.scriptCppBlocks,
261
- genVueId: !!process.env.UNI_AUTOMATOR_WS_ENDPOINT,
262
- disableStaticStyle,
263
- onVueTemplateCompileLog(type, error) {
264
- return (0, uni_cli_shared_1.onVueTemplateCompileLog)(type, error, descriptor.source, relativeFilename);
265
- },
266
- };
243
+ return (0, uni_cli_shared_1.initVueTemplateCompilerExtraOptions)(descriptor);
267
244
  };
268
245
  }
269
246
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/vite-plugin-uni",
3
- "version": "3.0.0-5000720260410001",
3
+ "version": "3.0.0-5010520260709001",
4
4
  "description": "uni-app vite plugin",
5
5
  "bin": {
6
6
  "uni": "bin/uni.js"
@@ -44,9 +44,9 @@
44
44
  "picocolors": "1.1.0",
45
45
  "terser": "^5.4.0",
46
46
  "unplugin-auto-import": "19.1.0",
47
- "@dcloudio/uni-cli-shared": "3.0.0-5000720260410001",
48
- "@dcloudio/uni-shared": "3.0.0-5000720260410001",
49
- "@dcloudio/uni-nvue-styler": "3.0.0-5000720260410001"
47
+ "@dcloudio/uni-cli-shared": "3.0.0-5010520260709001",
48
+ "@dcloudio/uni-nvue-styler": "3.0.0-5010520260709001",
49
+ "@dcloudio/uni-shared": "3.0.0-5010520260709001"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/debug": "4.1.12",
@@ -63,7 +63,7 @@
63
63
  "vite": "5.2.8"
64
64
  },
65
65
  "uni-app": {
66
- "compilerVersion": "5.07"
66
+ "compilerVersion": "5.15"
67
67
  },
68
68
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
69
69
  "scripts": {