- 
        Couldn't load subscription status. 
- Fork 10
feat(create-cedar-app): Create ESM apps #80
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
          
     Open
      
      
            Tobbe
  wants to merge
  284
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
tobbe-crxa-esm
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    | View your CI Pipeline Execution ↗ for commit 9681d08. 
 ☁️ Nx Cloud last updated this comment at  | 
| ✅ Deploy Preview for cedarjs canceled.
 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      Labels
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Steps for ESM support
"type": "module"to all threepackage.jsonfiles@cedarjs/testingas a devDependency in your rootpackage.jsonweb/config/postcss.config.jsandweb/config/tailwind.config.jsto end with.cjspostcss.config.cjsto end with.cjsprettier.config.cjsto end with.cjs.jsextension. Take care to addindex.jsif the relative import is an index import.jest.config.jsyarn add --exact vitest(right now I'm focusing on web tests, so I run that command insideweb/)describeetc everywhere you need it, or add vitest config to make it globally availableyarn why -R vitestandyarn why -R viteto make sure there's only one version of vite and one version of vitest being used. Add"resolutions"as needed to your rootpackage.json.vite.config.tsQuestions
ESM imports
With ESM you need to specify file extension for relative imports. So
import { fooFunc } from './some/path/foo'needs to beimport { fooFunc } from './some/path/foo.js'In RW/Cedar we have directory named imports, so you can do
import SomeComponent from 'src/components/SomeComponent'and it’ll be expanded toimport SomeComponent from './src/components/SomeComponent/SomeComponent'That now needs to be expanded to
import SomeComponent from './src/components/SomeComponent/SomeComponent.js'What would you prefer the syntax you use as a Cedar user is? Should I just keep it as it is, and still let you do
import SomeComponent from 'src/components/SomeComponent'or should I require you add.jsto make itimport SomeComponent from 'src/components/SomeComponent.js'to be consistent with other imports? Or should I support both with and without .js? Or should we just get rid of the magic and require you do full path imports?Vitest
Should we ship with
describe,expectetc globally available, or should we explicitly import it where it's needed? I'm leaning towards explicit imports, but let me know what you thinkIssues
react-helmet-asyncdoesn't work with ESM (Broken ESM support staylor/react-helmet-async#252).Can potentially replace with https://github.com/birdofpreyru/react-helmet. (Quote below from >>> REACT HELMET (ASYNC) IS DEAD! LONG LIVE REACT HELMET! <<< staylor/react-helmet-async#254)
@cedarjs/testingis the way to go.TODO
ssr: noExternal: []for exampleMajor areas of work
yarn rw exec- used to rely on Babel to support RW featuresyarn rw prerender- used to rely on Babel to support RW featuresyarn rw test- used to rely on Jest for running tests, and Babel for RW featuresyarn rw dataMigrate- used to rely on Babel to support RW featuresBreaking changes
--changedas an option if you want that behavior (it'sfalseby default).import { gql } from 'graphql-tag'. See Build issues when using gql with ESM apollographql/graphql-tag#804 and https://arethetypeswrong.github.io/?p=graphql-tag%402.12.6