@cocreate/unique 1.11.5 → 1.11.6
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/.github/FUNDING.yml +3 -3
- package/.github/workflows/automated.yml +95 -95
- package/.github/workflows/manual.yml +44 -44
- package/CHANGELOG.md +1286 -1279
- package/CONTRIBUTING.md +96 -96
- package/CoCreate.config.js +26 -26
- package/LICENSE +21 -21
- package/README.md +85 -85
- package/demo/index.html +68 -68
- package/docs/index.html +371 -371
- package/package.json +66 -66
- package/release.config.js +21 -21
- package/src/client.js +93 -93
- package/src/index.js +14 -14
- package/src/server.js +47 -47
- package/webpack.config.js +84 -84
package/package.json
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@cocreate/unique",
|
|
3
|
-
"version": "1.11.
|
|
4
|
-
"description": "A simple unique component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"unique",
|
|
7
|
-
"cocreate",
|
|
8
|
-
"low-code-framework",
|
|
9
|
-
"no-code-framework",
|
|
10
|
-
"cocreatejs",
|
|
11
|
-
"cocreatejs-component",
|
|
12
|
-
"cocreate-framework",
|
|
13
|
-
"no-code",
|
|
14
|
-
"low-code",
|
|
15
|
-
"collaborative-framework",
|
|
16
|
-
"realtime",
|
|
17
|
-
"realtime-framework",
|
|
18
|
-
"collaboration",
|
|
19
|
-
"shared-editing",
|
|
20
|
-
"html5-framework",
|
|
21
|
-
"javascript-framework"
|
|
22
|
-
],
|
|
23
|
-
"publishConfig": {
|
|
24
|
-
"access": "public"
|
|
25
|
-
},
|
|
26
|
-
"scripts": {
|
|
27
|
-
"start": "npx webpack --config webpack.config.js",
|
|
28
|
-
"build": "NODE_ENV=production npx webpack --config webpack.config.js",
|
|
29
|
-
"dev": "npx webpack --config webpack.config.js --watch",
|
|
30
|
-
"docs": "node ./node_modules/@cocreate/docs/src/index.js",
|
|
31
|
-
"hosting": "node ./node_modules/@cocreate/hosting/src/index.js"
|
|
32
|
-
},
|
|
33
|
-
"repository": {
|
|
34
|
-
"type": "git",
|
|
35
|
-
"url": "git+https://github.com/CoCreate-app/CoCreate-unique.git"
|
|
36
|
-
},
|
|
37
|
-
"author": "CoCreate LLC",
|
|
38
|
-
"license": "MIT",
|
|
39
|
-
"bugs": {
|
|
40
|
-
"url": "https://github.com/CoCreate-app/CoCreate-unique/issues"
|
|
41
|
-
},
|
|
42
|
-
"homepage": "https://cocreate.app/docs/unique",
|
|
43
|
-
"funding": {
|
|
44
|
-
"type": "GitHub Sponsors ❤",
|
|
45
|
-
"url": "https://github.com/sponsors/CoCreate-app"
|
|
46
|
-
},
|
|
47
|
-
"main": "./src/index.js",
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"@babel/core": "^7.9.6",
|
|
50
|
-
"@babel/preset-env": "^7.9.6",
|
|
51
|
-
"babel-loader": "^8.1.0",
|
|
52
|
-
"clean-webpack-plugin": "^3.0.0",
|
|
53
|
-
"file-loader": "^6.2.0",
|
|
54
|
-
"mini-css-extract-plugin": "^1.5.0",
|
|
55
|
-
"style-loader": "^3.3.1",
|
|
56
|
-
"terser-webpack-plugin": "^5.1.1",
|
|
57
|
-
"webpack": "^5.24.4",
|
|
58
|
-
"webpack-cli": "^4.5.0",
|
|
59
|
-
"webpack-log": "^3.0.1"
|
|
60
|
-
},
|
|
61
|
-
"dependencies": {
|
|
62
|
-
"@cocreate/crud-client": "^1.21.5",
|
|
63
|
-
"@cocreate/docs": "^1.7.13",
|
|
64
|
-
"@cocreate/uuid": "^1.4.11"
|
|
65
|
-
}
|
|
66
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@cocreate/unique",
|
|
3
|
+
"version": "1.11.6",
|
|
4
|
+
"description": "A simple unique component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"unique",
|
|
7
|
+
"cocreate",
|
|
8
|
+
"low-code-framework",
|
|
9
|
+
"no-code-framework",
|
|
10
|
+
"cocreatejs",
|
|
11
|
+
"cocreatejs-component",
|
|
12
|
+
"cocreate-framework",
|
|
13
|
+
"no-code",
|
|
14
|
+
"low-code",
|
|
15
|
+
"collaborative-framework",
|
|
16
|
+
"realtime",
|
|
17
|
+
"realtime-framework",
|
|
18
|
+
"collaboration",
|
|
19
|
+
"shared-editing",
|
|
20
|
+
"html5-framework",
|
|
21
|
+
"javascript-framework"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"start": "npx webpack --config webpack.config.js",
|
|
28
|
+
"build": "NODE_ENV=production npx webpack --config webpack.config.js",
|
|
29
|
+
"dev": "npx webpack --config webpack.config.js --watch",
|
|
30
|
+
"docs": "node ./node_modules/@cocreate/docs/src/index.js",
|
|
31
|
+
"hosting": "node ./node_modules/@cocreate/hosting/src/index.js"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/CoCreate-app/CoCreate-unique.git"
|
|
36
|
+
},
|
|
37
|
+
"author": "CoCreate LLC",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/CoCreate-app/CoCreate-unique/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://cocreate.app/docs/unique",
|
|
43
|
+
"funding": {
|
|
44
|
+
"type": "GitHub Sponsors ❤",
|
|
45
|
+
"url": "https://github.com/sponsors/CoCreate-app"
|
|
46
|
+
},
|
|
47
|
+
"main": "./src/index.js",
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@babel/core": "^7.9.6",
|
|
50
|
+
"@babel/preset-env": "^7.9.6",
|
|
51
|
+
"babel-loader": "^8.1.0",
|
|
52
|
+
"clean-webpack-plugin": "^3.0.0",
|
|
53
|
+
"file-loader": "^6.2.0",
|
|
54
|
+
"mini-css-extract-plugin": "^1.5.0",
|
|
55
|
+
"style-loader": "^3.3.1",
|
|
56
|
+
"terser-webpack-plugin": "^5.1.1",
|
|
57
|
+
"webpack": "^5.24.4",
|
|
58
|
+
"webpack-cli": "^4.5.0",
|
|
59
|
+
"webpack-log": "^3.0.1"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"@cocreate/crud-client": "^1.21.5",
|
|
63
|
+
"@cocreate/docs": "^1.7.13",
|
|
64
|
+
"@cocreate/uuid": "^1.4.11"
|
|
65
|
+
}
|
|
66
|
+
}
|
package/release.config.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
dryRun: false,
|
|
3
|
-
branches: ["master"],
|
|
4
|
-
plugins: [
|
|
5
|
-
"@semantic-release/commit-analyzer",
|
|
6
|
-
"@semantic-release/release-notes-generator",
|
|
7
|
-
[
|
|
8
|
-
"@semantic-release/changelog",
|
|
9
|
-
{
|
|
10
|
-
changelogFile: "CHANGELOG.md",
|
|
11
|
-
},
|
|
12
|
-
],
|
|
13
|
-
"@semantic-release/npm",
|
|
14
|
-
"@semantic-release/github",
|
|
15
|
-
[
|
|
16
|
-
"@semantic-release/git",
|
|
17
|
-
{
|
|
18
|
-
assets: ["CHANGELOG.md", "package.json"],
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
],
|
|
1
|
+
module.exports = {
|
|
2
|
+
dryRun: false,
|
|
3
|
+
branches: ["master"],
|
|
4
|
+
plugins: [
|
|
5
|
+
"@semantic-release/commit-analyzer",
|
|
6
|
+
"@semantic-release/release-notes-generator",
|
|
7
|
+
[
|
|
8
|
+
"@semantic-release/changelog",
|
|
9
|
+
{
|
|
10
|
+
changelogFile: "CHANGELOG.md",
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
"@semantic-release/npm",
|
|
14
|
+
"@semantic-release/github",
|
|
15
|
+
[
|
|
16
|
+
"@semantic-release/git",
|
|
17
|
+
{
|
|
18
|
+
assets: ["CHANGELOG.md", "package.json"],
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
],
|
|
22
22
|
};
|
package/src/client.js
CHANGED
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
import observer from '@cocreate/observer';
|
|
2
|
-
import crud from '@cocreate/crud-client';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Initializes input event listeners for the specified elements. This is a convenience method for calling setInputEvent on each element.
|
|
7
|
-
*
|
|
8
|
-
* @param elements - The HTMLElement or array of HTMLElements to listen
|
|
9
|
-
*/
|
|
10
|
-
function init(elements) {
|
|
11
|
-
// Returns an array of unique elements
|
|
12
|
-
if (!elements)
|
|
13
|
-
elements = document.querySelectorAll('[unique]')
|
|
14
|
-
// If elements is not an array of elements returns an array of elements.
|
|
15
|
-
else if (!Array.isArray(elements))
|
|
16
|
-
elements = [elements]
|
|
17
|
-
for (let element of elements)
|
|
18
|
-
setInputEvent(element)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Sets the input event to prevent duplicate. This is necessary because IE doesn't support unique = " true " in HTML5.
|
|
23
|
-
*
|
|
24
|
-
* @param input - The input element to listen for changes on. Note that it's an object
|
|
25
|
-
*/
|
|
26
|
-
function setInputEvent(input) {
|
|
27
|
-
let delayTimer
|
|
28
|
-
input.addEventListener('input', function () {
|
|
29
|
-
input.setAttribute('unique', true);
|
|
30
|
-
|
|
31
|
-
clearTimeout(delayTimer);
|
|
32
|
-
delayTimer = setTimeout(function () {
|
|
33
|
-
isUnique(input)
|
|
34
|
-
}, 1000);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Checks if a value is unique. This is a helper function for CRUD operations that need to be performed on documents in order to make sure they are unique.
|
|
40
|
-
*
|
|
41
|
-
* @param element - The element that is being checked for uniqueness. It should have the attribute ` name `
|
|
42
|
-
*/
|
|
43
|
-
async function isUnique(element) {
|
|
44
|
-
let name = element.getAttribute('name');
|
|
45
|
-
let value = element.getValue();
|
|
46
|
-
let request = {
|
|
47
|
-
db: 'indexeddb',
|
|
48
|
-
collection: element.getAttribute('collection'),
|
|
49
|
-
filter: {
|
|
50
|
-
query: [{
|
|
51
|
-
name,
|
|
52
|
-
value,
|
|
53
|
-
operator: '$eq'
|
|
54
|
-
}]
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
let data = await crud.readDocument(request)
|
|
59
|
-
let response = {
|
|
60
|
-
element,
|
|
61
|
-
name,
|
|
62
|
-
unique: true
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// If a document is returned, unique is set to false
|
|
66
|
-
if (data.document && data.document.length) {
|
|
67
|
-
response.unique = false;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// If indexedb response is unique is true, check server response
|
|
71
|
-
if (response.unique) {
|
|
72
|
-
delete request.db
|
|
73
|
-
response = await crud.socket.send('isUnique', request)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Set unique attribute on the element
|
|
77
|
-
if (response.unique)
|
|
78
|
-
element.setAttribute('unique', true);
|
|
79
|
-
else
|
|
80
|
-
element.setAttribute('unique', false);
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
observer.init({
|
|
85
|
-
name: 'CoCreateUnique',
|
|
86
|
-
observe: ['addedNodes'],
|
|
87
|
-
target: '[unique]',
|
|
88
|
-
callback: mutation =>
|
|
89
|
-
init(mutation.target)
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
init();
|
|
93
|
-
|
|
1
|
+
import observer from '@cocreate/observer';
|
|
2
|
+
import crud from '@cocreate/crud-client';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Initializes input event listeners for the specified elements. This is a convenience method for calling setInputEvent on each element.
|
|
7
|
+
*
|
|
8
|
+
* @param elements - The HTMLElement or array of HTMLElements to listen
|
|
9
|
+
*/
|
|
10
|
+
function init(elements) {
|
|
11
|
+
// Returns an array of unique elements
|
|
12
|
+
if (!elements)
|
|
13
|
+
elements = document.querySelectorAll('[unique]')
|
|
14
|
+
// If elements is not an array of elements returns an array of elements.
|
|
15
|
+
else if (!Array.isArray(elements))
|
|
16
|
+
elements = [elements]
|
|
17
|
+
for (let element of elements)
|
|
18
|
+
setInputEvent(element)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Sets the input event to prevent duplicate. This is necessary because IE doesn't support unique = " true " in HTML5.
|
|
23
|
+
*
|
|
24
|
+
* @param input - The input element to listen for changes on. Note that it's an object
|
|
25
|
+
*/
|
|
26
|
+
function setInputEvent(input) {
|
|
27
|
+
let delayTimer
|
|
28
|
+
input.addEventListener('input', function () {
|
|
29
|
+
input.setAttribute('unique', true);
|
|
30
|
+
|
|
31
|
+
clearTimeout(delayTimer);
|
|
32
|
+
delayTimer = setTimeout(function () {
|
|
33
|
+
isUnique(input)
|
|
34
|
+
}, 1000);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Checks if a value is unique. This is a helper function for CRUD operations that need to be performed on documents in order to make sure they are unique.
|
|
40
|
+
*
|
|
41
|
+
* @param element - The element that is being checked for uniqueness. It should have the attribute ` name `
|
|
42
|
+
*/
|
|
43
|
+
async function isUnique(element) {
|
|
44
|
+
let name = element.getAttribute('name');
|
|
45
|
+
let value = element.getValue();
|
|
46
|
+
let request = {
|
|
47
|
+
db: 'indexeddb',
|
|
48
|
+
collection: element.getAttribute('collection'),
|
|
49
|
+
filter: {
|
|
50
|
+
query: [{
|
|
51
|
+
name,
|
|
52
|
+
value,
|
|
53
|
+
operator: '$eq'
|
|
54
|
+
}]
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
let data = await crud.readDocument(request)
|
|
59
|
+
let response = {
|
|
60
|
+
element,
|
|
61
|
+
name,
|
|
62
|
+
unique: true
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// If a document is returned, unique is set to false
|
|
66
|
+
if (data.document && data.document.length) {
|
|
67
|
+
response.unique = false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// If indexedb response is unique is true, check server response
|
|
71
|
+
if (response.unique) {
|
|
72
|
+
delete request.db
|
|
73
|
+
response = await crud.socket.send('isUnique', request)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Set unique attribute on the element
|
|
77
|
+
if (response.unique)
|
|
78
|
+
element.setAttribute('unique', true);
|
|
79
|
+
else
|
|
80
|
+
element.setAttribute('unique', false);
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
observer.init({
|
|
85
|
+
name: 'CoCreateUnique',
|
|
86
|
+
observe: ['addedNodes'],
|
|
87
|
+
target: '[unique]',
|
|
88
|
+
callback: mutation =>
|
|
89
|
+
init(mutation.target)
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
init();
|
|
93
|
+
|
|
94
94
|
export default { init, isUnique }
|
package/src/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
// Check if browser, return client or server file
|
|
2
|
-
(function (root, factory) {
|
|
3
|
-
if (typeof define === 'function' && define.amd) {
|
|
4
|
-
define(["./client.js"], function (CoCreateUnique) {
|
|
5
|
-
return factory(CoCreateUnique)
|
|
6
|
-
});
|
|
7
|
-
} else if (typeof module === 'object' && module.exports) {
|
|
8
|
-
const CoCreateUnique = require("./server.js")
|
|
9
|
-
module.exports = factory(CoCreateUnique);
|
|
10
|
-
} else {
|
|
11
|
-
root.returnExports = factory(root["./client.js"]);
|
|
12
|
-
}
|
|
13
|
-
}(typeof self !== 'undefined' ? self : this, function (CoCreateUnique) {
|
|
14
|
-
return CoCreateUnique;
|
|
1
|
+
// Check if browser, return client or server file
|
|
2
|
+
(function (root, factory) {
|
|
3
|
+
if (typeof define === 'function' && define.amd) {
|
|
4
|
+
define(["./client.js"], function (CoCreateUnique) {
|
|
5
|
+
return factory(CoCreateUnique)
|
|
6
|
+
});
|
|
7
|
+
} else if (typeof module === 'object' && module.exports) {
|
|
8
|
+
const CoCreateUnique = require("./server.js")
|
|
9
|
+
module.exports = factory(CoCreateUnique);
|
|
10
|
+
} else {
|
|
11
|
+
root.returnExports = factory(root["./client.js"]);
|
|
12
|
+
}
|
|
13
|
+
}(typeof self !== 'undefined' ? self : this, function (CoCreateUnique) {
|
|
14
|
+
return CoCreateUnique;
|
|
15
15
|
}));
|
package/src/server.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
class CoCreateUnique {
|
|
2
|
-
/**
|
|
3
|
-
* @param crud
|
|
4
|
-
*/
|
|
5
|
-
constructor(crud) {
|
|
6
|
-
this.wsManager = crud.wsManager
|
|
7
|
-
this.crud = crud
|
|
8
|
-
this.init();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
init() {
|
|
12
|
-
if (this.wsManager) {
|
|
13
|
-
this.wsManager.on('isUnique',
|
|
14
|
-
(socket, data) => this.isUnique(socket, data));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Checks if a document is unique by sending a message to the socket. This is a blocking call so it returns a Promise
|
|
21
|
-
*
|
|
22
|
-
* @param socket - the socket to send the message to
|
|
23
|
-
* @param data - the data to read from the database usually an object
|
|
24
|
-
*
|
|
25
|
-
* @return { Promise } - resolves with the response from the server or rejects with an error if there was a
|
|
26
|
-
*/
|
|
27
|
-
async isUnique(socket, data) {
|
|
28
|
-
const self = this
|
|
29
|
-
try {
|
|
30
|
-
this.crud.readDocument(data).then((data) => {
|
|
31
|
-
let response = {
|
|
32
|
-
unique: true,
|
|
33
|
-
uid: data.uid
|
|
34
|
-
};
|
|
35
|
-
// If the document is unique
|
|
36
|
-
if (data.document.length) {
|
|
37
|
-
response.unique = false;
|
|
38
|
-
}
|
|
39
|
-
return self.wsManager.send(socket, 'isUnique', response);
|
|
40
|
-
})
|
|
41
|
-
} catch (error) {
|
|
42
|
-
console.log(error);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
1
|
+
class CoCreateUnique {
|
|
2
|
+
/**
|
|
3
|
+
* @param crud
|
|
4
|
+
*/
|
|
5
|
+
constructor(crud) {
|
|
6
|
+
this.wsManager = crud.wsManager
|
|
7
|
+
this.crud = crud
|
|
8
|
+
this.init();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
init() {
|
|
12
|
+
if (this.wsManager) {
|
|
13
|
+
this.wsManager.on('isUnique',
|
|
14
|
+
(socket, data) => this.isUnique(socket, data));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Checks if a document is unique by sending a message to the socket. This is a blocking call so it returns a Promise
|
|
21
|
+
*
|
|
22
|
+
* @param socket - the socket to send the message to
|
|
23
|
+
* @param data - the data to read from the database usually an object
|
|
24
|
+
*
|
|
25
|
+
* @return { Promise } - resolves with the response from the server or rejects with an error if there was a
|
|
26
|
+
*/
|
|
27
|
+
async isUnique(socket, data) {
|
|
28
|
+
const self = this
|
|
29
|
+
try {
|
|
30
|
+
this.crud.readDocument(data).then((data) => {
|
|
31
|
+
let response = {
|
|
32
|
+
unique: true,
|
|
33
|
+
uid: data.uid
|
|
34
|
+
};
|
|
35
|
+
// If the document is unique
|
|
36
|
+
if (data.document.length) {
|
|
37
|
+
response.unique = false;
|
|
38
|
+
}
|
|
39
|
+
return self.wsManager.send(socket, 'isUnique', response);
|
|
40
|
+
})
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.log(error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
48
|
module.exports = CoCreateUnique;
|
package/webpack.config.js
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
const path = require("path")
|
|
2
|
-
const TerserPlugin = require("terser-webpack-plugin")
|
|
3
|
-
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
|
|
4
|
-
let isProduction = process.env.NODE_ENV === "production"
|
|
5
|
-
const { CleanWebpackPlugin } = require("clean-webpack-plugin")
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
entry: {
|
|
9
|
-
"CoCreate-unique": "./src/index.js",
|
|
10
|
-
},
|
|
11
|
-
output: {
|
|
12
|
-
path: path.resolve(__dirname, "dist"),
|
|
13
|
-
filename: isProduction ? "[name].min.js" : "[name].js",
|
|
14
|
-
libraryTarget: "umd",
|
|
15
|
-
libraryExport: "default",
|
|
16
|
-
library: ["CoCreate", "unique"],
|
|
17
|
-
globalObject: "this",
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
plugins: [
|
|
21
|
-
new CleanWebpackPlugin(),
|
|
22
|
-
new MiniCssExtractPlugin({
|
|
23
|
-
filename: "[name].css",
|
|
24
|
-
}),
|
|
25
|
-
],
|
|
26
|
-
// Default mode for Webpack is production.
|
|
27
|
-
// Depending on mode Webpack will apply different things
|
|
28
|
-
// on final bundle. For now we don't need production's JavaScript
|
|
29
|
-
// minifying and other thing so let's set mode to development
|
|
30
|
-
mode: isProduction ? "production" : "development",
|
|
31
|
-
module: {
|
|
32
|
-
rules: [
|
|
33
|
-
{
|
|
34
|
-
test: /.js$/,
|
|
35
|
-
exclude: /(node_modules)/,
|
|
36
|
-
use: {
|
|
37
|
-
loader: "babel-loader",
|
|
38
|
-
options: {
|
|
39
|
-
plugins: ["@babel/plugin-transform-modules-commonjs"],
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
test: /.css$/i,
|
|
45
|
-
use: [
|
|
46
|
-
{ loader: "style-loader", options: { injectType: "linkTag" } },
|
|
47
|
-
"file-loader",
|
|
48
|
-
],
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
// add source map
|
|
54
|
-
...(isProduction ? {} : { devtool: "eval-source-map" }),
|
|
55
|
-
|
|
56
|
-
optimization: {
|
|
57
|
-
minimize: true,
|
|
58
|
-
minimizer: [
|
|
59
|
-
new TerserPlugin({
|
|
60
|
-
extractComments: true,
|
|
61
|
-
// cache: true,
|
|
62
|
-
parallel: true,
|
|
63
|
-
// sourceMap: true, // Must be set to true if using source-maps in production
|
|
64
|
-
terserOptions: {
|
|
65
|
-
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
|
|
66
|
-
// extractComments: 'all',
|
|
67
|
-
compress: {
|
|
68
|
-
drop_console: true,
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
}),
|
|
72
|
-
],
|
|
73
|
-
splitChunks: {
|
|
74
|
-
chunks: "all",
|
|
75
|
-
minSize: 200,
|
|
76
|
-
// maxSize: 99999,
|
|
77
|
-
//minChunks: 1,
|
|
78
|
-
|
|
79
|
-
cacheGroups: {
|
|
80
|
-
defaultVendors: false,
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
}
|
|
1
|
+
const path = require("path")
|
|
2
|
+
const TerserPlugin = require("terser-webpack-plugin")
|
|
3
|
+
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
|
|
4
|
+
let isProduction = process.env.NODE_ENV === "production"
|
|
5
|
+
const { CleanWebpackPlugin } = require("clean-webpack-plugin")
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
entry: {
|
|
9
|
+
"CoCreate-unique": "./src/index.js",
|
|
10
|
+
},
|
|
11
|
+
output: {
|
|
12
|
+
path: path.resolve(__dirname, "dist"),
|
|
13
|
+
filename: isProduction ? "[name].min.js" : "[name].js",
|
|
14
|
+
libraryTarget: "umd",
|
|
15
|
+
libraryExport: "default",
|
|
16
|
+
library: ["CoCreate", "unique"],
|
|
17
|
+
globalObject: "this",
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
plugins: [
|
|
21
|
+
new CleanWebpackPlugin(),
|
|
22
|
+
new MiniCssExtractPlugin({
|
|
23
|
+
filename: "[name].css",
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
// Default mode for Webpack is production.
|
|
27
|
+
// Depending on mode Webpack will apply different things
|
|
28
|
+
// on final bundle. For now we don't need production's JavaScript
|
|
29
|
+
// minifying and other thing so let's set mode to development
|
|
30
|
+
mode: isProduction ? "production" : "development",
|
|
31
|
+
module: {
|
|
32
|
+
rules: [
|
|
33
|
+
{
|
|
34
|
+
test: /.js$/,
|
|
35
|
+
exclude: /(node_modules)/,
|
|
36
|
+
use: {
|
|
37
|
+
loader: "babel-loader",
|
|
38
|
+
options: {
|
|
39
|
+
plugins: ["@babel/plugin-transform-modules-commonjs"],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
test: /.css$/i,
|
|
45
|
+
use: [
|
|
46
|
+
{ loader: "style-loader", options: { injectType: "linkTag" } },
|
|
47
|
+
"file-loader",
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
// add source map
|
|
54
|
+
...(isProduction ? {} : { devtool: "eval-source-map" }),
|
|
55
|
+
|
|
56
|
+
optimization: {
|
|
57
|
+
minimize: true,
|
|
58
|
+
minimizer: [
|
|
59
|
+
new TerserPlugin({
|
|
60
|
+
extractComments: true,
|
|
61
|
+
// cache: true,
|
|
62
|
+
parallel: true,
|
|
63
|
+
// sourceMap: true, // Must be set to true if using source-maps in production
|
|
64
|
+
terserOptions: {
|
|
65
|
+
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
|
|
66
|
+
// extractComments: 'all',
|
|
67
|
+
compress: {
|
|
68
|
+
drop_console: true,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
],
|
|
73
|
+
splitChunks: {
|
|
74
|
+
chunks: "all",
|
|
75
|
+
minSize: 200,
|
|
76
|
+
// maxSize: 99999,
|
|
77
|
+
//minChunks: 1,
|
|
78
|
+
|
|
79
|
+
cacheGroups: {
|
|
80
|
+
defaultVendors: false,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
}
|