@cocreate/webpack 1.9.0 → 1.11.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/CONTRIBUTING.md CHANGED
@@ -13,7 +13,7 @@ Fork the [project on Github](https://github.com/CoCreate-app/CoCreate-webpack) a
13
13
  ```
14
14
  git clone https://github.com/contributor/CoCreate-webpack.git
15
15
  cd CoCreate-webpack
16
- git remote add upstream https://github.com/CoCreate-app/CoCreate-webpack.git
16
+ git remote add upstream https://gitlab.com/cocreatejs/CoCreate-webpack.git
17
17
  ```
18
18
 
19
19
  ## Create a Topic Branch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/webpack",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "A Webpack integration tool for CoCreate applications, enabling file watching, automated chunking, lazy loading, and file uploading. It leverages CoCreate.config for streamlined project builds and development workflows.",
5
5
  "keywords": [
6
6
  "webpack",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "repository": {
29
29
  "type": "git",
30
- "url": "git+https://github.com/CoCreate-app/CoCreate-webpack.git"
30
+ "url": "git+https://gitlab.com/cocreatejs/CoCreate-webpack.git"
31
31
  },
32
32
  "author": "CoCreate LLC",
33
33
  "license": "MIT",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "main": "./src/index.js",
43
43
  "dependencies": {
44
- "@cocreate/cli": "^1.62.0",
44
+ "@cocreate/cli": "^1.64.0",
45
45
  "css-loader": "^7.1.4",
46
46
  "esbuild": "^0.25.12",
47
47
  "esbuild-loader": "^4.5.0",
package/src/index.js CHANGED
@@ -75,7 +75,17 @@ class ModuleGenerator {
75
75
 
76
76
  let entryContent = `import { dependency, lazyLoad } from '@cocreate/lazy-loader';\n\n`;
77
77
 
78
- const pluginsObj = CoCreateConfig.plugins || {};
78
+ const pluginsObj = Object.fromEntries(
79
+ Object.entries(CoCreateConfig.plugins || {})
80
+ .filter(([, pluginInfo]) =>
81
+ pluginInfo && typeof pluginInfo === "object" &&
82
+ (pluginInfo.js !== undefined || pluginInfo.css !== undefined)
83
+ )
84
+ .map(([pluginName, pluginInfo]) => [pluginName, {
85
+ ...(pluginInfo.js !== undefined ? { js: pluginInfo.js } : {}),
86
+ ...(pluginInfo.css !== undefined ? { css: pluginInfo.css } : {})
87
+ }])
88
+ );
79
89
  entryContent += `if (typeof window !== 'undefined') {\n`;
80
90
  entryContent += ` window.CoCreateConfig = window.CoCreateConfig || {};\n`;
81
91
  entryContent += ` window.CoCreateConfig.plugins = Object.assign(\n`;
@@ -85,19 +95,24 @@ class ModuleGenerator {
85
95
  entryContent += ` );\n`;
86
96
  entryContent += `}\n\n`;
87
97
 
88
- const modulesObj = CoCreateConfig.modules || {};
89
- Object.entries(modulesObj).forEach(([moduleName, moduleInfo]) => {
90
- if (typeof moduleInfo !== "object" || moduleInfo === null) return;
91
- if (!moduleInfo.import) return;
92
-
93
- if (moduleInfo.selector) {
94
- const sanitizedSelector = moduleInfo.selector.replaceAll("'", '"');
95
- entryContent += `lazyLoad('${moduleName}', '${sanitizedSelector}', () => import(/*webpackChunkName: "${moduleName}-chunk"*/ '${moduleInfo.import}'));\n`;
96
- } else {
97
- entryContent += `dependency('${moduleName}', import(/*webpackChunkName: "${moduleName}-chunk"*/ '${moduleInfo.import}'));\n`;
98
- }
99
- });
100
-
98
+ const appendImports = (entries) => {
99
+ Object.entries(entries || {}).forEach(([name, info]) => {
100
+ if (typeof info !== "object" || info === null || !info.import) return;
101
+
102
+ const importPath = JSON.stringify(info.import);
103
+ const chunkName = name.replace(/[^A-Za-z0-9_-]/g, "-");
104
+ const importExpression = `import(/* webpackChunkName: "${chunkName}" */ ${importPath})`;
105
+ if (info.selector) {
106
+ entryContent += `lazyLoad(${JSON.stringify(name)}, ${JSON.stringify(info.selector)}, () => ${importExpression});\n`;
107
+ } else {
108
+ entryContent += `dependency(${JSON.stringify(name)}, ${importExpression});\n`;
109
+ }
110
+ });
111
+ };
112
+
113
+ appendImports(CoCreateConfig.plugins);
114
+ appendImports(CoCreateConfig.modules);
115
+
101
116
  fs.writeFile(entryOutputPath, entryContent, "utf8", (err) => {
102
117
  if (err) {
103
118
  console.error(`[@cocreate/webpack] Error writing ${entryOutputPath}:`, err);
@@ -166,4 +181,4 @@ module.exports = {
166
181
  FileUploader,
167
182
  SymlinkCreator,
168
183
  UnicodeLoader: path.resolve(__dirname, 'replace-unicode.js')
169
- };
184
+ };