Skip to content

Commit ba8656c

Browse files
author
Steven Slack
authored
Merge pull request #33 from alleyinteractive/hotfix/NYP-13213/optimize
Adds an ES Module build to allow for reducing footprint and unused code
2 parents 07b1786 + 1787744 commit ba8656c

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

.babelrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

.babelrc.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"env": {
3+
"es": {
4+
"plugins": ["@babel/plugin-transform-runtime"],
5+
"presets": [
6+
[
7+
"@babel/preset-env",
8+
{
9+
"modules": false
10+
}
11+
]
12+
]
13+
},
14+
"cjs": {
15+
"plugins": ["@babel/plugin-transform-runtime"],
16+
"presets": [
17+
[
18+
"@babel/preset-env"
19+
]
20+
]
21+
}
22+
}
23+
}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/lib/
2-
/core/
2+
/es/
33
/node_modules/
44
*.sublime-*

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ npm install js-component-framework
2525
Below is a basic set up for using the component framework without the included Aria plugins:
2626

2727
```javascript
28-
// Import only the core component framework library.
29-
import { Component } from 'js-component-framework/core';
28+
// Import the ES modules to be consumed by a bundler such as webpack append the '/es' to the end of the import statement.
29+
import { Component } from 'js-component-framework/es';
3030

3131
/**
3232
* Custom component which extends the base component class.
@@ -42,12 +42,11 @@ class MyComponent extends Component {
4242
}
4343
```
4444

45-
If you also want to use the entire framework with the bundled Aria plugins use the default import:
45+
If you also want to use the entire framework using the CommonJS bundled scripts with Aria plugins use the default import:
4646
```js
4747
import { Component, plugins } from 'js-component-framework';
4848
```
4949

50-
5150
## Best practices for creating components
5251

5352
### Create one directory per component
@@ -74,6 +73,11 @@ To create a component, do the following at the top of the file:
7473
import { Component } from 'js-component-framework';
7574
```
7675

76+
If you are compiling your code with a bundler like webpack, only import what you need for a smaller footprint:
77+
```js
78+
import { Component } from 'js-component-framework/es';
79+
```
80+
7781
When writing a component class, are some rules you need to follow and some guidelines:
7882

7983
* You _must_ provide a constructor. At minimum, the constructor should look like the following:
@@ -96,7 +100,7 @@ Generally speaking, you'll want to instantiate your component in the footer or o
96100

97101
```js
98102

99-
import { ComponentManager } from `js-component-framework`;
103+
import { ComponentManager } from `js-component-framework/es`;
100104
import headerConfig from `./Components/Header`;
101105

102106
// Instantiate manager

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
"version": "2.0.2",
44
"description": "This framework is a method of attaching an ES6 class to a DOM element or collection of DOM elements.",
55
"main": "lib/index.js",
6+
"module": "es/index.js",
67
"scripts": {
7-
"build-core": "npx babel src/core --out-dir core",
8-
"build-main": "npx babel src --out-dir lib",
8+
"build:commonjs": "NODE_ENV=cjs npx babel src --out-dir lib",
9+
"build:esm": "NODE_ENV=es npx babel src --out-dir es",
910
"lint": "npx eslint src/**",
1011
"lint:fix": "npx eslint src/** --fix",
11-
"prepare": "npm run build-core && npm run build-main",
12+
"prepare": "npm run build:esm && npm run build:commonjs",
1213
"test": "echo \"Error: no test specified\" && exit 1"
1314
},
1415
"author": "Alley Interactive (alley.co)",
@@ -29,7 +30,7 @@
2930
"url": "https://github.com/alleyinteractive/js-component-framework/issues"
3031
},
3132
"files": [
32-
"core",
33+
"es",
3334
"lib"
3435
],
3536
"homepage": "https://github.com/alleyinteractive/js-component-framework#readme",

0 commit comments

Comments
 (0)