Skip to content

Commit

Permalink
chore: build esm for es6
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharf5 committed May 8, 2020
1 parent ddce56a commit 123a656
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,27 @@ yarn add runtime-memcache

## Usage

```javascript
const createStore = require('runtime-memcache').default;
### Node Environment (ES6 import/export)

// or using es6 imports
```javascript
import createStore from 'runtime-memcache';
```

### Node Environment (CJS)

```javascript
const createStore = require('runtime-memcache');
```

### Browser (use a script tag)

```html
<script src="https://unpkg.com/[email protected]/dist/umd/index.js"></script>
<script>
console.log(RMC());
</script>
```

## API

Calling the `createStore` function returns an object with the following properties.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "runtime-memcache",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.2",
"description": "A no dependency javascript runtime key-value cache store for small chunks of arbitrary data (strings, objects, numbers)",
"homepage": "https://github.com/tusharf5/runtime-memcache",
"main": "./dist/umd/index.js",
Expand All @@ -24,7 +24,7 @@
"lint": "eslint 'src/**/*.{ts}' 'tests/**/*.{ts}'",
"format": "npx prettier --write '**/*.{ts,js,json}'",
"build": "webpack --mode=production",
"prebuild": "rm -rf dist && tsc -p . && rm -rf dist/tests && rm -rf dist/src",
"prebuild": "rm -rf dist && tsc -p . && tsc -p tsconfig.cjs.json && rm -rf dist/tests && rm -rf dist/src",
"prepublish": "npm run build && npm run test"
},
"license": "MIT",
Expand Down
7 changes: 7 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist/cjs/",
"module": "commonjs"
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"outDir": "./dist/esm/",
"sourceMap": true,
"module": "commonjs",
"module": "es6",
"moduleResolution": "node",
"noEmitOnError": true,
"target": "es6",
Expand Down
34 changes: 17 additions & 17 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const path = require('path');

module.exports = (env, argv) => {
return {
entry: {
index: path.resolve(__dirname, './dist/esm/index.js'),
},
output: {
path: path.resolve(__dirname, './dist/umd'), // builds to ./dist/umd/
filename: '[name].js', // index.js
library: 'myLibrary', // aka window.myLibrary
libraryTarget: 'umd', // supports commonjs, amd and web browsers
globalObject: 'this',
libraryExport: 'default',
},
module: {
rules: [{ test: /\.t|js$/, use: 'babel-loader' }],
},
};
const umd = {
entry: {
index: path.resolve(__dirname, './dist/cjs/index.js'),
},
output: {
path: path.resolve(__dirname, './dist/umd'), // builds to ./dist/umd/
filename: '[name].js', // index.js
library: 'RMC', // aka window.RMC
libraryTarget: 'umd', // supports commonjs, amd and web browsers
globalObject: 'this',
libraryExport: 'default',
},
module: {
rules: [{ test: /\.t|js$/, use: 'babel-loader' }],
},
};

module.exports = [umd];

0 comments on commit 123a656

Please sign in to comment.