chore: 调整 esm 模块导出

This commit is contained in:
2betop 2022-06-16 21:07:14 +08:00
parent c0e4b82ff9
commit 3e0618ed8d
6 changed files with 59 additions and 171 deletions

20
amis.code-workspace Normal file
View File

@ -0,0 +1,20 @@
{
"folders": [
{
"path": "./",
"name": "monorepo"
},
{
"path": "./packages/amis-formula"
},
{
"path": "./packages/amis-core"
},
{
"path": "./packages/amis-ui"
},
{
"path": "./packages/amis"
}
]
}

View File

@ -18,6 +18,16 @@
"esm", "esm",
"scss" "scss"
], ],
"exports": {
".": {
"require": "./lib/index.js",
"import": "./esm/index.js"
},
"./lib/*": {
"require": "./lib/*.js",
"import": "./esm/*.js"
}
},
"dependencies": { "dependencies": {
"amis-core": "*", "amis-core": "*",
"amis-formula": "*", "amis-formula": "*",

View File

@ -7,3 +7,4 @@ sdk
/coverage /coverage
/schema.json /schema.json
/npm /npm
/esm

View File

@ -1,154 +0,0 @@
/**
* @file fis-conf.js 配置
*/
const path = require('path');
const fs = require('fs');
const package = require('./package.json');
const parserMarkdown = require('../../scripts/md-parser');
const convertSCSSIE11 = require('../../scripts/scss-ie11');
const parserCodeMarkdown = require('../../scripts/code-md-parser');
fis.match('*.scss', {
parser: fis.plugin('sass', {
sourceMap: true
}),
rExt: '.css'
});
fis.match('/src/icons/**.svg', {
rExt: '.js',
isJsXLike: true,
isJsLike: true,
isMod: true,
parser: [
fis.plugin('svgr', {
svgProps: {
className: 'icon'
},
prettier: false,
dimensions: false
}),
fis.plugin('typescript', {
importHelpers: true,
esModuleInterop: true,
experimentalDecorators: true,
sourceMap: false
})
]
});
fis.match('_*.scss', {
release: false
});
fis.get('project.ignore').push('lib/**');
fis.set('project.files', ['/scss/**', '/src/**']);
fis.on('compile:end', function (file) {
if (
file.subpath === '/src/index.tsx' ||
file.subpath === '/examples/mod.js'
) {
file.setContent(file.getContent().replace('@version', package.version));
}
});
fis.match('/scss/(**)', {
release: '/$1',
relative: true
});
fis.match('/src/(**)', {
release: '/$1',
relative: true
});
fis.match('/src/**.{jsx,tsx,js,ts}', {
rExt: '.js',
parser: [
// docsGennerator,
fis.plugin('typescript', {
importHelpers: true,
sourceMap: true,
experimentalDecorators: true,
esModuleInterop: true,
allowUmdGlobalAccess: true
}),
function (contents) {
return contents
.replace(
/(?:\w+\.)?\b__uri\s*\(\s*('|")(.*?)\1\s*\)/g,
function (_, quote, value) {
let str = quote + value + quote;
return (
'(function(){try {return __uri(' +
str +
')} catch(e) {return ' +
str +
'}})()'
);
}
)
.replace(/\(\d+, (tslib_\d+\.__importStar)\)/g, '$1')
.replace(
/return\s+(tslib_\d+)\.__importStar\(require\(('|")(.*?)\2\)\);/g,
function (_, tslib, quto, value) {
return `return new Promise(function(resolve){require(['${value}'], function(ret) {resolve(${tslib}.__importStar(ret));})});`;
}
);
}
],
preprocessor: null
});
fis.match('*', {
deploy: fis.plugin('local-deliver', {
to: fis.get('options.d') || fis.get('options.desc') || './lib'
})
});
fis.match('/src/**.{jsx,tsx,js,ts,svg}', {
isMod: false,
standard: false
});
fis.match('/src/**.{jsx,tsx,js,ts}', {
postprocessor: function (content, file) {
return content
.replace(/^''/gm, '')
.replace(/\/\/# sourceMappingURL=\//g, '//# sourceMappingURL=./');
}
});
fis.match('*.scss', {
postprocessor: function (content, file) {
return content.replace(
/\/\*# sourceMappingURL=\//g,
'/*# sourceMappingURL=./'
);
}
});
fis.match('::package', {
postpackager: function (ret) {
Object.keys(ret.src).forEach(function (subpath) {
var file = ret.src[subpath];
if (!file.isText()) {
return;
}
var content = file.getContent();
if (subpath === '/src/components/icons.tsx') {
content = content.replace(/\.svg/g, '.js');
} else {
content = content.replace(
/@require\s+(?:\.\.\/)?node_modules\//g,
'@require '
);
}
file.setContent(content);
});
}
});
// publishEnv.unhook('node_modules');
fis.hook('relative');
fis.match('_*.scss', {
release: false
});

View File

@ -3,6 +3,7 @@
"version": "2.0.0-rc.14", "version": "2.0.0-rc.14",
"description": "一种MIS页面生成工具", "description": "一种MIS页面生成工具",
"main": "lib/index.js", "main": "lib/index.js",
"module": "esm/index.js",
"scripts": { "scripts": {
"test": "jest", "test": "jest",
"coverage": "jest --coverage", "coverage": "jest --coverage",
@ -152,6 +153,16 @@
"sdk", "sdk",
"schema.json" "schema.json"
], ],
"exports": {
".": {
"require": "./lib/index.js",
"import": "./esm/index.js"
},
"./lib/*": {
"require": "./lib/*.js",
"import": "./esm/*.js"
}
},
"jest": { "jest": {
"testEnvironment": "jsdom", "testEnvironment": "jsdom",
"collectCoverageFrom": [ "collectCoverageFrom": [

View File

@ -47,24 +47,24 @@ export default [
], ],
external, external,
plugins: getPlugins('cjs') plugins: getPlugins('cjs')
},
{
input,
output: [
{
...settings,
dir: path.dirname(module),
format: 'esm',
exports: 'named',
preserveModulesRoot: './src',
preserveModules: true // Keep directory structure and files
}
],
external,
plugins: getPlugins('esm')
} }
// {
// input,
// output: [
// {
// ...settings,
// dir: path.dirname(module),
// format: 'esm',
// exports: 'named',
// preserveModulesRoot: './src',
// preserveModules: true // Keep directory structure and files
// }
// ],
// external,
// plugins: getPlugins('esm')
// }
]; ];
function transpileDynamicImportForCJS(options) { function transpileDynamicImportForCJS(options) {