Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 添加externals配置减小物料体检 #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/build-plugin-lowcode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"axios": "^0.21.4",
"build-plugin-component": "^1.12.0",
"build-scripts-config": "^3.0.3",
"change-case": "^5.4.3",
"chokidar": "^3.5.3",
"cross-spawn-promise": "^0.10.2",
"driver-universal": "^3.4.0",
Expand Down
68 changes: 68 additions & 0 deletions packages/build-plugin-lowcode/src/externals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const { pascalCase, camelCase } = require('change-case');
const antdStyle = /^antd\/.*(\/style|\.css|\.less|\.sass|\.scss)/;
const antdComp = /^antd\//;
const antdCompLowcase = ['message', 'notification', 'version'];
const nextStyle = /^\@alifd\/next\/.*(\.css|\.less|\.sass|\.scss)/;
const nextComp = /^\@alifd\/next\//;
const nextCompLowcase = [];
const momentLocal = /^moment\/locale/;
const lodash = /^lodash\//;
const externals = [
{
'@ant-design/icons': 'var window.icons',
"lodash": "var window._",
moment: 'var window.moment'
},
function(ctx, req, cb) {
if(lodash.test(req)) {
let comp = req.split('/').pop();
comp = `var window._.${comp}`
console.info(comp);
return cb(null, comp);
}
else if(momentLocal.test(req)) {
return cb(null, '{}');
}
else if(antdStyle.test(req)) {
return cb(null, 'var window.antd.styles');
}
else if(antdComp.test(req)) {
if(req.indexOf('/locale/') >= 0) {
return cb();
}
let comp = req.split('/').pop();
if(antdCompLowcase.includes(comp)) {
comp = camelCase(comp);
}
else {
comp = pascalCase(comp);
}
comp = `var window.antd.${comp}`;
console.info(comp);
return cb(null, comp);
}

else if(nextStyle.test(req)) {
return cb(null, 'var window.Next.styles');
}
else if(nextComp.test(req)) {
if(req.indexOf('/locale/') >= 0) {
return cb();
}
let comp = req.split('/').pop();
if(nextCompLowcase.includes(comp)) {
comp = camelCase(comp);
}
else {
comp = pascalCase(comp);
}
comp = `var window.Next.${comp}`;
console.info(comp);
return cb(null, comp);
}

return cb();
},
]

module.exports = externals;
33 changes: 27 additions & 6 deletions packages/build-plugin-lowcode/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const { debug } = console;

const UTILS = require('./utils');
const CONSTANTS = require('./constants');
const EXTERNALS = require('./externals');
const { installModule } = require('./utils/npm');
const userWebpackConfig = require('./config/user-config');

Expand Down Expand Up @@ -292,7 +293,7 @@ async function build(options, pluginOptions, execCompile) {
}),
);
const metaPathMap = {};
metaPaths.forEach((item) => {
metaPaths.forEach((item) => {
metaPathMap[path.basename(item).replace(path.extname(item), '')] = item;
// metaPathMap[item.slice(item.lastIndexOf('/') + 1, item.lastIndexOf('.'))] = item;
});
Expand Down Expand Up @@ -504,7 +505,11 @@ async function start(options, pluginOptions) {
},
});
}
config.externals({ ...COMMON_EXTERNALS_MAP[engineScope], ...externals });
let ext = externals || [];
if(!Array.isArray(ext)) {
ext = [ externals ];
}
config.externals([...EXTERNALS, COMMON_EXTERNALS_MAP[engineScope], ...ext]);
!disableStyleLoader && useStyleLoader(config);
if (baseLibrary === 'rax') {
config.module.rule('scss').use('rpx-loader').loader('rpx-loader').before('css-loader');
Expand Down Expand Up @@ -707,7 +712,11 @@ async function bundleMetaV2(options, pluginOptions, execCompile, metaType) {
});
config.output.library(metaExportName).libraryTarget('umd');
config.output.path(path.resolve(rootDir, `${buildTarget}/${lowcodeDir}`));
config.externals({ ...COMMON_EXTERNALS_MAP[engineScope], ...externals });
let ext = externals || [];
if(!Array.isArray(ext)) {
ext = [ externals ];
}
config.externals([...EXTERNALS, COMMON_EXTERNALS_MAP[engineScope], ...ext]);
useStyleLoader(config);
});
return metaPath;
Expand Down Expand Up @@ -915,7 +924,11 @@ async function bundleEditorView(
});
config.output.library(library).libraryTarget('umd');
config.output.path(path.resolve(rootDir, `${buildTarget}/${lowcodeDir}`));
config.externals({ ...COMMON_EXTERNALS_MAP[engineScope], ...externals });
let ext = externals || [];
if(!Array.isArray(ext)) {
ext = [ externals ];
}
config.externals([...EXTERNALS, COMMON_EXTERNALS_MAP[engineScope], ...ext]);
if (baseLibrary === 'rax') {
const scssRule = config.module.rule('scss');
scssRule.use('rpx-loader').loader('rpx-loader').before('css-loader');
Expand Down Expand Up @@ -997,7 +1010,11 @@ async function bundleRenderView(options, pluginOptions, platform, execCompile) {
});
config.output.library(library).libraryTarget('umd');
config.output.path(path.resolve(rootDir, `${buildTarget}/${lowcodeDir}/render/${platform}`));
config.externals({ ...COMMON_EXTERNALS_MAP[engineScope], ...externals });
let ext = externals || [];
if(!Array.isArray(ext)) {
ext = [ externals ];
}
config.externals([...EXTERNALS, COMMON_EXTERNALS_MAP[engineScope], ...ext]);
if (baseLibrary === 'rax') {
const scssRule = config.module.rule('scss');
scssRule.use('rpx-loader').loader('rpx-loader').before('css-loader');
Expand Down Expand Up @@ -1288,7 +1305,11 @@ async function bundleComponentMeta(webPackConfig, options, pluginOptions, execCo
});
config.output.library(componentMetaExportName).libraryTarget('umd');
config.output.path(path.resolve(rootDir, `${buildTarget}/${lowcodeDir}`));
config.externals({ ...COMMON_EXTERNALS_MAP[engineScope], ...externals });
let ext = externals || [];
if(!Array.isArray(ext)) {
ext = [ externals ];
}
config.externals([...EXTERNALS, COMMON_EXTERNALS_MAP[engineScope], ...ext]);
useStyleLoader(config);
});
})(component, idx);
Expand Down