-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow customising the Vite config #1465
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5f8fbc5
Initial custom Vite config override
infomiho 6da6c69
Reorganising
infomiho 209a8b3
Typo
infomiho faddbfb
Moves Vite config JS import code to Generator
infomiho 6ae239c
Updates changelog and docs
infomiho 190fd4f
Remove example app
infomiho f51005e
Updates e2e tests
infomiho 4451b3f
Updates the docs
infomiho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,34 @@ | ||
{{={= =}=}} | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from 'vite' | ||
import react from '@vitejs/plugin-react-swc' | ||
import { mergeConfig } from "vite"; | ||
import react from "@vitejs/plugin-react-swc"; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
{=# isCustomViteConfigUsed =} | ||
import _waspUserProvidedConfig from "./src/ext-src/vite.config"; | ||
Martinsos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{=/ isCustomViteConfigUsed =} | ||
{=^ isCustomViteConfigUsed =} | ||
const _waspUserProvidedConfig = {}; | ||
{=/ isCustomViteConfigUsed =} | ||
|
||
const defaultViteConfig = { | ||
plugins: [react()], | ||
server: { | ||
port: 3000, | ||
host: '0.0.0.0', | ||
host: "0.0.0.0", | ||
open: true, | ||
}, | ||
envPrefix: 'REACT_APP_', | ||
envPrefix: "REACT_APP_", | ||
build: { | ||
outDir: 'build', | ||
outDir: "build", | ||
}, | ||
test: { | ||
environment: 'jsdom', | ||
setupFiles: ['./src/test/vitest/setup.ts'], | ||
environment: "jsdom", | ||
setupFiles: ["./src/test/vitest/setup.ts"], | ||
}, | ||
}) | ||
}; | ||
|
||
// https://vitejs.dev/config/ | ||
export default mergeConfig( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the built-in Vite helper to merge the objects. |
||
defaultViteConfig, | ||
_waspUserProvidedConfig | ||
); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/.wasp/ | ||
|
||
# We ignore env files recognized and used by Wasp. | ||
.env.server | ||
.env.client | ||
|
||
# To be extra safe, we by default ignore any files with `.env` extension in them. | ||
# If this is too agressive for you, consider allowing specific files with `!` operator, | ||
# or modify/delete these two lines. | ||
*.env | ||
*.env.* |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
File marking the root of Wasp project. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
app customViteDemo { | ||
wasp: { | ||
version: "^0.11.5" | ||
}, | ||
title: "custom-vite-demo" | ||
} | ||
|
||
route RootRoute { path: "/", to: MainPage } | ||
page MainPage { | ||
component: import Main from "@client/MainPage.jsx" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Ignore editor tmp files | ||
**/*~ | ||
**/#*# |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
* { | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
box-sizing: border-box; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
padding: 0; | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", | ||
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", | ||
sans-serif; | ||
} | ||
|
||
.container { | ||
min-height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
main { | ||
padding: 5rem 0; | ||
flex: 1; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
main p { | ||
font-size: 1.2rem; | ||
} | ||
|
||
.logo { | ||
margin-bottom: 2rem; | ||
} | ||
|
||
.logo img { | ||
max-height: 200px; | ||
} | ||
|
||
.welcome-title { | ||
font-weight: 500; | ||
} | ||
|
||
.welcome-subtitle { | ||
font-weight: 400; | ||
margin-bottom: 3rem; | ||
} | ||
|
||
.buttons { | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
|
||
.buttons .button:not(:last-child) { | ||
margin-right: 0.5rem; | ||
} | ||
|
||
.button { | ||
border-radius: 3px; | ||
font-size: 1.2rem; | ||
padding: 1rem 2rem; | ||
text-align: center; | ||
font-weight: 700; | ||
text-decoration: none; | ||
} | ||
|
||
.button-filled { | ||
border: 2px solid #bf9900; | ||
background-color: #bf9900; | ||
color: #f4f4f4; | ||
} | ||
|
||
.button-outline { | ||
border: 2px solid #8a9cff; | ||
color: #8a9cff; | ||
background-color: none; | ||
} | ||
|
||
code { | ||
border-radius: 5px; | ||
padding: 0.2rem; | ||
background: #efefef; | ||
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, | ||
Bitstream Vera Sans Mono, Courier New, monospace; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import waspLogo from './waspLogo.png' | ||
import './Main.css' | ||
|
||
const MainPage = () => { | ||
return ( | ||
<div className="container"> | ||
<main> | ||
<div className="logo"> | ||
<img src={waspLogo} alt="wasp" /> | ||
</div> | ||
|
||
<h2 className="welcome-title"> Welcome to Wasp - you just started a new app! </h2> | ||
<h3 className="welcome-subtitle"> | ||
This is page <code>MainPage</code> located at route <code>/</code>. | ||
Open <code>src/client/MainPage.jsx</code> to edit it. | ||
</h3> | ||
|
||
<div className="buttons"> | ||
<a | ||
className="button button-filled" | ||
href="https://wasp-lang.dev/docs/tutorial/create" | ||
target="_blank" | ||
rel="noreferrer noopener" | ||
> | ||
Take the Tutorial | ||
</a> | ||
<a | ||
className="button button-outline" | ||
href="https://discord.com/invite/rzdnErX" | ||
target="_blank" | ||
rel="noreferrer noopener" | ||
> | ||
Chat on Discord | ||
</a> | ||
</div> | ||
</main> | ||
</div> | ||
) | ||
} | ||
export default MainPage |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// =============================== IMPORTANT ================================= | ||
// | ||
// This file is only used for Wasp IDE support. You can change it to configure | ||
// your IDE checks, but none of these options will affect the TypeScript | ||
// compiler. Proper TS compiler configuration in Wasp is coming soon :) | ||
{ | ||
"compilerOptions": { | ||
// JSX support | ||
"jsx": "preserve", | ||
"strict": true, | ||
// Allow default imports. | ||
"esModuleInterop": true, | ||
"lib": [ | ||
"dom", | ||
"dom.iterable", | ||
"esnext" | ||
], | ||
"allowJs": true, | ||
// Wasp needs the following settings enable IDE support in your source | ||
// files. Editing them might break features like import autocompletion and | ||
// definition lookup. Don't change them unless you know what you're doing. | ||
// | ||
// The relative path to the generated web app's root directory. This must be | ||
// set to define the "paths" option. | ||
"baseUrl": "../../.wasp/out/web-app/", | ||
"paths": { | ||
// Resolve all "@wasp" imports to the generated source code. | ||
"@wasp/*": [ | ||
"src/*" | ||
], | ||
// Resolve all non-relative imports to the correct node module. Source: | ||
// https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping | ||
"*": [ | ||
// Start by looking for the definiton inside the node modules root | ||
// directory... | ||
"node_modules/*", | ||
// ... If that fails, try to find it inside definitely-typed type | ||
// definitions. | ||
"node_modules/@types/*" | ||
] | ||
}, | ||
// Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots | ||
"typeRoots": [ | ||
"../../.wasp/out/web-app/node_modules/@types" | ||
], | ||
// Since this TS config is used only for IDE support and not for | ||
// compilation, the following directory doesn't exist. We need to specify | ||
// it to prevent this error: | ||
// https://stackoverflow.com/questions/42609768/typescript-error-cannot-write-file-because-it-would-overwrite-input-file | ||
"outDir": "phantom" | ||
}, | ||
"exclude": [ | ||
"phantom" | ||
], | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="../../.wasp/out/web-app/node_modules/vite/client" /> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example overrides. |
||
server: { | ||
open: false, | ||
port: 3004, | ||
}, | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// =============================== IMPORTANT ================================= | ||
// | ||
// This file is only used for Wasp IDE support. You can change it to configure | ||
// your IDE checks, but none of these options will affect the TypeScript | ||
// compiler. Proper TS compiler configuration in Wasp is coming soon :) | ||
{ | ||
"compilerOptions": { | ||
// Allows default imports. | ||
"esModuleInterop": true, | ||
"allowJs": true, | ||
"strict": true, | ||
// Wasp needs the following settings enable IDE support in your source | ||
// files. Editing them might break features like import autocompletion and | ||
// definition lookup. Don't change them unless you know what you're doing. | ||
// | ||
// The relative path to the generated web app's root directory. This must be | ||
// set to define the "paths" option. | ||
"baseUrl": "../../.wasp/out/server/", | ||
"paths": { | ||
// Resolve all "@wasp" imports to the generated source code. | ||
"@wasp/*": [ | ||
"src/*" | ||
], | ||
// Resolve all non-relative imports to the correct node module. Source: | ||
// https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping | ||
"*": [ | ||
// Start by looking for the definiton inside the node modules root | ||
// directory... | ||
"node_modules/*", | ||
// ... If that fails, try to find it inside definitely-typed type | ||
// definitions. | ||
"node_modules/@types/*" | ||
] | ||
}, | ||
// Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots | ||
"typeRoots": [ | ||
"../../.wasp/out/server/node_modules/@types" | ||
], | ||
// Since this TS config is used only for IDE support and not for | ||
// compilation, the following directory doesn't exist. We need to specify | ||
// it to prevent this error: | ||
// https://stackoverflow.com/questions/42609768/typescript-error-cannot-write-file-because-it-would-overwrite-input-file | ||
"outDir": "phantom", | ||
}, | ||
"exclude": [ | ||
"phantom" | ||
], | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"compilerOptions": { | ||
// Enable default imports in TypeScript. | ||
"esModuleInterop": true, | ||
"allowJs": true, | ||
// The following settings enable IDE support in user-provided source files. | ||
// Editing them might break features like import autocompletion and | ||
// definition lookup. Don't change them unless you know what you're doing. | ||
// | ||
// The relative path to the generated web app's root directory. This must be | ||
// set to define the "paths" option. | ||
"baseUrl": "../../.wasp/out/server/", | ||
"paths": { | ||
// Resolve all non-relative imports to the correct node module. Source: | ||
// https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping | ||
"*": [ | ||
// Start by looking for the definiton inside the node modules root | ||
// directory... | ||
"node_modules/*", | ||
// ... If that fails, try to find it inside definitely-typed type | ||
// definitions. | ||
"node_modules/@types/*" | ||
] | ||
}, | ||
// Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots | ||
"typeRoots": ["../../.wasp/out/server/node_modules/@types"] | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the file is defined, we import it. If not, we use an empty object.