imjuni / ctix

CLI to generate barrel file for webpack, rollup entrypoint
MIT License
82 stars 22 forks source link

Support import file #127

Closed smallmain closed 6 months ago

smallmain commented 7 months ago

Now only the export statement will be generated, but the project may have many polyfills files. At this time, you may need to generate a polyfills.ts as the entry file, with the following content:

import "@base/boost/js/polyfills/at.js";
import "@base/boost/js/polyfills/cause.js";
import "@base/boost/js/polyfills/disposable.js";
import "@base/boost/js/polyfills/has-own.js";
import "@base/boost/js/polyfills/metadata.js";
import "@base/boost/js/polyfills/queue-microtask.js";
import "@base/boost/js/polyfills/text-encoder-decoder.js";
import "@base/boost/js/polyfills/with-resolvers.js";
import "@base/macro/polyfills.js";

Currently, this kind of bucket file can only be maintained manually.

It would be great if you could add a comment at the top of a file, such as /** @ctix-import */, which would also add an import statement to the file.

// @base/boost/js/polyfills/at.js
/** @ctix-import */

......

And I hope to add a switch in the configuration to be more flexible when there are multiple configuration files in the same project.

Great work!

imjuni commented 6 months ago

@smallmain Hi,

Thank you for your feedback. I was added new directive @ctix-declaration. If the source code file only has an import statement or declare module statement, the import statement is added to the build-buldle mode output.

smallmain commented 6 months ago

@smallmain Hi,

Thank you for your feedback. I was added new directive @ctix-declaration. If the source code file only has an import statement or declare module statement, the import statement is added to the build-buldle mode output.

awesome!

If the source code file only has an import statement or declare module statement

If there is this condition, what if a source file can both inject (similar to IOC) and export classes?

/** @ctix-declaration */
@injectable
export class LoginService {}

Even if it is not used directly, it should be included in the final build product, and if there is no import but only an export, the tree may be shaken. (The file may also need to be imported first in the header, and even if there is no tree-shaking problem, it is still expected to be imported first for later injection)

imjuni commented 6 months ago

@smallmain

Hi, ctix is a preprocessor that generates an index.ts file for bundling. Even if the class is injected using decorator, it will be included in the index.ts file if you add the export keyword and add it to the option.include field. So the @ctix-declaration will only work if the export keyword is not present.