Skip to content

Commit b250a0a

Browse files
committed
feat(rxFileUpload): bundle only in ESNEXT because applications will compile in good version for them
1 parent 8d703ac commit b250a0a

File tree

5 files changed

+167
-270
lines changed

5 files changed

+167
-270
lines changed

README.md

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ However, we provide a [method](#supportsrxfileupload) that will allow you to **e
3030
* [RxFileUploadProgressData](#rxfileuploadprogressdata)
3131
* [RxFileUploadResponse\<T\>](#rxfileuploadresponset)
3232
* [RxFileUploadError](#rxfileuploaderror)
33-
* [Building for Production](#building-for-production)
34-
* [ES5](#es5)
35-
* [ESNEXT](#esnext)
36-
* [Webpack support](#webpack-support)
37-
* [Rollup support](#rollup-support)
3833
* [License](#license)
3934

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

412-
## Building for Production
413-
414-
Two unbundled versions of this library are offered for your convenience, one targeting `ES5` and a second targeting `ESNEXT`.
415-
416-
### *ES5:*
417-
418-
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**.
419-
420-
**TypeScript** and **JavaScript** codebases alike can import and use this library without any special build configuration considerations.
421-
422-
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**:
423-
424-
```sh
425-
$> npm install --save-dev tslib
426-
427-
or
428-
429-
$> yarn add -D tslib
430-
```
431-
432-
### *ESNEXT:*
433-
434-
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!
435-
436-
See bundler instructions below.
437-
438-
#### Webpack support
439-
440-
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**:
441-
442-
```js
443-
module.exports = {
444-
//...
445-
resolve: {
446-
mainFields: [ 'main:esnext', 'module', 'main' ],
447-
},
448-
};
449-
```
450-
451-
`'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.
452-
453-
#### Rollup support
454-
455-
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**:
456-
457-
```js
458-
// rollup.config.js
459-
import resolve from 'rollup-plugin-node-resolve';
460-
461-
export default {
462-
// input: ...
463-
// output: ...
464-
plugins: [
465-
//...
466-
resolve({ mainFields: [ 'main:esnext', 'module', 'main' ] }),
467-
]
468-
}
469-
```
470-
471-
`'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.
472-
473-
[back to top](#table-of-contents)
474-
475407
## License
476408

477409
This library is [MIT licensed](LICENSE.md).

package.json

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
22
"name": "@akanass/rx-file-upload",
3-
"version": "1.2.0",
3+
"version": "2.0.0",
44
"description": "Library to upload a file in the browser and send it fully or in several chunks to the server.",
5-
"main": "esm5/rx-file-upload.js",
6-
"main:esnext": "esm/rx-file-upload.js",
5+
"main": "bundle/rx-file-upload.js",
76
"unpkg": "bundle/rx-file-upload.umd.min.js",
87
"types": "types/index.d.ts",
98
"repository": {
@@ -18,7 +17,7 @@
1817
"private": false,
1918
"scripts": {
2019
"test": "echo 'To have a real implementation and test of this library, go to https://github.com/akanass/upload-file-with-chunks'",
21-
"build": "rollup -c"
20+
"build": "rollup -c rollup.config.js"
2221
},
2322
"bugs": "https://github.com/akanass/rx-file-upload/issues",
2423
"homepage": "https://github.com/akanass/rx-file-upload#readme",
@@ -52,25 +51,23 @@
5251
"devDependencies": {
5352
"@rollup/plugin-node-resolve": "^13.0.0",
5453
"@rollup/plugin-typescript": "^8.2.1",
55-
"@types/node": "^15.6.1",
54+
"@types/node": "^15.12.2",
5655
"@types/fs-extra": "^9.0.11",
57-
"@typescript-eslint/eslint-plugin": "^4.25.0",
58-
"@typescript-eslint/parser": "^4.25.0",
59-
"eslint": "^7.27.0",
56+
"@typescript-eslint/eslint-plugin": "^4.27.0",
57+
"@typescript-eslint/parser": "^4.27.0",
58+
"eslint": "^7.28.0",
6059
"eslint-config-prettier": "^8.3.0",
6160
"eslint-plugin-prettier": "^3.4.0",
6261
"fs-extra": "^10.0.0",
63-
"prettier": "^2.3.0",
64-
"rollup": "^2.50.2",
62+
"prettier": "^2.3.1",
63+
"rollup": "^2.52.1",
6564
"rollup-plugin-delete": "^2.0.0",
6665
"rollup-plugin-terser": "^7.0.2",
6766
"rxjs": "^7.1.0",
6867
"ts-node": "^10.0.0",
69-
"tslib": "^2.2.0",
70-
"typescript": "^4.3.2"
68+
"typescript": "^4.3.3"
7169
},
7270
"peerDependencies": {
73-
"rxjs": "^7.1.0",
74-
"tslib": "^2.2.0"
71+
"rxjs": "^7.1.0"
7572
}
7673
}

rollup.config.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const config: RollupOptions[] = [
1414
output: {
1515
dir: './dist',
1616
format: 'esm',
17-
entryFileNames: 'esm/rx-file-upload.js',
17+
entryFileNames: 'bundle/rx-file-upload.js',
1818
preferConst: true,
1919
},
2020
plugins: [
@@ -37,28 +37,6 @@ const config: RollupOptions[] = [
3737
'crypto-es/lib/core',
3838
],
3939
},
40-
{
41-
input: './src/index.ts',
42-
output: {
43-
dir: './dist',
44-
format: 'esm',
45-
entryFileNames: 'esm5/rx-file-upload.js',
46-
},
47-
plugins: [
48-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
49-
// @ts-ignore
50-
typescript({ tsconfig: './tsconfig.es5.json' }),
51-
nodeResolve(),
52-
],
53-
external: [
54-
'tslib',
55-
'rxjs',
56-
'rxjs/ajax',
57-
'rxjs/operators',
58-
'crypto-es/lib/sha256',
59-
'crypto-es/lib/core',
60-
],
61-
},
6240
{
6341
input: './src/index.ts',
6442
output: {

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"./node_modules/@types"
1414
],
1515
"lib": [
16-
"es2018",
16+
"esnext",
1717
"dom"
1818
]
1919
},

0 commit comments

Comments
 (0)