@dcloudio/vite-plugin-uni 3.0.0-4010420240430002 → 3.0.0-4020320240708001

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/bin/uni.js CHANGED
@@ -28,7 +28,13 @@ if (
28
28
  process.argv[2] === 'build' &&
29
29
  !process.argv.some((arg) => /^(?:-w|--watch)$/.test(arg))
30
30
  ) {
31
- process.env.NODE_ENV = 'production'
31
+ if (process.env.UNI_COMPILE_TARGET === 'uni_modules') {
32
+ if (!process.env.NODE_ENV) {
33
+ process.env.NODE_ENV = 'production'
34
+ }
35
+ } else {
36
+ process.env.NODE_ENV = 'production'
37
+ }
32
38
  }
33
39
 
34
40
  function initDebug() {
package/dist/cli/build.js CHANGED
@@ -48,7 +48,7 @@ async function buildSSR(options) {
48
48
  const ssrClientDir = path_1.default.resolve(outputDir, 'client');
49
49
  process.env.UNI_OUTPUT_DIR = ssrClientDir;
50
50
  const ssrBuildClientOptions = (0, utils_1.cleanOptions)(options);
51
- ssrBuildClientOptions.ssrManifest = true;
51
+ ssrBuildClientOptions.ssrManifest = 'ssr-manifest.json';
52
52
  ssrBuildClientOptions.outDir = process.env.UNI_OUTPUT_DIR;
53
53
  process.env.UNI_SSR_CLIENT = 'true';
54
54
  await buildByVite((0, utils_1.addConfigFile)(initBuildOptions(options, ssrBuildClientOptions)));
@@ -56,6 +56,12 @@ async function buildSSR(options) {
56
56
  process.env.UNI_OUTPUT_DIR = ssrServerDir;
57
57
  const ssrBuildServerOptions = (0, utils_1.cleanOptions)(options);
58
58
  ssrBuildServerOptions.ssr = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'entry-server.js');
59
+ // 强制 cjs 输出
60
+ ssrBuildServerOptions.rollupOptions = {
61
+ output: {
62
+ format: 'cjs',
63
+ },
64
+ };
59
65
  ssrBuildServerOptions.outDir = process.env.UNI_OUTPUT_DIR;
60
66
  process.env.UNI_SSR_CLIENT = '';
61
67
  process.env.UNI_SSR_SERVER = 'true';
@@ -121,6 +127,10 @@ async function buildApp(options) {
121
127
  // 指定为 vue 方便 App 插件初始化 vue 所需插件列表
122
128
  process.env.UNI_COMPILER = 'vue';
123
129
  const vueBuilder = await buildByVite((0, utils_1.addConfigFile)(initBuildOptions(options, (0, utils_1.cleanOptions)(options))));
130
+ if (process.env.UNI_COMPILE_TARGET === 'uni_modules') {
131
+ // 不需要 nvue 编译器
132
+ return vueBuilder;
133
+ }
124
134
  if (appWatcher) {
125
135
  appWatcher.setFirstWatcher(vueBuilder);
126
136
  }
package/dist/cli/nvue.js CHANGED
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initNVueEnv = void 0;
4
4
  const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
5
5
  function initNVueEnv() {
6
+ if (process.env.UNI_APP_X === 'true') {
7
+ return;
8
+ }
6
9
  const manifestJson = (0, uni_cli_shared_1.parseManifestJsonOnce)(process.env.UNI_INPUT_DIR);
7
10
  if ((0, uni_cli_shared_1.getAppRenderer)(manifestJson) === 'native') {
8
11
  process.env.UNI_RENDERER = 'native';
@@ -141,7 +141,7 @@ async function createSSRServer(options) {
141
141
  }
142
142
  else {
143
143
  logger.info(`Port ${port} is in use, trying another one...`);
144
- app.listen(++port, hostname, onSuccess).on('error', onError);
144
+ server = app.listen(++port, hostname, onSuccess).on('error', onError);
145
145
  }
146
146
  }
147
147
  else {
@@ -149,7 +149,7 @@ async function createSSRServer(options) {
149
149
  reject(e);
150
150
  }
151
151
  };
152
- const server = app.listen(port, hostname, onSuccess).on('error', onError);
152
+ let server = app.listen(port, hostname, onSuccess).on('error', onError);
153
153
  });
154
154
  }
155
155
  exports.createSSRServer = createSSRServer;
package/dist/cli/utils.js CHANGED
@@ -68,7 +68,14 @@ function initEnv(type, options) {
68
68
  process.env.NODE_ENV = 'development';
69
69
  }
70
70
  else {
71
- process.env.NODE_ENV = 'production';
71
+ if (process.env.UNI_COMPILE_TARGET === 'uni_modules') {
72
+ if (!process.env.NODE_ENV) {
73
+ process.env.NODE_ENV = 'production';
74
+ }
75
+ }
76
+ else {
77
+ process.env.NODE_ENV = 'production';
78
+ }
72
79
  }
73
80
  }
74
81
  if (!options.mode) {
@@ -98,6 +105,15 @@ function initEnv(type, options) {
98
105
  process.env.UNI_INPUT_DIR || path_1.default.resolve(process.cwd(), 'src');
99
106
  initCustomScripts(options);
100
107
  process.env.UNI_PLATFORM = options.platform;
108
+ if (process.env.UNI_PLATFORM === 'app-harmony') {
109
+ const manifestJson = (0, uni_cli_shared_1.parseManifestJsonOnce)(process.env.UNI_INPUT_DIR);
110
+ const projectPath = manifestJson['app-harmony']?.projectPath;
111
+ if (projectPath) {
112
+ process.env.UNI_APP_HARMONY_PROJECT_PATH = path_1.default.resolve(projectPath);
113
+ // 指定了鸿蒙项目根目录
114
+ process.env.UNI_OUTPUT_DIR = path_1.default.resolve(process.env.UNI_APP_HARMONY_PROJECT_PATH, `entry/src/main/resources/rawfile/apps/HBuilder/www`);
115
+ }
116
+ }
101
117
  const hasOutputDir = !!process.env.UNI_OUTPUT_DIR;
102
118
  if (hasOutputDir) {
103
119
  ;
@@ -122,6 +138,14 @@ function initEnv(type, options) {
122
138
  path_1.default.resolve(process.env.UNI_OUTPUT_DIR, options.subpackage);
123
139
  }
124
140
  }
141
+ const baseOutDir = path_1.default.basename(process.env.UNI_OUTPUT_DIR);
142
+ process.env.UNI_APP_X_CACHE_DIR =
143
+ process.env.UNI_APP_X_CACHE_DIR ||
144
+ path_1.default.resolve(process.env.UNI_OUTPUT_DIR, '../cache/.' + baseOutDir);
145
+ process.env.HX_DEPENDENCIES_DIR =
146
+ process.env.HX_DEPENDENCIES_DIR ||
147
+ path_1.default.resolve(process.env.UNI_OUTPUT_DIR, '../hx/' + baseOutDir);
148
+ process.env.UNI_MODULES_ENCRYPT_CACHE_DIR = path_1.default.resolve(process.env.UNI_APP_X_CACHE_DIR, '.encrypt', process.env.NODE_ENV === 'development' ? 'dev' : 'build', process.env.UNI_UTS_PLATFORM);
125
149
  initAutomator(options);
126
150
  initDevtools(options);
127
151
  if (process.env.UNI_PLATFORM === 'app') {
@@ -204,6 +228,9 @@ function initUTSPlatform(options) {
204
228
  else if (process.env.UNI_UTS_PLATFORM === 'app-ios') {
205
229
  process.env.UNI_UTS_TARGET_LANGUAGE = 'swift';
206
230
  }
231
+ else if (process.env.UNI_UTS_PLATFORM === 'app-harmony') {
232
+ process.env.UNI_UTS_TARGET_LANGUAGE = 'arkts';
233
+ }
207
234
  }
208
235
  function initDevtools({ devtools, devtoolsHost, devtoolsPort }) {
209
236
  if (!devtools) {
package/dist/cli/uvue.js CHANGED
@@ -13,14 +13,17 @@ function initUVueEnv() {
13
13
  if (process.env.UNI_APP_X === 'false') {
14
14
  return;
15
15
  }
16
- const manifestJson = (0, uni_cli_shared_1.parseManifestJsonOnce)(process.env.UNI_INPUT_DIR);
17
- const isNVueEnabled = (0, shared_1.hasOwn)(manifestJson, 'uni-app-x');
18
- if (!isNVueEnabled) {
19
- return;
20
- }
21
- process.env.UNI_APP_X = 'true';
22
- if (manifestJson['uni-app-x']?.singleThread === false) {
23
- process.env.UNI_APP_X_SINGLE_THREAD = 'false';
16
+ // 没有手动指定时,才需要动态读取 manifest.json
17
+ if (process.env.UNI_APP_X !== 'true') {
18
+ const manifestJson = (0, uni_cli_shared_1.parseManifestJsonOnce)(process.env.UNI_INPUT_DIR);
19
+ const isNVueEnabled = (0, shared_1.hasOwn)(manifestJson, 'uni-app-x');
20
+ if (!isNVueEnabled) {
21
+ return;
22
+ }
23
+ process.env.UNI_APP_X = 'true';
24
+ if (manifestJson['uni-app-x']?.singleThread === false) {
25
+ process.env.UNI_APP_X_SINGLE_THREAD = 'false';
26
+ }
24
27
  }
25
28
  if (process.env.UNI_PLATFORM === 'app') {
26
29
  process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE = 'native';
@@ -7,7 +7,7 @@ exports.createResolve = exports.customResolver = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
9
9
  function resolveUTSModuleProxyFile(id, importer) {
10
- const file = (0, uni_cli_shared_1.resolveUTSAppModule)(id, importer);
10
+ const file = (0, uni_cli_shared_1.resolveUTSAppModule)(process.env.UNI_UTS_PLATFORM, id, importer);
11
11
  if (file) {
12
12
  // app-js 会返回完整路径,不需要 uts-proxy
13
13
  if (file.endsWith('.uts')) {
@@ -20,12 +20,17 @@ const customResolver = (updatedId, importer) => {
20
20
  const utsImporter = importer
21
21
  ? path_1.default.dirname(importer)
22
22
  : process.env.UNI_INPUT_DIR;
23
- const utsModuleFile = process.env.UNI_PLATFORM === 'app'
23
+ const utsModuleFile = process.env.UNI_PLATFORM === 'app' ||
24
+ process.env.UNI_PLATFORM === 'app-harmony'
24
25
  ? resolveUTSModuleProxyFile(updatedId, utsImporter)
25
26
  : (0, uni_cli_shared_1.resolveUTSModule)(updatedId, utsImporter);
26
27
  if (utsModuleFile) {
27
28
  return uni_cli_shared_1.isWindows ? (0, uni_cli_shared_1.normalizePath)(utsModuleFile) : utsModuleFile;
28
29
  }
30
+ 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');
31
+ if (resolveId) {
32
+ return resolveId;
33
+ }
29
34
  if (uni_cli_shared_1.isWindows) {
30
35
  return (0, uni_cli_shared_1.normalizePath)((0, uni_cli_shared_1.requireResolve)(updatedId, importer || process.env.UNI_INPUT_DIR));
31
36
  }
@@ -34,6 +39,13 @@ const customResolver = (updatedId, importer) => {
34
39
  exports.customResolver = customResolver;
35
40
  function createResolve(options, _config) {
36
41
  const alias = [];
42
+ if (process.env.UNI_COMPILE_TARGET !== 'uni_modules') {
43
+ // 加密组件内部使用的 vue export helper,需要重新映射回来
44
+ alias.push({
45
+ find: 'plugin-vue:export-helper',
46
+ replacement: '\0plugin-vue:export-helper',
47
+ });
48
+ }
37
49
  return {
38
50
  // 必须使用alias解析,插件定制的resolveId,不会被应用到css等预处理器中
39
51
  alias: [
@@ -49,6 +61,7 @@ function createResolve(options, _config) {
49
61
  ...alias,
50
62
  ],
51
63
  extensions: process.env.UNI_APP_X === 'true' ? uni_cli_shared_1.uni_app_x_extensions : uni_cli_shared_1.extensions,
64
+ preserveSymlinks: true,
52
65
  };
53
66
  }
54
67
  exports.createResolve = createResolve;
@@ -1,14 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.initOptions = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const jsonc_parser_1 = require("jsonc-parser");
4
+ const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
10
5
  function resolveBase() {
11
- const manifest = (0, jsonc_parser_1.parse)(fs_1.default.readFileSync(path_1.default.join(process.env.UNI_INPUT_DIR, 'manifest.json'), 'utf8'));
6
+ const manifest = (0, uni_cli_shared_1.parseManifestJsonOnce)(process.env.UNI_INPUT_DIR);
12
7
  return (manifest.h5 && manifest.h5.router && manifest.h5.router.base) || '/';
13
8
  }
14
9
  function initOptions(options, config) {
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.initPlugins = void 0;
7
- const path_1 = __importDefault(require("path"));
8
4
  // import debug from 'debug'
9
5
  const shared_1 = require("@vue/shared");
10
6
  const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
@@ -28,14 +24,17 @@ function initPlugins(config, options) {
28
24
  addPlugin(plugins, (0, pre_1.uniPrePlugin)(config, (0, shared_1.extend)(uniPrePluginOptions, options)), 0, 'pre');
29
25
  addPlugin(plugins, (0, preCss_1.uniPreCssPlugin)(config, (0, shared_1.extend)(uniPreCssPluginOptions, options)), 'vite:css');
30
26
  addPlugin(plugins, (0, preVue_1.uniPreVuePlugin)(), 'vite:vue', 'pre');
31
- addPlugin(plugins, (0, ssr_1.uniSSRPlugin)(config, (0, shared_1.extend)({ exclude: [...uni_cli_shared_1.COMMON_EXCLUDE, /\/@dcloudio\/uni-app/] }, options)), 'vite:vue');
27
+ addPlugin(plugins, (0, ssr_1.uniSSRPlugin)(config, (0, shared_1.extend)({ exclude: [...uni_cli_shared_1.COMMON_EXCLUDE, /\/@dcloudio\/uni-app/] }, options)), process.env.UNI_APP_X === 'true' ? 'uts' : 'vite:vue');
32
28
  addPlugin(plugins, (0, json_1.uniJsonPlugin)(options), 'vite:json', 'pre');
33
29
  addPlugin(plugins, (0, static_1.uniStaticPlugin)(options, config), 'vite:asset', 'pre');
34
- if ((0, uni_cli_shared_1.isInHBuilderX)()) {
30
+ if (process.env.UNI_HBUILDERX_PLUGINS &&
31
+ process.env.UNI_COMPILE_TARGET !== 'uni_modules') {
35
32
  try {
36
- require(path_1.default.resolve(process.env.UNI_HBUILDERX_PLUGINS, 'uni_helpers/lib/bytenode'));
37
- const { V } = require(path_1.default.join(process.env.UNI_HBUILDERX_PLUGINS, 'uni_helpers'));
38
- addPlugin(plugins, V({ dir: process.env.UNI_INPUT_DIR }), 0, 'pre');
33
+ const { V } = (0, uni_cli_shared_1.requireUniHelpers)();
34
+ addPlugin(plugins, V({
35
+ dir: process.env.UNI_INPUT_DIR,
36
+ cacheDir: process.env.UNI_MODULES_ENCRYPT_CACHE_DIR,
37
+ }), 0, 'pre');
39
38
  }
40
39
  catch (e) { }
41
40
  }
package/dist/index.js CHANGED
@@ -82,7 +82,6 @@ function createPlugins(options) {
82
82
  plugins.push({
83
83
  name: 'uni',
84
84
  config: (0, config_1.createConfig)(options, uniPlugins),
85
- // resolveId: createResolveId(options),
86
85
  configResolved: (0, configResolved_1.createConfigResolved)(options),
87
86
  });
88
87
  plugins.push(...uniPlugins);
@@ -102,7 +101,7 @@ function createPlugins(options) {
102
101
  }
103
102
  else {
104
103
  // 仅在 vue 或 纯原生 App.vue 编译时做 copy
105
- if (process.env.UNI_COMPILER === 'vue' ||
104
+ if (process.env.UNI_COMPILER !== 'nvue' ||
106
105
  (process.env.UNI_RENDERER === 'native' &&
107
106
  process.env.UNI_RENDERER_NATIVE === 'appService')) {
108
107
  addCopyPlugin = true;
@@ -112,6 +111,9 @@ function createPlugins(options) {
112
111
  addCopyPlugin = true;
113
112
  }
114
113
  }
114
+ if (process.env.UNI_COMPILE_TARGET === 'uni_modules') {
115
+ addCopyPlugin = false;
116
+ }
115
117
  if (addCopyPlugin) {
116
118
  plugins.push((0, copy_1.uniCopyPlugin)({
117
119
  outputDir: process.env.UNI_OUTPUT_DIR,
@@ -157,9 +159,11 @@ function createUVueAndroidPlugins(options) {
157
159
  process.env.UNI_NODE_ENV !== process.env.NODE_ENV) {
158
160
  process.env.NODE_ENV = process.env.UNI_NODE_ENV;
159
161
  }
160
- plugins.push((0, copy_1.uniCopyPlugin)({
161
- outputDir: process.env.UNI_OUTPUT_DIR,
162
- copyOptions: options.copyOptions,
163
- }));
162
+ if (process.env.UNI_COMPILE_TARGET !== 'uni_modules') {
163
+ plugins.push((0, copy_1.uniCopyPlugin)({
164
+ outputDir: process.env.UNI_OUTPUT_DIR,
165
+ copyOptions: options.copyOptions,
166
+ }));
167
+ }
164
168
  return plugins;
165
169
  }
@@ -39,6 +39,7 @@ function uniCopyPlugin({ outputDir, copyOptions, }) {
39
39
  src: assets,
40
40
  dest: outputDir,
41
41
  watchOptions: {
42
+ followSymlinks: false, // 不设置为false的话,如果uni_modules软链了,会拷贝所有的不匹配文件
42
43
  ignored(path) {
43
44
  const normalizedPath = (0, uni_cli_shared_1.normalizePath)(path);
44
45
  if (ignorePlatformStaticDirs.find((dir) => normalizedPath.includes(dir))) {
@@ -87,14 +87,26 @@ function initPluginVueOptions(options, UniVitePlugins, uniPluginOptions) {
87
87
  if (!compilerOptions.nodeTransforms) {
88
88
  compilerOptions.nodeTransforms = [];
89
89
  }
90
- if (options.platform === 'h5' || options.platform === 'web') {
91
- templateOptions.transformAssetUrls = (0, uni_cli_shared_1.createUniVueTransformAssetUrls)((0, uni_cli_shared_1.isExternalUrl)(options.base) ? options.base : '');
92
- }
93
- else {
94
- // 替换内置的 transformAssetUrls 逻辑
90
+ // 合并 transformAssetUrls
91
+ // 内置配置
92
+ const builtInTransformAssetUrls = (0, uni_cli_shared_1.createUniVueTransformAssetUrls)((0, uni_cli_shared_1.isExternalUrl)(options.base) ? options.base : '');
93
+ // 用户传递配置 eg: transformAssetUrls.tags = {'my-image': ['src']}
94
+ // docs: https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue
95
+ const userOptionsTransformAssetUrls = templateOptions.transformAssetUrls;
96
+ templateOptions.transformAssetUrls = builtInTransformAssetUrls;
97
+ if (typeof userOptionsTransformAssetUrls !== 'boolean' &&
98
+ !!userOptionsTransformAssetUrls?.tags &&
99
+ !Array.isArray(userOptionsTransformAssetUrls.tags)) {
95
100
  templateOptions.transformAssetUrls = {
96
- tags: {},
101
+ ...builtInTransformAssetUrls,
102
+ ...userOptionsTransformAssetUrls,
103
+ tags: {
104
+ ...builtInTransformAssetUrls.tags,
105
+ ...userOptionsTransformAssetUrls.tags,
106
+ },
97
107
  };
108
+ }
109
+ if (options.platform !== 'h5' && options.platform !== 'web') {
98
110
  compilerOptions.nodeTransforms.push(...(0, uni_cli_shared_1.getBaseNodeTransforms)(options.base));
99
111
  }
100
112
  if (nodeTransforms) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/vite-plugin-uni",
3
- "version": "3.0.0-4010420240430002",
3
+ "version": "3.0.0-4020320240708001",
4
4
  "description": "uni-app vite plugin",
5
5
  "bin": {
6
6
  "uni": "bin/uni.js"
@@ -27,8 +27,8 @@
27
27
  "@babel/core": "^7.23.3",
28
28
  "@babel/plugin-syntax-import-meta": "^7.10.4",
29
29
  "@babel/plugin-transform-typescript": "^7.23.3",
30
- "@dcloudio/uni-cli-shared": "3.0.0-4010420240430002",
31
- "@dcloudio/uni-shared": "3.0.0-4010420240430002",
30
+ "@dcloudio/uni-cli-shared": "3.0.0-4020320240708001",
31
+ "@dcloudio/uni-shared": "3.0.0-4020320240708001",
32
32
  "@rollup/pluginutils": "^5.0.5",
33
33
  "@vitejs/plugin-legacy": "^5.3.2",
34
34
  "@vitejs/plugin-vue": "^5.0.4",
@@ -65,7 +65,7 @@
65
65
  "vite": "^5.2.8"
66
66
  },
67
67
  "uni-app": {
68
- "compilerVersion": "4.14"
68
+ "compilerVersion": "4.23"
69
69
  },
70
70
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da"
71
71
  }
@@ -1,3 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- import type { VitePluginUniResolvedOptions } from '..';
3
- export declare function createResolveId(options: VitePluginUniResolvedOptions): Plugin['resolveId'];
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createResolveId = void 0;
4
- const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
5
- function createResolveId(options) {
6
- const inputDir = (0, uni_cli_shared_1.normalizePath)(options.inputDir);
7
- return function (id) {
8
- if (id.startsWith('@/')) {
9
- return inputDir + id.slice(1);
10
- }
11
- else if (id.startsWith('~@/')) {
12
- return inputDir + id.slice(2);
13
- }
14
- };
15
- }
16
- exports.createResolveId = createResolveId;