@cocreate/element-prototype 1.8.13 → 1.8.14
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 +661 -654
- package/CONTRIBUTING.md +96 -96
- package/CoCreate.config.js +26 -26
- package/LICENSE +21 -21
- package/README.md +84 -84
- package/demo/index.html +20 -20
- package/docs/index.html +262 -262
- package/package.json +66 -66
- package/release.config.js +21 -21
- package/src/getValue.js +101 -101
- package/src/index.js +11 -11
- package/src/setValue.js +199 -199
- package/webpack.config.js +84 -84
package/src/setValue.js
CHANGED
|
@@ -1,199 +1,199 @@
|
|
|
1
|
-
import { getAttributes } from '@cocreate/utils';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
HTMLElement.prototype.setValue = function (value) {
|
|
5
|
-
setValue(this, value)
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
HTMLInputElement.prototype.setValue = function (value) {
|
|
9
|
-
setValue(this, value)
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
HTMLHeadingElement.prototype.setValue = function (value) {
|
|
14
|
-
setValue(this, value)
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const setValue = (el, value) => {
|
|
19
|
-
if (value === null || value === undefined) return;
|
|
20
|
-
let valueType = el.getAttribute('value-type');
|
|
21
|
-
let prefix = el.getAttribute('value-prefix') || "";
|
|
22
|
-
let suffix = el.getAttribute('value-suffix') || "";
|
|
23
|
-
if (prefix)
|
|
24
|
-
value = value.replace(prefix, "");
|
|
25
|
-
if (suffix)
|
|
26
|
-
value = value.replace(suffix, "");
|
|
27
|
-
|
|
28
|
-
if (el.tagName == 'INPUT' || el.tagName == 'TEXTAREA' || el.tagName == 'SELECT') {
|
|
29
|
-
let { isCrdt } = getAttributes(el)
|
|
30
|
-
if (isCrdt == null || isCrdt == undefined)
|
|
31
|
-
isCrdt = el.getAttribute('crdt')
|
|
32
|
-
if (isCrdt == "true" || el.type === 'file') return;
|
|
33
|
-
|
|
34
|
-
if (el.type == 'checkbox') {
|
|
35
|
-
let inputs = [el]
|
|
36
|
-
let name = el.getAttribute('name');
|
|
37
|
-
if (name)
|
|
38
|
-
inputs = document.querySelectorAll(`input[type="${el.type}"][name="${name}"]`);
|
|
39
|
-
|
|
40
|
-
for (let i = 0; i < inputs.length; i++) {
|
|
41
|
-
if (inputs[i].value) {
|
|
42
|
-
if (value.includes(inputs[i].value))
|
|
43
|
-
inputs[i].checked = true;
|
|
44
|
-
else
|
|
45
|
-
inputs[i].checked = false;
|
|
46
|
-
} else {
|
|
47
|
-
if (value === 'true' || value === true || value === 'checked')
|
|
48
|
-
inputs[i].checked = true;
|
|
49
|
-
else
|
|
50
|
-
inputs[i].checked = false;
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else if (el.type === 'radio') {
|
|
56
|
-
el.value == value ? el.checked = true : el.checked = false;
|
|
57
|
-
}
|
|
58
|
-
else if (el.type === 'password') {
|
|
59
|
-
el.value = __decryptPassword(value);
|
|
60
|
-
}
|
|
61
|
-
else if (el.tagName == "SELECT" && el.hasAttribute('multiple') && Array.isArray(value)) {
|
|
62
|
-
let options = el.options;
|
|
63
|
-
for (let i = 0; i < options.length; i++) {
|
|
64
|
-
if (value.includes(options[i].value)) {
|
|
65
|
-
options[i].selected = "selected";
|
|
66
|
-
} else {
|
|
67
|
-
options[i].selected = "";
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else
|
|
72
|
-
el.value = value;
|
|
73
|
-
dispatchEvents(el)
|
|
74
|
-
}
|
|
75
|
-
else if (el.tagName === 'IMG' || el.tagName === 'SOURCE')
|
|
76
|
-
el.src = value;
|
|
77
|
-
|
|
78
|
-
else if (el.tagName === 'IFRAME')
|
|
79
|
-
el.srcdoc = value;
|
|
80
|
-
|
|
81
|
-
else if (el.tagName === 'SCRIPT')
|
|
82
|
-
setScript(el, value);
|
|
83
|
-
|
|
84
|
-
else {
|
|
85
|
-
if (el.hasAttribute('contenteditable') && el == document.activeElement) return;
|
|
86
|
-
// if (el.tagName === 'DIV') {
|
|
87
|
-
// if (!el.classList.contains('domEditor')
|
|
88
|
-
// return
|
|
89
|
-
// }
|
|
90
|
-
|
|
91
|
-
if (valueType == 'string' || valueType == 'text')
|
|
92
|
-
el.textContent = value;
|
|
93
|
-
else {
|
|
94
|
-
let newElement = document.createElement("div");
|
|
95
|
-
newElement.innerHTML = value;
|
|
96
|
-
setPass(newElement)
|
|
97
|
-
|
|
98
|
-
let CoCreateJS = newElement.querySelector('script[src*="CoCreate.js"], script[src*="CoCreate.min.js"]')
|
|
99
|
-
if (CoCreateJS)
|
|
100
|
-
CoCreateJS.remove()
|
|
101
|
-
|
|
102
|
-
let CoCreateCSS = newElement.querySelector('link[href*="CoCreate.css"], link[href*="CoCreate.min.css"]')
|
|
103
|
-
if (CoCreateCSS)
|
|
104
|
-
CoCreateCSS.remove()
|
|
105
|
-
|
|
106
|
-
let css = newElement.querySelector('link[collection], link[document]')
|
|
107
|
-
if (css)
|
|
108
|
-
css.remove()
|
|
109
|
-
|
|
110
|
-
if (el.getAttribute('domEditor') == "replace") {
|
|
111
|
-
let parentNode = el.parentNode;
|
|
112
|
-
if (parentNode) {
|
|
113
|
-
if (newElement.children[0]) {
|
|
114
|
-
parentNode.replaceChild(newElement.children[0], el);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
parentNode.replaceChild(newElement, el);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
} else {
|
|
121
|
-
el.innerHTML = newElement.innerHTML;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (el.hasAttribute("value")) {
|
|
126
|
-
el.setAttribute("value", value);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (el.getAttribute('contenteditable'))
|
|
131
|
-
dispatchEvents(el);
|
|
132
|
-
|
|
133
|
-
if (el.tagName == 'HEAD' || el.tagName == 'BODY') {
|
|
134
|
-
el.removeAttribute('collection');
|
|
135
|
-
el.removeAttribute('document_id');
|
|
136
|
-
el.removeAttribute('pass_id');
|
|
137
|
-
|
|
138
|
-
let scripts = el.querySelectorAll('script');
|
|
139
|
-
for (let script of scripts) {
|
|
140
|
-
setScript(script)
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
function setPass(el) {
|
|
146
|
-
if (CoCreate.pass) {
|
|
147
|
-
let passElements = el.querySelectorAll('[pass_id]');
|
|
148
|
-
if (passElements)
|
|
149
|
-
CoCreate.pass.initElements(passElements)
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function setScript(script, value) {
|
|
154
|
-
let newScript = document.createElement('script');
|
|
155
|
-
newScript.attributes = script.attributes;
|
|
156
|
-
newScript.innerHTML = script.innerHTML;
|
|
157
|
-
if (value) {
|
|
158
|
-
if (script.hasAttribute("src"))
|
|
159
|
-
newScript.src = value;
|
|
160
|
-
else
|
|
161
|
-
newScript.innerHTML = value;
|
|
162
|
-
}
|
|
163
|
-
script.replaceWith(newScript);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function __decryptPassword(str) {
|
|
167
|
-
if (!str) return "";
|
|
168
|
-
let decode_str = atob(str);
|
|
169
|
-
return decode_str;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function dispatchEvents(el) {
|
|
173
|
-
let inputEvent = new CustomEvent('input', {
|
|
174
|
-
bubbles: true,
|
|
175
|
-
detail: {
|
|
176
|
-
skip: true
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
Object.defineProperty(inputEvent, 'target', {
|
|
180
|
-
writable: false,
|
|
181
|
-
value: el
|
|
182
|
-
});
|
|
183
|
-
el.dispatchEvent(inputEvent);
|
|
184
|
-
|
|
185
|
-
let changeEvent = new CustomEvent('change', {
|
|
186
|
-
bubbles: true,
|
|
187
|
-
detail: {
|
|
188
|
-
skip: true
|
|
189
|
-
},
|
|
190
|
-
});
|
|
191
|
-
Object.defineProperty(changeEvent, 'target', {
|
|
192
|
-
writable: false,
|
|
193
|
-
value: el
|
|
194
|
-
});
|
|
195
|
-
el.dispatchEvent(changeEvent);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
export { setValue };
|
|
1
|
+
import { getAttributes } from '@cocreate/utils';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
HTMLElement.prototype.setValue = function (value) {
|
|
5
|
+
setValue(this, value)
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
HTMLInputElement.prototype.setValue = function (value) {
|
|
9
|
+
setValue(this, value)
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
HTMLHeadingElement.prototype.setValue = function (value) {
|
|
14
|
+
setValue(this, value)
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const setValue = (el, value) => {
|
|
19
|
+
if (value === null || value === undefined) return;
|
|
20
|
+
let valueType = el.getAttribute('value-type');
|
|
21
|
+
let prefix = el.getAttribute('value-prefix') || "";
|
|
22
|
+
let suffix = el.getAttribute('value-suffix') || "";
|
|
23
|
+
if (prefix)
|
|
24
|
+
value = value.replace(prefix, "");
|
|
25
|
+
if (suffix)
|
|
26
|
+
value = value.replace(suffix, "");
|
|
27
|
+
|
|
28
|
+
if (el.tagName == 'INPUT' || el.tagName == 'TEXTAREA' || el.tagName == 'SELECT') {
|
|
29
|
+
let { isCrdt } = getAttributes(el)
|
|
30
|
+
if (isCrdt == null || isCrdt == undefined)
|
|
31
|
+
isCrdt = el.getAttribute('crdt')
|
|
32
|
+
if (isCrdt == "true" || el.type === 'file') return;
|
|
33
|
+
|
|
34
|
+
if (el.type == 'checkbox') {
|
|
35
|
+
let inputs = [el]
|
|
36
|
+
let name = el.getAttribute('name');
|
|
37
|
+
if (name)
|
|
38
|
+
inputs = document.querySelectorAll(`input[type="${el.type}"][name="${name}"]`);
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
41
|
+
if (inputs[i].value) {
|
|
42
|
+
if (value.includes(inputs[i].value))
|
|
43
|
+
inputs[i].checked = true;
|
|
44
|
+
else
|
|
45
|
+
inputs[i].checked = false;
|
|
46
|
+
} else {
|
|
47
|
+
if (value === 'true' || value === true || value === 'checked')
|
|
48
|
+
inputs[i].checked = true;
|
|
49
|
+
else
|
|
50
|
+
inputs[i].checked = false;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (el.type === 'radio') {
|
|
56
|
+
el.value == value ? el.checked = true : el.checked = false;
|
|
57
|
+
}
|
|
58
|
+
else if (el.type === 'password') {
|
|
59
|
+
el.value = __decryptPassword(value);
|
|
60
|
+
}
|
|
61
|
+
else if (el.tagName == "SELECT" && el.hasAttribute('multiple') && Array.isArray(value)) {
|
|
62
|
+
let options = el.options;
|
|
63
|
+
for (let i = 0; i < options.length; i++) {
|
|
64
|
+
if (value.includes(options[i].value)) {
|
|
65
|
+
options[i].selected = "selected";
|
|
66
|
+
} else {
|
|
67
|
+
options[i].selected = "";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else
|
|
72
|
+
el.value = value;
|
|
73
|
+
dispatchEvents(el)
|
|
74
|
+
}
|
|
75
|
+
else if (el.tagName === 'IMG' || el.tagName === 'SOURCE')
|
|
76
|
+
el.src = value;
|
|
77
|
+
|
|
78
|
+
else if (el.tagName === 'IFRAME')
|
|
79
|
+
el.srcdoc = value;
|
|
80
|
+
|
|
81
|
+
else if (el.tagName === 'SCRIPT')
|
|
82
|
+
setScript(el, value);
|
|
83
|
+
|
|
84
|
+
else {
|
|
85
|
+
if (el.hasAttribute('contenteditable') && el == document.activeElement) return;
|
|
86
|
+
// if (el.tagName === 'DIV') {
|
|
87
|
+
// if (!el.classList.contains('domEditor')
|
|
88
|
+
// return
|
|
89
|
+
// }
|
|
90
|
+
|
|
91
|
+
if (valueType == 'string' || valueType == 'text')
|
|
92
|
+
el.textContent = value;
|
|
93
|
+
else {
|
|
94
|
+
let newElement = document.createElement("div");
|
|
95
|
+
newElement.innerHTML = value;
|
|
96
|
+
setPass(newElement)
|
|
97
|
+
|
|
98
|
+
let CoCreateJS = newElement.querySelector('script[src*="CoCreate.js"], script[src*="CoCreate.min.js"]')
|
|
99
|
+
if (CoCreateJS)
|
|
100
|
+
CoCreateJS.remove()
|
|
101
|
+
|
|
102
|
+
let CoCreateCSS = newElement.querySelector('link[href*="CoCreate.css"], link[href*="CoCreate.min.css"]')
|
|
103
|
+
if (CoCreateCSS)
|
|
104
|
+
CoCreateCSS.remove()
|
|
105
|
+
|
|
106
|
+
let css = newElement.querySelector('link[collection], link[document]')
|
|
107
|
+
if (css)
|
|
108
|
+
css.remove()
|
|
109
|
+
|
|
110
|
+
if (el.getAttribute('domEditor') == "replace") {
|
|
111
|
+
let parentNode = el.parentNode;
|
|
112
|
+
if (parentNode) {
|
|
113
|
+
if (newElement.children[0]) {
|
|
114
|
+
parentNode.replaceChild(newElement.children[0], el);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
parentNode.replaceChild(newElement, el);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
el.innerHTML = newElement.innerHTML;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (el.hasAttribute("value")) {
|
|
126
|
+
el.setAttribute("value", value);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (el.getAttribute('contenteditable'))
|
|
131
|
+
dispatchEvents(el);
|
|
132
|
+
|
|
133
|
+
if (el.tagName == 'HEAD' || el.tagName == 'BODY') {
|
|
134
|
+
el.removeAttribute('collection');
|
|
135
|
+
el.removeAttribute('document_id');
|
|
136
|
+
el.removeAttribute('pass_id');
|
|
137
|
+
|
|
138
|
+
let scripts = el.querySelectorAll('script');
|
|
139
|
+
for (let script of scripts) {
|
|
140
|
+
setScript(script)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
function setPass(el) {
|
|
146
|
+
if (CoCreate.pass) {
|
|
147
|
+
let passElements = el.querySelectorAll('[pass_id]');
|
|
148
|
+
if (passElements)
|
|
149
|
+
CoCreate.pass.initElements(passElements)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function setScript(script, value) {
|
|
154
|
+
let newScript = document.createElement('script');
|
|
155
|
+
newScript.attributes = script.attributes;
|
|
156
|
+
newScript.innerHTML = script.innerHTML;
|
|
157
|
+
if (value) {
|
|
158
|
+
if (script.hasAttribute("src"))
|
|
159
|
+
newScript.src = value;
|
|
160
|
+
else
|
|
161
|
+
newScript.innerHTML = value;
|
|
162
|
+
}
|
|
163
|
+
script.replaceWith(newScript);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function __decryptPassword(str) {
|
|
167
|
+
if (!str) return "";
|
|
168
|
+
let decode_str = atob(str);
|
|
169
|
+
return decode_str;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function dispatchEvents(el) {
|
|
173
|
+
let inputEvent = new CustomEvent('input', {
|
|
174
|
+
bubbles: true,
|
|
175
|
+
detail: {
|
|
176
|
+
skip: true
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
Object.defineProperty(inputEvent, 'target', {
|
|
180
|
+
writable: false,
|
|
181
|
+
value: el
|
|
182
|
+
});
|
|
183
|
+
el.dispatchEvent(inputEvent);
|
|
184
|
+
|
|
185
|
+
let changeEvent = new CustomEvent('change', {
|
|
186
|
+
bubbles: true,
|
|
187
|
+
detail: {
|
|
188
|
+
skip: true
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
Object.defineProperty(changeEvent, 'target', {
|
|
192
|
+
writable: false,
|
|
193
|
+
value: el
|
|
194
|
+
});
|
|
195
|
+
el.dispatchEvent(changeEvent);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
export { setValue };
|
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-element-prototype": "./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", "element-prototype"],
|
|
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-element-prototype": "./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", "element-prototype"],
|
|
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
|
+
}
|