Giter Club home page Giter Club logo

webpack_experiments's Introduction

react_experiments

Practice React.js and Webpack following the tutorial http://survivejs.com/webpack/.


Webpack

Basics

  • Multiple ways:
    • Maintain configuration in multiple files and point Webpack to each through --config parameter.
    • Push configuration to a library which you then consume.
    • Maintain configuration within a single file and branch there.

build scripts

  • Multiple ways:
    • Run node_modules/.bin/webpack directly
    • Run npm run build by configuring npm scripts
    • Run serve and view localhost:3000
  • As developing your application through a build script will get boring eventually.

webpack-dev-server

  • better alernative to build scripts.
  • a development server running in-memory
  • refreshes content automatically in the browser while you develop your application
  • Hot Module Replacement (HMR) that provides a way to patch the browser state without a full refresh.
  • Basic usage:
    1. Configure npm scripts: "start": "webpack-dev-server --content-base build"
    2. Run npm run start
    3. localhost:8080 or http://localhost:8080/webpack-dev-server/
  • simple means to refresh the browser automatically as we make changes.
  • In order to make this work, we'll need to connect the generated bundle running in-memory to the development server.
ifconfig | grep inet
  • Load stylesheet through css-loader and style-loader that allow us to change CSS without forcing a full refresh.
  • npm i css-loader style-loader --save-dev and configure.
  • improve the debuggability of the application.
  • allow you to see exactly where an error was raised.
  • In Webpack this is controlled through the devtool setting
  • https://www.npmjs.com/package/npm-install-webpack-plugin
  • As we develop the project, it will detect changes made to Webpack configuration and the projects files and install the dependencies for us. It will modify package.json automatically as well.
  • You can still install dependencies manually if you want.
    • Any dependencies within app should be installed through --save (or -S).
    • Root level dependencies (i.e. packages needed by Webpack), should be installed through --save-dev (or -D).
  • Install npm i npm-install-webpack-plugin --save-dev and configure.

.
├── README.md
├── app
│   ├── component.js
│   └── index.js
├── build
│   └── index.html
├── node_modules
│   ├── babel-core
│   ├── babel-loader
│   └── webpack
├── package.json
└── webpack.config.js

babel

  • transform your futuristic code to a format browsers understand
  • built-in JSX support
  • support for certain experimental features from ES7 beyond standard ES6
  • babel online

babel-loader

  • allows us to use Babel with Webpack easily
  • takes our ES6 module definition based code and turn it into ES5 bundles

babel-core

  • contains the core logic of Babel
  • NOTE: we need to install this to be able to use babel-loader.
npm i babel-loader babel-core --save-dev

loader declaration

  • To make a loader to work, we need to add a loader declaration to the loaders section of the configuration.
  • The regex /\.jsx?$/ matches against both .js and .jsx.

Tell the loader which directories to include

  • Use include
  • E.g., restrict the loader to operate within ./app directory
  • Otherwise it would traverse node_modules

Misc

  • path.join just joins strings.
  • path.resolve is equivalent to navigating the file system through cd.

Resources

webpack_experiments's People

Contributors

mnishiguchi 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.