mirror of
https://gitee.com/WeBank/fes.js.git
synced 2024-11-29 18:28:09 +08:00
fix: run vite
This commit is contained in:
parent
242787c358
commit
c04148f84d
@ -1,4 +1,3 @@
|
||||
|
||||
module.exports = {
|
||||
copy: ['template']
|
||||
copy: ['template'],
|
||||
};
|
||||
|
@ -17,16 +17,14 @@ export default (api) => {
|
||||
.string()
|
||||
.pattern(/^[a-zA-Z]*$/)
|
||||
.allow(''),
|
||||
base: joi
|
||||
.string()
|
||||
.allow('')
|
||||
base: joi.string().allow(''),
|
||||
});
|
||||
},
|
||||
default: {
|
||||
base: '',
|
||||
dataField: ''
|
||||
}
|
||||
}
|
||||
dataField: '',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const namespace = 'plugin-request';
|
||||
@ -40,12 +38,13 @@ export default (api) => {
|
||||
// DEPRECATED
|
||||
logger.warn('[DEPRECATED]: reqeust base 即将废弃,建议使用 axios baseURL代替:https://github.com/axios/axios');
|
||||
}
|
||||
|
||||
api.writeTmpFile({
|
||||
path: absoluteFilePath,
|
||||
content: requestTemplate
|
||||
.replace('REPLACE_DATA_FIELD', JSON.stringify(dataField))
|
||||
.replace('REPLACE_BASE', base || '')
|
||||
.replace('AXIOS_PATH', resolvePkg('axios'))
|
||||
.replace('AXIOS_PATH', resolvePkg('axios')),
|
||||
});
|
||||
});
|
||||
|
||||
@ -56,14 +55,14 @@ export default (api) => {
|
||||
api.copyTmpFiles({
|
||||
namespace,
|
||||
path: join(__dirname, 'template'),
|
||||
ignore: ['request.js']
|
||||
ignore: ['request.js'],
|
||||
});
|
||||
});
|
||||
|
||||
api.addPluginExports(() => [
|
||||
{
|
||||
exportAll: true,
|
||||
source: absoluteFilePath
|
||||
}
|
||||
source: absoluteFilePath,
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
@ -2,10 +2,7 @@ import axios from 'AXIOS_PATH';
|
||||
import { ApplyPluginsType, plugin } from '@fesjs/fes';
|
||||
import { ref } from 'vue';
|
||||
import scheduler from './scheduler';
|
||||
import {
|
||||
checkHttpRequestHasBody,
|
||||
isFunction
|
||||
} from './helpers';
|
||||
import { checkHttpRequestHasBody, isFunction } from './helpers';
|
||||
|
||||
import setDataField from './setDataField';
|
||||
import paramsProcess from './paramsProcess';
|
||||
@ -53,13 +50,16 @@ function getRequestInstance() {
|
||||
} = plugin.applyPlugins({
|
||||
key: 'request',
|
||||
type: ApplyPluginsType.modify,
|
||||
initialValue: {}
|
||||
initialValue: {},
|
||||
});
|
||||
|
||||
const defaultConfig = Object.assign({
|
||||
timeout: 10000,
|
||||
withCredentials: true
|
||||
}, otherConfigs);
|
||||
const defaultConfig = Object.assign(
|
||||
{
|
||||
timeout: 10000,
|
||||
withCredentials: true,
|
||||
},
|
||||
otherConfigs,
|
||||
);
|
||||
const instance = axios.create(defaultConfig);
|
||||
|
||||
addRequestInterceptors(instance, requestInterceptors);
|
||||
@ -83,9 +83,9 @@ function getRequestInstance() {
|
||||
defaultConfig,
|
||||
dataField: REPLACE_DATA_FIELD, // eslint-disable-line
|
||||
responseDataAdaptor,
|
||||
errorHandler
|
||||
errorHandler,
|
||||
},
|
||||
request: scheduler.compose()
|
||||
request: scheduler.compose(),
|
||||
};
|
||||
}
|
||||
|
||||
@ -117,12 +117,11 @@ function createContext(userConfig) {
|
||||
...currentRequestInstance.context,
|
||||
config: {
|
||||
...currentRequestInstance.context.defaultConfig,
|
||||
...userConfig
|
||||
}
|
||||
...userConfig,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function getResponseCode(response) {
|
||||
if (response) {
|
||||
if (response._rawData) return response._rawData.code;
|
||||
@ -142,12 +141,7 @@ function skipErrorHandlerToObj(skipErrorHandler = []) {
|
||||
}, {});
|
||||
}
|
||||
|
||||
function handleRequestError({
|
||||
errorHandler = {},
|
||||
error,
|
||||
response,
|
||||
config
|
||||
}) {
|
||||
function handleRequestError({ errorHandler = {}, error, response, config }) {
|
||||
// 跳过所有错误类型处理
|
||||
if (config.skipErrorHandler === true) return;
|
||||
|
||||
@ -171,7 +165,7 @@ function handleRequestError({
|
||||
export const request = (url, data, options = {}) => {
|
||||
if (typeof options === 'string') {
|
||||
options = {
|
||||
method: options
|
||||
method: options,
|
||||
};
|
||||
}
|
||||
if (!currentRequestInstance) {
|
||||
@ -203,16 +197,19 @@ export const useRequest = (url, data, options = {}) => {
|
||||
} else {
|
||||
promise = request(url, data, options);
|
||||
}
|
||||
promise.then((res) => {
|
||||
dataRef.value = res;
|
||||
}).catch((error) => {
|
||||
errorRef.value = error;
|
||||
}).finally(() => {
|
||||
loadingRef.value = false;
|
||||
});
|
||||
promise
|
||||
.then((res) => {
|
||||
dataRef.value = res;
|
||||
})
|
||||
.catch((error) => {
|
||||
errorRef.value = error;
|
||||
})
|
||||
.finally(() => {
|
||||
loadingRef.value = false;
|
||||
});
|
||||
return {
|
||||
loading: loadingRef,
|
||||
error: errorRef,
|
||||
data: dataRef
|
||||
data: dataRef,
|
||||
};
|
||||
};
|
||||
|
@ -35,7 +35,6 @@
|
||||
"@babel/preset-typescript": "^7.15.0",
|
||||
"@fesjs/compiler": "^2.0.5",
|
||||
"@fesjs/utils": "^2.0.4",
|
||||
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
||||
"@soda/friendly-errors-webpack-plugin": "^1.8.0",
|
||||
"@vitejs/plugin-vue": "^2.2.4",
|
||||
"@vitejs/plugin-vue-jsx": "^1.3.8",
|
||||
|
@ -5,7 +5,6 @@
|
||||
import { createServer } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx';
|
||||
import { viteCommonjs } from '@originjs/vite-plugin-commonjs';
|
||||
import SFCConfigBlockPlugin from './SFCConfigBlockPlugin';
|
||||
|
||||
const assert = require('assert');
|
||||
@ -138,14 +137,18 @@ export default (api) => {
|
||||
|
||||
server = await createServer({
|
||||
mode: 'development',
|
||||
plugins: [vue(), SFCConfigBlockPlugin, vueJsx(), viteCommonjs()],
|
||||
plugins: [vue(), SFCConfigBlockPlugin, vueJsx()],
|
||||
configFile: false,
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': paths.absSrcPath,
|
||||
'@@': paths.absTmpPath,
|
||||
'@fesInner': '/',
|
||||
},
|
||||
},
|
||||
optimizeDeps: {
|
||||
// exclude: ['@fesjs/fes'],
|
||||
},
|
||||
server: {
|
||||
port: 8000,
|
||||
},
|
||||
|
@ -14,4 +14,9 @@ export {
|
||||
ApplyPluginsType
|
||||
} from 'RUNTIME_PATH';
|
||||
|
||||
CORE_EXPORTS
|
||||
CORE_EXPORTS
|
||||
|
||||
// TODO 优化,放到合适的位置,不能放在 routes,会造成循环依赖
|
||||
export const defineRouteMeta = (param)=>{
|
||||
return param
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ export default function (api) {
|
||||
|
||||
api.addCoreExports(() => [
|
||||
{
|
||||
specifiers: ['getRoutes', 'getRouter', 'getHistory', 'destroyRouter', 'defineRouteMeta'],
|
||||
specifiers: ['getRoutes', 'getRouter', 'getHistory', 'destroyRouter'],
|
||||
source: absCoreFilePath,
|
||||
},
|
||||
]);
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { createRouter as createVueRouter, {{{ CREATE_HISTORY }}}, ApplyPluginsType } from '{{{ runtimePath }}}';
|
||||
import { plugin } from '@@/core/coreExports';
|
||||
import { plugin } from '../plugin';
|
||||
|
||||
{{{ COMPONENTS_IMPORT }}}
|
||||
|
||||
@ -62,7 +62,3 @@ export const destroyRouter = ()=>{
|
||||
router = null;
|
||||
history = null;
|
||||
}
|
||||
|
||||
export const defineRouteMeta = (param)=>{
|
||||
return param
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
return () => 'hello ts';
|
||||
}
|
||||
});
|
@ -1,9 +0,0 @@
|
||||
import {defineComponent} from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
return () => {
|
||||
return 'hello tsx'
|
||||
}
|
||||
}
|
||||
})
|
@ -3,16 +3,12 @@
|
||||
fes h5 & 拉夫德鲁<br />
|
||||
<fes-icon :spin="true" class="one-icon" type="smile" @click="clickIcon" />
|
||||
<HelloWorld />
|
||||
<HelloTSX />
|
||||
<helloTS />
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { ref } from 'vue';
|
||||
import { request, defineRouteMeta, useRoute } from '@fesjs/fes';
|
||||
import HelloWorld from '@/components/helloWorld.vue';
|
||||
import HelloTSX from '@/components/helloTSX.vue';
|
||||
import helloTS from '@/components/helloTS.vue';
|
||||
|
||||
defineRouteMeta({
|
||||
title: '首页',
|
||||
@ -23,8 +19,6 @@ defineRouteMeta({
|
||||
export default {
|
||||
components: {
|
||||
HelloWorld,
|
||||
HelloTSX,
|
||||
helloTS,
|
||||
},
|
||||
setup() {
|
||||
const fes = ref('fes upgrade to vue3');
|
||||
|
@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="m-10px">{{fes}}</div>
|
||||
<div class="m-10px">{{ fes }}</div>
|
||||
<img :src="publicPath + 'logo.png'" />
|
||||
</template>
|
||||
<config>
|
||||
@ -16,8 +16,8 @@ export default {
|
||||
const fes = ref('fes upgrade to vue3');
|
||||
return {
|
||||
publicPath: process.env.BASE_URL,
|
||||
fes
|
||||
fes,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
@ -1,15 +1,17 @@
|
||||
import { defineRouteMeta, useRoute } from '@fesjs/fes';
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
defineRouteMeta({
|
||||
title: 'test',
|
||||
name: 'test'
|
||||
})
|
||||
// console.log(defineRouteMeta);
|
||||
|
||||
// defineRouteMeta({
|
||||
// title: 'test',
|
||||
// name: 'test',
|
||||
// });
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
const route = useRoute();
|
||||
console.log(route)
|
||||
console.log(route);
|
||||
return () => <div>hello tsx</div>;
|
||||
}
|
||||
},
|
||||
});
|
@ -1,6 +1,6 @@
|
||||
import { dirname } from 'path';
|
||||
import winPath from './winPath';
|
||||
|
||||
const resolvePkg = pkgName => winPath(dirname(require.resolve(`${pkgName}/package.json`)));
|
||||
const resolvePkg = (pkgName) => winPath(dirname(require.resolve(`${pkgName}/package.json`))).replace('/', '@fesInner/');
|
||||
|
||||
export default resolvePkg;
|
||||
|
@ -12,7 +12,6 @@ const argv = require('yargs-parser')(process.argv.slice(2));
|
||||
const compiler = require('./compiler');
|
||||
const randomColor = require('./randomColor');
|
||||
|
||||
|
||||
const ESM_OUTPUT_DIR = 'es';
|
||||
const NODE_CJS_OUTPUT_DIR = 'lib';
|
||||
const SOURCE_DIR = 'src';
|
||||
@ -21,7 +20,7 @@ const GLOBAL_CONFIG_PATH = path.join(process.cwd(), CONFIG_FILE_NAME);
|
||||
const DEFAULT_CONFIG = {
|
||||
target: 'node',
|
||||
pkgs: [],
|
||||
copy: []
|
||||
copy: [],
|
||||
};
|
||||
|
||||
const PACKAGE_PATH = path.join(process.cwd(), './packages');
|
||||
@ -129,23 +128,25 @@ function compilerPkg(codeDir, outputDir, config, log) {
|
||||
}
|
||||
|
||||
function watchFile(dir, outputDir, config, log) {
|
||||
chokidar.watch(dir, {
|
||||
ignoreInitial: true
|
||||
}).on('all', (event, changeFile) => {
|
||||
// 修改的可能是一个目录,一个文件,一个需要 copy 的文件 or 目录
|
||||
const baseName = path.basename(changeFile);
|
||||
const shortChangeFile = genShortPath(changeFile);
|
||||
const outputPath = changeFile.replace(dir, outputDir);
|
||||
const stat = fs.lstatSync(changeFile);
|
||||
log(`[${event}] ${shortChangeFile}`);
|
||||
if (config.copy.includes(baseName)) {
|
||||
fse.copySync(changeFile, outputPath);
|
||||
} else if (stat.isFile()) {
|
||||
transformFile(changeFile, outputPath, config, log);
|
||||
} else if (stat.isDirectory()) {
|
||||
compilerPkg(changeFile, outputPath, config);
|
||||
}
|
||||
});
|
||||
chokidar
|
||||
.watch(dir, {
|
||||
ignoreInitial: true,
|
||||
})
|
||||
.on('all', (event, changeFile) => {
|
||||
// 修改的可能是一个目录,一个文件,一个需要 copy 的文件 or 目录
|
||||
const baseName = path.basename(changeFile);
|
||||
const shortChangeFile = genShortPath(changeFile);
|
||||
const outputPath = changeFile.replace(dir, outputDir);
|
||||
const stat = fs.lstatSync(changeFile);
|
||||
log(`[${event}] ${shortChangeFile}`);
|
||||
if (config.copy.includes(baseName)) {
|
||||
fse.copySync(changeFile, outputPath);
|
||||
} else if (stat.isFile()) {
|
||||
transformFile(changeFile, outputPath, config, log);
|
||||
} else if (stat.isDirectory()) {
|
||||
compilerPkg(changeFile, outputPath, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function compilerPkgs(pkgs, globalConfig) {
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
const babel = require('@babel/core');
|
||||
|
||||
|
||||
function transform(code, options) {
|
||||
const result = babel.transformSync(code, options);
|
||||
return result.code;
|
||||
@ -12,11 +11,14 @@ function transform(code, options) {
|
||||
function transformNodeCode(code) {
|
||||
return transform(code, {
|
||||
presets: [
|
||||
['@babel/preset-env', {
|
||||
modules: 'cjs',
|
||||
targets: { node: '12' }
|
||||
}]
|
||||
]
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
modules: 'cjs',
|
||||
targets: { node: '12' },
|
||||
},
|
||||
],
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
@ -25,12 +27,15 @@ function transformBrowserCode(code) {
|
||||
// 因此这里不对 polyfill 进行处理,避免全局污染
|
||||
return transform(code, {
|
||||
presets: [
|
||||
['@babel/preset-env', {
|
||||
modules: false,
|
||||
useBuiltIns: false,
|
||||
targets: { chrome: '51' }
|
||||
}]
|
||||
]
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
modules: false,
|
||||
useBuiltIns: false,
|
||||
targets: { chrome: '51' },
|
||||
},
|
||||
],
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
@ -44,5 +49,4 @@ function compiler(code, config) {
|
||||
throw new Error(`config target error: ${config.target}, only can use 'node' and 'browser'`);
|
||||
}
|
||||
|
||||
|
||||
module.exports = compiler;
|
||||
|
@ -14,7 +14,7 @@ const colors = [
|
||||
'yellowBright',
|
||||
'blueBright',
|
||||
'magentaBright',
|
||||
'cyanBright'
|
||||
'cyanBright',
|
||||
];
|
||||
|
||||
let index = 0;
|
||||
|
@ -2591,13 +2591,6 @@
|
||||
dependencies:
|
||||
"@octokit/openapi-types" "^11.2.0"
|
||||
|
||||
"@originjs/vite-plugin-commonjs@^1.0.3":
|
||||
version "1.0.3"
|
||||
resolved "https://registry.npmmirror.com/@originjs/vite-plugin-commonjs/-/vite-plugin-commonjs-1.0.3.tgz#2e3fb11ec78847da9422b79c103953f94d667f09"
|
||||
integrity sha512-KuEXeGPptM2lyxdIEJ4R11+5ztipHoE7hy8ClZt3PYaOVQ/pyngd2alaSrPnwyFeOW1UagRBaQ752aA1dTMdOQ==
|
||||
dependencies:
|
||||
esbuild "^0.14.14"
|
||||
|
||||
"@polka/url@^1.0.0-next.20":
|
||||
version "1.0.0-next.21"
|
||||
resolved "https://registry.npmmirror.com/@polka/url/-/url-1.0.0-next.21.tgz#5de5a2385a35309427f6011992b544514d559aa1"
|
||||
|
Loading…
Reference in New Issue
Block a user