-
-
Notifications
You must be signed in to change notification settings - Fork 627
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(init-generator): add svelte template #2859
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Next
Next commit
feat: add svelte template
- Loading branch information
commit 1c3501a045c613a059186c6f7b0523fd9f36b760
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
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 @@ | ||
.DS_Store | ||
node_modules | ||
public/build/bundle.* |
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,15 @@ | ||
# 🚀 Welcome to your new awesome project! | ||
|
||
This project has been created using **webpack-cli**, you can now run | ||
|
||
``` | ||
npm run build | ||
``` | ||
|
||
or | ||
|
||
``` | ||
yarn build | ||
``` | ||
|
||
to bundle your application |
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,17 @@ | ||
{ | ||
"name": "svelte-webpack-template", | ||
"version": "1.0.0", | ||
"devDependencies": { | ||
"css-loader": "^6.2.0", | ||
"mini-css-extract-plugin": "^2.1.0", | ||
"svelte": "^3.40.2", | ||
"svelte-loader": "^3.1.2", | ||
"webpack": "^5.46.0", | ||
"webpack-cli": "^4.7.2", | ||
"webpack-dev-server": "^3.11.2" | ||
}, | ||
"scripts": { | ||
"build": "webpack --node-env production", | ||
"dev": "webpack serve" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions
17
packages/generators/init-template/svelte/public/index.html
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,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset='utf-8'> | ||
<meta name='viewport' content='width=device-width,initial-scale=1'> | ||
|
||
<title>Svelte app</title> | ||
|
||
<link rel='icon' type='image/png' href='/favicon.png'> | ||
<link rel='stylesheet' href='/build/bundle.css'> | ||
|
||
<script defer src='/build/bundle.js'></script> | ||
</head> | ||
|
||
<body> | ||
</body> | ||
</html> |
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,30 @@ | ||
<script> | ||
export let name; | ||
</script> | ||
|
||
<main> | ||
<h1>Hello {name}!</h1> | ||
<p>Visit the <a href="https://svelte.dev/tutorial">Svelte tutorial</a> to learn how to build Svelte apps.</p> | ||
</main> | ||
|
||
<style> | ||
main { | ||
text-align: center; | ||
padding: 1em; | ||
max-width: 240px; | ||
margin: 0 auto; | ||
} | ||
|
||
h1 { | ||
color: #ff3e00; | ||
text-transform: uppercase; | ||
font-size: 4em; | ||
font-weight: 100; | ||
} | ||
|
||
@media (min-width: 640px) { | ||
main { | ||
max-width: none; | ||
} | ||
} | ||
</style> |
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,63 @@ | ||
html, body { | ||
position: relative; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
body { | ||
color: #333; | ||
margin: 0; | ||
padding: 8px; | ||
box-sizing: border-box; | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; | ||
} | ||
|
||
a { | ||
color: rgb(0,100,200); | ||
text-decoration: none; | ||
} | ||
|
||
a:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
a:visited { | ||
color: rgb(0,80,160); | ||
} | ||
|
||
label { | ||
display: block; | ||
} | ||
|
||
input, button, select, textarea { | ||
font-family: inherit; | ||
font-size: inherit; | ||
-webkit-padding: 0.4em 0; | ||
padding: 0.4em; | ||
margin: 0 0 0.5em 0; | ||
box-sizing: border-box; | ||
border: 1px solid #ccc; | ||
border-radius: 2px; | ||
} | ||
|
||
input:disabled { | ||
color: #ccc; | ||
} | ||
|
||
button { | ||
color: #333; | ||
background-color: #f4f4f4; | ||
outline: none; | ||
} | ||
|
||
button:disabled { | ||
color: #999; | ||
} | ||
|
||
button:not(:disabled):active { | ||
background-color: #ddd; | ||
} | ||
|
||
button:focus { | ||
border-color: #666; | ||
} |
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,12 @@ | ||
import './global.css'; | ||
|
||
import App from './App.svelte'; | ||
|
||
const app = new App({ | ||
target: document.body, | ||
props: { | ||
name: 'world' | ||
} | ||
}); | ||
|
||
export default app; |
62 changes: 62 additions & 0 deletions
62
packages/generators/init-template/svelte/webpack.config.js
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,62 @@ | ||
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | ||
const path = require("path"); | ||
|
||
const mode = process.env.NODE_ENV || "development"; | ||
const isProduction = mode === "production"; | ||
|
||
module.exports = { | ||
entry: { | ||
"build/bundle": ["./src/main.js"], | ||
}, | ||
resolve: { | ||
alias: { | ||
svelte: path.dirname(require.resolve("svelte/package.json")), | ||
}, | ||
extensions: [".mjs", ".js", ".svelte"], | ||
mainFields: ["svelte", "browser", "module", "main"], | ||
}, | ||
output: { | ||
path: path.join(__dirname, "public"), | ||
filename: "[name].js", | ||
chunkFilename: "[name].[id].js", | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.svelte$/, | ||
use: { | ||
loader: "svelte-loader", | ||
options: { | ||
compilerOptions: { | ||
dev: !isProduction, | ||
}, | ||
emitCss: isProduction, | ||
hotReload: !isProduction, | ||
}, | ||
}, | ||
}, | ||
{ | ||
test: /\.css$/, | ||
use: [MiniCssExtractPlugin.loader, "css-loader"], | ||
}, | ||
{ | ||
// required to prevent errors from Svelte on Webpack 5+ | ||
test: /node_modules\/svelte\/.*\.mjs$/, | ||
resolve: { | ||
fullySpecified: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
mode, | ||
plugins: [ | ||
new MiniCssExtractPlugin({ | ||
filename: "[name].css", | ||
}), | ||
], | ||
devtool: isProduction ? false : "source-map", | ||
devServer: { | ||
contentBase: path.join(__dirname, "public"), | ||
hot: true, | ||
}, | ||
}; |
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,5 +1,7 @@ | ||
import * as defaultHandler from "./handlers/default"; | ||
import * as svelteHandler from "./handlers/svelte"; | ||
|
||
export default { | ||
default: defaultHandler, | ||
svelte: svelteHandler, | ||
}; |
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,32 @@ | ||
import path from "path"; | ||
|
||
import InitGenerator from "../init-generator"; | ||
import { getFiles } from "../utils/helpers"; | ||
|
||
const templatePath = path.join(__dirname, "../../init-template/svelte"); | ||
|
||
export function questions(): null { | ||
// No questions | ||
return; | ||
} | ||
|
||
/** | ||
* Runs the generator from webpack-defaults | ||
*/ | ||
export function generate(self: InitGenerator): void { | ||
let files = []; | ||
try { | ||
// An array of file paths (relative to `./templates`) of files to be copied to the generated project | ||
files = getFiles(templatePath); | ||
} catch (error) { | ||
self.utils.logger.error(`Failed to generate starter template.\n ${error}`); | ||
process.exit(2); | ||
} | ||
|
||
// Copy all starter files | ||
files.forEach((fileName) => { | ||
// `absolute-path/to/_file.js.tpl` -> `destination-path/file.js` | ||
const destFilePath = path.relative(templatePath, fileName); | ||
self.fs.copyTpl(fileName, self.destinationPath(destFilePath)); | ||
}); | ||
} |
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
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.
We should also add support for postcss, sass, etc here. Like we have in default template. Maybe we can have some refactoring here.
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.
I agree, ideally we should extend default template and add custom loaders/plugins