leanweb 1.2.8 → 1.3.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/commands/build.js +9 -1
- package/commands/dist.js +1 -2
- package/commands/init.js +2 -1
- package/package.json +1 -1
- package/templates/lib/lw-element.js +19 -17
package/commands/build.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import fse from 'fs-extra';
|
|
3
|
+
import { minify } from 'html-minifier';
|
|
3
4
|
import * as utils from './utils.js';
|
|
4
5
|
import * as parser from '../lib/lw-html-parser.js';
|
|
5
6
|
|
|
@@ -88,7 +89,14 @@ const require = createRequire(import.meta.url);
|
|
|
88
89
|
}
|
|
89
90
|
const styleString = cssString || '';
|
|
90
91
|
const htmlString = fs.readFileSync(htmlFilename, 'utf8');
|
|
91
|
-
const
|
|
92
|
+
const minifiedHtml = minify(htmlString, {
|
|
93
|
+
caseSensitive: true,
|
|
94
|
+
collapseWhitespace: true,
|
|
95
|
+
minifyCSS: true,
|
|
96
|
+
minifyJS: true,
|
|
97
|
+
removeComments: true,
|
|
98
|
+
});
|
|
99
|
+
const ast = parser.parse(minifiedHtml);
|
|
92
100
|
ast.css = styleString;
|
|
93
101
|
ast.componentFullName = project.name + '-' + cmp.replace(/\//g, '-');
|
|
94
102
|
ast.runtimeVersion = project.version;
|
package/commands/dist.js
CHANGED
|
@@ -2,7 +2,6 @@ import webpack from 'webpack';
|
|
|
2
2
|
import * as utils from './utils.js';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import fse from 'fs-extra';
|
|
5
|
-
// const minify = require('html-minifier').minify;
|
|
6
5
|
import { minify } from 'html-minifier';
|
|
7
6
|
import CleanCSS from 'clean-css';
|
|
8
7
|
|
|
@@ -49,7 +48,7 @@ if (args.length >= 3) {
|
|
|
49
48
|
collapseWhitespace: true,
|
|
50
49
|
minifyCSS: true,
|
|
51
50
|
minifyJS: true,
|
|
52
|
-
|
|
51
|
+
removeComments: true,
|
|
53
52
|
});
|
|
54
53
|
fs.writeFileSync(`./${utils.dirs.dist}/index.html`, minifiedIndexHtml);
|
|
55
54
|
|
package/commands/init.js
CHANGED
|
@@ -103,7 +103,8 @@ const require = createRequire(import.meta.url);
|
|
|
103
103
|
});
|
|
104
104
|
console.log('\nSome useful commands:');
|
|
105
105
|
console.log('"lw s" to start the dev server.');
|
|
106
|
-
console.log('"lw
|
|
106
|
+
console.log('"lw di" to build for production. The output will be in dist/ directory.');
|
|
107
107
|
console.log('"lw g my-new-component" to generate a new standard web component.');
|
|
108
|
+
console.log('"lw h" to get more help information.');
|
|
108
109
|
}
|
|
109
110
|
})();
|
package/package.json
CHANGED
|
@@ -143,7 +143,6 @@ export default class LWElement extends HTMLElement {
|
|
|
143
143
|
this._bindModels(rootNode);
|
|
144
144
|
this._bindEvents(rootNode);
|
|
145
145
|
this._bindInputs(rootNode);
|
|
146
|
-
rootNode.removeAttribute('lw-elem-bind');
|
|
147
146
|
}
|
|
148
147
|
if (rootNode.hasAttribute('lw-if')) {
|
|
149
148
|
this.updateIf(rootNode);
|
|
@@ -162,11 +161,17 @@ export default class LWElement extends HTMLElement {
|
|
|
162
161
|
const treeWalker = document.createTreeWalker(rootNode, NodeFilter.SHOW_ELEMENT, {
|
|
163
162
|
acceptNode: node => {
|
|
164
163
|
if (node.hasAttribute('lw-elem')) {
|
|
164
|
+
if (node.hasAttribute('lw-for')) {
|
|
165
|
+
this.updateFor(node);
|
|
166
|
+
return NodeFilter.FILTER_REJECT;
|
|
167
|
+
}
|
|
168
|
+
if (node.hasAttribute('lw-for-parent')) {
|
|
169
|
+
return NodeFilter.FILTER_REJECT;
|
|
170
|
+
}
|
|
165
171
|
if (node.hasAttribute('lw-elem-bind')) {
|
|
166
172
|
this._bindModels(node);
|
|
167
173
|
this._bindEvents(node);
|
|
168
174
|
this._bindInputs(node);
|
|
169
|
-
node.removeAttribute('lw-elem-bind');
|
|
170
175
|
}
|
|
171
176
|
if (node.hasAttribute('lw-if')) {
|
|
172
177
|
this.updateIf(node);
|
|
@@ -174,13 +179,6 @@ export default class LWElement extends HTMLElement {
|
|
|
174
179
|
if (node.hasAttribute('lw-false')) {
|
|
175
180
|
return NodeFilter.FILTER_REJECT;
|
|
176
181
|
}
|
|
177
|
-
if (node.hasAttribute('lw-for-parent')) {
|
|
178
|
-
return NodeFilter.FILTER_REJECT;
|
|
179
|
-
}
|
|
180
|
-
if (node.hasAttribute('lw-for')) {
|
|
181
|
-
this.updateFor(node);
|
|
182
|
-
return NodeFilter.FILTER_REJECT;
|
|
183
|
-
}
|
|
184
182
|
this.updateEval(node);
|
|
185
183
|
this.updateClass(node);
|
|
186
184
|
this.updateBind(node);
|
|
@@ -203,6 +201,10 @@ export default class LWElement extends HTMLElement {
|
|
|
203
201
|
}
|
|
204
202
|
|
|
205
203
|
_bindInputs(inputNode) {
|
|
204
|
+
if (inputNode['lw_input_bound']) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
inputNode['lw_input_bound'] = true;
|
|
206
208
|
for (const attr of inputNode.attributes) {
|
|
207
209
|
const attrName = attr.name;
|
|
208
210
|
const attrValue = attr.value;
|
|
@@ -218,17 +220,17 @@ export default class LWElement extends HTMLElement {
|
|
|
218
220
|
}
|
|
219
221
|
|
|
220
222
|
// properties:
|
|
221
|
-
//
|
|
223
|
+
// lw_event_bound: boolean
|
|
222
224
|
_bindEvents(eventNode) {
|
|
225
|
+
if (eventNode['lw_event_bound']) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
eventNode['lw_event_bound'] = true;
|
|
223
229
|
const me = this;
|
|
224
230
|
for (const attr of eventNode.attributes) {
|
|
225
231
|
const attrName = attr.name;
|
|
226
232
|
const attrValue = attr.value;
|
|
227
233
|
if (attrName.startsWith('lw-on:')) {
|
|
228
|
-
if (eventNode[attrName]) {
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
eventNode[attrName] = true;
|
|
232
234
|
const interpolation = this.ast[attrValue];
|
|
233
235
|
interpolation.lwValue.split(',').forEach(eventType => {
|
|
234
236
|
eventNode.addEventListener(eventType.trim(), (event => {
|
|
@@ -250,16 +252,16 @@ export default class LWElement extends HTMLElement {
|
|
|
250
252
|
}
|
|
251
253
|
|
|
252
254
|
// properties:
|
|
253
|
-
//
|
|
255
|
+
// lw_model_bound: boolean
|
|
254
256
|
_bindModels(modelNode) {
|
|
255
257
|
const key = modelNode.getAttribute('lw-model');
|
|
256
258
|
if (!key) {
|
|
257
259
|
return;
|
|
258
260
|
}
|
|
259
|
-
if (modelNode['
|
|
261
|
+
if (modelNode['lw_model_bound']) {
|
|
260
262
|
return;
|
|
261
263
|
}
|
|
262
|
-
modelNode['
|
|
264
|
+
modelNode['lw_model_bound'] = true;
|
|
263
265
|
const interpolation = this.ast[key];
|
|
264
266
|
modelNode.addEventListener('input', (event => {
|
|
265
267
|
const context = this._getNodeContext(modelNode);
|