package.json dosyası yoksa terminale
npm init -y
Ardından webpack'in kendisini ve komutla çalıştırabilmek için webpack-cli kütüphanelerini indiriyoruz. Bu kütüphanelere paketleme esnasında ihtiyacımız olduğu için devDependency
olarak yüklememiz yeterli.
npm i --save-dev webpack webpack-cli
Eğer webpack-dev-server kütüphanesini de önden yüklemek isterseniz onu da ekleyebilirsiniz.
npm i --save-dev webpack webpack-cli webpack-dev-server
// Veya
npm i --save-dev webpack-dev-server
package.json
dosyasında scripts
özelliğinin içine çalıştıracağımız komut adı ve içeriğini yazarak terminalden webpack'i kullanabiliriz
"scripts": {
"run": "webpack"
},
Bu adımlardan sonra webpack kullanıma hazır durumda olmalı. Tabi bu haliyle default konfigürasyon olduğu için kök dizinde bulunan src klasörü içinde index.js dosyanız yoksa webpack derleme yaparken hata fırlatacaktır.
-
webpack birden fazla entry noktasından birden fazla çıktı alma
-
webpack resim dosyalarını JavaScript çıktı dosyasında kullanma
-
webpack resim dosyalarını dosya tipine göre farklı yerlere çıktı alma
-
Listeden çıkarılanlar
- webpack çıktısını parçalara bölme
- webpack dev server proxy
- webpack mode seçeneğini argümanla alma
package.json
"scripts": {
"selectConfigFile": "webpack -c config/selectConfigFile.config.js"
},
terminal
npm run-script selectConfigFile
Flag / Alias | Type | Description |
---|---|---|
--config, -c |
string[] | webpack konfigürasyon dosyasının adresini belirtmek için kullanılır |
Konfigürasyon Listesine Geri Dön
mode
seçeneği production
, development
veya none
değeri alabilir. mode
özelliğini webpack-cli ile belirlemek mümkündür.
package.json
"scripts": {
"selectModeCLI": "webpack --mode=development -c config/selectModeCLI.config.js"
},
terminal
npm run-script selectModeCLI
Flag / Alias | Type | Description |
---|---|---|
--mode |
string[] | Paketlemenin hangi ortamda kullanılacağını belirtir. |
Konfigürasyon Listesine Geri Dön
mode
seçeneği production
, development
veya none
değeri alabilir. mode
özelliğini konfigürasyon dosyasında mode
anahtar kelimesiyle string değeri olarak belirleyebiliriz.
package.json
"scripts": {
"selectModeConfig": -c config/selectModeConfig.config.js"
},
terminal
npm run-script selectModeConfig
Flag / Alias | Type | Description |
---|---|---|
--mode |
string[] | Paketlemenin hangi ortamda kullanılacağını belirtir. |
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"diffOutputWithArg": "webpack mode=development -c config/diffOutputWithArg.config.js"
},
terminal
npm run-script diffOutputWithArg
Flag / Alias | Type | Description |
---|---|---|
--mode |
string[] | Paketlemenin hangi ortamda kullanılacağını belirtir. |
Konfigürasyon Listesine Geri Dön
entry
özelliğine array halinde dosya adresleri vererek bunları tek bir çıktıda birleştirmek mümkündür.
package.json
"scripts": {
"multipleEntryOneOutput": "webpack -c config/multipleEntryOneOutput.config.js"
},
terminal
npm run-script multipleEntryOneOutput
Konfigürasyon Listesine Geri Dön
output
özelliğinin filename
özelliğine değer atayarak dosya çıktı dosyasının ismini değiştirmemiz mümkündür.
package.json
"scripts": {
"selectOutputName": "webpack -c config/selectOutputName.config.js"
},
terminal
npm run-script selectOutputName
Konfigürasyon Listesine Geri Dön
Giriş noktalarını entry
parametresine obje halinde verdiğimizde ve output
parametresinide '[name].js' olarak girersek, objedeki anahtar kelimeler dosya adı, değerleri de derlenecek dosyaları ifade eder.
package.json
"scripts": {
"multipleEntryMultipleOutput": "webpack -c config/multipleEntryMultipleOutput.config.js"
},
terminal
npm run-script multipleEntryMultipleOutput
Konfigürasyon Listesine Geri Dön
Konfigürasyonda output
özelliğinin filename özelliğine '[hash]' ekleyerek dosyaları hash'lemek mümkündür. Dosyalarda bir değişiklik olursa farklı hash üreteceği için tarayıcıda dosyanın güncellenmemesi durumu oluşmayacaktır. Derlediğiniz dosyada değişiklik yapıp tekrar derlerseniz farklı bir dosyanın üretildiğini görebilirsiniz.
package.json
"scripts": {
"hashOutput": "webpack -c config/hashOutput.config.js"
},
terminal
npm run-script hashOutput
Konfigürasyon Listesine Geri Dön
HTML dosyasına sırasıyla ekleyerek kullanabiliriz.
<script src="./lodashVendor.js"></script>
<script src="./app.js"></script>
package.json
"scripts": {
"libraryDepend": "webpack -c config/libraryDepend.config.js"
},
terminal
npm run-script libraryDepend
Konfigürasyon Listesine Geri Dön
HTML dosyasına sırasıyla ekleyerek kullanabiliriz.
<script src="./lodashVendor.js"></script>
<script src="./app.js"></script>
<script src="./appTwo.js"></script>
package.json
"scripts": {
"libraryShared": "webpack -c config/libraryShared.config.js"
},
terminal
npm run-script libraryShared
Konfigürasyon Listesine Geri Dön
HTML dosyasına sırasıyla ekleyerek kullanabiliriz.
<script src="./vendor.js"></script>
<script src="./lodashVendor.js"></script>
<script src="./app.js"></script>
package.json
"scripts": {
"entryRuntime": "webpack -c config/entryRuntime.config.js"
},
terminal
npm run-script entryRuntime
Konfigürasyon Listesine Geri Dön
terminal
npm install --save-dev style-loader css-loader
package.json
"scripts": {
"loadCSS": "webpack -c config/loadCSS.config.js"
},
terminal
npm run-script loadCSS
Konfigürasyon Listesine Geri Dön
terminal
npm install --save-dev style-loader css-loader
package.json
"scripts": {
"loadSass": "webpack -c config/loadSass.config.js"
},
terminal
npm run-script loadCSS
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"loadFile": "webpack -c config/loadFile.config.js"
},
terminal
npm run-script loadFile
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"loadFileInlineJS": "webpack -c config/loadFileInlineJS.config.js"
},
terminal
npm run-script loadFileInlineJS
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"loadFileResource": "webpack -c config/loadFileResource.config.js"
},
terminal
npm run-script loadFileResource
Konfigürasyon Listesine Geri Dön
terminal
package.json
"scripts": {
"exportedFilePath": "webpack -c config/exportedFilePath.config.js"
},
terminal
npm run-script exportedFilePath
Konfigürasyon Listesine Geri Dön
terminal
package.json
"scripts": {
"exportedFilePath": "webpack -c config/exportDiffAssettoDiffPlace.config.js"
},
terminal
npm run-script exportDiffAssettoDiffPlace
Konfigürasyon Listesine Geri Dön
terminal
package.json
"scripts": {
"cleanOutput": "webpack -c config/cleanOutput.config.js"
},
terminal
npm run-script cleanOutput
Konfigürasyon Listesine Geri Dön
terminal
npm i webpack-dev-server --save-dev
package.json
"scripts": {
"setupWebpackDevServer": "webpack serve -c config/setupWebpackDevServer.config.js"
},
terminal
npm run-script setupWebpackDevServer
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"webpackDevServerSSL": "webpack serve -c config/webpackDevServerSSL.config.js"
},
terminal
npm run-script webpackDevServerSSL
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"webpackDevServerHeaders": "webpack serve -c config/webpackDevServerHeaders.config.js"
},
terminal
npm run-script webpackDevServerHeaders
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"webpackDevServerCompress": "webpack serve -c config/webpackDevServerCompress.config.js"
},
terminal
npm run-script webpackDevServerCompress
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"webpackDevServerOpenPage": "webpack serve -c config/webpackDevServerOpenPage.config.js"
},
terminal
npm run-script webpackDevServerOpenPage
Konfigürasyon Listesine Geri Dön
terminal
npm i html-webpack-plugin --save-dev
package.json
"scripts": {
"HTMLWebpackPluginSetup": "webpack -c config/HTMLWebpackPluginSetup.config.js"
},
terminal
npm run-script HTMLWebpackPluginSetup
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"HTMLWebpackPluginTemplate": "webpack -c config/HTMLWebpackPluginTemplate.config.js"
},
terminal
npm run-script HTMLWebpackPluginTemplate
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"HTMLWebpackPluginMultipleFileCreation": "webpack -c config/HTMLWebpackPluginMultipleFileCreation.config.js"
},
terminal
npm run-script HTMLWebpackPluginMultipleFileCreation
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"HTMLWebpackPluginOptionParameters": "webpack -c config/HTMLWebpackPluginOptionParameters.config.js"
},
terminal
npm run-script HTMLWebpackPluginOptionParameters
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"HTMLWebpackPluginAdditionalParameters": "webpack -c config/HTMLWebpackPluginAdditionalParameters.config.js"
},
terminal
npm run-script HTMLWebpackPluginAdditionalParameters
Konfigürasyon Listesine Geri Dön
package.json`
"scripts": {
"minimizeOutput": "webpack -c config/minimizeOutput.config.js"
},
terminal
npm run-script minimizeOutput
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"clearConsole": "webpack -c config/clearConsole.config.js"
},
terminal
npm run-script clearConsole
Konfigürasyon Listesine Geri Dön
Konfigürasyon Listesine Geri Dön
Konfigürasyon Listesine Geri Dön
Konfigürasyon Listesine Geri Dön
Konfigürasyon Listesine Geri Dön
package.json
"scripts": {
"splitChunks": "webpack -c config/splitChunks.config.js"
},
terminal
npm run-script splitChunks
Konfigürasyon Listesine Geri Dön