mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
调整 sdk 产出
This commit is contained in:
parent
1cc931b685
commit
00212309ca
59
fis-conf.js
59
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'
|
||||
],
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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<React.ReactType> {
|
||||
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<EditorProps, any> {
|
||||
>
|
||||
<LazyComponent
|
||||
classPrefix={ns}
|
||||
getComponent={loadComponent}
|
||||
component={Editor}
|
||||
value={finnalValue}
|
||||
onChange={onChange}
|
||||
disabled={disabled}
|
||||
|
Loading…
Reference in New Issue
Block a user