leanweb 3.0.9 → 3.10.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 +17 -2
- package/commands/dist.js +0 -1
- package/package.json +1 -1
- package/templates/lib/lw-element.js +10 -1
package/commands/build.js
CHANGED
|
@@ -40,10 +40,24 @@ const buildModule = (projectPath) => {
|
|
|
40
40
|
const cmpName = utils.getComponentName(cur);
|
|
41
41
|
let importString = `import './components/${cur}/${cmpName}.js';`;
|
|
42
42
|
return acc + importString + '\n';
|
|
43
|
-
}, '');
|
|
43
|
+
}, `import './global-styles.js';\n`);
|
|
44
44
|
utils.writeIfChanged(`${utils.dirs.build}/${project.name}.js`, jsString);
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
+
const buildGlobalStyles = () => {
|
|
48
|
+
const globalCssPath = `${utils.dirs.build}/global-styles.css`;
|
|
49
|
+
const globalCss = fs.existsSync(globalCssPath) ? fs.readFileSync(globalCssPath, 'utf8') : '';
|
|
50
|
+
|
|
51
|
+
// Extract @import statements and create a JS module that sets up the global styles, including the inline styles and the imports, and write it to global-styles.js
|
|
52
|
+
const imports = [];
|
|
53
|
+
const inlineCss = globalCss.replace(/@import\s+(?:url\()?['"]?([^'"\)]+)['"]?\)?[^;]*;/g, (_, url) => {
|
|
54
|
+
imports.push(url);
|
|
55
|
+
return '';
|
|
56
|
+
});
|
|
57
|
+
const jsModule = `const sheet = new CSSStyleSheet();\nsheet.replaceSync(${JSON.stringify(inlineCss)});\nglobalThis.__lw_globalStyleSheet = sheet;\nglobalThis.__lw_globalStyleImports = ${JSON.stringify(imports)};\n`;
|
|
58
|
+
utils.writeIfChanged(`${utils.dirs.build}/global-styles.js`, jsModule);
|
|
59
|
+
};
|
|
60
|
+
|
|
47
61
|
const buildHTML = () => {
|
|
48
62
|
try {
|
|
49
63
|
project.components.forEach(cmp => {
|
|
@@ -53,7 +67,7 @@ const buildModule = (projectPath) => {
|
|
|
53
67
|
if (htmlFileExists) {
|
|
54
68
|
const cssFilename = `${utils.dirs.build}/components/${cmp}/${cmpName}.css`;
|
|
55
69
|
const cssFileExists = fs.existsSync(cssFilename);
|
|
56
|
-
let cssString =
|
|
70
|
+
let cssString = '';
|
|
57
71
|
if (cssFileExists) {
|
|
58
72
|
cssString += fs.readFileSync(cssFilename, 'utf8');
|
|
59
73
|
}
|
|
@@ -82,6 +96,7 @@ const buildModule = (projectPath) => {
|
|
|
82
96
|
copySrc();
|
|
83
97
|
copyEnv();
|
|
84
98
|
buildJS();
|
|
99
|
+
buildGlobalStyles();
|
|
85
100
|
buildHTML();
|
|
86
101
|
|
|
87
102
|
return project.name;
|
package/commands/dist.js
CHANGED
|
@@ -60,7 +60,6 @@ const appCSS = fs.readFileSync(`./${utils.dirs.build}/${project.name}.css`, 'utf
|
|
|
60
60
|
fs.writeFileSync(`./${utils.dirs.dist}/${project.name}.css`, appCSS);
|
|
61
61
|
|
|
62
62
|
fse.copySync(`./${utils.dirs.build}/favicon.svg`, `./${utils.dirs.dist}/favicon.svg`);
|
|
63
|
-
fse.copySync(`./${utils.dirs.build}/global-styles.css`, `./${utils.dirs.dist}/global-styles.css`);
|
|
64
63
|
project.resources?.forEach(resource => {
|
|
65
64
|
const source = `./${utils.dirs.build}/${resource}`;
|
|
66
65
|
if (fs.existsSync(source)) {
|
package/package.json
CHANGED
|
@@ -106,8 +106,17 @@ export default class LWElement extends HTMLElement {
|
|
|
106
106
|
leanweb.builderVersion = ast.builderVersion;
|
|
107
107
|
|
|
108
108
|
const node = document.createElement('template');
|
|
109
|
-
|
|
109
|
+
const componentSheet = new CSSStyleSheet();
|
|
110
|
+
componentSheet.replaceSync(ast.css);
|
|
111
|
+
node.innerHTML = ast.html;
|
|
110
112
|
this.attachShadow({ mode: 'open' }).appendChild(node.content);
|
|
113
|
+
this.shadowRoot.adoptedStyleSheets = [globalThis.__lw_globalStyleSheet, componentSheet];
|
|
114
|
+
globalThis.__lw_globalStyleImports?.forEach(url => {
|
|
115
|
+
const link = document.createElement('link');
|
|
116
|
+
link.rel = 'stylesheet';
|
|
117
|
+
link.href = url;
|
|
118
|
+
this.shadowRoot.appendChild(link);
|
|
119
|
+
});
|
|
111
120
|
|
|
112
121
|
this._bindMethods();
|
|
113
122
|
setTimeout(() => {
|