@umijs/preset-vue 4.0.0-rc.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @umijs/preset-vue
2
+
3
+ See our website [umijs](https://umijs.org) for more information.
@@ -0,0 +1 @@
1
+ export declare const TEMPLATES_DIR: string;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TEMPLATES_DIR = void 0;
4
+ const path_1 = require("path");
5
+ exports.TEMPLATES_DIR = (0, path_1.join)(__dirname, '../templates');
@@ -0,0 +1,8 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { IApi } from 'umi';
3
+ interface IOpts {
4
+ config: Config;
5
+ api: IApi;
6
+ }
7
+ export declare function addAssetRules({ config, api }: IOpts): Promise<void>;
8
+ export {};
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addAssetRules = void 0;
13
+ function addAssetRules({ config, api }) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ // bundler-webpack 本身自带的静态资源会触发 vue-loader currently does not support vue rules with oneOf. 需要禁用掉
16
+ config.module.rules.delete('asset');
17
+ const { userConfig } = api;
18
+ const inlineLimit = parseInt(userConfig.inlineLimit || '10000', 10);
19
+ const staticPathPrefix = api.config.staticPathPrefix !== undefined
20
+ ? api.config.staticPathPrefix
21
+ : 'static/';
22
+ config.module
23
+ .rule('avif')
24
+ .test(/\.avif$/)
25
+ .type('asset')
26
+ .mimetype('image/avif')
27
+ .parser({
28
+ dataUrlCondition: {
29
+ maxSize: inlineLimit,
30
+ },
31
+ })
32
+ .generator({
33
+ filename: `${staticPathPrefix}[name].[hash:8].[ext]`,
34
+ });
35
+ config.module
36
+ .rule('image')
37
+ .test(/\.(bmp|gif|jpg|jpeg|png)$/)
38
+ .type('asset')
39
+ .parser({
40
+ dataUrlCondition: {
41
+ maxSize: inlineLimit,
42
+ },
43
+ })
44
+ .generator({
45
+ filename: `${staticPathPrefix}[name].[hash:8].[ext]`,
46
+ });
47
+ });
48
+ }
49
+ exports.addAssetRules = addAssetRules;
@@ -0,0 +1,3 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { IApi } from 'umi';
3
+ export declare function getConfig(config: Config, api: IApi): void;
@@ -0,0 +1,45 @@
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.getConfig = void 0;
7
+ const pluginWebpack5_js_1 = __importDefault(require("vue-loader/dist/pluginWebpack5.js"));
8
+ const assetRules_1 = require("./assetRules");
9
+ function getConfig(config, api) {
10
+ config.module.noParse(/^(vue|vue-router|vuex|vuex-router-sync)$/);
11
+ // https://github.com/webpack/webpack/issues/14532#issuecomment-947525539
12
+ config.output.set('hashFunction', 'xxhash64');
13
+ // https://github.com/webpack/webpack/issues/11467#issuecomment-691873586
14
+ config.module
15
+ .rule('esm')
16
+ .test(/\.m?jsx?$/)
17
+ .resolve.set('fullySpecified', false);
18
+ config.resolve.extensions.merge(['.vue']).end();
19
+ config.module
20
+ .rule('vue')
21
+ .test(/\.vue$/)
22
+ .use('vue-loader')
23
+ .loader(require.resolve('vue-loader'))
24
+ .options({
25
+ babelParserPlugins: ['jsx', 'classProperties', 'decorators-legacy'],
26
+ });
27
+ config.plugin('vue-loader-plugin').use(pluginWebpack5_js_1.default);
28
+ // https://github.com/vuejs/vue-loader/issues/1435#issuecomment-869074949
29
+ config.module
30
+ .rule('vue-style')
31
+ .test(/\.vue$/)
32
+ .resourceQuery(/type=style/)
33
+ .sideEffects(true);
34
+ // 兼容 element-ui plus
35
+ config.module
36
+ .rule('fix-element-ui-plus')
37
+ .test(/\.mjs$/)
38
+ .include.add(/node_modules/)
39
+ .end()
40
+ .type('javascript/auto')
41
+ .resolve.fullySpecified(false);
42
+ // asset
43
+ (0, assetRules_1.addAssetRules)({ api, config });
44
+ }
45
+ exports.getConfig = getConfig;
@@ -0,0 +1,3 @@
1
+ import type { IApi } from 'umi';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path_1 = require("path");
4
+ const resolveProjectDep_1 = require("../utils/resolveProjectDep");
5
+ exports.default = (api) => {
6
+ api.describe({
7
+ key: 'preset-vue:default',
8
+ });
9
+ const vuePath = (0, resolveProjectDep_1.resolveProjectDep)({
10
+ pkg: api.pkg,
11
+ cwd: api.cwd,
12
+ dep: 'vue/dist/vue.esm-bundler.js',
13
+ }) || require.resolve('vue/dist/vue.esm-bundler.js');
14
+ const vueRuntimePath = (0, resolveProjectDep_1.resolveProjectDep)({
15
+ pkg: api.pkg,
16
+ cwd: api.cwd,
17
+ dep: 'vue/dist/vue.runtime.esm-bundler.js',
18
+ }) || require.resolve('vue/dist/vue.runtime.esm-bundler.js');
19
+ api.modifyDefaultConfig((config) => {
20
+ var _a;
21
+ config.alias = Object.assign(Object.assign({}, config.alias), { vue$: ((_a = api.userConfig.vue) === null || _a === void 0 ? void 0 : _a.runtimeCompiler) ? vuePath : vueRuntimePath, 'vue-router': (0, resolveProjectDep_1.resolveProjectDep)({
22
+ pkg: api.pkg,
23
+ cwd: api.cwd,
24
+ dep: 'vue-router',
25
+ }) || (0, path_1.dirname)(require.resolve('vue-router/package.json')) });
26
+ // feature flags https://link.vuejs.org/feature-flags.
27
+ config.define = Object.assign(Object.assign({}, config.define), { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false });
28
+ return config;
29
+ });
30
+ api.modifyConfig((memo) => {
31
+ // react 独有配置需要禁用
32
+ memo.fastRefresh = false;
33
+ return memo;
34
+ });
35
+ api.modifyRendererPath(() => (0, path_1.dirname)(require.resolve('@umijs/renderer-vue/package.json')));
36
+ // 增加运行时key
37
+ api.addRuntimePluginKey(() => [
38
+ 'router',
39
+ 'onRouterCreated',
40
+ 'onAppCreated',
41
+ 'onMounted',
42
+ ]);
43
+ };
@@ -0,0 +1,3 @@
1
+ import type { IApi } from 'umi';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const path_1 = require("path");
13
+ const plugin_utils_1 = require("umi/plugin-utils");
14
+ const constants_1 = require("../../constants");
15
+ exports.default = (api) => {
16
+ api.describe({
17
+ key: 'preset-vue:tmpFiles',
18
+ });
19
+ api.onGenerateFiles(() => __awaiter(void 0, void 0, void 0, function* () {
20
+ // useAppData.ts
21
+ const rendererPath = (0, plugin_utils_1.winPath)(yield api.applyPlugins({
22
+ key: 'modifyRendererPath',
23
+ }));
24
+ api.writeTmpFile({
25
+ noPluginDir: true,
26
+ path: 'plugin-vue/index.ts',
27
+ tplPath: (0, path_1.join)(constants_1.TEMPLATES_DIR, 'useAppData.tpl'),
28
+ context: {
29
+ rendererPath,
30
+ },
31
+ });
32
+ }));
33
+ api.register({
34
+ key: 'onGenerateFiles',
35
+ fn: () => __awaiter(void 0, void 0, void 0, function* () {
36
+ // history.ts
37
+ const rendererPath = (0, plugin_utils_1.winPath)(yield api.applyPlugins({
38
+ key: 'modifyRendererPath',
39
+ }));
40
+ api.writeTmpFile({
41
+ noPluginDir: true,
42
+ path: 'core/history.ts',
43
+ tplPath: (0, path_1.join)(constants_1.TEMPLATES_DIR, 'history.tpl'),
44
+ context: {
45
+ rendererPath,
46
+ },
47
+ });
48
+ // EmptyRoutes.tsx
49
+ api.writeTmpFile({
50
+ noPluginDir: true,
51
+ path: 'core/EmptyRoute.tsx',
52
+ content: `
53
+ import { defineComponent } from 'vue';
54
+
55
+ export default defineComponent({
56
+ setup() {
57
+ return () => <router-view></router-view>;
58
+ },
59
+ });
60
+ `,
61
+ });
62
+ // App.vue
63
+ api.writeTmpFile({
64
+ noPluginDir: true,
65
+ path: 'core/App.vue',
66
+ content: `
67
+ <template>
68
+ <router-view></router-view>
69
+ </template>
70
+ `,
71
+ });
72
+ }),
73
+ stage: Infinity,
74
+ });
75
+ };
@@ -0,0 +1,3 @@
1
+ import type { IApi } from 'umi';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config_1 = require("./config/config");
4
+ exports.default = (api) => {
5
+ api.describe({
6
+ key: 'preset-vue:webpack',
7
+ });
8
+ api.chainWebpack((config) => {
9
+ (0, config_1.getConfig)(config, api);
10
+ return config;
11
+ });
12
+ api.modifyConfig((memo) => {
13
+ // 处理 mfsu 包含vue 模块的依赖处理
14
+ const enableMFSU = memo.mfsu !== false;
15
+ if (enableMFSU) {
16
+ memo.mfsu = Object.assign(Object.assign({}, (memo.mfsu || {})), { chainWebpack(config) {
17
+ (0, config_1.getConfig)(config, api);
18
+ return config;
19
+ } });
20
+ }
21
+ return memo;
22
+ });
23
+ };
@@ -0,0 +1,6 @@
1
+ import type { IApi } from 'umi';
2
+ import './requireHook';
3
+ declare const _default: (api: IApi) => {
4
+ plugins: string[];
5
+ };
6
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./requireHook");
4
+ exports.default = (api) => {
5
+ api.describe({
6
+ key: 'vue',
7
+ config: {
8
+ schema(joi) {
9
+ return joi.object();
10
+ },
11
+ },
12
+ enableBy: api.EnableBy.config,
13
+ });
14
+ return {
15
+ plugins: [
16
+ require.resolve('./features/default'),
17
+ require.resolve('./features/webpack'),
18
+ require.resolve('./features/tmpFiles/tmpFiles'),
19
+ ],
20
+ };
21
+ };
@@ -0,0 +1,2 @@
1
+ declare const hookPropertyMap: Map<string, string>;
2
+ export { hookPropertyMap };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ // MIT: copy from https://github.com/vercel/next.js/blob/canary/packages/next/build/webpack/require-hook.ts
3
+ // sync injects a hook for webpack and webpack/... requires to use the internal ncc webpack version
4
+ // this is in order for userland plugins to attach to the same webpack instance as umi
5
+ // the individual compiled modules are as defined for the compilation in bundles/webpack/packages/*
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.hookPropertyMap = void 0;
11
+ // TODO 之后走预打包处理
12
+ // @ts-ignore
13
+ const deepImports_json_1 = __importDefault(require("@umijs/bundler-webpack/compiled/webpack/deepImports.json"));
14
+ const hookPropertyMap = new Map([
15
+ ['webpack', '@umijs/bundler-webpack/compiled/webpack'],
16
+ ['webpack/package', '@umijs/bundler-webpack/compiled/webpack/package'],
17
+ ['webpack/package.json', '@umijs/bundler-webpack/compiled/webpack/package'],
18
+ ['webpack/lib/webpack', '@umijs/bundler-webpack/compiled/webpack'],
19
+ ['webpack/lib/webpack.js', '@umijs/bundler-webpack/compiled/webpack'],
20
+ ['tapable', '@umijs/bundler-utils/compiled/tapable'],
21
+ ['vite', '@umijs/bundler-vite/compiled/vite'],
22
+ ]);
23
+ exports.hookPropertyMap = hookPropertyMap;
24
+ deepImports_json_1.default.forEach((item) => {
25
+ const name = item.split('/').pop();
26
+ hookPropertyMap.set(item, `@umijs/bundler-webpack/compiled/webpack/${name}`);
27
+ hookPropertyMap.set(`${item}.js`, `@umijs/bundler-webpack/compiled/webpack/${name}`);
28
+ });
29
+ const mod = require('module');
30
+ const resolveFilename = mod._resolveFilename;
31
+ mod._resolveFilename = function (request, parent, isMain, options) {
32
+ const hookResolved = hookPropertyMap.get(request);
33
+ if (hookResolved) {
34
+ request = hookResolved;
35
+ }
36
+ return resolveFilename.call(mod, request, parent, isMain, options);
37
+ };
@@ -0,0 +1,5 @@
1
+ export declare function resolveProjectDep(opts: {
2
+ pkg: any;
3
+ cwd: string;
4
+ dep: string;
5
+ }): string | undefined;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveProjectDep = void 0;
4
+ const path_1 = require("path");
5
+ const plugin_utils_1 = require("umi/plugin-utils");
6
+ function resolveProjectDep(opts) {
7
+ var _a, _b;
8
+ if (((_a = opts.pkg.dependencies) === null || _a === void 0 ? void 0 : _a[opts.dep]) ||
9
+ ((_b = opts.pkg.devDependencies) === null || _b === void 0 ? void 0 : _b[opts.dep])) {
10
+ return (0, path_1.dirname)(plugin_utils_1.resolve.sync(`${opts.dep}/package.json`, {
11
+ basedir: opts.cwd,
12
+ }));
13
+ }
14
+ }
15
+ exports.resolveProjectDep = resolveProjectDep;
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@umijs/preset-vue",
3
+ "version": "4.0.0-rc.13",
4
+ "description": "@umijs/preset-vue",
5
+ "homepage": "https://github.com/umijs/umi-next/tree/master/packages/preset-vue#readme",
6
+ "bugs": "https://github.com/umijs/umi-next/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/umijs/umi-next"
10
+ },
11
+ "license": "MIT",
12
+ "main": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "files": [
15
+ "dist",
16
+ "templates",
17
+ "compiled"
18
+ ],
19
+ "scripts": {
20
+ "build": "pnpm tsc",
21
+ "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
22
+ "dev": "pnpm build -- --watch"
23
+ },
24
+ "dependencies": {
25
+ "@umijs/renderer-vue": "4.0.0-rc.13",
26
+ "vue": "3.2.31",
27
+ "vue-loader": "17.0.0",
28
+ "vue-router": "4.0.12"
29
+ },
30
+ "devDependencies": {
31
+ "umi": "4.0.0-rc.13"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "authors": [
37
+ "chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
38
+ ]
39
+ }
@@ -0,0 +1,15 @@
1
+ import { createWebHashHistory, createMemoryHistory, createWebHistory, RouterHistory } from '{{{ rendererPath }}}';
2
+
3
+ let history: RouterHistory;
4
+ export function createHistory(opts: any) {
5
+ if (opts.type === 'hash') {
6
+ history = createWebHashHistory(opts.basename);
7
+ } else if (opts.type === 'memory') {
8
+ history = createMemoryHistory(opts.basename);
9
+ } else {
10
+ history = createWebHistory(opts.basename);
11
+ }
12
+ return history;
13
+ }
14
+
15
+ export { history };
@@ -0,0 +1,11 @@
1
+ import { inject } from 'vue';
2
+ import { AppContextKey } from '{{{ rendererPath }}}';
3
+
4
+ export function useAppData() {
5
+ const state = inject(AppContextKey);
6
+ if (!state) {
7
+ throw new Error('AppContext is no provide');
8
+ }
9
+
10
+ return state;
11
+ }