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

Support <script src="tsconfig.json"></script> as asset type #1627

Closed
mihailik opened this issue Jun 27, 2018 · 5 comments
Closed

Support <script src="tsconfig.json"></script> as asset type #1627

mihailik opened this issue Jun 27, 2018 · 5 comments

Comments

@mihailik
Copy link

🙋 feature request

Parcel handles TypeScript compilation/post-processing in its custom way, which limits certain useful TS scenarios.

To allow simple way to use full TS feature set, it would be super cool to let TS handle more through tsconfig.json, and feed results into parcel pipeline at that stage.

Suggested approach

When .ts asset is referred, the usual parcel handling is used. But if tsconfig.json is used as asset, parcel fires TS compiler, which discovers and processes inputs on its own.

TypeScript would produce one or many outputs, which parcel would then pass through its remaining processing/transforms.

The disk cache would be less involved in this case, as processing is not file-per-file anymore. But in-memory partial recompilation is a part of TS compiler.

@mohsen1
Copy link
Contributor

mohsen1 commented Jun 27, 2018

I'm not sure if we can swap Parcel Resolver with TypeScript. It does a lot of things:

parcel/src/Resolver.js

Lines 10 to 23 in 2aa7215

/**
* This resolver implements a modified version of the node_modules resolution algorithm:
* https://nodejs.org/api/modules.html#modules_all_together
*
* In addition to the standard algorithm, Parcel supports:
* - All file extensions supported by Parcel.
* - Glob file paths
* - Absolute paths (e.g. /foo) resolved relative to the project root.
* - Tilde paths (e.g. ~/foo) resolved relative to the nearest module root in node_modules.
* - The package.json module, jsnext:main, and browser field as replacements for package.main.
* - The package.json browser and alias fields as an alias map within a local module.
* - The package.json alias field in the root package for global aliases across all modules.
*/
class Resolver {

@mihailik
Copy link
Author

In this case TypeScript will only go as far as resolving within its set of *.ts/*.tsx sources.

The result of TS compilation will pipe through the same sophisticated parcel resolver.

@mmmeff
Copy link

mmmeff commented Nov 20, 2018

Not a fan of this approach - it feels slightly off-mark of the zero-config goal of Parcel to require an extra configuration step for proper typescript support.

I think it's safe to say the vast majority of devs looking to use typescript in parcel are getting a sub-optimal experience when they directly import a ts/tsx file.

The correct default behavior should be to use the tsc toolchain and allow it to use the local tsconfig.json file if it exists or fall back to defaults (which tsc currently does by default). Anything else just feels like reinventing the wheel.

@mihailik
Copy link
Author

mihailik commented Nov 20, 2018

@mmmeff I am totally confused — you've described what I have suggested, and actually that is your preferred correct way, but at the same time you disagree with it?

The original suggestion is to avoid reinventing the wheel, and rely on TS wheels more.

It would be great to be able to use a whole of tsc processing in more holistic way, when/if a developer finds it fit for their app.

@devongovett
Copy link
Member

Parcel 2's resolver supports tsconfig settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants