-
-
Notifications
You must be signed in to change notification settings - Fork 593
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 create webpack app #4167
base: master
Are you sure you want to change the base?
Changes from 14 commits
f910fe3
c175c9d
12fbc20
92c2f19
488f3df
a17fa63
bb6ca9f
d5e9fc3
667d50d
8f89b98
d2ca7f6
acf5fa5
df39698
93c2142
85b06bc
88acfd2
55e13ec
897e00b
f9cb74a
b6baa6a
d9a0856
d8ec7e1
4c59396
04b5f90
1bdf924
5e6a70b
bb5e201
9bf21bf
a295914
e6add83
4ac8bf0
d1fb3e7
2928772
3f66230
769e095
cb309df
860e5c2
de92604
b150fa8
f3315f4
19f59ea
02f04cb
284ab14
b80f340
944bb33
b82f4be
b4cca8f
e3ef415
0a42c64
f0196bd
8e9dfb6
ff53355
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `create-webpack-app` | ||
|
||
> TODO: description | ||
## Usage | ||
|
||
```js | ||
const createWebpackApp = require("create-webpack-app"); | ||
|
||
// TODO: DEMONSTRATE API | ||
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. Do we need to promote the API usage? IMO, CWA interaction should be limited to CLI. 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. I was thinking the same thing, will surely work on a better readme. |
||
``` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,19 @@ | ||||||
import path from "node:path"; | ||||||
import { fileURLToPath } from "node:url"; | ||||||
import minimist from "minimist"; | ||||||
import { Plop, run } from "plop"; | ||||||
/* cSpell:disable */ | ||||||
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. Does this disable cspell for the whole file or just the next line? 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. section of code but I have found a better alternative
Suggested change
|
||||||
const args = process.argv.slice(2); | ||||||
const argv = minimist(args); | ||||||
const __filename = fileURLToPath(import.meta.url); | ||||||
const __dirname = path.dirname(__filename); | ||||||
|
||||||
Plop.prepare( | ||||||
{ | ||||||
cwd: argv.cwd, | ||||||
configPath: path.resolve(__dirname, "../lib/plopfile.js"), | ||||||
preload: argv.preload || [], | ||||||
completion: argv.completion, | ||||||
}, | ||||||
(env) => Plop.execute(env, run), | ||||||
); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,53 @@ | ||||||
{ | ||||||
"name": "create-webpack-app", | ||||||
"version": "1.0.0", | ||||||
"description": "CLI for scaffolding webpack projects using default config, framework templates, loader or plugins templates", | ||||||
"license": "MIT", | ||||||
"repository": { | ||||||
"type": "git", | ||||||
"url": "https://github.com/webpack/create-webpack-app.git" | ||||||
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. This is under the webpacki-cli repo |
||||||
}, | ||||||
"homepage": "https://github.com/webpack/webpack-cli/tree/master/packages/create-webpack-app", | ||||||
"bugs": "https://github.com/webpack/webpack-cli/issues", | ||||||
"funding": { | ||||||
"type": "opencollective", | ||||||
"url": "https://opencollective.com/webpack" | ||||||
}, | ||||||
"bin": { | ||||||
"create-webpack-app": "./bin/index.js" | ||||||
}, | ||||||
"type": "module", | ||||||
"main": "./lib/index.js", | ||||||
"scripts": { | ||||||
"build": "tsc --build", | ||||||
"watch": "tsc --watch" | ||||||
}, | ||||||
"engines": { | ||||||
"node": ">=14.15.0" | ||||||
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. Let's support the minimum version as v18, we also have plans to drop support for v14 in other packages too.
Suggested change
|
||||||
}, | ||||||
"keywords": [ | ||||||
"webpack", | ||||||
"cli", | ||||||
"scaffolding", | ||||||
"module", | ||||||
"bundler", | ||||||
"web", | ||||||
"frameworks" | ||||||
], | ||||||
"files": [ | ||||||
"bin", | ||||||
"lib", | ||||||
"!**/*__tests__" | ||||||
], | ||||||
"dependencies": { | ||||||
"ejs": "^3.1.10", | ||||||
"minimist": "^1.2.8", | ||||||
"node-plop": "^0.32.0", | ||||||
"plop": "^4.0.1" | ||||||
}, | ||||||
"devDependencies": { | ||||||
"@types/ejs": "^3.1.5" | ||||||
}, | ||||||
"peerDependencies": {}, | ||||||
"peerDependenciesMeta": {} | ||||||
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.
Suggested change
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. changed this in latest commit |
||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// refactored generator will be written here shortly |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,179 @@ | ||||||
import { NodePlopAPI } from "./types"; | ||||||
import { resolve } from "path"; | ||||||
import ejs from "ejs"; | ||||||
/* eslint-disable no-unused-vars */ | ||||||
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. Let's not disable the rule for the whole file, prefer to use 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. changed this in latest commits |
||||||
|
||||||
export default function (plop: NodePlopAPI) { | ||||||
const dependencies = ["webpack", "webpack-cli"]; | ||||||
// Define a base generator for the project structure | ||||||
plop.setGenerator("init", { | ||||||
description: "Create a basic Webpack project", | ||||||
prompts: [ | ||||||
{ | ||||||
type: "input", | ||||||
name: "projectName", | ||||||
message: "Enter your project name:", | ||||||
default: "webpack-project", | ||||||
validate(input, _) { | ||||||
if (!input) { | ||||||
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. A more strict check, in case the user just passes space.
Suggested change
|
||||||
return "Project name cannot be empty"; | ||||||
} | ||||||
return true; | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
type: "input", | ||||||
name: "configPath", | ||||||
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.
Suggested change
|
||||||
message: "Enter the project destination:", | ||||||
default: ".", | ||||||
filter: (input, answers) => { | ||||||
return resolve(input, answers.projectName); | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
type: "input", | ||||||
name: "entryPoint", | ||||||
message: "Enter the entry point of your application:", | ||||||
default: "src/index.js", | ||||||
validate(input, _) { | ||||||
if (!input) { | ||||||
return "Entry point cannot be empty"; | ||||||
} | ||||||
return true; | ||||||
}, | ||||||
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. Since we are the ones generating templates we should have control over the entry point. We should not ask this question for scaffolding, users can refactor templates if they wish to post scaffolding. 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. That makes sense. |
||||||
}, | ||||||
{ | ||||||
type: "list", | ||||||
name: "langType", | ||||||
message: "Which of the following JS solutions do you want to use?", | ||||||
choices: ["none", "ES6", "Typescript"], | ||||||
default: "none", | ||||||
filter: (input, _) => { | ||||||
switch (input) { | ||||||
case "ES6": | ||||||
dependencies.push("babel-loader", "@babel/core", "@babel/preset-env"); | ||||||
break; | ||||||
case "Typescript": | ||||||
dependencies.push("typescript", "ts-loader"); | ||||||
break; | ||||||
} | ||||||
return input; | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
type: "confirm", | ||||||
name: "devServer", | ||||||
message: "Would you like to use Webpack Dev server?", | ||||||
default: true, | ||||||
filter: (input, _) => { | ||||||
if (input) { | ||||||
dependencies.push("webpack-dev-server"); | ||||||
} | ||||||
return input; | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
type: "confirm", | ||||||
name: "htmlWebpackPlugin", | ||||||
message: "Do you want to simplify the creation of HTML files for your bundle?", | ||||||
default: true, | ||||||
filter: (input, _) => { | ||||||
if (input) { | ||||||
dependencies.push("html-webpack-plugin", "html-loader"); | ||||||
} | ||||||
return input; | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
type: "confirm", | ||||||
name: "workboxWebpackPlugin", | ||||||
message: "Do you want to add PWA support?", | ||||||
default: true, | ||||||
filter: (input, _) => { | ||||||
if (input) { | ||||||
dependencies.push("workbox-webpack-plugin"); | ||||||
} | ||||||
return input; | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
type: "list", | ||||||
name: "cssType", | ||||||
message: "Which of the following CSS solution do you want to use?", | ||||||
choices: ["none", "CSS only", "SASS", "LESS", "Stylus"], | ||||||
default: "Css only", | ||||||
filter: (input, answers) => { | ||||||
if (input === "none") { | ||||||
answers.isCSS = false; | ||||||
answers.isPostCSS = false; | ||||||
answers.extractPlugin = "No"; | ||||||
} else { | ||||||
dependencies.push("style-loader", "css-loader"); | ||||||
switch (input) { | ||||||
case "CSS only": | ||||||
answers.isCSS = true; | ||||||
break; | ||||||
case "SASS": | ||||||
dependencies.push("sass-loader", "node-sass"); | ||||||
break; | ||||||
case "LESS": | ||||||
dependencies.push("less-loader", "less"); | ||||||
break; | ||||||
case "Stylus": | ||||||
dependencies.push("stylus-loader", "stylus"); | ||||||
break; | ||||||
} | ||||||
} | ||||||
return input; | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
type: "confirm", | ||||||
name: "isCSS", | ||||||
message: (answers) => | ||||||
`Will you be using CSS styles along with ${answers.cssType}in your project?`, | ||||||
when: (answers) => answers.cssType !== "CSS only", | ||||||
default: true, | ||||||
}, | ||||||
{ | ||||||
type: "confirm", | ||||||
name: "isPostCSS", | ||||||
message: "Do you want to use PostCSS in your project?", | ||||||
when: (answers) => answers.isCSS, | ||||||
filter: (input, _) => { | ||||||
if (input) { | ||||||
dependencies.push("postcss-loader", "autoprefixer"); | ||||||
} | ||||||
return input; | ||||||
}, | ||||||
default: true, | ||||||
}, | ||||||
{ | ||||||
type: "list", | ||||||
name: "extractPlugin", | ||||||
message: "Do you want to extract CSS into separate files?", | ||||||
choices: ["No", "Only for Production", "Yes"], | ||||||
when: (answers) => answers.isCSS, | ||||||
default: "No", | ||||||
filter: (input, _) => { | ||||||
if (input !== "No") { | ||||||
dependencies.push("mini-css-extract-plugin"); | ||||||
} | ||||||
return input; | ||||||
}, | ||||||
}, | ||||||
], | ||||||
actions: [ | ||||||
{ | ||||||
type: "addMany", | ||||||
destination: "{{configPath}}", | ||||||
base: "../templates/init/default", | ||||||
templateFiles: "../templates/init/default/**/*", | ||||||
transform: (content, data) => ejs.render(content, data), | ||||||
stripExtensions: ["tpl"], | ||||||
force: true, | ||||||
verbose: true, | ||||||
}, | ||||||
], | ||||||
}); | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export type { | ||
ActionConfig, | ||
ActionType, | ||
AddActionConfig, | ||
AddManyActionConfig, | ||
AppendActionConfig, | ||
CustomActionFunction, | ||
ModifyActionConfig, | ||
PlopCfg, | ||
PlopGenerator, | ||
NodePlopAPI, | ||
PlopGeneratorConfig, | ||
Actions, | ||
} from "node-plop"; | ||
|
||
export type InitOptions = { template: string; force?: boolean }; | ||
export type LoaderOptions = { template: string }; | ||
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. RE: slack conv, you should make this generic. You see the pattern 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. Okay I will work on this soon, |
||
export type PluginOptions = { template: string }; | ||
export type InitGeneratorOptions = { generationPath: string } & InitOptions; | ||
export type LoaderGeneratorOptions = { generationPath: string } & LoaderOptions; | ||
export type PluginGeneratorOptions = { generationPath: string } & PluginOptions; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"plugins": ["@babel/syntax-dynamic-import"], | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"modules": false | ||
} | ||
] | ||
] | ||
} |
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 | ||||||
|
||||||
```bash | ||||||
npm run build | ||||||
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. 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. I am not sure what I am supposed to do here I would love if you can be a bit more specific,
Suggested change
like this? |
||||||
``` | ||||||
|
||||||
or | ||||||
|
||||||
```bash | ||||||
yarn build | ||||||
``` | ||||||
|
||||||
to bundle your application |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("Hello World!"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"version": "1.0.0", | ||
|
||
"description": "My webpack project", | ||
|
||
"name": <%= projectName %>, | ||
"scripts": { | ||
"build": "webpack --mode=production --node-env=production", | ||
|
||
"build:dev": "webpack --mode=development", | ||
"build:prod": "webpack --mode=production --node-env=production", | ||
"watch": "webpack --watch", | ||
<% if (devServer) { %> | ||
"serve": "webpack serve" | ||
<% } %> | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
// Add you postcss configuration here | ||
// Learn more about it at https://github.com/webpack-contrib/postcss-loader#config-files | ||
plugins: [["autoprefixer"]], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("Hello, World!"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Webpack App</title> | ||
</head> | ||
<body> | ||
<h1>Hello world!</h1> | ||
<h2>Tip: Check your console</h2> | ||
</body> | ||
<% if (workboxWebpackPlugin) { %> | ||
<script> | ||
if ("serviceWorker" in navigator) { | ||
window.addEventListener("load", () => { | ||
navigator.serviceWorker | ||
.register("service-worker.js") | ||
.then((registration) => { | ||
console.log("Service Worker registered: ", registration); | ||
}) | ||
.catch((registrationError) => { | ||
console.error("Service Worker registration failed: ", registrationError); | ||
}); | ||
}); | ||
} | ||
</script><% } %> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowSyntheticDefaultImports": true, | ||
"noImplicitAny": true, | ||
"module": "es6", | ||
"target": "es5", | ||
"allowJs": true | ||
}, | ||
"files": ["src/index.ts"] | ||
} |
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 run ESlint on all packages.