├── .gitignore ├── postcss.config.js ├── src ├── assets │ └── images │ │ ├── logo.png │ │ ├── logo.jpeg │ │ └── webpack.gif ├── app │ ├── header.js │ └── footer.ts ├── index.js ├── styles │ └── scss │ │ └── main.scss └── index.html ├── config ├── webpack.dev.config.js ├── webpack.prod.config.js └── webpack.common.config.js ├── webpack.config.js ├── tsconfig.json ├── readme.md └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .git/ 3 | node_modules/ 4 | .vscode 5 | dist/ 6 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | require('autoprefixer') 4 | ] 5 | } -------------------------------------------------------------------------------- /src/assets/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thejsdeveloper/webpack4-setup/HEAD/src/assets/images/logo.png -------------------------------------------------------------------------------- /src/assets/images/logo.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thejsdeveloper/webpack4-setup/HEAD/src/assets/images/logo.jpeg -------------------------------------------------------------------------------- /src/assets/images/webpack.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thejsdeveloper/webpack4-setup/HEAD/src/assets/images/webpack.gif -------------------------------------------------------------------------------- /config/webpack.dev.config.js: -------------------------------------------------------------------------------- 1 | const merge = require('webpack-merge') 2 | const webpackBaseConfig = require('./webpack.common.config.js') 3 | 4 | module.exports = merge(webpackBaseConfig, {}) 5 | -------------------------------------------------------------------------------- /src/app/header.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | export class Header { 4 | constructor() { 5 | console.log(`This is header constructor`); 6 | } 7 | 8 | getFirstHeading() { 9 | return `Webpack Starter page`; 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const environment = (process.env.NODE_ENV || 'development').trim(); 2 | 3 | if (environment === 'development') { 4 | module.exports = require('./config/webpack.dev.config.js'); 5 | } else { 6 | console.log('In PROD') 7 | module.exports = require('./config/webpack.prod.config.js'); 8 | } -------------------------------------------------------------------------------- /src/app/footer.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | export class Footer { 4 | 5 | footertext: string; 6 | 7 | constructor() { 8 | console.log(`This is Footer constructor`); 9 | this.footertext = `Demo for webpack 4 set up`; 10 | } 11 | 12 | getFooterText(): string { 13 | return this.footertext 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /config/webpack.prod.config.js: -------------------------------------------------------------------------------- 1 | const merge = require('webpack-merge'); 2 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); 3 | const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); 4 | const webpackBaseConfig = require('./webpack.common.config.js'); 5 | 6 | 7 | module.exports = merge(webpackBaseConfig, { 8 | optimization: { 9 | minimizer: [ 10 | new UglifyJsPlugin(), 11 | new OptimizeCSSAssetsPlugin() 12 | ] 13 | } 14 | }) -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import '@scss/main.scss' 2 | 3 | import { Header } from '@/app/header'; 4 | import { Footer } from '@/app/footer'; 5 | import webpackgif from '@img/webpack.gif'; 6 | 7 | document.getElementById('webpack-gif').setAttribute('src', webpackgif) 8 | 9 | console.log(`***Header******`); 10 | let header = new Header(); 11 | let firstHeading = header.getFirstHeading(); 12 | console.log(firstHeading); 13 | 14 | console.log(`***footer******`); 15 | let footer = new Footer(); 16 | let footerText = footer.getFooterText(); 17 | console.log(footerText); -------------------------------------------------------------------------------- /src/styles/scss/main.scss: -------------------------------------------------------------------------------- 1 | @import '../../../node_modules/bootstrap/scss/bootstrap.scss'; 2 | 3 | body { 4 | height: 100vh; 5 | display: flex; 6 | flex-direction: column; 7 | background-color: #f7f9fd; 8 | } 9 | 10 | 11 | header { 12 | color: #fff; 13 | height: 70px; 14 | user-select: none; 15 | 16 | .logo { 17 | width: 40px; 18 | height: 40px; 19 | } 20 | } 21 | 22 | footer { 23 | height: 50px; 24 | } 25 | 26 | main { 27 | display: flex; 28 | flex: 1; 29 | align-items: center; 30 | justify-content: center; 31 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | // Target latest version of ECMAScript. 4 | "target": "esnext", 5 | // Search under node_modules for non-relative imports. 6 | "moduleResolution": "node", 7 | // Process & infer types from .js files. 8 | "allowJs": true, 9 | // Don't emit; allow Babel to transform files. 10 | "noEmit": true, 11 | // Enable strictest settings like strictNullChecks & noImplicitAny. 12 | "strict": true, 13 | // Disallow features that require cross-file information for emit. 14 | "isolatedModules": false, 15 | // Import non-ES modules as default imports. 16 | "esModuleInterop": true, 17 | "baseUrl": ".", 18 | "paths": { 19 | "@components": [ "src/components" ], 20 | "@scss": [ "src/styles/scss" ], 21 | "@img": [ "src/assets/images" ], 22 | "@": [ "src" ], 23 | } 24 | }, 25 | "include": [ 26 | "src" 27 | ] 28 | } 29 | 30 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Let's Start with Webpack 4 2 | ### Webpack configuration introduction 3 | 4 |  5 | 6 | ## This project provide following functionality: 7 | 1. Webpack configuration for development and production 8 | 2. Transpile .ts and ES6+ to ES5 9 | 3. Convert SCSS to CSS 10 | 4. Managing static resources 11 | 5. Use of different plugins in Webpack 12 | 13 | ### To clone the repository 14 | > Run `git clone https://github.com/thejsdeveloper/webpack4-setup.git` 15 | 16 | ### Change directory 17 | > cd `webpack4-setup` 18 | 19 | ### Install dependencies 20 | > npm install 21 | 22 | ### Run development server 23 | 24 | > Run `npm run dev` for a dev server. Navigate to `http://localhost:8080/`. 25 | The app will automatically reload if you change any of the source files. 26 | 27 | ### Build 28 | 29 | > Run `npm run build:dev` to build the project in development mode. 30 | > Run `npm run build:prod` to build the project in production mode. 31 | 32 | The build artifacts will be stored in the `dist/` directory. 33 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 |