fix(init): generate webpack.config.ts instead of webpack.config.js when TypeScript is selected#4723
Conversation
🦋 Changeset detectedLatest commit: 57f8de2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4723 +/- ##
=======================================
Coverage 91.43% 91.44%
=======================================
Files 14 14
Lines 4716 4721 +5
Branches 679 682 +3
=======================================
+ Hits 4312 4317 +5
Misses 402 402
Partials 2 2
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
test/create-webpack-app/init/__snapshots__/init.test.js.snap.webpack5
Outdated
Show resolved
Hide resolved
test/create-webpack-app/init/__snapshots__/init.test.js.snap.webpack5
Outdated
Show resolved
Hide resolved
packages/create-webpack-app/templates/init/default/package.json.tpl
Outdated
Show resolved
Hide resolved
|
So @alexander-akait here we don't need ts-node and NODE_OPTION anymore since it will use Node22 from this month? |
|
I think for typescript we can use only ECMA syntax and so use built-in Typescript Node.js API |
-Add ts-node to load the configuration file
- Replace `webpack.config.js.tpl` with a unified `webpack.config.tpl` based on `langType` - Add conditional `import "webpack-dev-server"` when devServer is selected - Add `ts-node` to devDependencies when TypeScript is selected - Update tests to assert `webpack.config.ts` is generated for TypeScript projects
\n Node22 natively support typescript
c13517d to
35458fb
Compare
test/create-webpack-app/init/__snapshots__/init.test.js.snap.webpack5
Outdated
Show resolved
Hide resolved
packages/create-webpack-app/templates/init/default/tsconfig.json.tpl
Outdated
Show resolved
Hide resolved
packages/create-webpack-app/templates/init/default/tsconfig.json.tpl
Outdated
Show resolved
Hide resolved
alexander-akait
left a comment
There was a problem hiding this comment.
Let's do couple improvements and we can merge
let's go |
Yes, there is no point in support |
|
@alexander-akait @evenstensberg This is completely off-topic, but what do you think if I changed the CLI UI for the
|
|
@ThierryRakotomanana I like it, feel free to start it after we resolve it |
|
Don't forget we support |
Got it, will start with the help command first |
test/create-webpack-app/init/__snapshots__/init.test.js.snap.webpack5
Outdated
Show resolved
Hide resolved
|
@ThierryRakotomanana oh, forgot to check, do we add |
Got it. I'll check that. |


Summary
When running
npx create-webpack-appand selecting TypeScript as the language, the generator createswebpack.config.jsinstead ofwebpack.config.ts.ts-nodeis not add as dependency,webpack -c ./webpack.config.tsdoesn't work.es5as target, that creates a compiler errorWhat kind of change does this PR introduce?
Fix :
langTypeanswerwebpack.config.js.tplwith a unifiedwebpack.config.tplthat renders JS or TS syntax based onlangTypeimport webpack from "webpack"and typedwebpack.Configurationannotation in the TS outputimport "webpack-dev-server"when devServer is selectedts-nodeto devDependencies when TypeScript is selectedNODE_OPTIONS='--loader ts-node/esm --no-warningsto load webpack.config.ts in the package.jsowebpack.config.tsis generated for TypeScript projectsDid you add tests for your changes?
Yes, and I updated the test case
Does this PR introduce a breaking change?
Not really,
If relevant, what needs to be documented once your changes are merged or what have you already documented?
The Typescript docs, but I am already on it.
Use of AI
No