Webpack is a popular tool for bundling JavaScript projects, and it can be used to bundle a wide range of assets, including CSS, images, and fonts
dist/
src/
app/
styles/
index.ts
index.html
First we need to install webpack npm packages. I assume you already have npm and nodejs in your local machine. If you don’t please follow the link see instractions to install nodejs and npm.
Let install the webpack and webpack-cli packages using npm
npm install webpack webpack-cli --save-dev
When the installation is done we gonna create config file called webpack.config.js under the root directory of the project.
In this configuration file, we specify that index.js
is the entry point for our project, and bundle.js
is the output file that Webpack will generate. We also specify the output path as dist
, which stands for distribution. Generated bundle file will be located under the dist folder.
Run npx webpack command to generate bundle files. It will create bundle files once then we will add some configuration to keep webpack and up and detect changes in the files and re bundle everything for everychanges. So we won’t have to call the webpack cli every time.
In order to bundle SCSS files to CSS using Webpack, you can use the sass-loader
and css-loader
modules. Here are the general steps to do this:
sass-loader
, css-loader
, and style-loader
modules as development dependencies. You can do this by running the following command in your terminal:npm install sass-loader css-loader style-loader --save-dev
webpack.config.js
file:Webpack also supports working with typescript but you need to install some external libraries to help webpack to understand and transform typescript files. We will use typescript compiler and in order to that first we need to define at least initial typescript config file. Below configuration file is enough for initial compiling but you can extend above file as you wish. For more information please visit typescript configurations
npm install typescript ts-loader --save-dev
{
"compilerOptions": {
"module": "es6",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"declaration": true,
"moduleResolution": "node",
"outDir": "./dist",
"rootDir": "."
},
"include": ["src"]
}
Thats it. Our webpack configuration file is ready. But to be sure it is only for development. In order to generate production ready bundle we need to add some more configurations. Like minifying css files and add cross platform support, browser support for javascript files and so on. But it will be part of another story that I will post some day 🙂
Herkese Merhabalar. Bildiğiniz üzere bu ay Angular 17 yepyeni bir imaj çalışması ile birlikte yayına…
Herkese merhaba arkadaşlar. Önceki yazımızda openlayers nedir ve neden kullanmalıyız sorunu yanıtlamıştık. Popüler harita kütüphanelerinden…
Merhaba arkadaşlar. Eğer CBS (Coğrafi Bilgi Sistemleri) dünyasına yeni yeni adımlar atıyorsanız adını sık sık…
Herkese merhabalar. Bugün angular ekosisteminde NGXS kullanarak nasıl state management yapacağımızı inceleyeceğiz. Angular state management…
Herkese Merhaba. Bu yazımızda frontend camiasında faaliyet gösteren herkesin aklındaki o soruya bir açıklık getireceğiz.…
Uzun bir aradan sonra herkese merhaba :) Angular Template Driven Form Nedir, Ne işe yarar…