Coder Social home page Coder Social logo

webpack-4-configuration's Introduction

Webpack 4 Configuration

A Webpack 4 starter configuration ready for production

Structure:

structure

The Webpack 4 configuration provides:

  • Dev Server with configuration options in development:
    • see the webpack.dev.js file
    • open the browser after server had been started
    • configurable delay (1200ms) before rebuilding once the first file changed
    • watch for changes in any of the webpack resolved files
    • watch ignored directory with regex ex: node_modules
    • full-screen overlay with errors or warnings
  • SCSS source maps in development
  • Linter in development:
    • ESLint
    • JavaScript Style Guide
    • settings:
      • check syntax
      • find problems
      • enforce code style
    • see the .eslintrc.js config file
    • more about the configuration
    • ignoring files:
      • see the .eslintignore file

  • contentHash in bundle files names for cache busting in production
  • export images in production
  • export SCSS into own CSS file in production
  • minified CSS in production
  • Babel.js ES6 to ES5 transpillation with configuration options in production:
    • see the provided .babelrc file
  • minified JS in production
  • minified HTML in production
  • CSS autoprefixer in production
    • Note: CSS3 Grid Layout polyfill (IE 10-11) is available
  • netlify deployment helpers for production:
    • ./netlify/_redirects file:
    • netlify NPM build script "build:netlify" to copy/past the _redirects file at build time to the ./dist directory

  • export favicon.png both in development and production
  • export SEO files both in development and production:

Usage:

Clone or download this repository

$ git clone https://github.com/Drozerah/webpack-4-configuration.git

Then

$ cd webpack-4-configuration

Then

$ npm install

Development mode

structure

$ npm start
  • Will run the webpack-dev-server then opening the application into the browser

package.json scripts:

...
{

    "scripts": {

        "start": "webpack-dev-server --config webpack.dev.js --open",

    }

}
...

Production mode

$ npm run build
  • Will create a ./dist directory with all your assets images, index.html, main.css and main.js bundles
    • Note: the clean-webpack-plugin will clean the ./dist directory before each execution of the build command

package.json scripts:

...
{
    "scripts": {

        "build": "webpack --config webpack.prod.js"

    }
}
...

Tip

To open the built app into the browser:

$ cd dist && start index.html

More about the start command line

Working with a 3rd party library

If you need to import a 3rd party library it's easy. What you have to do is to add a vendor.js file (whatever the name) into the ./src folder:

$ touch src/vendor.js

Then you have to declare this file into the webpack.common.js file as an additional entry point like so:

webpack.common.js

module.exports = {
  entry: {
    main: './src/index.js',
+   vendor: './src/vendor.js' // 3rd party library import
  },
  //...
}

Now you can import your library:

vendor.js

/**
* Import your 3rd party library thereafter like so:
* import "materialize-css" or import "bootstrap"...
*/
import "myLibrary"

Make sure your library is npm installed before you try to import it!

Run your application and Webpack will now output 2 bundles.

More about Webpack Entry Points


Deployment

Netlify Status

This application is deployed using netlify, check it out bellow !

https://webpack-4-configuration.netlify.com/

Built with:

  • Node.js
  • NPM
  • JavaScript ES6
  • Webpack 4
  • ESLint
  • HTML5
  • CSS3
    • Grid Layout
  • SCSS
  • VScode

Author:

  • Thomas G. aka Drozerah - Github

Acknowledgments:

License:

ISC

webpack-4-configuration's People

Contributors

drozerah avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.