diff --git a/fis-conf.js b/fis-conf.js index 2dc243559..67175f1ab 100644 --- a/fis-conf.js +++ b/fis-conf.js @@ -156,10 +156,6 @@ fis.match('::package', { }) }); -fis.match('*.worker.js', { - useHash: true -}); - fis.media('dev').match('/node_modules/**.js', { packTo: '/pkg/npm.js' }); @@ -219,10 +215,6 @@ if (fis.project.currentMedia() === 'publish') { standard: false }); - publishEnv.match('/src/components/Editor.tsx', { - standard: 'builtin' - }); - publishEnv.match('/src/**.{jsx,tsx,js,ts}', { postprocessor: function(content, file) { return content @@ -246,23 +238,7 @@ if (fis.project.currentMedia() === 'publish') { return; } var content = file.getContent(); - if (subpath === '/src/components/Editor.tsx') { - content = content - .replace('require("node_modules/tslib/tslib")', 'require("tslib")') - .replace('require("node_modules/react/index")', 'require("react")') - .replace( - 'require("node_modules/classnames/index")', - 'require("classnames")' - ) - .replace( - 'require("src/themes/default.ts")', - 'require("../themes/default.js")' - ) - .replace('require("src/theme.tsx")', 'require("../theme.js")') - .replace(/('|")(\.\.\/thirds.*?)\1/g, function(_, quote, value) { - return '__uri(' + quote + value + quote + ')'; - }); - } else if (subpath === '/src/components/icons.tsx') { + if (subpath === '/src/components/icons.tsx') { content = content.replace(/\.svg/g, '.js'); } else { content = content.replace( @@ -340,10 +316,6 @@ if (fis.project.currentMedia() === 'publish') { } }); - env.match('src/components/Editor.tsx', { - release: '/ide.js' - }); - env.match('::package', { packager: fis.plugin('deps-pack', { 'sdk.js': [ @@ -367,9 +339,9 @@ if (fis.project.currentMedia() === 'publish') { 'jquery/**' ], - 'echarts.js': ['zrender/**', 'echarts/**'], + 'charts.js': ['zrender/**', 'echarts/**'], - 'monaco-editor.js': [ + 'editor.js': [ 'monaco-editor/esm/vs/editor/editor.main.js', 'monaco-editor/esm/vs/editor/editor.main.js:deps' ], @@ -400,20 +372,22 @@ if (fis.project.currentMedia() === 'publish') { if (file.isJsLike && file.isMod) { var contents = file.getContent(); + // 替换 worker 地址的路径,让 sdk 加载同目录下的文件。 + // 如果 sdk 和 worker 不是部署在一个地方,请通过指定 MonacoEnvironment.getWorkerUrl if (file.subpath === '/src/components/Editor.tsx') { - contents = contents - .replace(/function\snoJsExt\(raw\)\s\{/, function() { + contents = contents.replace( + /function\sfilterUrl\(url\)\s\{\s*return\s*url;/m, + function() { return `var _path = ''; try { - throw new Error() + throw new Error() } catch (e) { - _path = (/((?:https?|file)\:.*)$/.test(e.stack) && RegExp.$1).replace(/\\/[^\\/]*$/, ''); + _path = (/((?:https?|file)\:.*)$/.test(e.stack) && RegExp.$1).replace(/\\/[^\\/]*$/, ''); } - function noJsExt(raw) {`; - }) - .replace(/('|")(\.\/thirds.*?)\1/g, function(_, quote, value) { - return `_path + ${quote}${value.substring(1)}${quote}`; - }); + function filterUrl(url) { + return _path + url.substring(1);`; + } + ); } if ( @@ -542,7 +516,6 @@ if (fis.project.currentMedia() === 'publish') { '!monaco-editor/**', '!flv.js/**', '!hls.js/**', - '!amis/lib/editor/**', '!froala-editor/**', '!amis/lib/components/RichText.js', '!jquery/**', @@ -554,14 +527,14 @@ if (fis.project.currentMedia() === 'publish') { 'froala-editor/**', 'jquery/**' ], - 'pkg/echarts.js': ['zrender/**', 'echarts/**'], + 'pkg/charts.js': ['zrender/**', 'echarts/**'], 'pkg/api-mock.js': ['mock/*.ts'], 'pkg/app.js': [ '/examples/components/App.jsx', '/examples/components/App.jsx:deps' ], - 'pkg/monaco-editor.js': [ + 'pkg/editor.js': [ 'monaco-editor/esm/vs/editor/editor.main.js', 'monaco-editor/esm/vs/editor/editor.main.js:deps' ], diff --git a/src/components/Editor.tsx b/src/components/Editor.tsx index 4ea5895bf..7f5d78f7c 100644 --- a/src/components/Editor.tsx +++ b/src/components/Editor.tsx @@ -9,6 +9,12 @@ import cx from 'classnames'; import {ClassNamesFn, themeable} from '../theme'; import {__uri} from '../utils/helper'; +// 用于发布 sdk 版本的时候替换,因为不确定 sdk 版本怎么部署,而 worker 地址路径不可知。 +// 所以会被 fis3 替换成取相对的代码。 +function filterUrl(url: string) { + return url; +} + (window as any).MonacoEnvironment = { getWorkerUrl: function(moduleId: string, label: string) { let url = '/pkg/editor.worker.js'; @@ -23,12 +29,13 @@ import {__uri} from '../utils/helper'; url = '/pkg/ts.worker.js'; } + url = filterUrl(url); + + // url 有可能会插件替换成 cdn 地址,比如:fis3-prepackager-stand-alone-pack if (/^https?/.test(url)) { return `data:text/javascript;charset=utf-8,${encodeURIComponent(` - self.MonacoEnvironment = { - baseUrl: '${url.replace(/\/.*$/, '/')}' - }; - importScripts('${url}');`)}`; + importScripts('${url}');`)} + `; } return url; diff --git a/src/components/index.tsx b/src/components/index.tsx index 6d5632bc6..53ad6fc9d 100644 --- a/src/components/index.tsx +++ b/src/components/index.tsx @@ -17,7 +17,7 @@ import DatePicker from './DatePicker'; import DateRangePicker from './DateRangePicker'; import Drawer from './Drawer'; import {default as Tabs, Tab} from './Tabs'; -// import Editor from './Editor'; +import Editor from './Editor'; import Html from './Html'; import * as Icons from './icons'; import Layout from './Layout'; @@ -59,7 +59,7 @@ export { Drawer, Tabs, Tab, - // Editor, + Editor, Html, Icons, Layout, diff --git a/src/renderers/Form/Editor.tsx b/src/renderers/Form/Editor.tsx index 6085073ce..934534b4a 100644 --- a/src/renderers/Form/Editor.tsx +++ b/src/renderers/Form/Editor.tsx @@ -1,16 +1,8 @@ import React from 'react'; import {FormItem, FormControlProps} from './Item'; -import cx from 'classnames'; import LazyComponent from '../../components/LazyComponent'; import debouce = require('lodash/debounce'); - -function loadComponent(): Promise { - return new Promise(resolve => - (require as any)(['../../components/Editor'], (component: any) => - resolve(component.default) - ) - ); -} +import Editor from '../../components/Editor'; export interface EditorProps extends FormControlProps { options?: object; @@ -126,7 +118,7 @@ export default class EditorControl extends React.Component { >