未验证 提交 c2700fbc 编写于 作者: M Marco Fugaro 提交者: GitHub

build-examples: Support namespaced modules (#22270)

* build-examples: Support namespaced modules

* Namespace modules that end with Utils
上级 6276d11b
......@@ -41,7 +41,11 @@ function unmodularize() {
return {
renderChunk( code ) {
renderChunk( code, { fileName } ) {
// Namespace the modules that end with Utils
const fileNameNoExtension = fileName.slice( 0, fileName.indexOf( '.' ) );
const namespace = fileNameNoExtension.endsWith( 'Utils' ) ? fileNameNoExtension : undefined;
// export { Example };
// ↓
......@@ -49,7 +53,22 @@ function unmodularize() {
code = code.replace( /export { ([a-zA-Z0-9_, ]+) };/g, ( match, p1 ) => {
const exps = p1.split( ', ' );
return exps.map( exp => `THREE.${exp} = ${exp};` ).join( EOL );
let output = '';
if ( namespace ) {
output += `THREE.${namespace} = {};${ EOL }`;
output += exps.map( exp => `THREE.${namespace}.${exp} = ${exp};` ).join( EOL );
} else {
output += exps.map( exp => `THREE.${exp} = ${exp};` ).join( EOL );
}
return output;
} );
......@@ -66,6 +85,18 @@ function unmodularize() {
} );
// import * as Example from '...';
// but excluding imports importing from the libs/ folder
code = code.replace( /import \* as ([a-zA-Z0-9_, ]+) from '((?!libs).)*';/g, ( match, p1 ) => {
const imp = p1;
imports.push( imp );
return '';
} );
// new Example()
// (Example)
// [Example]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册