Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rupeshtiwari/e7235addd5f52dc3e449672c4d8b88d5 to your computer and use it in GitHub Desktop.

Select an option

Save rupeshtiwari/e7235addd5f52dc3e449672c4d8b88d5 to your computer and use it in GitHub Desktop.
Setting up Webpack for Typescript Project From Scratch
@ganhammar
Copy link
Copy Markdown

In Step 1, npm i -D wepack-cli webpack type... should probably be npm i -D webpack-cli webpack type (wepack vs webpack), right?

Thanks for this!

@rupeshtiwari
Copy link
Copy Markdown
Author

rupeshtiwari commented May 12, 2021 via email

@ArtursTimofejevs
Copy link
Copy Markdown

Thanks for this 👍

@yxney-mayank
Copy link
Copy Markdown

Nice explaination . Thanks

@rupeshtiwari
Copy link
Copy Markdown
Author

@charleslukes
Copy link
Copy Markdown

This is awesome. Thank you!

@bruceharrison1984
Copy link
Copy Markdown

Slam dunk! I wish everyone wrote technical docs like this 👍

@rupeshtiwari
Copy link
Copy Markdown
Author

Thanks @charleslukes and @bruceharrison1984 I am glad this is helpful.

@williamwdoyle
Copy link
Copy Markdown

williamwdoyle commented Apr 18, 2022

Warning
ts-loader uses tsc, the TypeScript compiler, and relies on your tsconfig.json configuration. Make sure to avoid setting module to "CommonJS", or webpack won't be able to tree-shake your code.

The tsconfig.json will still work, but the caveat is still good to keep in mind.

source

@er0603
Copy link
Copy Markdown

er0603 commented May 29, 2022

@rupeshtiwari Thank you for your great tutorial!

In this chapter "Creation of the Project Draft Document", I want to learn more about it, but your link seems to have been broken.

Could you fix it?

@Sergeo1989
Copy link
Copy Markdown

Thanks

@michailmoiropoulos
Copy link
Copy Markdown

At the very first steps of initialization, at "Creating Webpack.config.js file" step, and after typing "npx webpack-cli init" I get the following question:
[webpack-cli] For using this command you need to install: '@webpack-cli/generators' package. [webpack-cli] Would you like to install '@webpack-cli/generators' package? (That will run 'npm install -D @webpack-cli/generators') (Y/n)

I guess should continue by installing the generators package...
Which leads me to very different questions:

  • Which of the following JS solutions do you want to use? (Use arrow keys)

none
ES6
Typescript

  • Do you want to use webpack-dev-server? (Y/n)
  • Do you want to simplify the creation of HTML files for your bundle? (Y/n)
  • Do you want to add PWA support? (Y/n)
  • Which of the following CSS solutions do you want to use? (Use arrow keys)

none
CSS only
SASS
LESS
Stylus

  • Do you like to install prettier to format generated configuration? (Y/n)
  • Pick a package manager: (Use arrow keys)

npm
yarn
pnpm

Which then asks me to overwrite some files; like the package.json for example.
It was very early in those steps but I don't think I misstepped anywhere. Did I?

@tjmoore
Copy link
Copy Markdown

tjmoore commented Jun 20, 2025

npx webpack-cli init doesn't work in later versions

Removed in favour of create-webpack-app apparently https://github.com/webpack/webpack-cli/blob/master/CHANGELOG.md#600-2024-12-19

Which replaces this entirely? Though I was hoping to add webpack to an existing project with this, but this creates a whole app from a template?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment