• Stars
    star
    190
  • Rank 197,679 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Learn webpack by sample, each of the samples contains a readme.md file that indicates the purpose of the sample plus an step by step guide to reproduce it.

Webpack by sample

Learn webpack by sample, each of the samples contains a readme.md file that indicates the purpose of the sample plus an step by step guide to reproduce it.

The Lemoncode Frontend Master Students are working on a review process, if you want to cooperate in this process or add more useful samples don't hesitate to contact us, fork the project and asking for PR once ready.

Demos

00 Intro

00 Boilerplate

In this sample we are going to setup a web project that can be easily managed by webpack.

We will setup an initial npm project, give support to ES6, and install webpack.

We will create a hellword.js sample.

Summary steps:

  • Intialize package.json (npm init)
  • Create a simple HTML file.

01 Import

In this sample we are going to start working with ES6 modules (import).

We will start from sample 00 Intro/00 Boilerplate and add a new JavaScript service that will hold a simple algorithm to calculate the average of an score array.

We will use this JavaScript array into the main students.js file by importing it.

Summary steps:

  • Add a new file averageService.js
  • Add an array on students.js
  • Import averageService into students.js
  • Use the averageService features inside the students.js code.
  • Transpile and test on index.html

02 Server

In this sample we are going to enter into "dev mode". Working with files service is not ideal when you are developing a web application, we will learn how to launch a lite web server, how deploy our bundle into a dist folder (including index.html) , how to debug our es6 code directly into the browser debugger and minify our bundle.js.

We will start from sample 00 Intro/01 Import, install webpack-dev-server, setup our config to deploy on config folder and support maps (debug), then we will minify our bundle.js file via webpack cli params.

Summary steps:

  • Install via npm webpack-dev-server.
  • Execute webpack-dev-server with live reload.
  • Add start command to package.json.

03 Output

In this sample we are going to setup a dist folder where the webpack bundle and main HTML page will be copied to.

We will start from sample 00 Intro/02 Server,

Summary steps:

  • Redirect output (bundle.js) to "dist" folder.
  • Include into the build proccess: copying the index.html file to "dist" folder
  • Let webpack include the bundle.js script into the index.html file.
  • Add map support in order to enable ES6 files to be debugged directly on the browser.
  • Generate a minified version of the bundle.js.

04 JQuery

So far we have made good progress on our journey... but we are lacking one of the basic pillars of web development, consuming third party libraries.

In this demo we will install a legacy library (jquery) via npm, define it as global, and use it. Finally we will end up creating a separate bundle for libraries.

We will start from sample 00 Intro/03 Output.

Summary steps:

  • Install jquery via npm.
  • Setup a global alias ($).
  • Create some sample code using this library.
  • Break into two bundles app.js and vendor.js.

01 Styles

01 Custom CSS

Let's get started working with styles.

In this demo will create a custom CSS file (it will contain a simple css class that will setup a background color to red).

We will start from sample 00 Intro/04 JQuery.

Summary steps:

  • Create a custom css file.
  • Install style loader and css loader packages.
  • Configure webpackconfig.

02 Import Bootstrap

In this demo we will install and configure webpack to import the well known Bootstrap CSS library.

We will start from sample 01 Styles / 01 Custom CSS.

Summary steps:

  • Install Bootstrap.
  • Import the CSS library.
  • Use a jumbotron element from Bootstrap in our HTML.
  • Check that we get errors when running webpack.
  • Install additional loaders in order to manage fonts and other files required by Bootstrap.
  • Check results.

03 SASS

In this demo we rename our css file to scss extension and add a simple SASS variable. We will learn how to add a loader that can make the SASS preprocess and then chain it to our css / style pipe.

We will start from sample 01 Styles/02 Import Bootstrap.

Summary steps:

  • Rename mystyles.css to scss.
  • Add some SASS specific code.
  • Install a SASS preprocessor loader.
  • Add this preprocessor to the pipe (update webpack.config.js).

04 Handling Images

In this demo we are going to include images in our project in two flavours: via JavaScript and via HTML. On the JavaScript side we will see it's something straightforward (using the same plugins we used for fonts), for the HTML we will use a new loader: html-loader.

We will start from sample 01 Styles/03 SASS.

Summary steps:

  • Add two images to our project.
  • Add first image from HTML.
  • Add second image from JavaScript.
  • Configure the loader.

05 Import Materialize

In this demo we will install and configure webpack to import the Google framework Materialize.

We will start from sample 01 Styles / 01 Custom CSS.

Summary steps:

  • Fix jQuery dependency version.
  • Install Materialize.
  • Import the CSS and JS library.
  • Use a card element from Materialize in our HTML.
  • Check that we get errors when running webpack.
  • Install additional loaders in order to manage fonts and other files required by Materialize.
  • Check results.

02 Fx (frameworks / libraries / languages)

00 TypeScript

In this demo we will add support for TypeScript.

We will start from sample 01 Styles/03 SASS, install TypeScript locally, configure a tsconfig file, add some ts like, install awesome-typescript-loader and apply it to webpackconfig.

Summary steps:

  • Remove babel configuration.
  • Install TypeScript as a local dependency.
  • Configure TypeScript for our project (tsconfig)
  • Port our project to TypeScript and add use in our code some of the ts features.
  • Install awesome-typescript-loader.
  • Add the proper configuration in webpack.config.js

01 React

In this demo we will add support for React.

We will start from sample 01 Styles / 03 SASS, install React locally, update students.js to students.jsx and include some basic rendering.

Summary steps:

  • Install React as a local dependency.
  • Update students.js to students.jsx and update its content accordingly.
  • Resolve the jsx extensions and point out that the entry point has changed.
  • Configure the webpack.config.js to support jsx.

02 Angular

In this sample we are going to create a simple Angular 1.x sample (es6 based).

We will start from sample 01 Styles/03 SASS.

Summary steps:

  • Installing Angular 1.x libraries.
  • Creating the app.
  • Instantiating the app from the html.
  • Creating a component (inline HTML).
  • Creating a service.
  • Displaying the component.
  • Creating an external HTML template and consuming it.

03 Angular 2

In this sample we are going to setup a basic Angular 2 app with Webpack.

We will start from sample 02 Fx/00 TypeScript.

Summary steps:

  • Install Angular 2.x libraries.
  • Create the app.
  • Instantiate the app from the html.
  • Create a component (inline HTML).
  • Create a service.
  • Display the component.
  • Create an external HTML template and consuming it.

03 Environments (development and production configs)

01 Linting

In this sample we are going to introduce Linting. This is a technique which you can analyse code for potential errors, so that can help you to make less mistakes.

We will start from sample 01 Styles/03 SASS.

Summary steps:

  • Installing ESLint.
  • Configuring ESLint.
  • Connecting with Babel.
  • Connecting with Webpack.
  • Adding custom rules.

02 CSS Modules

In this demo we are going to isolate different scss files using same css class names. We will learn how to configure it and how to deal with external css class provided by third libraries like Bootstrap.

We will start from sample 02 Fx/01 React.

Summary steps:

  • Update webpack.config.js with CSS Modules config.
  • Add scss file with averageComponent styles.
  • Create other component and scss file with same class name.
  • Create selector using custom class and Bootstrap class.

03 HMR

In this demo we are going to configure Hot Module Replacement. This feature is great for productivity in development environment, allowing us to update the app code without having to redeploy the whole files or refresh our browser to get the changes updated.

We will start from sample 03 Environments/02 CSS Modules.

Summary steps:

  • Update webpack.config.js with HMR config.
  • Install react-hot-loader.
  • Update student.jsx file.
  • Create index.jsx file.

04 Production Configuration

In this demo we are going to create different builds for each environment. We will learn how to configure it and how to reduce bundle file sizes.

We will start from sample 03 Environments/03 HMR.

Summary steps:

  • Add base webpack config file
  • Add webpack-merge package.
  • Add development config file.
  • Add production config file.

04 Peformance

01 Tree Shaking ES6

On of the most interest features that ships Webpack 2 and it has Webpack 3 too, is Tree Shaking: this allows to remove from a destination bundle the exports that are not in use by the project, reducing dramatically the site of our bundle.

We will start from sample 01 Styles/03 SASS and we are going to create a simple sample in ES6:

  • A calculator module where we create an export per basic operation (sum, substract, mul, div..).

  • A main.js file that will import this calculator module and use only sum operation.

We will use webpack's 2 tree shaking and check that we end up having a bundle that doesn't contain the code for substract, mul, and div

02 Tree Shaking TypeScript

On of the most interest features that ships Webpack 2 and it has Webpack 3 too, is Tree Shaking: this allows to remove from a destination bundle the exports that are not in use by the project, reducing dramatically the site of our bundle.

We will start from sample 02 Fx/00 TypeScript and we are going to create a simple sample in TypeScript:

  • A calculator module where we create an export per basic operation (sum, substract, mul, div..).

  • A main.js file that will import this calculator module and use only sum operation.

We will use webpack's 2 tree shaking and check that we end up having a bundle that doesn't contain the code for substract, mul, and div

03 Reduce TypeScript build time

In this demo we are going to play with the build time speed with Webpack and TypeScript. For that, we are going to configure awesome-typescript-loader options.

We will start from sample 04 Performance/02 Tree shaking TypeScript.

Summary steps:

  • Take some base measures.
  • Apply useCache flag.
  • Apply CheckerPlugin.

04 DLL plugin

In this demo we are going to play with the build time speed installing autodll-webpack-plugin.

We will start from sample 04 Performance/03 Reduce TypeScript build time.

Summary steps:

  • Take some base measures.
  • Configure autodll-webpack-plugin.
  • See new measures.

05 Misc (other samples)

01 Commons Chunk Plugin

In this demo we will learn how to split our application in different bundles and how does Webpack manage to do so with the CommonsChunkPlugin. We will also learn some tips and tricks.

We will start from sample 02 Fx/00 TypeScript.

Summary steps:

  • Comment out the CommonsChunkPlugin to analyze what happens.
  • Add it back and see the changes.
  • Add a new third party library and see how the inline vendor grows.
  • create a vendor file as an alternative to inline vendor in the config.
  • move all the vendors imports there.

02 DefinePlugin

In this demo, we will see how can we do a basic usage of environment variables to enable the production mode of Angular

We will start from sample 02 Fx/03 Angular 2.

Summary steps:

  • importing enableProdMode on index.ts.
  • adding an if clause that will enableProdMode based on the -p parameter.

03 DefinePlugin advanced

This demo shows how to have alternative API_URL for development and production

Starts from sample 03 Environments/04 Production Configuration.

Summary steps:

  • create a students service and a student list component
  • See it working with hardcoded data
  • Update the service to use the dev endpoint
  • Update the component to use async data.
  • Update the dev and prod config to have environment variables
  • Update the services to use the new environment variables.

04 Right pad library

Do you want to create a library? This example is for you.

We will start from scratch in here

Summary steps:

  • npm init, to initialize the repo
  • install dependencies
  • create webpack config for libraries
  • put some tsconfig for typescript
  • generate library to see it working
  • add d.ts generation features
  • try it with "npm link"

05 Right pad usage

Here we try our new shiny library

We start from sample 02 Fx/00 TypeScript.

Summary steps:

  • npm install
  • npm link right-pad
  • add right pad usage into students.ts
  • profit.

About Basefactor + Lemoncode

We are an innovating team of Javascript experts, passionate about turning your ideas into robust products.

Basefactor, consultancy by Lemoncode provides consultancy and coaching services.

Lemoncode provides training services.

For the LATAM/Spanish audience we are running an Online Front End Master degree, more info: http://lemoncode.net/master-frontend

More Repositories

1

react-typescript-samples

The goal of this project is to provide a set of simple samples, providing and step by step guide to start working with React and Typescript.
TypeScript
1,839
star
2

react-hooks-by-example

The goal of this project is to provide a set of react hooks step by step guided examples, coverting from starter scenarios to advanced topics.
JavaScript
362
star
3

redux-sagas-typescript-by-example

Set of step by step guided samples to help you get started with redux sagas + typescript
TypeScript
287
star
4

react-by-sample

Set of basic React + Typescript guided samples, cover basic principles of this technology.
TypeScript
205
star
5

react-promise-tracker

Simple promise tracker React Hook and Hoc. https://lemoncode.github.io/react-promise-tracker/
JavaScript
205
star
6

master-frontend-lemoncode

Master Front End Online Lemoncode Demos source code + step by step guides
TypeScript
148
star
7

fonk

Form schema validation library
TypeScript
140
star
8

redux-by-sample

The goal of this project is to provide a set of step by step guided samples, covering core concepts of React + Redux (basic concepts, middleware, ...)
TypeScript
131
star
9

vuejs-by-sample

The goal of this project is to provide a set of step by step samples, covering core concepts of Vue.js
TypeScript
71
star
10

react-testing-by-example

JavaScript
69
star
11

lcFormValidation

Javascript based form validation library, third party library / framework agnostic.
TypeScript
58
star
12

i18next-example-typescript

n this example we are going to start form a simple login application and add multilanguage support.
TypeScript
55
star
13

mongo-modeler

Mongo Modeler is a free, open source online web application that allows you to design and model MongoDB databases.
TypeScript
54
star
14

jest-testing-by-sample

Learn testing by sample using Jest, each of the samples contains a readme.md file that indicates the purpose of the sample plus an step by step guide to reproduce it.
TypeScript
48
star
15

parcel-by-sample

Learn parcel by sample, each of the samples contains a readme.md file that indicates the purpose of the sample plus an step by step guide to reproduce it.
HTML
45
star
16

jest-vs-code-debugging-example

JavaScript
41
star
17

from-react-to-redux-ts

Implementing a simple list application in a progressive way
TypeScript
40
star
18

d3js-typescript-examples

Chart Examples using d3js + Typescript
CSS
39
star
19

integrate-react-legacy-apps

Migration from Legacy projects to React guide samples
JavaScript
39
star
20

nextjs-typescript-by-sample

Set of guided samples about how to get started with nextjs + typescript
TypeScript
39
star
21

git-from-ui-to-terminal

HTML
37
star
22

webinar-es6

36
star
23

code-paster

TypeScript
36
star
24

bootcamp-devops-lemoncode

TypeScript
33
star
25

webinar-typescript

JavaScript
31
star
26

manfred-export-app

TypeScript
28
star
27

language-sessions

JavaScript
28
star
28

webpack-1.x-by-sample

Learn webpack 1.x by sample
JavaScript
27
star
29

LeanMood

TypeScript
27
star
30

english-quiz

TypeScript
26
star
31

webinar-github-actions

HTML
25
star
32

react-image-focal-point

Let the user set the picture focal point just by visually dragging and dropping on top of the selected image.
TypeScript
25
star
33

planning-poker-example

TypeScript
23
star
34

movies-pods

Sample app, using redux / pods / react / typescript
TypeScript
20
star
35

react-by-sample-es6

Es6 version of original typescript react by sample repo
JavaScript
19
star
36

node-training

JavaScript
19
star
37

Angular-Architecture-Fundamentals

This repository will cover Angular techniques to manage state and use the best practices provided by Angular team
TypeScript
17
star
38

fonk-formik

This package serves as the entry point to the Formik Form state management library. It is intended to be paired with the generic Fonk package, which is shipped as to npm.
TypeScript
17
star
39

angular-5-sample-app

Complete Angular 5 app that will help you to start with the ain topics of the framework
17
star
40

angular2-sample-app

[Work in progress] Simple LOB app includes login, list, form edit
TypeScript
17
star
41

d3js-samples

Somes simple d3js samples
16
star
42

gatsby-by-sample

Base project to use Gatsby, Contentful and Netlify
TypeScript
15
star
43

k8s-fundamentals

Kubernetes course from cero knowledge to proactive Kubernetes user as developer
TypeScript
15
star
44

bootcamp-backend

TypeScript
15
star
45

async-javascript-fundamentals

Getting started with the concurrency model on JavaScript
JavaScript
14
star
46

scaffolding-express-typescript

Babel + Typescript + Express
CSS
14
star
47

react-alicante-hooks-workshop

React Alicante Workshop Demo Material https://reactalicante.es/
HTML
14
star
48

lemon-front-estructura

13
star
49

redux-testing-typescript

Guide to add unit test support to your redux project (typescript based).
TypeScript
13
star
50

react-from-classes-to-hooks-typescript

Sample simple applications migrations from class based components to hooks
TypeScript
13
star
51

simplechart

Simplechart seed
TypeScript
12
star
52

simple-hotels-mock-rest-api

A very simple local test rest-api, ideal to make quick front end examples, or to share with students.
12
star
53

angular1_5-sample-app

[Work in progress] Simple LOB app includes login, list, form edit β€”
TypeScript
12
star
54

webinar-kubernetes

HTML
12
star
55

promises-ts-samples

TypeScript
11
star
56

redux-chat-front

JavaScript
11
star
57

react-training-es6

JavaScript
11
star
58

lc-validation-summary

Angular directive for providing a validation summary to angular based forms.
JavaScript
11
star
59

layout-samples

CSS
11
star
60

react-lab-sessions

TypeScript
11
star
61

fonk-final-form

This package serves as the entry point to the React Final Form library. It is intended to be paired with the generic Fonk package, which is shipped as to npm.
TypeScript
11
star
62

CSS_Samples

CSS
10
star
63

webinar-vuejs-typescript

The goal of this project is to provide a set of step by step samples, covering core concepts of Vue.js with TypeScript
Vue
10
star
64

react-form-validation

React hook implementation to easify using lc-form-validation
TypeScript
10
star
65

bar.io

TypeScript
10
star
66

XFormsPushNotifications

Source code for the tutorial: Adding Push Notifications to your Xamarin Forms app Parts 1 and 2
C#
10
star
67

redux-2023

TypeScript
9
star
68

beer-geek-menu

TypeScript
8
star
69

language-exercises

Master Front-End Lemoncode | Exercises for module Languages
TypeScript
8
star
70

react-training-ts

TypeScript
8
star
71

angular-6-sample-app

Application focused on Angular 6
8
star
72

treeshaking-samples

Some sample about how to proper add tree shaking when using popular libraries like material-ui
JavaScript
8
star
73

gulp4-by-sample

[work in progress] Step by step guided samples gulp 4
JavaScript
8
star
74

redux-chat-back

JavaScript
8
star
75

vuejs-typescript-lob-examples

Vuejs + Typescript Line of business applications guided examples
Vue
7
star
76

angular-architecture-essentials

Repository to show the main architecture areas, components, DI and routing
TypeScript
7
star
77

react-promise-tracker-workshop

TypeScript
7
star
78

componentization-examples

Simple ui componentization example plus excercise
TypeScript
7
star
79

grunt-by-sample

Just some simple step by step guided samples to help you on getting started with grunt
JavaScript
7
star
80

demosBootstrap3

Basic training material Bootstrap 3 (building a layout)
HTML
7
star
81

graphql-by-sample

A repository to teach GraphQL technology
TypeScript
6
star
82

css4-training

Basics for css4 grid and flexbox training
CSS
6
star
83

react-simple-testing

TypeScript
6
star
84

git-training-2023

HTML
6
star
85

origin-front-admin

TypeScript
5
star
86

redux-by-sample-es6

Port from redux by sample (typescript) to Ecmascript 6
JavaScript
5
star
87

ngrx-by-sample

Angular ngrx example application, step by step
TypeScript
5
star
88

vuejs-excercise

Simple vuejs excercise to get your hands wet on code
Vue
5
star
89

lc-validator-dni

DNI validator for
TypeScript
5
star
90

fonk-iban-validator

IBAN validator for https://github.com/Lemoncode/fonk
TypeScript
5
star
91

typescript-sandbox

CSS
5
star
92

Angular_Testing

A project to deal with unit testing in Angular 5
TypeScript
5
star
93

sesion-componentes-accesibles

TypeScript
4
star
94

d3js-from-scratch

JavaScript
4
star
95

redux-excercise

Simple redux excercise to get your hands wet on code
TypeScript
4
star
96

use-route-matching

JavaScript
4
star
97

redux-workshop

TypeScript
4
star
98

angular-1-6-tutorial

TypeScript
4
star
99

web-security-fundamentals

Web security fundamentals
JavaScript
4
star
100

typingsBySample

JavaScript
4
star