@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
package/dist/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
var _a;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.runBuild = exports.runDev = void 0;
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const debug_1 = __importDefault(require("debug"));
|
|
10
|
+
const plugin_vue_1 = __importDefault(require("@vitejs/plugin-vue"));
|
|
11
|
+
const plugin_vue_jsx_1 = __importDefault(require("@vitejs/plugin-vue-jsx"));
|
|
12
|
+
const plugin_legacy_1 = __importDefault(require("@vitejs/plugin-legacy"));
|
|
13
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
14
|
+
const config_1 = require("./config");
|
|
15
|
+
const configResolved_1 = require("./configResolved");
|
|
16
|
+
const copy_1 = require("./plugins/copy");
|
|
17
|
+
const utils_1 = require("./utils");
|
|
18
|
+
const vue_1 = require("./vue");
|
|
19
|
+
// import { createResolveId } from './resolveId'
|
|
20
|
+
const debugUni = (0, debug_1.default)('uni:plugin');
|
|
21
|
+
const pkg = require(path_1.default.resolve(__dirname, '../package.json'));
|
|
22
|
+
(0, uni_cli_shared_1.initModuleAlias)();
|
|
23
|
+
(0, utils_1.rewriteCompilerSfcParse)();
|
|
24
|
+
process.env.UNI_COMPILER_VERSION = ((_a = pkg['uni-app']) === null || _a === void 0 ? void 0 : _a['compilerVersion']) || '';
|
|
25
|
+
process.env.UNI_COMPILER_VERSION_TYPE = pkg.version.includes('alpha')
|
|
26
|
+
? 'a'
|
|
27
|
+
: 'r';
|
|
28
|
+
var action_1 = require("./cli/action");
|
|
29
|
+
Object.defineProperty(exports, "runDev", { enumerable: true, get: function () { return action_1.runDev; } });
|
|
30
|
+
Object.defineProperty(exports, "runBuild", { enumerable: true, get: function () { return action_1.runBuild; } });
|
|
31
|
+
function uniPlugin(rawOptions = {}) {
|
|
32
|
+
const options = {
|
|
33
|
+
...rawOptions,
|
|
34
|
+
base: '/',
|
|
35
|
+
assetsDir: 'assets',
|
|
36
|
+
inputDir: '',
|
|
37
|
+
outputDir: '',
|
|
38
|
+
command: 'serve',
|
|
39
|
+
platform: 'h5',
|
|
40
|
+
};
|
|
41
|
+
options.platform = process.env.UNI_PLATFORM || 'h5';
|
|
42
|
+
options.inputDir = process.env.UNI_INPUT_DIR;
|
|
43
|
+
(0, uni_cli_shared_1.initPreContext)(options.platform, process.env.UNI_CUSTOM_CONTEXT);
|
|
44
|
+
const plugins = [];
|
|
45
|
+
if (options.viteLegacyOptions) {
|
|
46
|
+
plugins.push(...(0, plugin_legacy_1.default)((0, vue_1.initPluginViteLegacyOptions)(options)));
|
|
47
|
+
}
|
|
48
|
+
const uniPlugins = (0, utils_1.initExtraPlugins)(process.env.UNI_CLI_CONTEXT || process.cwd(), process.env.UNI_PLATFORM || 'h5', options);
|
|
49
|
+
debugUni(uniPlugins);
|
|
50
|
+
const uniPluginOptions = (0, utils_1.initPluginUniOptions)(uniPlugins);
|
|
51
|
+
options.copyOptions = uniPluginOptions.copyOptions;
|
|
52
|
+
if (options.vueJsxOptions) {
|
|
53
|
+
plugins.push((0, plugin_vue_jsx_1.default)((0, vue_1.initPluginVueJsxOptions)(options, uniPluginOptions.compilerOptions, uniPluginOptions.jsxOptions)));
|
|
54
|
+
}
|
|
55
|
+
plugins.push({
|
|
56
|
+
name: 'uni',
|
|
57
|
+
config: (0, config_1.createConfig)(options, uniPlugins),
|
|
58
|
+
// resolveId: createResolveId(options),
|
|
59
|
+
configResolved: (0, configResolved_1.createConfigResolved)(options),
|
|
60
|
+
});
|
|
61
|
+
plugins.push(...uniPlugins);
|
|
62
|
+
// 执行 build 命令时,vite 强制了 NODE_ENV
|
|
63
|
+
// https://github.com/vitejs/vite/blob/main/packages/vite/src/node/build.ts#L405
|
|
64
|
+
// const config = await resolveConfig(inlineConfig, 'build', 'production')
|
|
65
|
+
// 在 @vitejs/plugin-vue 之前校正回来
|
|
66
|
+
if (process.env.UNI_NODE_ENV &&
|
|
67
|
+
process.env.UNI_NODE_ENV !== process.env.NODE_ENV) {
|
|
68
|
+
process.env.NODE_ENV = process.env.UNI_NODE_ENV;
|
|
69
|
+
}
|
|
70
|
+
plugins.unshift((0, plugin_vue_1.default)((0, vue_1.initPluginVueOptions)(options, uniPlugins, uniPluginOptions)));
|
|
71
|
+
// 混合编译时,nvue 下,不需要 copy
|
|
72
|
+
if (process.env.UNI_RENDERER === 'native' ||
|
|
73
|
+
process.env.UNI_COMPILER === 'vue') {
|
|
74
|
+
plugins.push((0, copy_1.uniCopyPlugin)({
|
|
75
|
+
outputDir: process.env.UNI_OUTPUT_DIR,
|
|
76
|
+
copyOptions: options.copyOptions,
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
return plugins;
|
|
80
|
+
}
|
|
81
|
+
exports.default = uniPlugin;
|
|
@@ -0,0 +1,55 @@
|
|
|
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.uniCopyPlugin = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const debug_1 = __importDefault(require("debug"));
|
|
10
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
11
|
+
const debugCopy = (0, debug_1.default)('uni:copy');
|
|
12
|
+
function uniCopyPlugin({ outputDir, copyOptions, }) {
|
|
13
|
+
const staticDir = uni_cli_shared_1.PUBLIC_DIR + '/**/*';
|
|
14
|
+
const uniModulesStaticDir = 'uni_modules/*/' + uni_cli_shared_1.PUBLIC_DIR + '/**/*';
|
|
15
|
+
const assets = [staticDir, uniModulesStaticDir];
|
|
16
|
+
const subpackages = (0, uni_cli_shared_1.parseSubpackagesRootOnce)(process.env.UNI_INPUT_DIR, process.env.UNI_PLATFORM);
|
|
17
|
+
subpackages.forEach((root) => {
|
|
18
|
+
assets.push((0, uni_cli_shared_1.normalizePath)(path_1.default.join(root, staticDir)));
|
|
19
|
+
assets.push((0, uni_cli_shared_1.normalizePath)(path_1.default.join(root, uniModulesStaticDir)));
|
|
20
|
+
});
|
|
21
|
+
copyOptions.assets.forEach((asset) => {
|
|
22
|
+
assets.push(asset);
|
|
23
|
+
});
|
|
24
|
+
const platform = process.env.UNI_PLATFORM;
|
|
25
|
+
// 非当前平台 static 目录
|
|
26
|
+
const platformStaticDirs = (0, uni_cli_shared_1.getPlatforms)()
|
|
27
|
+
.filter((p) => {
|
|
28
|
+
if (platform === 'app') {
|
|
29
|
+
return p !== 'app' && p !== 'app-plus';
|
|
30
|
+
}
|
|
31
|
+
return p !== platform;
|
|
32
|
+
})
|
|
33
|
+
.map((p) => '/' + uni_cli_shared_1.PUBLIC_DIR + '/' + p);
|
|
34
|
+
const targets = [
|
|
35
|
+
{
|
|
36
|
+
src: assets,
|
|
37
|
+
dest: outputDir,
|
|
38
|
+
watchOptions: {
|
|
39
|
+
ignored(path) {
|
|
40
|
+
const normalizedPath = (0, uni_cli_shared_1.normalizePath)(path);
|
|
41
|
+
if (platformStaticDirs.find((dir) => normalizedPath.includes(dir))) {
|
|
42
|
+
return fs_1.default.statSync(normalizedPath).isDirectory;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
targets.push(...copyOptions.targets);
|
|
49
|
+
debugCopy(targets);
|
|
50
|
+
return (0, uni_cli_shared_1.uniViteCopyPlugin)({
|
|
51
|
+
targets,
|
|
52
|
+
verbose: process.env.DEBUG ? true : false,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exports.uniCopyPlugin = uniCopyPlugin;
|
|
@@ -0,0 +1,16 @@
|
|
|
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.substr(1);
|
|
10
|
+
}
|
|
11
|
+
else if (id.startsWith('~@/')) {
|
|
12
|
+
return inputDir + id.substr(2);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.createResolveId = createResolveId;
|
|
@@ -0,0 +1,37 @@
|
|
|
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.initEasycom = void 0;
|
|
7
|
+
const debug_1 = __importDefault(require("debug"));
|
|
8
|
+
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
9
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
10
|
+
const debugEasycom = (0, debug_1.default)('uni:easycom');
|
|
11
|
+
const initEasycom = (watcher) => {
|
|
12
|
+
const { filter, refresh, options } = (0, uni_cli_shared_1.initEasycomsOnce)(process.env.UNI_INPUT_DIR, {
|
|
13
|
+
dirs: [(0, uni_cli_shared_1.resolveComponentsLibPath)()],
|
|
14
|
+
platform: process.env.UNI_PLATFORM,
|
|
15
|
+
});
|
|
16
|
+
if (!watcher) {
|
|
17
|
+
// build 模式,手动初始化 watcher
|
|
18
|
+
debugEasycom('initWatch', options.dirs);
|
|
19
|
+
watcher = uni_cli_shared_1.chokidar.watch(options.dirs, {
|
|
20
|
+
ignored: ['**/node_modules/**', '**/.git/**'],
|
|
21
|
+
ignoreInitial: true,
|
|
22
|
+
ignorePermissionErrors: true,
|
|
23
|
+
disableGlobbing: true,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const refreshEasycom = (0, uni_shared_1.debounce)(refresh, 100);
|
|
27
|
+
watcher.on('all', (eventName, path) => {
|
|
28
|
+
if (!['add', 'unlink'].includes(eventName)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (filter(path)) {
|
|
32
|
+
debugEasycom('watch', eventName, path);
|
|
33
|
+
refreshEasycom();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
exports.initEasycom = initEasycom;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createPublicFileFilter(base?: string): (id: unknown) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
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.createPublicFileFilter = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const pluginutils_1 = require("@rollup/pluginutils");
|
|
9
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
10
|
+
function createPublicFileFilter(base = '/') {
|
|
11
|
+
const publicDir = (0, uni_cli_shared_1.normalizePath)(path_1.default.join(base, uni_cli_shared_1.PUBLIC_DIR + '/**/*'));
|
|
12
|
+
const uniModulesDir = (0, uni_cli_shared_1.normalizePath)(path_1.default.join(base, 'uni_modules/*/' + uni_cli_shared_1.PUBLIC_DIR + '/**/*'));
|
|
13
|
+
return (0, pluginutils_1.createFilter)([publicDir, uniModulesDir]);
|
|
14
|
+
}
|
|
15
|
+
exports.createPublicFileFilter = createPublicFileFilter;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./filter"), exports);
|
|
14
|
+
__exportStar(require("./plugin"), exports);
|
|
15
|
+
__exportStar(require("./polyfill"), exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import { UniViteCopyPluginTarget, UniVitePlugin } from '@dcloudio/uni-cli-shared';
|
|
3
|
+
import type { TemplateCompiler } from '@vue/compiler-sfc';
|
|
4
|
+
import { VitePluginUniResolvedOptions } from '..';
|
|
5
|
+
export declare function initPluginUniOptions(UniVitePlugins: UniVitePlugin[]): {
|
|
6
|
+
compiler: TemplateCompiler | undefined;
|
|
7
|
+
copyOptions: {
|
|
8
|
+
assets: string[];
|
|
9
|
+
targets: UniViteCopyPluginTarget[];
|
|
10
|
+
};
|
|
11
|
+
transformEvent: Record<string, string>;
|
|
12
|
+
compilerOptions: {
|
|
13
|
+
miniProgram?: {
|
|
14
|
+
emitFile?: ((emittedFile: import("rollup").EmittedAsset) => string) | undefined;
|
|
15
|
+
} | undefined;
|
|
16
|
+
isNativeTag?: ((tag: string) => boolean) | undefined;
|
|
17
|
+
isCustomElement?: ((tag: string) => boolean | void) | undefined;
|
|
18
|
+
directiveTransforms?: Record<string, import("@vue/compiler-core").DirectiveTransform | undefined> | undefined;
|
|
19
|
+
nodeTransforms?: import("@vue/compiler-core").NodeTransform[] | undefined;
|
|
20
|
+
};
|
|
21
|
+
jsxOptions: {
|
|
22
|
+
babelPlugins?: any[] | undefined;
|
|
23
|
+
};
|
|
24
|
+
styleOptions: Pick<import("@vue/compiler-sfc").SFCStyleCompileOptions, "postcssPlugins">;
|
|
25
|
+
};
|
|
26
|
+
export declare function initExtraPlugins(cliRoot: string, platform: UniApp.PLATFORM, options: VitePluginUniResolvedOptions): Plugin[];
|
|
@@ -0,0 +1,115 @@
|
|
|
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.initExtraPlugins = exports.initPluginUniOptions = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const shared_1 = require("@vue/shared");
|
|
9
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
10
|
+
function initPluginUniOptions(UniVitePlugins) {
|
|
11
|
+
const assets = [];
|
|
12
|
+
const targets = [];
|
|
13
|
+
const transformEvent = Object.create(null);
|
|
14
|
+
const compilerOptions = {};
|
|
15
|
+
const jsxOptions = {};
|
|
16
|
+
const styleOptions = {};
|
|
17
|
+
let compiler;
|
|
18
|
+
UniVitePlugins.forEach((plugin) => {
|
|
19
|
+
const { compiler: pluginTemplateCompiler, copyOptions: pluginCopyOptions, compilerOptions: pluginCompilerOptions, jsxOptions: pluginJsxOptions, styleOptions: pluginStyleOpitons, } = plugin.uni || {};
|
|
20
|
+
if (pluginTemplateCompiler) {
|
|
21
|
+
compiler = pluginTemplateCompiler;
|
|
22
|
+
}
|
|
23
|
+
if (pluginCompilerOptions) {
|
|
24
|
+
(0, shared_1.extend)(compilerOptions, pluginCompilerOptions);
|
|
25
|
+
}
|
|
26
|
+
if (pluginJsxOptions) {
|
|
27
|
+
(0, shared_1.extend)(jsxOptions, pluginJsxOptions);
|
|
28
|
+
}
|
|
29
|
+
if (pluginStyleOpitons) {
|
|
30
|
+
(0, shared_1.extend)(styleOptions, pluginStyleOpitons);
|
|
31
|
+
}
|
|
32
|
+
if (pluginCopyOptions) {
|
|
33
|
+
let copyOptions = pluginCopyOptions;
|
|
34
|
+
if ((0, shared_1.isFunction)(pluginCopyOptions)) {
|
|
35
|
+
copyOptions = pluginCopyOptions();
|
|
36
|
+
}
|
|
37
|
+
if (copyOptions.assets) {
|
|
38
|
+
assets.push(...copyOptions.assets);
|
|
39
|
+
}
|
|
40
|
+
if (copyOptions.targets) {
|
|
41
|
+
targets.push(...copyOptions.targets);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
compiler,
|
|
47
|
+
copyOptions: {
|
|
48
|
+
assets,
|
|
49
|
+
targets,
|
|
50
|
+
},
|
|
51
|
+
transformEvent,
|
|
52
|
+
compilerOptions,
|
|
53
|
+
jsxOptions,
|
|
54
|
+
styleOptions,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.initPluginUniOptions = initPluginUniOptions;
|
|
58
|
+
function initExtraPlugins(cliRoot, platform, options) {
|
|
59
|
+
return initPlugins(resolvePlugins(cliRoot, platform), options);
|
|
60
|
+
}
|
|
61
|
+
exports.initExtraPlugins = initExtraPlugins;
|
|
62
|
+
function initPlugin({ id, config: { main } }, options) {
|
|
63
|
+
let plugin = require(path_1.default.join(id, main || '/lib/uni.plugin.js'));
|
|
64
|
+
plugin = plugin.default || plugin;
|
|
65
|
+
if ((0, shared_1.isFunction)(plugin)) {
|
|
66
|
+
plugin = plugin(options);
|
|
67
|
+
}
|
|
68
|
+
return plugin;
|
|
69
|
+
}
|
|
70
|
+
function initPlugins(plugins, options) {
|
|
71
|
+
return plugins
|
|
72
|
+
.map((plugin) => initPlugin(plugin, options))
|
|
73
|
+
.flat()
|
|
74
|
+
.filter(Boolean)
|
|
75
|
+
.map((plugin) => {
|
|
76
|
+
if ((0, shared_1.isFunction)(plugin)) {
|
|
77
|
+
return plugin(options);
|
|
78
|
+
}
|
|
79
|
+
return plugin;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function resolvePlugins(cliRoot, platform) {
|
|
83
|
+
const pkg = require(path_1.default.join(cliRoot, 'package.json'));
|
|
84
|
+
return Object.keys(pkg.devDependencies || {})
|
|
85
|
+
.concat(Object.keys(pkg.dependencies || {}))
|
|
86
|
+
.map((id) => {
|
|
87
|
+
try {
|
|
88
|
+
const pluginPkg = require(id + '/package.json');
|
|
89
|
+
const config = pluginPkg['uni-app'];
|
|
90
|
+
if (!config || !config.name) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const { apply } = config;
|
|
94
|
+
if ((0, shared_1.isArray)(apply)) {
|
|
95
|
+
// 注册所有平台
|
|
96
|
+
apply.forEach((p) => (0, uni_cli_shared_1.registerPlatform)(p));
|
|
97
|
+
if (!apply.includes(platform)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if ((0, shared_1.isString)(apply)) {
|
|
102
|
+
if (!new RegExp(apply).test(platform)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
id,
|
|
108
|
+
name: config.name,
|
|
109
|
+
config,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
catch (e) { }
|
|
113
|
+
})
|
|
114
|
+
.filter(Boolean);
|
|
115
|
+
}
|
|
@@ -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.rewriteCompilerSfcParse = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
9
|
+
/**
|
|
10
|
+
* TODO 临时重写,解决 @vitejs/plugin-vue 的 Bug
|
|
11
|
+
*/
|
|
12
|
+
function rewriteCompilerSfcParse() {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
const compilerSfc = require((0, uni_cli_shared_1.resolveBuiltIn)('@vue/compiler-sfc'));
|
|
15
|
+
const { parse } = compilerSfc;
|
|
16
|
+
compilerSfc.parse = (source, options) => {
|
|
17
|
+
if (options === null || options === void 0 ? void 0 : options.filename) {
|
|
18
|
+
const extname = path_1.default.extname(options.filename);
|
|
19
|
+
// wxs、filter、renderjs
|
|
20
|
+
if (extname && !uni_cli_shared_1.EXTNAME_VUE.includes(extname)) {
|
|
21
|
+
const tag = extname.slice(1);
|
|
22
|
+
source = `<${tag}>` + source + `</${tag}>`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return parse(source, options);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.rewriteCompilerSfcParse = rewriteCompilerSfcParse;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './options';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./options"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TemplateCompiler } from '@vue/compiler-sfc';
|
|
2
|
+
import { UniVitePlugin } from '@dcloudio/uni-cli-shared';
|
|
3
|
+
import { VitePluginUniResolvedOptions } from '..';
|
|
4
|
+
export declare function initPluginVueOptions(options: VitePluginUniResolvedOptions, UniVitePlugins: UniVitePlugin[], uniPluginOptions: Required<Omit<Required<UniVitePlugin>['uni'], 'compiler'>> & {
|
|
5
|
+
compiler?: TemplateCompiler;
|
|
6
|
+
}): import("@vitejs/plugin-vue").Options;
|
|
7
|
+
export declare function initPluginVueJsxOptions(options: VitePluginUniResolvedOptions, { isCustomElement, }: Required<Required<UniVitePlugin>['uni']>['compilerOptions'], jsxOptions: Required<Required<UniVitePlugin>['uni']>['jsxOptions']): import("@vue/babel-plugin-jsx").VueJSXPluginOptions & {
|
|
8
|
+
babelPlugins?: any[] | undefined;
|
|
9
|
+
};
|
|
10
|
+
export declare function initPluginViteLegacyOptions(options: VitePluginUniResolvedOptions): import("@vitejs/plugin-legacy").Options;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initPluginViteLegacyOptions = exports.initPluginVueJsxOptions = exports.initPluginVueOptions = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
6
|
+
function initPluginVueOptions(options, UniVitePlugins, uniPluginOptions) {
|
|
7
|
+
const vueOptions = options.vueOptions || (options.vueOptions = {});
|
|
8
|
+
// if (!hasOwn(vueOptions, 'reactivityTransform')) {
|
|
9
|
+
// vueOptions.reactivityTransform = true
|
|
10
|
+
// }
|
|
11
|
+
if (!vueOptions.include) {
|
|
12
|
+
vueOptions.include = [];
|
|
13
|
+
}
|
|
14
|
+
if (!(0, shared_1.isArray)(vueOptions.include)) {
|
|
15
|
+
vueOptions.include = [vueOptions.include];
|
|
16
|
+
}
|
|
17
|
+
vueOptions.include.push(uni_cli_shared_1.EXTNAME_VUE_RE);
|
|
18
|
+
const styleOptions = vueOptions.style || (vueOptions.style = {});
|
|
19
|
+
if (!styleOptions.postcssPlugins) {
|
|
20
|
+
styleOptions.postcssPlugins = [];
|
|
21
|
+
}
|
|
22
|
+
// 解析 scoped 中 deep 等特殊语法
|
|
23
|
+
styleOptions.postcssPlugins.push((0, uni_cli_shared_1.uniPostcssScopedPlugin)());
|
|
24
|
+
const templateOptions = vueOptions.template || (vueOptions.template = {});
|
|
25
|
+
const compilerOptions = templateOptions.compilerOptions || (templateOptions.compilerOptions = {});
|
|
26
|
+
const { compiler, styleOptions: { postcssPlugins }, compilerOptions: { miniProgram, isNativeTag, isCustomElement, nodeTransforms, directiveTransforms, }, } = uniPluginOptions;
|
|
27
|
+
if (postcssPlugins) {
|
|
28
|
+
styleOptions.postcssPlugins.push(...postcssPlugins);
|
|
29
|
+
}
|
|
30
|
+
if (compiler) {
|
|
31
|
+
templateOptions.compiler = compiler;
|
|
32
|
+
}
|
|
33
|
+
if (miniProgram) {
|
|
34
|
+
;
|
|
35
|
+
compilerOptions.miniProgram = miniProgram;
|
|
36
|
+
}
|
|
37
|
+
if (isNativeTag) {
|
|
38
|
+
const userIsNativeTag = compilerOptions.isNativeTag;
|
|
39
|
+
compilerOptions.isNativeTag = (tag) => {
|
|
40
|
+
if (isNativeTag(tag)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (userIsNativeTag && userIsNativeTag(tag)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (isCustomElement) {
|
|
50
|
+
const userIsCustomElement = compilerOptions.isCustomElement;
|
|
51
|
+
compilerOptions.isCustomElement = (tag) => {
|
|
52
|
+
if (isCustomElement(tag)) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
if (userIsCustomElement && userIsCustomElement(tag)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
compilerOptions.directiveTransforms = {
|
|
62
|
+
...compilerOptions.directiveTransforms,
|
|
63
|
+
...directiveTransforms,
|
|
64
|
+
};
|
|
65
|
+
if (!compilerOptions.nodeTransforms) {
|
|
66
|
+
compilerOptions.nodeTransforms = [];
|
|
67
|
+
}
|
|
68
|
+
if (options.platform === 'h5') {
|
|
69
|
+
templateOptions.transformAssetUrls = (0, uni_cli_shared_1.createUniVueTransformAssetUrls)((0, uni_cli_shared_1.isExternalUrl)(options.base) ? options.base : '');
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// 替换内置的 transformAssetUrls 逻辑
|
|
73
|
+
templateOptions.transformAssetUrls = {
|
|
74
|
+
tags: {},
|
|
75
|
+
};
|
|
76
|
+
compilerOptions.nodeTransforms.push(...(0, uni_cli_shared_1.getBaseNodeTransforms)(options.base));
|
|
77
|
+
}
|
|
78
|
+
if (nodeTransforms) {
|
|
79
|
+
compilerOptions.nodeTransforms.push(...nodeTransforms);
|
|
80
|
+
}
|
|
81
|
+
// const compatConfig = parseCompatConfigOnce(options.inputDir)
|
|
82
|
+
// compilerOptions.compatConfig = extend(
|
|
83
|
+
// compilerOptions.compatConfig || {},
|
|
84
|
+
// compatConfig
|
|
85
|
+
// )
|
|
86
|
+
// App,MP 平台不支持使用静态节点
|
|
87
|
+
compilerOptions.hoistStatic = false;
|
|
88
|
+
compilerOptions.root = process.env.UNI_INPUT_DIR;
|
|
89
|
+
// app-nvue 需要启用 customElement 机制来内联 styles
|
|
90
|
+
if (process.env.UNI_COMPILER === 'nvue') {
|
|
91
|
+
vueOptions.customElement = true;
|
|
92
|
+
}
|
|
93
|
+
return vueOptions;
|
|
94
|
+
}
|
|
95
|
+
exports.initPluginVueOptions = initPluginVueOptions;
|
|
96
|
+
function initPluginVueJsxOptions(options, { isCustomElement, }, jsxOptions) {
|
|
97
|
+
const vueJsxOptions = (0, shared_1.isPlainObject)(options.vueJsxOptions)
|
|
98
|
+
? options.vueJsxOptions
|
|
99
|
+
: (options.vueJsxOptions = {});
|
|
100
|
+
if (!(0, shared_1.hasOwn)(vueJsxOptions, 'optimize')) {
|
|
101
|
+
vueJsxOptions.optimize = true;
|
|
102
|
+
}
|
|
103
|
+
vueJsxOptions.isCustomElement = isCustomElement;
|
|
104
|
+
if (!vueJsxOptions.babelPlugins) {
|
|
105
|
+
vueJsxOptions.babelPlugins = [];
|
|
106
|
+
}
|
|
107
|
+
if ((0, shared_1.isArray)(jsxOptions.babelPlugins)) {
|
|
108
|
+
vueJsxOptions.babelPlugins.push(...jsxOptions.babelPlugins);
|
|
109
|
+
}
|
|
110
|
+
return vueJsxOptions;
|
|
111
|
+
}
|
|
112
|
+
exports.initPluginVueJsxOptions = initPluginVueJsxOptions;
|
|
113
|
+
function initPluginViteLegacyOptions(options) {
|
|
114
|
+
const viteLegacyOptions = options.viteLegacyOptions || (options.viteLegacyOptions = {});
|
|
115
|
+
return viteLegacyOptions;
|
|
116
|
+
}
|
|
117
|
+
exports.initPluginViteLegacyOptions = initPluginViteLegacyOptions;
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dcloudio/vite-plugin-uni",
|
|
3
|
+
"version": "0.0.1-nvue3.3030820220125001",
|
|
4
|
+
"description": "uni-app vite plugin",
|
|
5
|
+
"bin": {
|
|
6
|
+
"uni": "bin/uni.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"dist",
|
|
13
|
+
"lib"
|
|
14
|
+
],
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/dcloudio/uni-app.git",
|
|
18
|
+
"directory": "packages/vite-plugin-uni"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
22
|
+
},
|
|
23
|
+
"license": "Apache-2.0",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@babel/core": "^7.16.5",
|
|
26
|
+
"@babel/plugin-syntax-import-meta": "^7.10.4",
|
|
27
|
+
"@babel/plugin-transform-typescript": "^7.16.1",
|
|
28
|
+
"@dcloudio/uni-cli-shared": "0.0.1-nvue3.3030820220125001",
|
|
29
|
+
"@dcloudio/uni-shared": "0.0.1-nvue3.3030820220125001",
|
|
30
|
+
"@rollup/pluginutils": "^4.1.2",
|
|
31
|
+
"@vitejs/plugin-legacy": "^1.6.4",
|
|
32
|
+
"@vitejs/plugin-vue": "^2.1.0",
|
|
33
|
+
"@vitejs/plugin-vue-jsx": "^1.3.3",
|
|
34
|
+
"@vue/compiler-core": "3.2.29",
|
|
35
|
+
"@vue/compiler-dom": "3.2.29",
|
|
36
|
+
"@vue/compiler-sfc": "3.2.29",
|
|
37
|
+
"@vue/shared": "3.2.29",
|
|
38
|
+
"cac": "^6.7.3",
|
|
39
|
+
"debug": "^4.3.2",
|
|
40
|
+
"estree-walker": "^2.0.2",
|
|
41
|
+
"express": "^4.17.1",
|
|
42
|
+
"fs-extra": "^10.0.0",
|
|
43
|
+
"hash-sum": "^2.0.0",
|
|
44
|
+
"jsonc-parser": "^3.0.0",
|
|
45
|
+
"picocolors": "^1.0.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/debug": "^4.1.7",
|
|
49
|
+
"@types/express": "^4.17.12",
|
|
50
|
+
"@types/fs-extra": "^9.0.13",
|
|
51
|
+
"@types/sass": "^1.16.0",
|
|
52
|
+
"@vue/babel-plugin-jsx": "^1.1.1",
|
|
53
|
+
"chokidar": "^3.5.2"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"vite": "^2.7.0"
|
|
57
|
+
},
|
|
58
|
+
"uni-app": {
|
|
59
|
+
"compilerVersion": "3.3.8"
|
|
60
|
+
},
|
|
61
|
+
"gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da"
|
|
62
|
+
}
|