A presentation by Alper Ortac

Yes, their logo is awesome.

var template = '' +
'Find. Anything.
' +
'';
document.getElementById("app").innerHTML = template;
<html>
<head>
<title>Find. Anything. - A Webpack Experiment</title>
</head>
<body>
<div id="app"></div>
<script type="text/javascript" src="dist/bundle.js"></script>
</body>
</html>
Where does bundle.js come from?
module.exports = {
entry: {
app: "source/script/app.js"
},
output: {
path: "dist",
filename: "bundle.js"
}
}
webpack [--color] [--watch]

search.js
var template = "...";
module.exports = {
template: template
};
app.js
var search = require("search.js");
// do something with search.template

$ _
npm install babel-loader
webpack.config.js
module: {
loaders: [
{ test: /\.js$/, loader: 'babel' }
]
}
//var search = require("search.js");
import search from "search.js";

json: Loads file as JSONhson: Loads HanSON file (JSON for Humans) as JSON objectraw: Loads raw content of a file (as utf-8)val: Executes code as module and consider exports as JavaScript codeto-string: Executes code as a module, casts output to a string and exports itimports: Imports stuff to the moduleexports: Exports stuff from the moduleexpose: Expose exports from a module to the global contextscript: Executes a JavaScript file once in global context (like in script tag), requires are not parsed.source-map: Extract sourceMappingURL comments from modules and offer it to webpackchecksum: Computes the checksum of a filenull: Emits an empty module.cowsay: Emits a module with a cowsay header.dsv: Loads csv/tsv files.glsl: Loads glsl files and support glsl-chunks.render-placement: Adds React.render to your component for you (not very practical in most cases)xml: Loads XML as JSON.svg-react: Load SVG files as JSX-ified React.createClass declarations.base64: Loads file content as base64 stringfile: Emits the file into the output folder and returns the (relative) url.url: The url loader works like the file loader, but can return a Data Url if the file is smaller than a limit.worker: The worker loader creates a WebWorker for the provided file. The bundling of dependencies of the Worker is transparent.shared-worker: Like the worker loader, but for Shared Workers.serviceworker: Like the worker loader, but designed for Service Workers.bundle: Wraps request in a require.ensure block (callback)promise: Wraps request in a require.ensure block (promise)react-proxy: Code Splitting for react components.react-hot: Allows to live-edit React components while keeping them mounted and preserving their state.image: Compresses your images. Ideal to use together with file or url.img: Load and compress images with imagemin.svgo-loader: Compresses SVG images using svgo librarybaggage: Automatically require any resources related to the required onepolymer-loader: Process HTML & CSS with preprocessor of choice and require() Web Components like first-class modules.uglify-loader: Uglify contents of a module. Unlike uglify plugin you can minify with mangling only your application files and not the librarieshtml-minify-loader: Minifies HTML using minimizevue-loader: Load single-file Vue.js components as modules, with loader-support for preprocessors.tojson-loader Serialize module exports as JSON. Cache generated static data as JSON at build time.zip-it-loader Convert files and directories to zip. Great with file.coffee: Loads coffee-script like JavaScriptcoffee-jsx: Loads coffee-script with JSX like JavaScriptcoffee-redux: Loads coffee-script like JavaScriptjson5: Like json, but not so strict.es6: Loads ES6 modules. (old)esnext: Transpile ES6 code using esnext.babel: Turn ES6 code into vanilla ES5 using Babel.regenerator: Use ES6 generators via Facebook’s Regenerator module.livescript: Loads LiveScript like JavaScriptsweetjs: Use sweetjs macros. traceur: Use future JavaScript features with Traceur.ts: Loads TypeScript like JavaScript.typescript: Loads TypeScript like JavaScript.typescript-simple-loader: Loads TypeScript with syntactic and semantic errors.awesome-typescript-loader: Loads TypeScript like JavaScript with watching support. Works with TypeScript 1.5-alfapurs-loader: Loads PureScript like JavaScript.oj: Loads OJ (an Objective-C like language) files and compiles them to plain JavaScript.ulmus: Loads Elm files and compiles them to plain JavaScript.miel: Loads Miel syntax and compiles to JavaScript.html: Exports HTML as string, require references to static resources.riot: Load RiotJS tags and convert them to javascript.jade: Loads jade template and returns a functionjade-html: Loads jade template and returns generated HTMLtemplate-html: Loads any template with consolidate.js and returns generated HTMLhandlebars: Loads handlebars template and returns a functiondust: Loads dust template and returns a functionractive: Pre-compiles Ractive templates for interactive DOM manipulationjsx: Transform jsx code for React to js code.react-templates: Loads react-template and returns a functionem: Compiles Emblem to Handlebars.jsejs: Loads EJS (underscore( templating engine) template and returns a pre-compiled functionmustache: Pre-compiles Mustache templates with Hogan.js and returns a functionyaml: Converts YAML to JSONmarkdown: Compiles Markdown to HTMLremarkable: Compiles Markdown to HTML using the Remarkable parsermarkdown-it: Compiles Markdown to HTML using the markdown-it parserng-cache: Puts HTML partials in the Angular’s $templateCachengtemplate: Bundles your AngularJS templates and Pre-loads the template cache.hamlc: Compiles haml-coffee templates (.hamlc) and returns a function.haml: Renders haml-coffee templates (.html.hamlc) and returns a string.jinja: Precompiles nunjucks and jinja2 templatessoy: Compiles Google Closure templates and returns the namespace with render functionssmarty: Pre-compiles php smarty templates and returns a functiontemplate-string: Use ES6 template strings for html templatesbootstrap-sass: Loads a configuration file for Twitter Bootstrap integration using Sass. Allows complete customization via Sass.style: Add exports of a module as style to DOMcss: Loads css file with resolved imports and returns css codeless: Loads and compiles a less filesass: Loads and compiles a scss filestylus: Loads and compiles a stylus filerework: Post-process CSS with Rework and returns CSS codepostcss: Post-process CSS with Autoprefixer and other PostCSS pluginsautoprefixer: Add vendor prefixes to CSS rules using values from Can I Usenamespace-css: Namespace your css with a given selector (for encapsulating all rules in one subset of your site)fontgen: Create your own webfont with proper CSS on-the-fly and include it into WebPack.po: Loads a PO gettext file and returns JSONformat-message: Compiles translations to ICU Message Format strings in formatMessage callsjsxlate-loader: Transform React source code for use with jsxlatewebpack-angular-translate: Extracts angular-translate translation id’s and default text’smocha: do tests with mocha in browser or node.jscoverjs: PostLoader to code coverage with CoverJsistanbul-instrumenter: Istanbul postLoader to code coverage with karma-webpack and karma-coverageisparta-instrumenter: Isparta preLoader to code coverage with karma-webpack and douglasduteil/karma-coverage#nextibrik-instrumenter: Ibrik preLoader to CoffeeScript code coverage with karma-webpack and douglasduteil/karma-coverageeslint: PreLoader for linting code using ESLint.jshint: PreLoader for linting code.jscs: PreLoader for style checking.standard: Conform to standard code style.injectable: Allow to inject dependencies into modulestransform: Use browserify transforms as loader.image-size: Loads an image and returns its dimensions and typecsslint: PreLoader for linting code using CSSLintcoffeelint-loader: PreLoader for linting CoffeeScript.tslint-loader: PreLoader for linting TypeScript using TSLintparker: Output a stylesheet analysis report using parker.sjsp: Inject some codes for profiling using node-sjsp.
npm install html-loader css-loader
npm install template-string-loader
npm install style-loader
webpack.config.js
module: {
loaders: [
{ test: /\.html/, loader: "babel!template-string" },
{ test: /\.css$/i, loader: "style!css?modules" }
]
}
!
(read the chain from right to left)
? indicates loader parameters
(modules is for unique class names)
index.html
<head>
<link rel="stylesheet" href="style/app.css" />
<link rel="stylesheet" href="style/search.css" />
</head>
search.css
.search {
width: 100%;
vertical-align: middle;
white-space: nowrap;
position: relative;
}
// ...
search.html
search.js
import template from 'template/search.html';
import styles from 'style/search.css';
module.exports = {
template: template({
styles: styles
})
};

webpack.config.js
module: {
loaders: [
{ test: /\.(png|jpe?g|gif)$/, loader: 'url-loader?limit=8192' }
]
}
app.js
import logo from 'image/logo.png';
What means limit=8192?
If file size is below, create an inline
Base64 string instead of copying the file
index.html
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
app.css
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,900);
Note: Webpack does not provide a way
to modularize externally hosted files
Ok, there is a trick, but it's not possible to use multiple domains.

$ _
npm install jquery
webpack.config.js
module: {
loaders: [
{ test: /\.js$/, loader: 'babel', exclude: 'node_modules') }
]
}
Exclude node_modules from Babel preprocessor
to avoid longer build time and potential problems
search.js
import $ from 'jquery';
$(document).ready(function() {
// do something
});
Easy.

It's a classic, but lacks many features.
Webpack overloads require, so if you want
reusable server-side code use browserify
Besides, it's difficult to setup (at least in my experience)
Strong because ES6 compliant, but requires
a partner tool for precompiling needs
Task runners are basically without restrictions,
but all parts need to be glued together manually


Thanks for your attention!