diff --git a/.fatherrc.js b/.fatherrc.js index 5bf28d97..fa714010 100644 --- a/.fatherrc.js +++ b/.fatherrc.js @@ -8,7 +8,7 @@ const headPkgs = [ "fes-runtime", "fes-core", "fes", - "fes-plugin-built-in", + "fes-preset-built-in", "fes-plugin-request", "fes-plugin-access", "fes-plugin-model", diff --git a/packages/fes-core/src/index.js b/packages/fes-core/src/index.js index 250d25cd..d155cf4e 100644 --- a/packages/fes-core/src/index.js +++ b/packages/fes-core/src/index.js @@ -5,13 +5,13 @@ import Logger from './logger'; import Service from './service'; import PluginAPI from './service/pluginAPI'; import { PluginType } from './service/enums'; -import { isPlugin } from './service/utils/pluginUtils'; +import { isPluginOrPreset } from './service/utils/pluginUtils'; export { Config, Service, PluginAPI, - isPlugin, + isPluginOrPreset, PluginType, Logger }; diff --git a/packages/fes-core/src/service/index.js b/packages/fes-core/src/service/index.js index 0e0ea1d2..49f7fd89 100644 --- a/packages/fes-core/src/service/index.js +++ b/packages/fes-core/src/service/index.js @@ -3,8 +3,8 @@ import { EventEmitter } from 'events'; import assert from 'assert'; import { AsyncSeriesWaterfallHook } from 'tapable'; import { existsSync } from 'fs'; -import { BabelRegister } from '@umijs/utils'; -import { resolvePlugins } from './utils/pluginUtils'; +import { BabelRegister, lodash } from '@umijs/utils'; +import { resolvePresets, pathToObj, resolvePlugins } from './utils/pluginUtils'; import loadDotEnv from './utils/loadDotEnv'; import isPromise from './utils/isPromise'; import PluginAPI from './pluginAPI'; @@ -12,6 +12,7 @@ import { ApplyPluginsType, ConfigChangeType, EnableBy, + PluginType, ServiceStage } from './enums'; import Config from '../config'; @@ -21,7 +22,6 @@ import getPaths from './getPaths'; // TODO // 1. duplicated key // 2. Logger -// 3. 支持插件集? export default class Service extends EventEmitter { cwd; @@ -41,9 +41,14 @@ export default class Service extends EventEmitter { // plugin methods pluginMethods = {}; + // initial presets and plugins from arguments, config, process.env, and package.json + initialPresets = []; + // initial plugins from arguments, config, process.env, and package.json initialPlugins = []; + _extraPresets = []; + _extraPlugins = []; // user config @@ -111,6 +116,11 @@ export default class Service extends EventEmitter { pkg: this.pkg, cwd: this.cwd }; + this.initialPresets = resolvePresets({ + ...baseOpts, + presets: opts.presets || [], + userConfigPresets: this.userConfig.presets || [] + }); this.initialPlugins = resolvePlugins({ ...baseOpts, plugins: opts.plugins || [], @@ -140,8 +150,7 @@ export default class Service extends EventEmitter { async init() { this.setStage(ServiceStage.init); - // we should have the final hooksByPluginId which is added with api.register() - await this.initPlugins(); + await this.initPresetsAndPlugins(); // hooksByPluginId -> hooks // hooks is mapped with hook key, prepared for applyPlugins() @@ -199,8 +208,14 @@ export default class Service extends EventEmitter { }); } - async initPlugins() { + async initPresetsAndPlugins() { + this.setStage(ServiceStage.initPresets); this._extraPlugins = []; + while (this.initialPresets.length) { + // eslint-disable-next-line + await this.initPreset(this.initialPresets.shift()); + } + this.setStage(ServiceStage.initPlugins); this._extraPlugins.push(...this.initialPlugins); while (this._extraPlugins.length) { @@ -248,6 +263,7 @@ export default class Service extends EventEmitter { 'env', 'args', 'hasPlugins', + 'hasPresets', 'setConfig' ].includes(prop) ) { @@ -268,6 +284,61 @@ export default class Service extends EventEmitter { return ret || {}; } + async initPreset(preset) { + const { id, key, apply } = preset; + preset.isPreset = true; + + const api = this.getPluginAPI({ id, key, service: this }); + + // register before apply + this.registerPlugin(preset); + const { presets, plugins } = await this.applyAPI({ + api, + apply + }); + + // register extra presets and plugins + if (presets) { + assert( + Array.isArray(presets), + `presets returned from preset ${id} must be Array.`, + ); + // 插到最前面,下个 while 循环优先执行 + this._extraPresets.splice( + 0, + 0, + ...presets.map(path => pathToObj({ + type: PluginType.preset, + path, + cwd: this.cwd + })), + ); + } + + // 深度优先 + const extraPresets = lodash.clone(this._extraPresets); + this._extraPresets = []; + while (extraPresets.length) { + // eslint-disable-next-line + await this.initPreset(extraPresets.shift()); + } + + if (plugins) { + assert( + Array.isArray(plugins), + `plugins returned from preset ${id} must be Array.`, + ); + this._extraPlugins.push( + ...plugins.map(path => pathToObj({ + type: PluginType.plugin, + path, + cwd: this.cwd + })), + ); + } + } + + async initPlugin(plugin) { const { id, key, apply } = plugin; @@ -319,10 +390,17 @@ export default class Service extends EventEmitter { return true; } + hasPresets(presetIds) { + return presetIds.every((presetId) => { + const preset = this.plugins[presetId]; + return preset && preset.isPreset && this.isPluginEnable(presetId); + }); + } + hasPlugins(pluginIds) { return pluginIds.every((pluginId) => { const plugin = this.plugins[pluginId]; - return plugin && this.isPluginEnable(pluginId); + return plugin && !plugin.isPreset && this.isPluginEnable(pluginId); }); } diff --git a/packages/fes-core/src/service/pluginAPI.js b/packages/fes-core/src/service/pluginAPI.js index 7954f3b6..64e2efd4 100644 --- a/packages/fes-core/src/service/pluginAPI.js +++ b/packages/fes-core/src/service/pluginAPI.js @@ -99,6 +99,26 @@ export default class PluginAPI { } } + registerPresets(presets) { + assert( + this.service.stage === ServiceStage.initPresets, + 'api.registerPresets() failed, it should only used in presets.', + ); + assert( + Array.isArray(presets), + 'api.registerPresets() failed, presets must be Array.', + ); + const extraPresets = presets.map(preset => (isValidPlugin(preset) + ? (preset) + : pathToObj({ + type: PluginType.preset, + path: preset, + cwd: this.service.cwd + }))); + // 插到最前面,下个 while 循环优先执行 + this.service._extraPresets.splice(0, 0, ...extraPresets); + } + registerMethod({ name, fn, diff --git a/packages/fes-core/src/service/utils/pluginUtils.js b/packages/fes-core/src/service/utils/pluginUtils.js index 0c2ecf5d..d394cff7 100644 --- a/packages/fes-core/src/service/utils/pluginUtils.js +++ b/packages/fes-core/src/service/utils/pluginUtils.js @@ -9,27 +9,37 @@ import { lodash } from '@umijs/utils'; +import { PluginType } from '../enums'; + const RE = { - plugin: /^(@webank\/)?fes-plugin-/ + [PluginType.plugin]: /^(@webank\/)?fes-plugin-/, + [PluginType.preset]: /^(@webank\/)?fes-preset-/ }; -export function isPlugin(name) { +export function isPluginOrPreset(type, name) { const hasScope = name.charAt(0) === '@'; - const re = RE.plugin; + const re = RE[type]; if (hasScope) { return re.test(name.split('/')[1]) || re.test(name); } return re.test(name); } -export function getPlugins(opts) { +export function getPluginsOrPresets(type, opts) { + const upperCaseType = type.toUpperCase(); return [ // dependencies - ...opts.plugins, + // opts + ...((opts[type === PluginType.preset ? 'presets' : 'plugins']) || []), + // env + ...(process.env[`FES_${upperCaseType}S`] || '').split(',').filter(Boolean), ...Object.keys(opts.pkg.devDependencies || {}) .concat(Object.keys(opts.pkg.dependencies || {})) - .filter(isPlugin.bind(null)), - ...opts.userConfigPlugins + .filter(isPluginOrPreset.bind(null, type)), + // user config + ...((opts[ + type === PluginType.preset ? 'userConfigPresets' : 'userConfigPlugins' + ]) || []) ].map(path => resolve.sync(path, { basedir: opts.cwd, extensions: ['.js', '.ts'] @@ -46,14 +56,14 @@ function nameToKey(name) { .join('.'); } -function pkgNameToKey(pkgName) { +function pkgNameToKey(pkgName, type) { if (pkgName.charAt(0) === '@' && !pkgName.startsWith('@webank/')) { pkgName = pkgName.split('/')[1]; } - return nameToKey(pkgName.replace(RE.plugin, '')); + return nameToKey(pkgName.replace(RE[type], '')); } -export function pathToObj({ path, cwd }) { +export function pathToObj({ path, type, cwd }) { let pkg = null; let isPkgPlugin = false; const pkgJSONPath = pkgUp.sync({ cwd: path }); @@ -74,11 +84,11 @@ export function pathToObj({ path, cwd }) { } else { id = winPath(path); } - id = id.replace('@webank/fes-plugin-built-in/lib/plugins', '@@'); + id = id.replace('@webank/fes-preset-built-in/lib/plugins', '@@'); id = id.replace(/\.js$/, ''); const key = isPkgPlugin - ? pkgNameToKey(pkg.name) + ? pkgNameToKey(pkg.name, type) : nameToKey(basename(path, extname(path))); return { @@ -100,10 +110,22 @@ export function pathToObj({ path, cwd }) { }; } +export function resolvePresets(opts) { + const type = PluginType.preset; + const presets = [...getPluginsOrPresets(type, opts)]; + return presets.map(path => pathToObj({ + type, + path, + cwd: opts.cwd + })); +} + export function resolvePlugins(opts) { - const plugins = getPlugins(opts); + const type = PluginType.plugin; + const plugins = getPluginsOrPresets(type, opts); return plugins.map(path => pathToObj({ path, + type, cwd: opts.cwd })); } diff --git a/packages/fes-plugin-built-in/src/index.js b/packages/fes-plugin-built-in/src/index.js deleted file mode 100644 index 8cdb2618..00000000 --- a/packages/fes-plugin-built-in/src/index.js +++ /dev/null @@ -1,53 +0,0 @@ -// TODO 拆成独立的包作为内置插件包 - -export default [ - // register methods - require.resolve('./plugins/registerMethods'), - - // misc - require.resolve('./plugins/misc/route'), - - // generate files - require.resolve('./plugins/generateFiles/core/plugin'), - require.resolve('./plugins/generateFiles/core/exports/coreExports'), - require.resolve('./plugins/generateFiles/core/exports/pluginExports'), - require.resolve('./plugins/generateFiles/fes'), - - // bundle configs - require.resolve('./plugins/features/alias'), - require.resolve('./plugins/features/analyze'), - require.resolve('./plugins/features/autoprefixer'), - require.resolve('./plugins/features/base'), - require.resolve('./plugins/features/chainWebpack'), - require.resolve('./plugins/features/chunks'), - require.resolve('./plugins/features/cssLoader'), - require.resolve('./plugins/features/cssnano'), - require.resolve('./plugins/features/copy'), - require.resolve('./plugins/features/define'), - require.resolve('./plugins/features/devServer'), - require.resolve('./plugins/features/devtool'), - require.resolve('./plugins/features/externals'), - require.resolve('./plugins/features/extraBabelPlugins'), - require.resolve('./plugins/features/extraBabelPresets'), - require.resolve('./plugins/features/extraPostCSSPlugins'), - require.resolve('./plugins/features/hash'), - require.resolve('./plugins/features/html'), - require.resolve('./plugins/features/inlineLimit'), - require.resolve('./plugins/features/lessLoader'), - require.resolve('./plugins/features/mountElementId'), - require.resolve('./plugins/features/nodeModulesTransform'), - require.resolve('./plugins/features/outputPath'), - require.resolve('./plugins/features/plugins'), - require.resolve('./plugins/features/postcssLoader'), - require.resolve('./plugins/features/proxy'), - require.resolve('./plugins/features/publicPath'), - require.resolve('./plugins/features/styleLoader'), - require.resolve('./plugins/features/targets'), - require.resolve('./plugins/features/terserOptions'), - require.resolve('./plugins/features/theme'), - require.resolve('./plugins/features/vueLoader'), - - // commands - require.resolve('./plugins/commands/build'), - require.resolve('./plugins/commands/dev') -]; diff --git a/packages/fes-plugin-built-in/.fatherrc.js b/packages/fes-preset-built-in/.fatherrc.js similarity index 100% rename from packages/fes-plugin-built-in/.fatherrc.js rename to packages/fes-preset-built-in/.fatherrc.js diff --git a/packages/fes-plugin-built-in/package.json b/packages/fes-preset-built-in/package.json similarity index 87% rename from packages/fes-plugin-built-in/package.json rename to packages/fes-preset-built-in/package.json index 26143769..b727fc74 100644 --- a/packages/fes-plugin-built-in/package.json +++ b/packages/fes-preset-built-in/package.json @@ -1,7 +1,7 @@ { - "name": "@webank/fes-plugin-built-in", + "name": "@webank/fes-preset-built-in", "version": "2.0.0", - "description": "@webank/fes-plugin-built-in", + "description": "@webank/fes-preset-built-in", "main": "lib/index.js", "types": "lib/index.d.ts", "files": [ diff --git a/packages/fes-preset-built-in/src/index.js b/packages/fes-preset-built-in/src/index.js new file mode 100644 index 00000000..ad5c1762 --- /dev/null +++ b/packages/fes-preset-built-in/src/index.js @@ -0,0 +1,55 @@ +export default function () { + return { + plugins: [ + // register methods + require.resolve('./plugins/registerMethods'), + + // misc + require.resolve('./plugins/misc/route'), + + // generate files + require.resolve('./plugins/generateFiles/core/plugin'), + require.resolve('./plugins/generateFiles/core/exports/coreExports'), + require.resolve('./plugins/generateFiles/core/exports/pluginExports'), + require.resolve('./plugins/generateFiles/fes'), + + // bundle configs + require.resolve('./plugins/features/alias'), + require.resolve('./plugins/features/analyze'), + require.resolve('./plugins/features/autoprefixer'), + require.resolve('./plugins/features/base'), + require.resolve('./plugins/features/chainWebpack'), + require.resolve('./plugins/features/chunks'), + require.resolve('./plugins/features/cssLoader'), + require.resolve('./plugins/features/cssnano'), + require.resolve('./plugins/features/copy'), + require.resolve('./plugins/features/define'), + require.resolve('./plugins/features/devServer'), + require.resolve('./plugins/features/devtool'), + require.resolve('./plugins/features/externals'), + require.resolve('./plugins/features/extraBabelPlugins'), + require.resolve('./plugins/features/extraBabelPresets'), + require.resolve('./plugins/features/extraPostCSSPlugins'), + require.resolve('./plugins/features/hash'), + require.resolve('./plugins/features/html'), + require.resolve('./plugins/features/inlineLimit'), + require.resolve('./plugins/features/lessLoader'), + require.resolve('./plugins/features/mountElementId'), + require.resolve('./plugins/features/nodeModulesTransform'), + require.resolve('./plugins/features/outputPath'), + require.resolve('./plugins/features/plugins'), + require.resolve('./plugins/features/postcssLoader'), + require.resolve('./plugins/features/proxy'), + require.resolve('./plugins/features/publicPath'), + require.resolve('./plugins/features/styleLoader'), + require.resolve('./plugins/features/targets'), + require.resolve('./plugins/features/terserOptions'), + require.resolve('./plugins/features/theme'), + require.resolve('./plugins/features/vueLoader'), + + // commands + require.resolve('./plugins/commands/build'), + require.resolve('./plugins/commands/dev') + ] + }; +} diff --git a/packages/fes-plugin-built-in/src/plugins/commands/build/index.js b/packages/fes-preset-built-in/src/plugins/commands/build/index.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/commands/build/index.js rename to packages/fes-preset-built-in/src/plugins/commands/build/index.js diff --git a/packages/fes-plugin-built-in/src/plugins/commands/dev/index.js b/packages/fes-preset-built-in/src/plugins/commands/dev/index.js similarity index 99% rename from packages/fes-plugin-built-in/src/plugins/commands/dev/index.js rename to packages/fes-preset-built-in/src/plugins/commands/dev/index.js index 3c03fbcf..ad6151dd 100644 --- a/packages/fes-plugin-built-in/src/plugins/commands/dev/index.js +++ b/packages/fes-preset-built-in/src/plugins/commands/dev/index.js @@ -33,6 +33,7 @@ export default (api) => { description: 'start a dev server for development', async fn({ args = {} }) { const defaultPort = process.env.PORT || args.port || api.config.devServer?.port; + console.log(api.config.devServer); port = await portfinder.getPortPromise({ port: defaultPort ? parseInt(String(defaultPort), 10) : 8000 }); diff --git a/packages/fes-plugin-built-in/src/plugins/commands/dev/watchPkg.js b/packages/fes-preset-built-in/src/plugins/commands/dev/watchPkg.js similarity index 89% rename from packages/fes-plugin-built-in/src/plugins/commands/dev/watchPkg.js rename to packages/fes-preset-built-in/src/plugins/commands/dev/watchPkg.js index 41f23c6a..4573ad41 100644 --- a/packages/fes-plugin-built-in/src/plugins/commands/dev/watchPkg.js +++ b/packages/fes-preset-built-in/src/plugins/commands/dev/watchPkg.js @@ -1,14 +1,15 @@ import { join } from 'path'; import { chokidar, winPath, lodash } from '@umijs/utils'; import { existsSync, readFileSync } from 'fs'; -import { isPlugin, PluginType } from '@webank/fes-core'; +import { isPluginOrPreset, PluginType } from '@webank/fes-core'; function getPlugins(opts) { return Object.keys({ ...opts.pkg.dependencies, ...opts.pkg.devDependencies }).filter(name => ( - isPlugin(PluginType.plugin, name) + isPluginOrPreset(PluginType.plugin, name) + || isPluginOrPreset(PluginType.preset, name) )); } diff --git a/packages/fes-plugin-built-in/src/plugins/features/alias.js b/packages/fes-preset-built-in/src/plugins/features/alias.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/alias.js rename to packages/fes-preset-built-in/src/plugins/features/alias.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/analyze.js b/packages/fes-preset-built-in/src/plugins/features/analyze.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/analyze.js rename to packages/fes-preset-built-in/src/plugins/features/analyze.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/autoprefixer.js b/packages/fes-preset-built-in/src/plugins/features/autoprefixer.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/autoprefixer.js rename to packages/fes-preset-built-in/src/plugins/features/autoprefixer.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/base.js b/packages/fes-preset-built-in/src/plugins/features/base.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/base.js rename to packages/fes-preset-built-in/src/plugins/features/base.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/chainWebpack.js b/packages/fes-preset-built-in/src/plugins/features/chainWebpack.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/chainWebpack.js rename to packages/fes-preset-built-in/src/plugins/features/chainWebpack.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/chunks.js b/packages/fes-preset-built-in/src/plugins/features/chunks.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/chunks.js rename to packages/fes-preset-built-in/src/plugins/features/chunks.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/copy.js b/packages/fes-preset-built-in/src/plugins/features/copy.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/copy.js rename to packages/fes-preset-built-in/src/plugins/features/copy.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/cssLoader.js b/packages/fes-preset-built-in/src/plugins/features/cssLoader.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/cssLoader.js rename to packages/fes-preset-built-in/src/plugins/features/cssLoader.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/cssnano.js b/packages/fes-preset-built-in/src/plugins/features/cssnano.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/cssnano.js rename to packages/fes-preset-built-in/src/plugins/features/cssnano.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/define.js b/packages/fes-preset-built-in/src/plugins/features/define.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/define.js rename to packages/fes-preset-built-in/src/plugins/features/define.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/devServer.js b/packages/fes-preset-built-in/src/plugins/features/devServer.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/devServer.js rename to packages/fes-preset-built-in/src/plugins/features/devServer.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/devtool.js b/packages/fes-preset-built-in/src/plugins/features/devtool.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/devtool.js rename to packages/fes-preset-built-in/src/plugins/features/devtool.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/externals.js b/packages/fes-preset-built-in/src/plugins/features/externals.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/externals.js rename to packages/fes-preset-built-in/src/plugins/features/externals.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/extraBabelPlugins.js b/packages/fes-preset-built-in/src/plugins/features/extraBabelPlugins.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/extraBabelPlugins.js rename to packages/fes-preset-built-in/src/plugins/features/extraBabelPlugins.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/extraBabelPresets.js b/packages/fes-preset-built-in/src/plugins/features/extraBabelPresets.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/extraBabelPresets.js rename to packages/fes-preset-built-in/src/plugins/features/extraBabelPresets.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/extraPostCSSPlugins.js b/packages/fes-preset-built-in/src/plugins/features/extraPostCSSPlugins.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/extraPostCSSPlugins.js rename to packages/fes-preset-built-in/src/plugins/features/extraPostCSSPlugins.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/hash.js b/packages/fes-preset-built-in/src/plugins/features/hash.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/hash.js rename to packages/fes-preset-built-in/src/plugins/features/hash.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/html.js b/packages/fes-preset-built-in/src/plugins/features/html.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/html.js rename to packages/fes-preset-built-in/src/plugins/features/html.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/index-default.html b/packages/fes-preset-built-in/src/plugins/features/index-default.html similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/index-default.html rename to packages/fes-preset-built-in/src/plugins/features/index-default.html diff --git a/packages/fes-plugin-built-in/src/plugins/features/inlineLimit.js b/packages/fes-preset-built-in/src/plugins/features/inlineLimit.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/inlineLimit.js rename to packages/fes-preset-built-in/src/plugins/features/inlineLimit.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/lessLoader.js b/packages/fes-preset-built-in/src/plugins/features/lessLoader.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/lessLoader.js rename to packages/fes-preset-built-in/src/plugins/features/lessLoader.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/mountElementId.js b/packages/fes-preset-built-in/src/plugins/features/mountElementId.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/mountElementId.js rename to packages/fes-preset-built-in/src/plugins/features/mountElementId.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/nodeModulesTransform.js b/packages/fes-preset-built-in/src/plugins/features/nodeModulesTransform.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/nodeModulesTransform.js rename to packages/fes-preset-built-in/src/plugins/features/nodeModulesTransform.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/outputPath.js b/packages/fes-preset-built-in/src/plugins/features/outputPath.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/outputPath.js rename to packages/fes-preset-built-in/src/plugins/features/outputPath.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/plugins.js b/packages/fes-preset-built-in/src/plugins/features/plugins.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/plugins.js rename to packages/fes-preset-built-in/src/plugins/features/plugins.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/postcssLoader.js b/packages/fes-preset-built-in/src/plugins/features/postcssLoader.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/postcssLoader.js rename to packages/fes-preset-built-in/src/plugins/features/postcssLoader.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/proxy.js b/packages/fes-preset-built-in/src/plugins/features/proxy.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/proxy.js rename to packages/fes-preset-built-in/src/plugins/features/proxy.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/publicPath.js b/packages/fes-preset-built-in/src/plugins/features/publicPath.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/publicPath.js rename to packages/fes-preset-built-in/src/plugins/features/publicPath.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/styleLoader.js b/packages/fes-preset-built-in/src/plugins/features/styleLoader.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/styleLoader.js rename to packages/fes-preset-built-in/src/plugins/features/styleLoader.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/targets.js b/packages/fes-preset-built-in/src/plugins/features/targets.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/targets.js rename to packages/fes-preset-built-in/src/plugins/features/targets.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/terserOptions.js b/packages/fes-preset-built-in/src/plugins/features/terserOptions.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/terserOptions.js rename to packages/fes-preset-built-in/src/plugins/features/terserOptions.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/theme.js b/packages/fes-preset-built-in/src/plugins/features/theme.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/theme.js rename to packages/fes-preset-built-in/src/plugins/features/theme.js diff --git a/packages/fes-plugin-built-in/src/plugins/features/vueLoader.js b/packages/fes-preset-built-in/src/plugins/features/vueLoader.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/features/vueLoader.js rename to packages/fes-preset-built-in/src/plugins/features/vueLoader.js diff --git a/packages/fes-plugin-built-in/src/plugins/generateFiles/core/exports/coreExports.js b/packages/fes-preset-built-in/src/plugins/generateFiles/core/exports/coreExports.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/generateFiles/core/exports/coreExports.js rename to packages/fes-preset-built-in/src/plugins/generateFiles/core/exports/coreExports.js diff --git a/packages/fes-plugin-built-in/src/plugins/generateFiles/core/exports/coreExports.tpl b/packages/fes-preset-built-in/src/plugins/generateFiles/core/exports/coreExports.tpl similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/generateFiles/core/exports/coreExports.tpl rename to packages/fes-preset-built-in/src/plugins/generateFiles/core/exports/coreExports.tpl diff --git a/packages/fes-plugin-built-in/src/plugins/generateFiles/core/exports/doc.md b/packages/fes-preset-built-in/src/plugins/generateFiles/core/exports/doc.md similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/generateFiles/core/exports/doc.md rename to packages/fes-preset-built-in/src/plugins/generateFiles/core/exports/doc.md diff --git a/packages/fes-plugin-built-in/src/plugins/generateFiles/core/exports/pluginExports.js b/packages/fes-preset-built-in/src/plugins/generateFiles/core/exports/pluginExports.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/generateFiles/core/exports/pluginExports.js rename to packages/fes-preset-built-in/src/plugins/generateFiles/core/exports/pluginExports.js diff --git a/packages/fes-plugin-built-in/src/plugins/generateFiles/core/plugin/index.js b/packages/fes-preset-built-in/src/plugins/generateFiles/core/plugin/index.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/generateFiles/core/plugin/index.js rename to packages/fes-preset-built-in/src/plugins/generateFiles/core/plugin/index.js diff --git a/packages/fes-plugin-built-in/src/plugins/generateFiles/core/plugin/plugin.tpl b/packages/fes-preset-built-in/src/plugins/generateFiles/core/plugin/plugin.tpl similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/generateFiles/core/plugin/plugin.tpl rename to packages/fes-preset-built-in/src/plugins/generateFiles/core/plugin/plugin.tpl diff --git a/packages/fes-plugin-built-in/src/plugins/generateFiles/core/plugin/pluginRegister.tpl b/packages/fes-preset-built-in/src/plugins/generateFiles/core/plugin/pluginRegister.tpl similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/generateFiles/core/plugin/pluginRegister.tpl rename to packages/fes-preset-built-in/src/plugins/generateFiles/core/plugin/pluginRegister.tpl diff --git a/packages/fes-plugin-built-in/src/plugins/generateFiles/fes/fes.tpl b/packages/fes-preset-built-in/src/plugins/generateFiles/fes/fes.tpl similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/generateFiles/fes/fes.tpl rename to packages/fes-preset-built-in/src/plugins/generateFiles/fes/fes.tpl diff --git a/packages/fes-plugin-built-in/src/plugins/generateFiles/fes/index.js b/packages/fes-preset-built-in/src/plugins/generateFiles/fes/index.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/generateFiles/fes/index.js rename to packages/fes-preset-built-in/src/plugins/generateFiles/fes/index.js diff --git a/packages/fes-plugin-built-in/src/plugins/misc/route/index.js b/packages/fes-preset-built-in/src/plugins/misc/route/index.js similarity index 99% rename from packages/fes-plugin-built-in/src/plugins/misc/route/index.js rename to packages/fes-preset-built-in/src/plugins/misc/route/index.js index df06f964..2afb5d61 100644 --- a/packages/fes-plugin-built-in/src/plugins/misc/route/index.js +++ b/packages/fes-preset-built-in/src/plugins/misc/route/index.js @@ -185,7 +185,7 @@ const getRoutesJSON = function ({ routes, config }) { // eslint-disable-next-line return ( /^\((.+)?\)(\s+)?=>/.test(component) - || /^function([^\(]+)?\(([^\)]+)?\)([^{]+)?{/.test(component) + || /^function([^(]+)?\(([^)]+)?\)([^{]+)?{/.test(component) ); } diff --git a/packages/fes-plugin-built-in/src/plugins/misc/route/template/routes.tpl b/packages/fes-preset-built-in/src/plugins/misc/route/template/routes.tpl similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/misc/route/template/routes.tpl rename to packages/fes-preset-built-in/src/plugins/misc/route/template/routes.tpl diff --git a/packages/fes-plugin-built-in/src/plugins/misc/route/template/runtime.tpl b/packages/fes-preset-built-in/src/plugins/misc/route/template/runtime.tpl similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/misc/route/template/runtime.tpl rename to packages/fes-preset-built-in/src/plugins/misc/route/template/runtime.tpl diff --git a/packages/fes-plugin-built-in/src/plugins/registerMethods.js b/packages/fes-preset-built-in/src/plugins/registerMethods.js similarity index 100% rename from packages/fes-plugin-built-in/src/plugins/registerMethods.js rename to packages/fes-preset-built-in/src/plugins/registerMethods.js diff --git a/packages/fes-plugin-built-in/src/utils/buildDevUtils.js b/packages/fes-preset-built-in/src/utils/buildDevUtils.js similarity index 100% rename from packages/fes-plugin-built-in/src/utils/buildDevUtils.js rename to packages/fes-preset-built-in/src/utils/buildDevUtils.js diff --git a/packages/fes-plugin-built-in/src/utils/constants.js b/packages/fes-preset-built-in/src/utils/constants.js similarity index 100% rename from packages/fes-plugin-built-in/src/utils/constants.js rename to packages/fes-preset-built-in/src/utils/constants.js diff --git a/packages/fes-plugin-built-in/src/utils/generateExports.js b/packages/fes-preset-built-in/src/utils/generateExports.js similarity index 100% rename from packages/fes-plugin-built-in/src/utils/generateExports.js rename to packages/fes-preset-built-in/src/utils/generateExports.js diff --git a/packages/fes-plugin-built-in/src/utils/generateFiles.js b/packages/fes-preset-built-in/src/utils/generateFiles.js similarity index 100% rename from packages/fes-plugin-built-in/src/utils/generateFiles.js rename to packages/fes-preset-built-in/src/utils/generateFiles.js diff --git a/packages/fes-template/.fes.js b/packages/fes-template/.fes.js index f1206968..3afe65a6 100644 --- a/packages/fes-template/.fes.js +++ b/packages/fes-template/.fes.js @@ -11,5 +11,8 @@ export default { menus: [{ path: '/' }] + }, + devServer: { + port: 8080 } }; diff --git a/packages/fes/package.json b/packages/fes/package.json index 168fe417..79e9c6c3 100644 --- a/packages/fes/package.json +++ b/packages/fes/package.json @@ -30,7 +30,7 @@ "strong" ], "dependencies": { - "@webank/fes-plugin-built-in": "^2.0.0", + "@webank/fes-preset-built-in": "^2.0.0", "@webank/fes-core": "^2.0.0", "@webank/fes-runtime": "^2.0.0", "@umijs/utils": "3.2.24", diff --git a/packages/fes/src/serviceWithBuiltIn.js b/packages/fes/src/serviceWithBuiltIn.js index e8778e0e..c9a1bfe2 100644 --- a/packages/fes/src/serviceWithBuiltIn.js +++ b/packages/fes/src/serviceWithBuiltIn.js @@ -1,6 +1,5 @@ import { dirname } from 'path'; import { Service as CoreService } from '@webank/fes-core'; -import innerPlugins from '@webank/fes-plugin-built-in'; class Service extends CoreService { constructor(opts) { @@ -9,7 +8,11 @@ class Service extends CoreService { super({ ...opts, - plugins: [...innerPlugins, ...(opts.plugins || [])] + presets: [ + require.resolve('@webank/fes-preset-built-in'), + ...(opts.presets || []) + ], + plugins: [...(opts.plugins || [])] }); } } diff --git a/vetur.config.js b/vetur.config.js new file mode 100644 index 00000000..e993ee8c --- /dev/null +++ b/vetur.config.js @@ -0,0 +1,16 @@ +// vetur.config.js +/** @type {import('vls').VeturConfig} */ +module.exports = { + // **optional** default: `{}` + // override vscode settings + // Notice: It only affects the settings used by Vetur. + settings: { + 'vetur.useWorkspaceDependencies': true, + 'vetur.experimental.templateInterpolationService': true + }, + // **optional** default: `[{ root: './' }]` + // support monorepos + projects: [ + './packages/fes-template' // shorthand for only root + ] +};