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: supports cts and mts config #8729

Merged
merged 5 commits into from
Jun 24, 2022
Merged

feat: supports cts and mts config #8729

merged 5 commits into from
Jun 24, 2022

Conversation

sxzz
Copy link
Member

@sxzz sxzz commented Jun 22, 2022

Description

Support mts / cts / cjs config files

closes #5201

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@netlify
Copy link

netlify bot commented Jun 22, 2022

Deploy Preview for vite-docs-main ready!

Name Link
🔨 Latest commit 438a9b8
🔍 Latest deploy log https://app.netlify.com/sites/vite-docs-main/deploys/62b5827b4001a50009f584cc
😎 Deploy Preview https://deploy-preview-8729--vite-docs-main.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@sxzz sxzz changed the title feat: supports cjs and esm config feat: supports cts and mts config Jun 22, 2022
@sxzz sxzz marked this pull request as ready for review June 22, 2022 17:34
@sxzz

This comment was marked as outdated.

@sapphi-red sapphi-red added enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority) labels Jun 23, 2022
poyoho
poyoho previously approved these changes Jun 24, 2022
poyoho
poyoho previously approved these changes Jun 24, 2022
Copy link
Member

@poyoho poyoho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this filter needs to be /\.[mc]?[jt]s$/ now.

build.onLoad({ filter: /\.[jt]s$/ }, async (args) => {

For example, this code does not work.

// vite.config.mts
import { u } from './foo.mjs'
console.log(u) // expected: 'file://path/to/foo.mjs', actual: `ReferenceError: __vite_injected_original_import_meta_url is not defined`
// foo.mjs
export const u = import.meta.url

@sxzz
Copy link
Member Author

sxzz commented Jun 24, 2022

@sapphi-red
Thanks for reminding. Just fixed!

Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@patak-dev patak-dev merged commit c2b09db into vitejs:main Jun 24, 2022
@sxzz sxzz deleted the feat/config-ext branch June 24, 2022 15:41
@sxzz
Copy link
Member Author

sxzz commented Jun 24, 2022

Can I backport this feature to 2.x branch?

@andrewbranch
Copy link

I don’t think this fully addresses #5201—this only supports .cts and .mts config files, but .cts and .mts source files are not recognized as TypeScript. Is that intended to be supported by Vite?

Unexpected token (Note that you need plugins to import files that are not JavaScript)
file: /Users/andrew/Developer/microsoft/module-resolvers/code/resolvers/vite/main.mts:1:7
1: const x: string = 'hello';
          ^
error during build:
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)

@bluwy
Copy link
Member

bluwy commented Jul 16, 2022

Yeah looks like this covers config files only. We should support source files too. Re-opening the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support mts and cts file
6 participants