@esportsplus/web-storage 0.0.8 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.d.ts CHANGED
@@ -1,19 +1,30 @@
1
1
  import local from './local';
2
2
  declare const _default: {
3
3
  local: {
4
- clear: () => void;
5
- delete: (key: string) => Promise<void>;
6
- get: (key: string, value?: any) => Promise<any>;
7
- has: (key: string) => Promise<boolean>;
8
- prepend: (key: string, value: any) => Promise<void>;
9
- push: (key: string, value: any) => Promise<void>;
10
- replace: (values: {
11
- [key: string]: any;
12
- }) => void;
13
- set: (key: string, value: any) => Promise<void>;
14
- useIndexedDB: (options?: import("./local/types").Options) => void;
15
- useLocalStorage: (options?: import("./local/types").Options) => void;
16
- useOptions: (options?: import("./local/types").Options) => void;
4
+ store: (options?: LocalForageOptions) => {
5
+ instance: LocalForage;
6
+ iterate: <T, U>(iteratee: (value: T, key: string, iterationNumber: number) => U, callback?: ((err: any, result: U) => void) | undefined) => Promise<U>;
7
+ keys: (callback?: ((err: any, keys: string[]) => void) | undefined) => Promise<string[]>;
8
+ length: (callback?: ((err: any, numberOfKeys: number) => void) | undefined) => Promise<number>;
9
+ promises: (Promise<any> | (() => void))[];
10
+ assign(key: string, value: import("./local/types").Object): void;
11
+ clear(): Promise<void>;
12
+ delete(...keys: string[]): void;
13
+ entries(): Promise<import("./local/types").Object>;
14
+ filter(fn: Function): Promise<import("./local/types").Object>;
15
+ get(key: string, value?: any): Promise<any>;
16
+ has(...keys: string[]): Promise<boolean>;
17
+ only(...keys: string[]): Promise<import("./local/types").Object>;
18
+ pop(key: string): Promise<any>;
19
+ push(key: string, ...values: any[]): void;
20
+ replace(values: {
21
+ [key: string]: any;
22
+ }): void;
23
+ shift(key: string): Promise<any>;
24
+ set(key: string, value: any): void;
25
+ sync(): Promise<void>;
26
+ unshift(key: string, ...values: any[]): void;
27
+ };
17
28
  };
18
29
  };
19
30
  export default _default;
package/build/index.js CHANGED
@@ -1,3 +1,9 @@
1
- import local from './local';
2
- export default { local };
3
- export { local };
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.local = void 0;
7
+ const local_1 = __importDefault(require("./local"));
8
+ exports.local = local_1.default;
9
+ exports.default = { local: local_1.default };
@@ -1,17 +1,30 @@
1
- import type { Options } from './types';
2
- declare const _default: {
3
- clear: () => void;
4
- delete: (key: string) => Promise<void>;
5
- get: (key: string, value?: any) => Promise<any>;
6
- has: (key: string) => Promise<boolean>;
7
- prepend: (key: string, value: any) => Promise<void>;
8
- push: (key: string, value: any) => Promise<void>;
9
- replace: (values: {
1
+ import { Object } from './types';
2
+ declare class Store {
3
+ instance: LocalForage;
4
+ iterate: LocalForage['iterate'];
5
+ keys: LocalForage['keys'];
6
+ length: LocalForage['length'];
7
+ promises: (Promise<any> | (() => void))[];
8
+ constructor(options?: LocalForageOptions);
9
+ assign(key: string, value: Object): void;
10
+ clear(): Promise<void>;
11
+ delete(...keys: string[]): void;
12
+ entries(): Promise<Object>;
13
+ filter(fn: Function): Promise<Object>;
14
+ get(key: string, value?: any): Promise<any>;
15
+ has(...keys: string[]): Promise<boolean>;
16
+ only(...keys: string[]): Promise<Object>;
17
+ pop(key: string): Promise<any>;
18
+ push(key: string, ...values: any[]): void;
19
+ replace(values: {
10
20
  [key: string]: any;
11
- }) => void;
12
- set: (key: string, value: any) => Promise<void>;
13
- useIndexedDB: (options?: Options) => void;
14
- useLocalStorage: (options?: Options) => void;
15
- useOptions: (options?: Options) => void;
21
+ }): void;
22
+ shift(key: string): Promise<any>;
23
+ set(key: string, value: any): void;
24
+ sync(): Promise<void>;
25
+ unshift(key: string, ...values: any[]): void;
26
+ }
27
+ declare const _default: {
28
+ store: (options?: LocalForageOptions) => Store;
16
29
  };
17
30
  export default _default;
@@ -1,91 +1,140 @@
1
- import dot from '@esportsplus/dot';
2
- import localforage from 'localforage';
3
- let cache = {}, driver = localforage.LOCALSTORAGE;
4
- function init(options = {}) {
5
- localforage.config(Object.assign({ name: 'store' }, options, { driver }));
6
- }
7
- async function sync(key) {
8
- let root = (key.split('.')[0] || '');
9
- await localforage.setItem(root, dot.get(cache, root));
10
- }
11
- const clear = () => {
12
- cache = {};
13
- localforage.clear();
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
4
  };
15
- const del = async (key) => {
16
- dot.set(cache, key, undefined);
17
- if (key.includes('.')) {
18
- await sync(key);
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const types_1 = require("./types");
7
+ const localforage_1 = __importDefault(require("localforage"));
8
+ class Store {
9
+ instance;
10
+ iterate;
11
+ keys;
12
+ length;
13
+ promises;
14
+ constructor(options = {}) {
15
+ let driver, name = options.name || 'store';
16
+ switch ((options.driver || types_1.Driver.IndexedDB)) {
17
+ case types_1.Driver.LocalStorage:
18
+ driver = localforage_1.default.LOCALSTORAGE;
19
+ break;
20
+ default:
21
+ driver = localforage_1.default.INDEXEDDB;
22
+ break;
23
+ }
24
+ this.instance = localforage_1.default.createInstance(Object.assign(options, { driver, name }));
25
+ this.iterate = this.instance.iterate;
26
+ this.keys = this.instance.keys;
27
+ this.length = this.instance.length;
28
+ this.promises = [];
19
29
  }
20
- else {
21
- localforage.removeItem(key);
30
+ assign(key, value) {
31
+ this.promises.push(async () => {
32
+ let data = (await this.get(key)) || {};
33
+ await this.instance.setItem(key, Object.assign(data, value));
34
+ });
22
35
  }
23
- };
24
- const get = async (key, value = null) => {
25
- if (await has(key)) {
26
- return dot.get(cache, key);
36
+ clear() {
37
+ this.promises = [];
38
+ return this.instance.clear();
27
39
  }
28
- if (typeof value === 'function') {
29
- value = await value();
40
+ delete(...keys) {
41
+ this.promises.push(async () => {
42
+ for (let i = 0, n = keys.length; i < n; i++) {
43
+ await this.instance.removeItem(keys[i]);
44
+ }
45
+ });
30
46
  }
31
- set(key, value);
32
- value = dot.get(cache, key);
33
- if (value === null) {
34
- throw new Error(`'${key}' has not been set in storage`);
47
+ async entries() {
48
+ let values = {};
49
+ await this.instance.iterate((value, key) => {
50
+ values[key] = value;
51
+ });
52
+ return values;
35
53
  }
36
- return value;
37
- };
38
- const has = async (key) => {
39
- if (dot.has(cache, key)) {
40
- return true;
54
+ async filter(fn) {
55
+ let values = {};
56
+ await this.instance.iterate((value, key) => {
57
+ let result = fn(value, key), stop = typeof result !== 'boolean';
58
+ if (stop || (!stop && result)) {
59
+ values[key] = value;
60
+ }
61
+ if (stop) {
62
+ return true;
63
+ }
64
+ });
65
+ return values;
41
66
  }
42
- let k = key.split('.'), f = k.shift() || '', value = await localforage.getItem(f);
43
- if (value !== null) {
44
- set(f, value);
45
- if (Array.isArray(value) && k.length == 0) {
46
- return true;
67
+ async get(key, value = null) {
68
+ let data = await this.instance.getItem(key);
69
+ if (data === null) {
70
+ if (typeof value === 'function') {
71
+ data = await value();
72
+ }
73
+ else {
74
+ data = value;
75
+ }
76
+ if (data !== null) {
77
+ this.set(key, data);
78
+ }
47
79
  }
48
- if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
49
- return dot.has(value, k.join('.'));
80
+ if (data === null) {
81
+ throw new Error(`'${key}' has not been set in Storage`);
50
82
  }
83
+ return data;
51
84
  }
52
- return false;
53
- };
54
- const prepend = async (key, value) => {
55
- let values = await get(key, []);
56
- if (!Array.isArray(values)) {
57
- values = [values];
85
+ async has(...keys) {
86
+ let haystack = await this.instance.keys();
87
+ for (let i = 0, n = keys.length; i < n; i++) {
88
+ if (haystack.includes(keys[i])) {
89
+ continue;
90
+ }
91
+ return false;
92
+ }
93
+ return true;
58
94
  }
59
- values.unshift(value);
60
- set(key, values);
61
- };
62
- const push = async (key, value) => {
63
- let values = await get(key, []);
64
- if (!Array.isArray(values)) {
65
- values = [values];
95
+ async only(...keys) {
96
+ return await this.filter((key) => keys.includes(key));
66
97
  }
67
- values.push(value);
68
- set(key, values);
69
- };
70
- const replace = (values) => {
71
- for (let key in values) {
72
- set(key, values[key]);
98
+ async pop(key) {
99
+ let value, values = (await this.get(key)) || [];
100
+ value = values.pop();
101
+ this.promises.push(this.instance.setItem(key, values));
102
+ return value;
73
103
  }
104
+ push(key, ...values) {
105
+ this.promises.push(async () => {
106
+ let data = (await this.get(key)) || [];
107
+ data.push(...values);
108
+ await this.instance.setItem(key, data);
109
+ });
110
+ }
111
+ replace(values) {
112
+ this.promises.push(async () => {
113
+ for (let key in values) {
114
+ await this.instance.setItem(key, values[key]);
115
+ }
116
+ });
117
+ }
118
+ async shift(key) {
119
+ let value, values = (await this.get(key)) || [];
120
+ value = values.shift();
121
+ this.promises.push(this.instance.setItem(key, values));
122
+ return value;
123
+ }
124
+ set(key, value) {
125
+ this.promises.push(this.instance.setItem(key, value));
126
+ }
127
+ async sync() {
128
+ await Promise.allSettled(this.promises.splice(0));
129
+ }
130
+ unshift(key, ...values) {
131
+ this.promises.push(async () => {
132
+ let data = (await this.get(key)) || [];
133
+ data.unshift(...values);
134
+ await this.instance.setItem(key, data);
135
+ });
136
+ }
137
+ }
138
+ exports.default = {
139
+ store: (options = {}) => new Store(options)
74
140
  };
75
- const set = async (key, value) => {
76
- dot.set(cache, key, value);
77
- await sync(key);
78
- };
79
- const useIndexedDB = (options = {}) => {
80
- driver = localforage.INDEXEDDB;
81
- init(options);
82
- };
83
- const useLocalStorage = (options = {}) => {
84
- driver = localforage.LOCALSTORAGE;
85
- init(options);
86
- };
87
- const useOptions = (options = {}) => {
88
- init(options);
89
- };
90
- init();
91
- export default { clear, delete: del, get, has, prepend, push, replace, set, useIndexedDB, useLocalStorage, useOptions };
@@ -1,7 +1,8 @@
1
- declare type Options = {
2
- description?: string;
3
- name?: string;
4
- storeName?: string;
5
- version?: number;
1
+ declare enum Driver {
2
+ IndexedDB = 0,
3
+ LocalStorage = 1
4
+ }
5
+ declare type Object = {
6
+ [key: string]: any;
6
7
  };
7
- export type { Options };
8
+ export { Driver, Object };
@@ -1 +1,10 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Driver = void 0;
4
+ var Driver;
5
+ (function (Driver) {
6
+ Driver[Driver["IndexedDB"] = 0] = "IndexedDB";
7
+ Driver[Driver["LocalStorage"] = 1] = "LocalStorage";
8
+ })(Driver || (Driver = {}));
9
+ exports.Driver = Driver;
10
+ ;
package/package.json CHANGED
@@ -1,20 +1,17 @@
1
1
  {
2
2
  "author": "ICJR",
3
3
  "dependencies": {
4
- "@esportsplus/dot": "^0.0.3",
5
4
  "localforage": "^1.10.0"
6
5
  },
7
6
  "description": "Web storage utility",
8
7
  "devDependencies": {
9
- "glob": "^7.1.7",
10
- "node-polyfill-webpack-plugin": "^1.1.4",
11
- "npm-run-all": "^4.1.5",
12
- "ts-loader": "^9.2.6",
13
- "tsc-alias": "^1.5.0",
14
- "tsconfig-paths-webpack-plugin": "^3.5.2",
15
- "typescript": "^4.5.2",
16
- "webpack": "^5.64.4",
17
- "webpack-cli": "^4.9.1"
8
+ "glob": "^8.0.3",
9
+ "ts-loader": "^9.4.1",
10
+ "tsc-alias": "^1.7.0",
11
+ "tsconfig-paths-webpack-plugin": "^4.0.0",
12
+ "typescript": "^4.8.4",
13
+ "webpack": "^5.74.0",
14
+ "webpack-cli": "^4.10.0"
18
15
  },
19
16
  "main": "./build/index.js",
20
17
  "name": "@esportsplus/web-storage",
@@ -26,5 +23,5 @@
26
23
  "prepublishOnly": "npm run build"
27
24
  },
28
25
  "types": "./build/index.d.ts",
29
- "version": "0.0.8"
26
+ "version": "0.1.1"
30
27
  }
@@ -1,135 +1,191 @@
1
- import type { Options } from './types';
2
- import dot from '@esportsplus/dot';
3
- import localforage from 'localforage';
4
-
5
-
6
- let cache: any = {},
7
- driver: any = localforage.LOCALSTORAGE;
8
-
9
-
10
- function init(options: Options = {}): void {
11
- localforage.config(Object.assign({ name: 'store' }, options, { driver }));
12
- }
13
-
14
- async function sync(key: string) {
15
- let root = (key.split('.')[0] || '');
16
-
17
- await localforage.setItem(root, dot.get(cache, root));
18
- }
19
-
20
-
21
- const clear = () => {
22
- cache = {};
23
- localforage.clear();
24
- };
25
-
26
- const del = async (key: string): Promise<void> => {
27
- dot.set(cache, key, undefined);
28
-
29
- if (key.includes('.')) {
30
- await sync(key);
31
- }
32
- else {
33
- localforage.removeItem(key);
34
- }
35
- }
36
-
37
- const get = async (key: string, value: any = null): Promise<any> => {
38
- if (await has(key)) {
39
- return dot.get(cache, key);
40
- }
41
-
42
- if (typeof value === 'function') {
43
- value = await value();
44
- }
45
-
46
- set(key, value);
47
-
48
- value = dot.get(cache, key);
49
-
50
- if (value === null) {
51
- throw new Error(`'${key}' has not been set in storage`);
52
- }
53
-
54
- return value;
55
- };
56
-
57
- const has = async (key: string): Promise<boolean> => {
58
- if (dot.has(cache, key)) {
59
- return true;
60
- }
61
-
62
- let k = key.split('.'),
63
- f = k.shift() || '',
64
- value = await localforage.getItem(f);
65
-
66
- if (value !== null) {
67
- set(f, value);
68
-
69
- if (Array.isArray(value) && k.length == 0) {
70
- return true;
71
- }
72
-
73
- if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
74
- return dot.has(value, k.join('.'));
75
- }
76
- }
77
-
78
- return false;
79
- };
80
-
81
- const prepend = async (key: string, value: any): Promise<void> => {
82
- let values = await get(key, []);
83
-
84
- if (!Array.isArray(values)) {
85
- values = [values];
86
- }
87
-
88
- values.unshift(value);
89
-
90
- set(key, values);
91
- };
92
-
93
- const push = async (key: string, value: any): Promise<void> => {
94
- let values = await get(key, []);
95
-
96
- if (!Array.isArray(values)) {
97
- values = [values];
98
- }
99
-
100
- values.push(value);
101
-
102
- set(key, values);
103
- };
104
-
105
- const replace = (values: { [key: string]: any }): void => {
106
- for (let key in values) {
107
- set(key, values[key]);
108
- }
109
- };
110
-
111
- const set = async (key: string, value: any): Promise<void> => {
112
- dot.set(cache, key, value);
113
- await sync(key);
114
- };
115
-
116
- const useIndexedDB = (options: Options = {}): void => {
117
- driver = localforage.INDEXEDDB;
118
- init(options);
119
- };
120
-
121
- const useLocalStorage = (options: Options = {}): void => {
122
- driver = localforage.LOCALSTORAGE;
123
- init(options);
124
- };
125
-
126
- const useOptions = (options: Options = {}): void => {
127
- init(options);
128
- };
129
-
130
-
131
- // Initialize using localstorage as default storage
132
- init();
133
-
134
-
135
- export default { clear, delete: del, get, has, prepend, push, replace, set, useIndexedDB, useLocalStorage, useOptions };
1
+ import { Driver, Object } from './types';
2
+ import localforage from 'localforage';
3
+
4
+
5
+ class Store {
6
+ instance: LocalForage;
7
+ iterate: LocalForage['iterate'];
8
+ keys: LocalForage['keys'];
9
+ length: LocalForage['length'];
10
+ promises: (Promise<any> | (() => void))[];
11
+
12
+
13
+ constructor(options: LocalForageOptions = {}) {
14
+ let driver,
15
+ name = options.name || 'store';
16
+
17
+ switch ((options.driver || Driver.IndexedDB) as Driver) {
18
+ case Driver.LocalStorage:
19
+ driver = localforage.LOCALSTORAGE;
20
+ break;
21
+ default:
22
+ driver = localforage.INDEXEDDB;
23
+ break;
24
+ }
25
+
26
+ this.instance = localforage.createInstance( Object.assign(options, { driver, name }) );
27
+ this.iterate = this.instance.iterate;
28
+ this.keys = this.instance.keys;
29
+ this.length = this.instance.length;
30
+ this.promises = [];
31
+ }
32
+
33
+
34
+ assign(key: string, value: Object): void {
35
+ this.promises.push(async () => {
36
+ let data = (await this.get(key)) || {};
37
+
38
+ await this.instance.setItem(
39
+ key,
40
+ Object.assign(data, value)
41
+ );
42
+ });
43
+ }
44
+
45
+ clear(): Promise<void> {
46
+ this.promises = [];
47
+
48
+ return this.instance.clear();
49
+ }
50
+
51
+ delete(...keys: string[]): void {
52
+ this.promises.push(async () => {
53
+ for (let i = 0, n = keys.length; i < n; i++) {
54
+ await this.instance.removeItem(keys[i]);
55
+ }
56
+ });
57
+ }
58
+
59
+ async entries(): Promise<Object> {
60
+ let values: Object = {};
61
+
62
+ await this.instance.iterate((value: any, key: string) => {
63
+ values[key] = value;
64
+ });
65
+
66
+ return values;
67
+ }
68
+
69
+ async filter(fn: Function): Promise<Object> {
70
+ let values: Object = {};
71
+
72
+ await this.instance.iterate((value: any, key: string) => {
73
+ let result = fn(value, key),
74
+ stop = typeof result !== 'boolean';
75
+
76
+ if (stop || (!stop && result)) {
77
+ values[key] = value;
78
+ }
79
+
80
+ if (stop) {
81
+ return true;
82
+ }
83
+ });
84
+
85
+ return values;
86
+ }
87
+
88
+ async get(key: string, value: any = null): Promise<any> {
89
+ let data: any = await this.instance.getItem(key);
90
+
91
+ if (data === null) {
92
+ if (typeof value === 'function') {
93
+ data = await value();
94
+ }
95
+ else {
96
+ data = value;
97
+ }
98
+
99
+ if (data !== null) {
100
+ this.set(key, data);
101
+ }
102
+ }
103
+
104
+ if (data === null) {
105
+ throw new Error(`'${key}' has not been set in Storage`);
106
+ }
107
+
108
+ return data;
109
+ }
110
+
111
+ async has(...keys: string[]): Promise<boolean> {
112
+ let haystack = await this.instance.keys();
113
+
114
+ for (let i = 0, n = keys.length; i < n; i++) {
115
+ if (haystack.includes(keys[i])) {
116
+ continue;
117
+ }
118
+
119
+ return false;
120
+ }
121
+
122
+ return true;
123
+ }
124
+
125
+ async only(...keys: string[]): Promise<Object> {
126
+ return await this.filter((key: string) => keys.includes(key));
127
+ }
128
+
129
+ async pop(key: string): Promise<any> {
130
+ let value,
131
+ values = (await this.get(key)) || [];
132
+
133
+ value = values.pop();
134
+
135
+ this.promises.push( this.instance.setItem(key, values) );
136
+
137
+ return value;
138
+ }
139
+
140
+ push(key: string, ...values: any[]): void {
141
+ this.promises.push(async () => {
142
+ let data = (await this.get(key)) || [];
143
+
144
+ data.push(...values);
145
+
146
+ await this.instance.setItem(key, data);
147
+ });
148
+ }
149
+
150
+ replace(values: { [key: string]: any }): void {
151
+ this.promises.push(async () => {
152
+ for (let key in values) {
153
+ await this.instance.setItem(key, values[key])
154
+ }
155
+ });
156
+ }
157
+
158
+ async shift(key: string): Promise<any> {
159
+ let value,
160
+ values = (await this.get(key)) || [];
161
+
162
+ value = values.shift();
163
+
164
+ this.promises.push( this.instance.setItem(key, values) );
165
+
166
+ return value;
167
+ }
168
+
169
+ set(key: string, value: any): void {
170
+ this.promises.push( this.instance.setItem(key, value) );
171
+ }
172
+
173
+ async sync(): Promise<void> {
174
+ await Promise.allSettled(this.promises.splice(0));
175
+ }
176
+
177
+ unshift(key: string, ...values: any[]): void {
178
+ this.promises.push(async () => {
179
+ let data = (await this.get(key)) || [];
180
+
181
+ data.unshift(...values);
182
+
183
+ await this.instance.setItem(key, data);
184
+ });
185
+ }
186
+ }
187
+
188
+
189
+ export default {
190
+ store: (options: LocalForageOptions = {}): Store => new Store(options)
191
+ };
@@ -1,9 +1,9 @@
1
- type Options = {
2
- description?: string,
3
- name?: string,
4
- storeName?: string,
5
- version?: number
1
+ enum Driver {
2
+ IndexedDB,
3
+ LocalStorage
6
4
  };
7
5
 
6
+ type Object = { [key: string]: any };
8
7
 
9
- export type { Options };
8
+
9
+ export { Driver, Object };
package/tsconfig.json CHANGED
@@ -1,35 +1,23 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "allowJs": true,
4
- "allowUmdGlobalAccess": true,
5
4
  "alwaysStrict": true,
6
5
  "baseUrl": "src",
7
6
  "declaration": true,
8
7
  "declarationDir": "./build",
9
- "esModuleInterop": true,
10
- "forceConsistentCasingInFileNames": true,
11
- "lib": ["dom", "es7"],
12
- "module": "esnext",
8
+ "lib": ["dom", "ESNext"],
9
+ "module": "NodeNext",
13
10
  "moduleResolution": "node",
14
- "noFallthroughCasesInSwitch": true,
15
- "noImplicitAny": true,
16
- "noImplicitReturns": true,
17
- "noImplicitThis": true,
18
- "noUncheckedIndexedAccess": true,
19
11
  "noUnusedLocals": true,
20
12
  "noUnusedParameters": true,
21
13
  "outDir": "./build",
22
- "paths": { },
14
+ "paths": {
15
+ "~/*": ["*"]
16
+ },
23
17
  "removeComments": true,
24
18
  "resolveJsonModule": true,
25
- "skipLibCheck": true,
26
- "sourceMap": false,
27
19
  "strict": true,
28
- "strictBindCallApply": true,
29
- "strictFunctionTypes": true,
30
- "strictNullChecks": true,
31
- "strictPropertyInitialization": true,
32
- "target": "esnext"
20
+ "target": "ESNext"
33
21
  },
34
22
  "exclude": ["node_modules"],
35
23
  "include": ["src"],
@@ -1,64 +1,54 @@
1
- const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
2
1
  const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
3
2
  const glob = require('glob');
4
- const webpack = require('webpack');
5
3
 
6
4
 
7
- const config = ({ filename, input, library, output, production }) => {
8
- let optimization = {
9
- usedExports: false
10
- };
11
-
5
+ module.exports = ({ directory, entry, filename, library, output, production }) => {
12
6
  filename = filename || 'app';
13
- production = production ? false : true;
7
+ production = production == 'true' ? true : false;
8
+
9
+ if (directory) {
10
+ entry = glob.sync(`${directory}/{,!(node_modules)/**/}!(webpack)*!(.d).{ts,js}`);
11
+ }
14
12
 
15
13
  if (production) {
16
- optimization = {
17
- mangleWasmImports: false,
18
- minimize: false,
19
- usedExports: false
20
- };
14
+ filename += '.min';
21
15
  }
22
16
 
23
17
  return {
24
18
  entry: {
25
- [(filename || 'app') + (production ? '.min' : '')]: glob.sync(`${input}/{,!(node_modules)/**/}!(webpack)*!(.d).ts`)
19
+ [filename]: entry
26
20
  },
27
- mode: (production ? 'development' : 'production'),
21
+ mode: (production ? 'production' : 'development'),
28
22
  module: {
29
23
  rules: [
30
24
  {
31
25
  test: /\.tsx?$/,
32
26
  use: 'ts-loader',
33
- exclude: /node_modules/
27
+ exclude: /node_modules/,
28
+ resolve: {
29
+ fullySpecified: false,
30
+ }
34
31
  }
35
32
  ]
36
33
  },
37
- optimization,
34
+ optimization: {
35
+ mangleWasmImports: production,
36
+ minimize: production,
37
+ usedExports: production
38
+ },
38
39
  output: {
39
- // fixes ReferenceError: window is not defined
40
- globalObject: "(typeof self !== 'undefined' ? self : this)",
41
40
  library: library || filename,
42
41
  path: output,
43
42
  },
44
- plugins: [
45
- new NodePolyfillPlugin(),
46
- new webpack.ProvidePlugin({
47
- Buffer: ['buffer', 'Buffer'],
48
- process: 'process/browser'
49
- })
50
- ],
51
43
  resolve: {
52
44
  extensions: ['.js', '.ts', '.tsx'],
53
- fallback: {
54
- fs: false
55
- },
45
+ fullySpecified: false,
56
46
  plugins: [
57
- new TsconfigPathsPlugin()
47
+ new TsconfigPathsPlugin({
48
+ extensions: ['.js', '.ts', '.tsx']
49
+ })
58
50
  ]
59
- }
51
+ },
52
+ watch: true
60
53
  };
61
54
  };
62
-
63
-
64
- module.exports = config;