Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat: update default npm export to ES5 js files #3245

Merged
merged 23 commits into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
80eca3b
WIP: add main to package jsons
Jul 26, 2018
b55f5cc
fix: added main props to package.jsons for remaining components
Jul 26, 2018
6410afe
Update package.json
Jul 26, 2018
e43c556
Update package.json
Jul 26, 2018
21955dd
Merge branch 'master' into chore/infra/update-default-package-es5
Aug 22, 2018
cc1ee56
fix: unit test
Aug 22, 2018
39f9f31
fix: add main fields to packagejson
Aug 22, 2018
2e58cd5
Merge branch 'master' into chore/infra/update-default-package-es5
Aug 22, 2018
94fbfda
Merge branch 'master' into chore/infra/update-default-package-es5
Aug 28, 2018
3246ac5
Merge branch 'master' into chore/infra/update-default-package-es5
Aug 28, 2018
0570083
Merge branch 'master' into chore/infra/update-default-package-es5
Aug 29, 2018
48efeec
Merge remote-tracking branch 'origin/master' into chore/infra/update-…
Sep 26, 2018
20d06ae
WIP Update imports in new tests
Sep 26, 2018
62ced69
WIP Update scripts to verify main properties
Sep 26, 2018
399727b
WIP Fix broken package main properties
Sep 26, 2018
bd78014
WIP Add license to new script
Sep 26, 2018
853f2d5
WIP doc updates
Sep 27, 2018
ecacefc
WIP Add link to babel plugin
Sep 27, 2018
b1c6e83
WIP Update main README
Sep 28, 2018
5149579
Merge branch 'master' into chore/infra/update-default-package-es5
kfranqueiro Sep 28, 2018
44dde56
WIP Remove empty files introduced during an earlier merge
Sep 28, 2018
7fcf8f1
Merge branch 'master' into chore/infra/update-default-package-es5
Sep 28, 2018
3cbdb21
Merge branch 'master' into chore/infra/update-default-package-es5
Sep 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ npm install @material/ripple
Then import the ES2015 file for @material/ripple into your application, and initialize an MDCRipple with a DOM element:

```js
import {MDCRipple} from '@material/ripple';
import {MDCRipple} from '@material/ripple/index';
const ripple = new MDCRipple(document.querySelector('.foo-button'));
```

> Note: Import `@material/ripple/index` if you wish to transpile MDC Web's ES2015 sources as part of your build process.
> If your build toolchain is configured to only transpile your own sources, import `@material/ripple` instead, which will
> reference the distributed UMD module instead.

This will produce a Material Design ripple on the button!

<img src="docs/button_with_ripple.png" alt="Button with Ripple" width="90" height="36">
Expand Down
32 changes: 26 additions & 6 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ path: /docs/getting-started/

# Getting Started

## Quick Start
## Quick Start (CDN)

To try Material Components for the web with minimal setup, load the CSS and JS from unpkg:
To try Material Components for the web with minimal setup, load the precompiled all-in-one CSS and JS bundles from unpkg:

```html
https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css
Expand All @@ -28,11 +28,27 @@ Then include MDC markup...
mdc.ripple.MDCRipple.attachTo(document.querySelector('.foo-button'));
```

However, it is highly recommended to install Material Components for the web via npm and consume its ES2015 modules and Sass directly. This is outlined in the steps below.
## Installing Locally

## Using MDC Web with ES2015 and Sass
Material Components for the web can be installed locally using npm. It is available as a single all-in-one package:

This section walks you 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.
```
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.

> Note: This guide assumes you have Node.js and npm installed locally.

Expand Down Expand Up @@ -325,10 +341,14 @@ npm install --save-dev @material/ripple
We need to tell our `app.js` to import the ES2015 file for `@material/ripple`. We also need to initialize an `MDCRipple` with a DOM element. Replace your “hello world” version of `app.js` with this code:

```js
import {MDCRipple} from '@material/ripple';
import {MDCRipple} from '@material/ripple/index';
const ripple = new MDCRipple(document.querySelector('.foo-button'));
```

> Note: We explicitly reference `index` within each MDC Web package in order to import the ES2015 source directly.
> This allows for tree-shaking and avoiding duplicate code for common dependencies (e.g. Ripple).
> However, it requires transpiling the MDC Web modules using the tools installed in Step 3.

Now run `npm start` again and open http://localhost:8080. You should see a Material Design ripple on the button!

<img src="button_with_ripple.png" alt="Button with Ripple" width="90" height="36">
Expand Down
38 changes: 20 additions & 18 deletions docs/importing-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,37 @@ Most components ship with Component / Foundation classes which are used to provi

## ES2015

```javascript
```js
import {MDCFoo, MDCFooFoundation} from '@material/foo';
```

Note that MDC Web's packages point `main` to pre-compiled UMD modules under `dist` to maximize compatibility.
Build toolchains often assume that dependencies under `node_modules` are already ES5, and thus skip transpiling them.

However, if you want to take advantage of tree-shaking and dependency sharing within MDC Web's code to reduce the size
of your built assets, you will want to explicitly reference the package's `index.js`, which contains the ES2015+ source:

```js
import {MDCFoo, MDCFooFoundation} from '@material/foo/index';
```

Note that in this case, you must ensure your build toolchain is configured to process and transpile MDC Web's modules
as well as your own. You will also need to include babel's
[`transform-object-assign`](https://www.npmjs.com/package/babel-plugin-transform-object-assign) plugin for IE 11 support.

See the [Getting Started guide](getting-started.md) for more details on setting up an environment.

## CommonJS

```javascript
```js
const mdcFoo = require('mdc-foo');
const MDCFoo = mdcFoo.MDCFoo;
const MDCFooFoundation = mdcFoo.MDCFooFoundation;
```

## AMD

```javascript
```js
require(['path/to/mdc-foo'], mdcFoo => {
const MDCFoo = mdcFoo.MDCFoo;
const MDCFooFoundation = mdcFoo.MDCFooFoundation;
Expand All @@ -35,21 +51,7 @@ require(['path/to/mdc-foo'], mdcFoo => {

## Global

```javascript
```js
const MDCFoo = mdc.foo.MDCFoo;
const MDCFooFoundation = mdc.foo.MDCFooFoundation;
```

## Automatic Instantiation

```javascript
mdc.foo.MDCFoo.attachTo(document.querySelector('.mdc-foo'));
```

## Manual Instantiation

```javascript
import {MDCFoo} from '@material/foo';

const foo = new MDCFoo(document.querySelector('.mdc-foo'));
```
2 changes: 1 addition & 1 deletion packages/material-components-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"material components",
"material design"
],
"main": "index.js",
"main": "dist/material-components-web.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-animation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"material design",
"animation"
],
"main": "index.js",
"main": "dist/mdc.animation.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-auto-init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@material/auto-init",
"description": "Declarative, easy-to-use auto-initialization for Material Components for the web",
"version": "0.39.0",
"main": "index.js",
"main": "dist/mdc.autoInit.js",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "The set of base classes for Material Components for the web",
"version": "0.39.0",
"license": "MIT",
"main": "index.js",
"main": "dist/mdc.base.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-checkbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"material design",
"checkbox"
],
"main": "index.js",
"main": "dist/mdc.checkbox.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-chips/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "The Material Components for the Web chips component",
"version": "0.40.0",
"license": "MIT",
"main": "dist/mdc.chips.js",
"keywords": [
"material components",
"material design",
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-dialog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dialog",
"modal"
],
"main": "index.js",
"main": "dist/mdc.dialog.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "DOM manipulation utilities for Material Components for the web",
"version": "0.40.0",
"license": "MIT",
"main": "index.js",
"main": "dist/mdc.dom.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-drawer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"navigation",
"drawer"
],
"main": "index.js",
"main": "dist/mdc.drawer.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-floating-label/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"floatinglabel",
"floating label"
],
"main": "index.js",
"main": "dist/mdc.floatingLabel.js",
"repository": {
"type": "git",
"url": "git+https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-form-field/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"material design",
"form"
],
"main": "index.js",
"main": "dist/mdc.formField.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-grid-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.40.0",
"description": "The Material Components for the web grid list component",
"license": "MIT",
"main": "dist/mdc.gridList.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-icon-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "The Material Components for the web icon button component",
"version": "0.40.0",
"license": "MIT",
"main": "dist/mdc.iconButton.js",
"keywords": [
"material components",
"material design",
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-icon-toggle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"material design",
"icon toggle"
],
"main": "index.js",
"main": "dist/mdc.iconToggle.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-line-ripple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lineripple",
"line-ripple"
],
"main": "index.js",
"main": "dist/mdc.lineRipple.js",
"repository": {
"type": "git",
"url": "git+https://github.com/material-components/material-components-web.git"
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-linear-progress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "The Material Components for the web linear progress indicator component",
"version": "0.40.0",
"license": "MIT",
"main": "dist/mdc.linearProgress.js",
"keywords": [
"material components",
"material design",
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "The Material Components for the web list component",
"version": "0.40.0",
"license": "MIT",
"main": "dist/mdc.list.js",
"keywords": [
"material components",
"material design",
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-menu-surface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"material design",
"menu surface"
],
"main": "index.js",
"main": "dist/mdc.menuSurface.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-menu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"material design",
"menu"
],
"main": "index.js",
"main": "dist/mdc.menu.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-notched-outline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"notchedoutline",
"notched outline"
],
"main": "index.js",
"main": "dist/mdc.notchedOutline.js",
"repository": {
"type": "git",
"url": "git+https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-radio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"material design",
"radio"
],
"main": "index.js",
"main": "dist/mdc.radio.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-ripple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"material design",
"ripple"
],
"main": "index.js",
"main": "dist/mdc.ripple.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-select/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"select",
"multi select"
],
"main": "index.js",
"main": "dist/mdc.select.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-selection-control/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "The set of base classes for Material selection controls",
"version": "0.40.0",
"license": "MIT",
"main": "index.js",
"main": "dist/mdc.selectionControl.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-slider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@material/slider",
"version": "0.40.0",
"description": "The Material Components for the web slider component",
"main": "index.js",
"main": "dist/mdc.slider.js",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-snackbar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"material design",
"snackbar"
],
"main": "index.js",
"main": "dist/mdc.snackbar.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-switch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"material design",
"switch"
],
"main": "index.js",
"main": "dist/mdc.switch.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-tab-bar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"tab",
"bar"
],
"main": "index.js",
"main": "dist/mdc.tabBar.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-tab-indicator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"tab",
"indicator"
],
"main": "index.js",
"main": "dist/mdc.tabIndicator.js",
"repository": {
"type": "git",
"url": "https://github.com/material-components/material-components-web.git"
Expand Down
Loading