Skip to content

Commit

Permalink
feat(rxFileUpload): bundle only in ESNEXT because applications will c…
Browse files Browse the repository at this point in the history
…ompile in good version for them
  • Loading branch information
akanass committed Jun 17, 2021
1 parent 8d703ac commit b250a0a
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 270 deletions.
68 changes: 0 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ However, we provide a [method](#supportsrxfileupload) that will allow you to **e
* [RxFileUploadProgressData](#rxfileuploadprogressdata)
* [RxFileUploadResponse\<T\>](#rxfileuploadresponset)
* [RxFileUploadError](#rxfileuploaderror)
* [Building for Production](#building-for-production)
* [ES5](#es5)
* [ESNEXT](#esnext)
* [Webpack support](#webpack-support)
* [Rollup support](#rollup-support)
* [License](#license)

## Installation
Expand Down Expand Up @@ -409,69 +404,6 @@ Represents the error response, from the server, streamed by the `Observable`, du
[back to top](#table-of-contents)

## Building for Production

Two unbundled versions of this library are offered for your convenience, one targeting `ES5` and a second targeting `ESNEXT`.

### *ES5:*

The `ES5` version is suitable for use when **deprecated browsers** like `IE10+` or `Edge Legacy` need to be supported. This version is also the **default** version that gets pulled in as the `"main"` entry in **package.json**.

**TypeScript** and **JavaScript** codebases alike can import and use this library without any special build configuration considerations.

However, you will need to ensure that the `tslib@^2.2.0` dependency gets pulled into your build artifact then you will need to install this package **manually** by adding it to `devDependencies` in your project's **package.json**:

```sh
$> npm install --save-dev tslib

or

$> yarn add -D tslib
```

### *ESNEXT:*

The `ESNEXT` version is suitable for use when only **modern browsers** need to be supported. **TypeScript** and **JavaScript** codebases alike can import and use this library. However, you will need to ensure that your bundler pulls in the `ESNEXT` version of the library when building your application!

See bundler instructions below.

#### Webpack support

No matter the `"target"` of your build you'll need to indicate additional files for webpack to resolve via the [`"resolve.mainFields"`](https://webpack.js.org/configuration/resolve/#resolvemainfields) property in your config. Resolve the `"main:esnext"` field defined in **package.json**:

```js
module.exports = {
//...
resolve: {
mainFields: [ 'main:esnext', 'module', 'main' ],
},
};
```

`'main:esnext'` must come first in the list to ensure that the `ESNEXT` version of this library is bundled. Additional values can be added afterwards as needed.

#### Rollup support

Add the [`@rollup/plugin-node-resolve`](https://github.com/rollup/rollup-plugin-node-resolve#usage) plugin to your Rollup config to read in the `"main:esnext"` field from **package.json**:

```js
// rollup.config.js
import resolve from 'rollup-plugin-node-resolve';

export default {
// input: ...
// output: ...
plugins: [
//...
resolve({ mainFields: [ 'main:esnext', 'module', 'main' ] }),
]
}
```

`'main:esnext'` must come first in the list to ensure that the `ESNEXT` version of this library is bundled. Additional values can be added afterwards as needed.

[back to top](#table-of-contents)

## License

This library is [MIT licensed](LICENSE.md).
Expand Down
25 changes: 11 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "@akanass/rx-file-upload",
"version": "1.2.0",
"version": "2.0.0",
"description": "Library to upload a file in the browser and send it fully or in several chunks to the server.",
"main": "esm5/rx-file-upload.js",
"main:esnext": "esm/rx-file-upload.js",
"main": "bundle/rx-file-upload.js",
"unpkg": "bundle/rx-file-upload.umd.min.js",
"types": "types/index.d.ts",
"repository": {
Expand All @@ -18,7 +17,7 @@
"private": false,
"scripts": {
"test": "echo 'To have a real implementation and test of this library, go to https://github.com/akanass/upload-file-with-chunks'",
"build": "rollup -c"
"build": "rollup -c rollup.config.js"
},
"bugs": "https://github.com/akanass/rx-file-upload/issues",
"homepage": "https://github.com/akanass/rx-file-upload#readme",
Expand Down Expand Up @@ -52,25 +51,23 @@
"devDependencies": {
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/node": "^15.6.1",
"@types/node": "^15.12.2",
"@types/fs-extra": "^9.0.11",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"eslint": "^7.27.0",
"@typescript-eslint/eslint-plugin": "^4.27.0",
"@typescript-eslint/parser": "^4.27.0",
"eslint": "^7.28.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"fs-extra": "^10.0.0",
"prettier": "^2.3.0",
"rollup": "^2.50.2",
"prettier": "^2.3.1",
"rollup": "^2.52.1",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-terser": "^7.0.2",
"rxjs": "^7.1.0",
"ts-node": "^10.0.0",
"tslib": "^2.2.0",
"typescript": "^4.3.2"
"typescript": "^4.3.3"
},
"peerDependencies": {
"rxjs": "^7.1.0",
"tslib": "^2.2.0"
"rxjs": "^7.1.0"
}
}
24 changes: 1 addition & 23 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const config: RollupOptions[] = [
output: {
dir: './dist',
format: 'esm',
entryFileNames: 'esm/rx-file-upload.js',
entryFileNames: 'bundle/rx-file-upload.js',
preferConst: true,
},
plugins: [
Expand All @@ -37,28 +37,6 @@ const config: RollupOptions[] = [
'crypto-es/lib/core',
],
},
{
input: './src/index.ts',
output: {
dir: './dist',
format: 'esm',
entryFileNames: 'esm5/rx-file-upload.js',
},
plugins: [
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
typescript({ tsconfig: './tsconfig.es5.json' }),
nodeResolve(),
],
external: [
'tslib',
'rxjs',
'rxjs/ajax',
'rxjs/operators',
'crypto-es/lib/sha256',
'crypto-es/lib/core',
],
},
{
input: './src/index.ts',
output: {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"./node_modules/@types"
],
"lib": [
"es2018",
"esnext",
"dom"
]
},
Expand Down
Loading

0 comments on commit b250a0a

Please sign in to comment.