leanweb 1.1.7 → 1.2.0

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/README.md CHANGED
@@ -488,21 +488,6 @@ Importing a JSON file:
488
488
  import someJSON from "./some.json";
489
489
  ```
490
490
 
491
- Importing CSS/SCSS:
492
-
493
- ```javascript
494
- import agate from "/node_modules/highlight.js/scss/agate.scss";
495
-
496
- // customElements.define('demo-root',
497
- // class extends LWElement { // LWElement extends HTMLElement
498
- // constructor() {
499
- // super(ast);
500
- super.applyStyles(agate);
501
- // }
502
- // }
503
- //);
504
- ```
505
-
506
491
  ## Component Communication
507
492
 
508
493
  The following project demonstrates how Leanweb helps web components to talk to
@@ -674,11 +659,6 @@ Called when the componnet `lw-if` is evaluated `false`.
674
659
  If `urlHashChanged()` is defined as a function, it will be called whenever the
675
660
  urlHash changes. This could be useful to update the DOM in component routing.
676
661
 
677
- #### applyStyles(...styles)
678
-
679
- `applyStyles` will apply the styles that is imported from a css or scss into
680
- the web component DOM.
681
-
682
662
  ### LWEventBus
683
663
 
684
664
  `LWElement` comes with a global instance of `LWEventBus` that helps web
@@ -708,6 +688,11 @@ being notified when a next event is fired.
708
688
  parameters. `eventName` is the name of the event, and `data` is the payload data
709
689
  of the event.
710
690
 
691
+ ### Post dist hook
692
+
693
+ If `post-dist` file is present in the project root directory, it will be called
694
+ after `lw dist` is done. This could be useful to copy dist/\* to somewhere else.
695
+
711
696
  ## More examples and tutorials
712
697
 
713
698
  https://leanweb.app
package/commands/build.js CHANGED
@@ -81,10 +81,10 @@ const require = createRequire(import.meta.url);
81
81
  const scssFileExists = fs.existsSync(scssFilename);
82
82
  let cssString = '';
83
83
  if (scssFileExists) {
84
- let scssString = `@use "${buildDir}/global-styles.scss";\n`;
84
+ let scssString = `@use "global-styles.scss";\n`;
85
85
  scssString += fs.readFileSync(scssFilename, 'utf8');
86
86
  scssString += '\n[lw-false],[lw-for]{display:none !important;}\n';
87
- cssString = utils.buildCSS(scssString, `${buildDir}/components/${cmp}`);
87
+ cssString = utils.buildCSS(scssString, buildDir, `${buildDir}/components/${cmp}`);
88
88
  }
89
89
  const styleString = cssString || '';
90
90
  const htmlString = fs.readFileSync(htmlFilename, 'utf8');
package/commands/dist.js CHANGED
@@ -61,5 +61,9 @@ if (args.length >= 3) {
61
61
  project.resources?.forEach(resource => {
62
62
  fse.copySync(`./${utils.dirs.build}/${resource}`, `./${utils.dirs.dist}/${resource}`, { dereference: true });
63
63
  });
64
+
65
+ if (fs.statSync(`./post-dist`).isFile()) {
66
+ await utils.exec(`./post-dist`);
67
+ }
64
68
  });
65
69
  })();
package/commands/utils.js CHANGED
@@ -28,10 +28,10 @@ export const copySymbolLinkFilter = (src, dest) => {
28
28
 
29
29
  export const exec = command => execSync(command, { encoding: 'utf8', stdio: 'inherit' });
30
30
 
31
- export const buildCSS = (scssString, currentPaths) => {
31
+ export const buildCSS = (scssString, ...currentPaths) => {
32
32
  if (scssString.trim()) {
33
- const includePaths = [currentPaths, path.resolve(process.cwd(), dirs.build), path.resolve(process.cwd(), 'node_modules')];
34
- const cssResult = sass.renderSync({ data: scssString, includePaths });
33
+ const loadPaths = [...currentPaths, path.resolve(process.cwd(), dirs.build), path.resolve(process.cwd(), 'node_modules')];
34
+ const cssResult = sass.compileString(scssString, { loadPaths });
35
35
  return cssResult.css.toString().trim();
36
36
  }
37
37
  return '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leanweb",
3
- "version": "1.1.7",
3
+ "version": "1.2.0",
4
4
  "description": "Builds framework agnostic web components.",
5
5
  "bin": {
6
6
  "leanweb": "leanweb.js",
@@ -20,25 +20,25 @@
20
20
  "author": "Qian Chen",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "@babel/core": "^7.17.0",
24
- "@babel/parser": "^7.17.0",
25
- "@babel/plugin-transform-runtime": "^7.17.0",
26
- "@babel/preset-env": "^7.16.11",
27
- "babel-loader": "^8.2.3",
28
- "clean-css": "^5.2.4",
29
- "css-loader": "^6.6.0",
30
- "fs-extra": "^10.0.0",
31
- "globby": "^13.1.1",
23
+ "@babel/core": "^7.18.10",
24
+ "@babel/parser": "^7.18.10",
25
+ "@babel/plugin-transform-runtime": "^7.18.10",
26
+ "@babel/preset-env": "^7.18.10",
27
+ "babel-loader": "^8.2.5",
28
+ "clean-css": "^5.3.1",
29
+ "css-loader": "^6.7.1",
30
+ "fs-extra": "^10.1.0",
31
+ "globby": "^13.1.2",
32
32
  "html-minifier": "^4.0.0",
33
- "isomorphic-git": "^1.11.2",
33
+ "isomorphic-git": "^1.19.1",
34
34
  "json5-loader": "^4.0.1",
35
35
  "node-watch": "^0.7.3",
36
- "parse5": "^6.0.1",
36
+ "parse5": "^7.0.0",
37
37
  "raw-loader": "^4.0.2",
38
- "sass": "^1.49.7",
39
- "sass-loader": "^12.4.0",
40
- "semver": "^7.3.5",
41
- "webpack": "^5.68.0",
42
- "webpack-dev-server": "^4.7.4"
38
+ "sass": "^1.54.2",
39
+ "sass-loader": "^13.0.2",
40
+ "semver": "^7.3.7",
41
+ "webpack": "^5.74.0",
42
+ "webpack-dev-server": "^4.9.3"
43
43
  }
44
44
  }
@@ -193,7 +193,7 @@ export default class LWElement extends HTMLElement {
193
193
  }
194
194
 
195
195
  _bindMethods() {
196
- const methodNames = ['update', 'applyStyles'];
196
+ const methodNames = ['update'];
197
197
  const proto = Object.getPrototypeOf(this);
198
198
  methodNames.push(...Object.getOwnPropertyNames(proto).filter(name => hasMethod(proto, name)));
199
199
  methodNames.push(...Object.getOwnPropertyNames(this).filter(name => hasMethod(this, name)));
@@ -467,18 +467,4 @@ export default class LWElement extends HTMLElement {
467
467
  this.update(node);
468
468
  });
469
469
  }
470
-
471
- applyStyles(...styles) {
472
- if (!styles) {
473
- return;
474
- }
475
- styles.forEach(style => {
476
- if (typeof style !== 'string') {
477
- style = style.toString();
478
- }
479
- const styleNode = document.createElement('style');
480
- styleNode.innerHTML = style;
481
- this.shadowRoot.appendChild(styleNode);
482
- });
483
- }
484
470
  }