Skip to content

Instantly share code, notes, and snippets.

@marcusshepp
Last active September 12, 2016 15:01
Show Gist options
  • Save marcusshepp/7d90a5d076a8eae967de6970cd946d55 to your computer and use it in GitHub Desktop.
Save marcusshepp/7d90a5d076a8eae967de6970cd946d55 to your computer and use it in GitHub Desktop.
webpack notes

Webpack

install

npm install webpack -g

npm install --save-dev webpack

set up babel transpiler and ecma 2015

npm install babel-preset-react

npm install babel-preset-es2015

sample package.json

{
  "name": "todo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Marcus Shepherd",
  "license": "ISC",
  "dependencies": {
    "react": "^15.3.1",
    "react-dom": "^15.3.1"
  },
  "devDependencies": {
    "babel-core": "^6.14.0",
    "babel-loader": "^6.2.5",
    "babel-preset-es2015": "^6.14.0",
    "babel-preset-react": "^6.11.1",
    "webpack": "^1.13.2"
  }
}

in webpack.config.js

...
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: "babel",
                query: {
                    presets: ["es2015", "react"]
                }
            }
        ]
    }
...

https://www.youtube.com/watch?v=MzVFrIAwwS8

The bundler of all things.

CLI

  • modules hidden by default
    • --display-modules
    • --display-reasons (where all the modules are used/defined)
    • --display-chunks
  • any options you can define in config can be called on CLI
  • --watch to recompile assets when surce files change/saved
  • -p
  • --profile --json >> stats.json (analyzation stuffz)

keeping above the fold content loading in under two seconds

  • require/require.ensure

Build Targets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment