Webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.
# Download repository:
git clone https://github.com/obiwan00/webpack-template.git webpack-template
# Go to the app:
cd webpack-template
# Install dependencies:
npm install
# Server with hot reload at http://localhost:4000/
npm run start
# Output will be at dist/ folder
npm run build
src/index.html
- main app HTMLsrc/styles
- put custom app SCSS styles here. Don't forget to import them inindex.js
src/styles/components
- folder with custom.scss
componentssrc/fonts
- put your fonts here. Don't forget to plugin them insrs/style/_fonts.scss
src/img
- put images here.src/js
- put custom app scripts heresrc/js/index.js
- main app file where you include/import all required libs and init app
- Install libs
- Import libs in
./index.js
// React example
import React from 'react'
// Bootstrap example
import Bootstrap from 'bootstrap/dist/js/bootstrap.min.js'
import 'bootstrap/dist/js/bootstrap.min.js'
- Create another js module in
./js/components
folder - Import modules in
./js/index.js
file
Example:
// ./js/index.js
import initMenu from './components/menu';
function runAfterDomLoad() {
...
initMenu()
...
}
Usage:
All files must be created in the ./src
folder.
Example:
./src/index.html
./src/about.html
Automatic creation any html pages:
- Create another html file in
./src
(main folder) - Open new page
http://localhost:4000/newPageName.html
Сhoose one of the ways:
- Handle menthod,
- Use @import;
Add files with fonts in ./src/fonts/
.
└── CustomFont
└── CustomFont.woff2
Add @font-face
in ./src/styles/_fonts.scss
:
// Example with CustomFont
@font-face {
font-family: 'CustomFont';
font-weight: 700;
src: url('../fonts/CustomFont/CustomFont.woff2');
}
Add vars for font in ./src/styles/_variables.scss
:
$myFont : 'CustomFont', Arial, sans-serif;
Add @import
before import of _typography.scss
file.
// ./srs/styles/style.scss
...
@import url("https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;0,400;0,500;0,900;1,300;1,400;1,900&display=swap");
@import '_fonts';
@import '_typography';
...
Copyright (c) 2020-present, Ivan Maidaniuk - Contact