# Getting Started ## Quick Start (CDN) To try Material Components for the web with minimal setup, load the precompiled all-in-one CSS and JS bundles from unpkg: ```html
``` We also recommend using [Material Icons](https://material.io/tools/icons/) from Google Fonts. (Some of our examples implicitly use Material Icons.) ```html ``` Then include MDC markup... ```html ``` ...and instantiate JavaScript: ```js mdc.ripple.MDCRipple.attachTo(document.querySelector('.foo-button')); ``` ## Installing Locally Material Components for the web can be installed locally using npm. It is available as a single all-in-one package: ``` npm i material-components-web ``` ...or as individual components: ``` npm i @material/button @material/ripple ``` Each package provides precompiled CSS and JS under its `dist` folder. The precompiled JS is converted to UMD format and is consumable directly by browsers or within any workflow that expects to consume ES5. Referencing `@material/foo` within a Node.js context will automatically reference the precompiled JS under `dist`. However, for optimal results, we recommend consuming MDC Web's ES2015 modules and Sass directly. This is outlined in the steps below. ## Using MDC Web with Sass and ES2015 This section walks through how to [install MDC Web Node modules](https://www.npmjs.com/org/material), and bundle the Sass and JavaScript from those Node modules in your [webpack](https://webpack.js.org/) configuration. You can also see the final code and result in the [Material Starter Kit](https://glitch.com/~material-starter-kit). > Note: This guide assumes you have Node.js and npm installed locally. ### Step 1: Webpack with Sass We’re going to use `webpack-dev-server` to demonstrate how webpack bundles our Sass and JavaScript. First, run `npm init` to create a `package.json` file. When complete, add the `start` property to the `scripts` section. ```json { "scripts": { "start": "webpack-dev-server" } } ``` You’ll need all of these Node dependencies: - [webpack](https://www.npmjs.com/package/webpack): Bundles Sass and JavaScript - [webpack-dev-server](https://www.npmjs.com/package/webpack-dev-server): Development server - [sass-loader](https://www.npmjs.com/package/sass-loader): Loads a Sass file and compiles it to CSS - [node-sass](https://www.npmjs.com/package/node-sass): Provides binding for Node.js to Sass, peer dependency to sass-loader - [css-loader](https://www.npmjs.com/package/css-loader): Resolves CSS @import and url() paths - [extract-loader](https://github.com/peerigon/extract-loader): Extracts the CSS into a `.css` file - [file-loader](https://github.com/webpack-contrib/file-loader): Serves the `.css` file as a public URL You can install all of them by running this command: ``` npm install --save-dev webpack webpack-cli webpack-dev-server css-loader sass-loader node-sass extract-loader file-loader ``` In order to demonstrate how webpack bundles our Sass, you’ll need an `index.html`. This HTML file needs to include CSS. The CSS is generated by sass-loader, which compiles Sass files into CSS. The CSS is extracted into a `.css` file by extract-loader. Create this simple “hello world” `index.html`: ```html Hello World ``` And create a simple Sass file called `app.scss`: ```scss body { color: blue; } ``` Then configure webpack to convert `app.scss` into `bundle.css`. For that you need a new `webpack.config.js` file: ```js module.exports = [{ entry: './app.scss', output: { // This is necessary for webpack to compile // But we never use style-bundle.js filename: 'style-bundle.js', }, module: { rules: [ { test: /\.scss$/, use: [ { loader: 'file-loader', options: { name: 'bundle.css', }, }, { loader: 'extract-loader' }, { loader: 'css-loader' }, { loader: 'sass-loader' }, ] } ] }, }]; ``` To test your webpack configuration, run: ``` npm start ``` And open http://localhost:8080 in a browser. You should see a blue “Hello World”.