balm-core 5.2.0 → 6.0.0-alpha.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.
Files changed (299) hide show
  1. package/dist/index.cjs +2191 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +559 -0
  4. package/dist/index.d.ts +559 -0
  5. package/dist/index.js +2098 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +48 -123
  8. package/src/balm.ts +103 -0
  9. package/src/bundler/esbuild.ts +47 -0
  10. package/src/bundler/index.ts +3 -0
  11. package/src/bundler/rollup.ts +39 -0
  12. package/src/bundler/webpack.ts +82 -0
  13. package/src/config/constants.ts +12 -0
  14. package/src/config/defaults.ts +209 -0
  15. package/src/config/index.ts +112 -0
  16. package/src/hooks/index.ts +192 -0
  17. package/src/index.ts +16 -0
  18. package/src/pipeline/file.ts +69 -0
  19. package/src/pipeline/index.ts +10 -0
  20. package/src/pipeline/pipeline.ts +132 -0
  21. package/src/pipeline/transforms/cache.ts +96 -0
  22. package/src/pipeline/transforms/htmlmin.ts +18 -0
  23. package/src/pipeline/transforms/less.ts +75 -0
  24. package/src/pipeline/transforms/postcss.ts +43 -0
  25. package/src/pipeline/transforms/rename.ts +37 -0
  26. package/src/pipeline/transforms/replace.ts +30 -0
  27. package/src/pipeline/transforms/sass.ts +106 -0
  28. package/src/pipeline/transforms/terser.ts +20 -0
  29. package/src/runner/dag.ts +77 -0
  30. package/src/runner/task.ts +38 -0
  31. package/src/shims.d.ts +5 -0
  32. package/src/tasks/cache.ts +58 -0
  33. package/src/tasks/clean.ts +21 -0
  34. package/src/tasks/copy.ts +36 -0
  35. package/src/tasks/ftp.ts +90 -0
  36. package/src/tasks/html.ts +78 -0
  37. package/src/tasks/index.ts +13 -0
  38. package/src/tasks/publish.ts +71 -0
  39. package/src/tasks/pwa.ts +49 -0
  40. package/src/tasks/remove.ts +24 -0
  41. package/src/tasks/replace.ts +34 -0
  42. package/src/tasks/script.ts +28 -0
  43. package/src/tasks/server.ts +89 -0
  44. package/src/tasks/style.ts +57 -0
  45. package/src/tasks/zip.ts +65 -0
  46. package/src/types/index.ts +200 -0
  47. package/src/utilities/file.ts +120 -0
  48. package/src/utilities/logger.ts +63 -0
  49. package/src/utilities/utils.ts +46 -0
  50. package/src/utilities/workspace.ts +38 -0
  51. package/src/watcher/index.ts +100 -0
  52. package/tsconfig.json +8 -0
  53. package/tsup.config.ts +12 -0
  54. package/README.md +0 -196
  55. package/index.d.ts +0 -360
  56. package/lib/balm.js +0 -49
  57. package/lib/bootstrap/check_config.js +0 -43
  58. package/lib/bootstrap/index.js +0 -87
  59. package/lib/bundler/esbuild/build.js +0 -26
  60. package/lib/bundler/esbuild/index.js +0 -7
  61. package/lib/bundler/esbuild/options.js +0 -7
  62. package/lib/bundler/esbuild/transform.js +0 -36
  63. package/lib/bundler/rollup/build.js +0 -52
  64. package/lib/bundler/rollup/entry.js +0 -28
  65. package/lib/bundler/rollup/index.js +0 -20
  66. package/lib/bundler/rollup/output.js +0 -20
  67. package/lib/bundler/rollup/plugins.js +0 -31
  68. package/lib/bundler/webpack/config/common.js +0 -135
  69. package/lib/bundler/webpack/config/dev.js +0 -12
  70. package/lib/bundler/webpack/config/env.js +0 -67
  71. package/lib/bundler/webpack/config/index.js +0 -6
  72. package/lib/bundler/webpack/config/prod.js +0 -39
  73. package/lib/bundler/webpack/config/regex.js +0 -10
  74. package/lib/bundler/webpack/entry.js +0 -65
  75. package/lib/bundler/webpack/index.js +0 -32
  76. package/lib/bundler/webpack/loaders.js +0 -50
  77. package/lib/bundler/webpack/output.js +0 -41
  78. package/lib/bundler/webpack/rules/asset.js +0 -33
  79. package/lib/bundler/webpack/rules/babel.js +0 -19
  80. package/lib/bundler/webpack/rules/css.js +0 -109
  81. package/lib/bundler/webpack/rules/html.js +0 -15
  82. package/lib/bundler/webpack/rules/index.js +0 -10
  83. package/lib/config/assets.js +0 -30
  84. package/lib/config/constants.js +0 -14
  85. package/lib/config/env.js +0 -35
  86. package/lib/config/extras.js +0 -6
  87. package/lib/config/ftp.js +0 -6
  88. package/lib/config/globals.js +0 -43
  89. package/lib/config/html.js +0 -22
  90. package/lib/config/images.js +0 -4
  91. package/lib/config/index.js +0 -63
  92. package/lib/config/logs.js +0 -11
  93. package/lib/config/paths.js +0 -46
  94. package/lib/config/pwa.js +0 -24
  95. package/lib/config/roots.js +0 -9
  96. package/lib/config/scripts.js +0 -162
  97. package/lib/config/server.js +0 -84
  98. package/lib/config/spinner.js +0 -9
  99. package/lib/config/styles.js +0 -67
  100. package/lib/hello.js +0 -19
  101. package/lib/hooks/index.js +0 -94
  102. package/lib/hooks/maker.js +0 -59
  103. package/lib/index.js +0 -5
  104. package/lib/middlewares/history.js +0 -6
  105. package/lib/middlewares/index.js +0 -11
  106. package/lib/middlewares/proxy.js +0 -28
  107. package/lib/middlewares/webpack.js +0 -26
  108. package/lib/plugins/htmlmin.js +0 -39
  109. package/lib/plugins/imagemin.js +0 -95
  110. package/lib/plugins/index.js +0 -27
  111. package/lib/plugins/jsmin.js +0 -37
  112. package/lib/plugins/less.js +0 -97
  113. package/lib/plugins/plumber.js +0 -87
  114. package/lib/plugins/postcss-plugins.js +0 -13
  115. package/lib/plugins/postcss.js +0 -117
  116. package/lib/plugins/rename.js +0 -51
  117. package/lib/plugins/replace.js +0 -91
  118. package/lib/plugins/sass-legacy.js +0 -131
  119. package/lib/plugins/sass.js +0 -134
  120. package/lib/plugins/sftp.js +0 -288
  121. package/lib/tasks/default.js +0 -46
  122. package/lib/tasks/foundation/balm.js +0 -72
  123. package/lib/tasks/foundation/balm_style.js +0 -65
  124. package/lib/tasks/foundation/index.js +0 -10
  125. package/lib/tasks/index.js +0 -48
  126. package/lib/tasks/private/build.js +0 -18
  127. package/lib/tasks/private/cache.js +0 -31
  128. package/lib/tasks/private/clean.js +0 -69
  129. package/lib/tasks/private/end.js +0 -24
  130. package/lib/tasks/private/extra.js +0 -35
  131. package/lib/tasks/private/font.js +0 -15
  132. package/lib/tasks/private/image.js +0 -37
  133. package/lib/tasks/private/index.js +0 -34
  134. package/lib/tasks/private/lint.js +0 -20
  135. package/lib/tasks/private/media.js +0 -15
  136. package/lib/tasks/private/modernizr.js +0 -59
  137. package/lib/tasks/private/pwa-cache.js +0 -32
  138. package/lib/tasks/private/script.js +0 -9
  139. package/lib/tasks/private/sprite.js +0 -105
  140. package/lib/tasks/private/start.js +0 -16
  141. package/lib/tasks/private/style.js +0 -9
  142. package/lib/tasks/private/workbox-sw.js +0 -15
  143. package/lib/tasks/public/copy.js +0 -16
  144. package/lib/tasks/public/esbuild.js +0 -18
  145. package/lib/tasks/public/ftp.js +0 -39
  146. package/lib/tasks/public/html.js +0 -65
  147. package/lib/tasks/public/index.js +0 -38
  148. package/lib/tasks/public/jsmin.js +0 -23
  149. package/lib/tasks/public/less.js +0 -21
  150. package/lib/tasks/public/postcss.js +0 -16
  151. package/lib/tasks/public/publish.js +0 -51
  152. package/lib/tasks/public/pwa.js +0 -84
  153. package/lib/tasks/public/remove.js +0 -46
  154. package/lib/tasks/public/replace.js +0 -26
  155. package/lib/tasks/public/rollup.js +0 -17
  156. package/lib/tasks/public/sass.js +0 -27
  157. package/lib/tasks/public/server.js +0 -130
  158. package/lib/tasks/public/url.js +0 -35
  159. package/lib/tasks/public/version.js +0 -23
  160. package/lib/tasks/public/webpack.js +0 -39
  161. package/lib/tasks/public/zip.js +0 -19
  162. package/lib/utilities/address.js +0 -55
  163. package/lib/utilities/cache-core.js +0 -66
  164. package/lib/utilities/color.js +0 -27
  165. package/lib/utilities/compiling.js +0 -24
  166. package/lib/utilities/detect-port.js +0 -100
  167. package/lib/utilities/escape-string-regexp.js +0 -10
  168. package/lib/utilities/file.js +0 -70
  169. package/lib/utilities/index.js +0 -8
  170. package/lib/utilities/loading.js +0 -37
  171. package/lib/utilities/logger.js +0 -99
  172. package/lib/utilities/merge-stream.js +0 -38
  173. package/lib/utilities/namespace.js +0 -11
  174. package/lib/utilities/public-url.js +0 -37
  175. package/lib/utilities/replacestream.js +0 -106
  176. package/lib/utilities/typeof.js +0 -5
  177. package/lib/utilities/utils.js +0 -43
  178. package/tslib/balm.js +0 -44
  179. package/tslib/bootstrap/check_config.js +0 -36
  180. package/tslib/bootstrap/index.js +0 -82
  181. package/tslib/bundler/esbuild/build.js +0 -30
  182. package/tslib/bundler/esbuild/index.js +0 -11
  183. package/tslib/bundler/esbuild/options.js +0 -7
  184. package/tslib/bundler/esbuild/transform.js +0 -38
  185. package/tslib/bundler/rollup/build.js +0 -17
  186. package/tslib/bundler/rollup/entry.js +0 -24
  187. package/tslib/bundler/rollup/index.js +0 -21
  188. package/tslib/bundler/rollup/output.js +0 -23
  189. package/tslib/bundler/rollup/plugins.js +0 -27
  190. package/tslib/bundler/webpack/config/common.js +0 -130
  191. package/tslib/bundler/webpack/config/dev.js +0 -14
  192. package/tslib/bundler/webpack/config/env.js +0 -44
  193. package/tslib/bundler/webpack/config/index.js +0 -8
  194. package/tslib/bundler/webpack/config/prod.js +0 -43
  195. package/tslib/bundler/webpack/config/regex.js +0 -10
  196. package/tslib/bundler/webpack/entry.js +0 -68
  197. package/tslib/bundler/webpack/index.js +0 -30
  198. package/tslib/bundler/webpack/loaders.js +0 -51
  199. package/tslib/bundler/webpack/output.js +0 -41
  200. package/tslib/bundler/webpack/rules/asset.js +0 -33
  201. package/tslib/bundler/webpack/rules/babel.js +0 -16
  202. package/tslib/bundler/webpack/rules/css.js +0 -95
  203. package/tslib/bundler/webpack/rules/html.js +0 -15
  204. package/tslib/bundler/webpack/rules/index.js +0 -10
  205. package/tslib/config/assets.js +0 -24
  206. package/tslib/config/constants.js +0 -14
  207. package/tslib/config/env.js +0 -43
  208. package/tslib/config/extras.js +0 -6
  209. package/tslib/config/ftp.js +0 -6
  210. package/tslib/config/globals.js +0 -47
  211. package/tslib/config/html.js +0 -17
  212. package/tslib/config/images.js +0 -4
  213. package/tslib/config/index.js +0 -56
  214. package/tslib/config/logs.js +0 -6
  215. package/tslib/config/paths.js +0 -30
  216. package/tslib/config/pwa.js +0 -18
  217. package/tslib/config/roots.js +0 -8
  218. package/tslib/config/scripts.js +0 -93
  219. package/tslib/config/server.js +0 -33
  220. package/tslib/config/spinner.js +0 -10
  221. package/tslib/config/styles.js +0 -37
  222. package/tslib/hello.js +0 -19
  223. package/tslib/hooks/index.js +0 -75
  224. package/tslib/hooks/maker.js +0 -66
  225. package/tslib/index.js +0 -5
  226. package/tslib/middlewares/history.js +0 -12
  227. package/tslib/middlewares/index.js +0 -18
  228. package/tslib/middlewares/proxy.js +0 -27
  229. package/tslib/middlewares/webpack.js +0 -29
  230. package/tslib/plugins/htmlmin.js +0 -38
  231. package/tslib/plugins/imagemin.js +0 -97
  232. package/tslib/plugins/index.js +0 -27
  233. package/tslib/plugins/jsmin.js +0 -39
  234. package/tslib/plugins/less.js +0 -90
  235. package/tslib/plugins/plumber.js +0 -81
  236. package/tslib/plugins/postcss-plugins.js +0 -24
  237. package/tslib/plugins/postcss.js +0 -111
  238. package/tslib/plugins/rename.js +0 -51
  239. package/tslib/plugins/replace.js +0 -72
  240. package/tslib/plugins/sass-legacy.js +0 -95
  241. package/tslib/plugins/sass.js +0 -109
  242. package/tslib/plugins/sftp.js +0 -258
  243. package/tslib/tasks/default.js +0 -59
  244. package/tslib/tasks/foundation/balm.js +0 -75
  245. package/tslib/tasks/foundation/balm_style.js +0 -68
  246. package/tslib/tasks/foundation/index.js +0 -10
  247. package/tslib/tasks/index.js +0 -43
  248. package/tslib/tasks/private/build.js +0 -15
  249. package/tslib/tasks/private/cache.js +0 -48
  250. package/tslib/tasks/private/clean.js +0 -82
  251. package/tslib/tasks/private/end.js +0 -21
  252. package/tslib/tasks/private/extra.js +0 -34
  253. package/tslib/tasks/private/font.js +0 -12
  254. package/tslib/tasks/private/image.js +0 -42
  255. package/tslib/tasks/private/index.js +0 -34
  256. package/tslib/tasks/private/lint.js +0 -17
  257. package/tslib/tasks/private/media.js +0 -12
  258. package/tslib/tasks/private/modernizr.js +0 -54
  259. package/tslib/tasks/private/pwa-cache.js +0 -32
  260. package/tslib/tasks/private/script.js +0 -9
  261. package/tslib/tasks/private/sprite.js +0 -93
  262. package/tslib/tasks/private/start.js +0 -13
  263. package/tslib/tasks/private/style.js +0 -12
  264. package/tslib/tasks/private/workbox-sw.js +0 -15
  265. package/tslib/tasks/public/copy.js +0 -18
  266. package/tslib/tasks/public/esbuild.js +0 -18
  267. package/tslib/tasks/public/ftp.js +0 -39
  268. package/tslib/tasks/public/html.js +0 -75
  269. package/tslib/tasks/public/index.js +0 -38
  270. package/tslib/tasks/public/jsmin.js +0 -24
  271. package/tslib/tasks/public/less.js +0 -21
  272. package/tslib/tasks/public/postcss.js +0 -16
  273. package/tslib/tasks/public/publish.js +0 -50
  274. package/tslib/tasks/public/pwa.js +0 -87
  275. package/tslib/tasks/public/remove.js +0 -44
  276. package/tslib/tasks/public/replace.js +0 -27
  277. package/tslib/tasks/public/rollup.js +0 -17
  278. package/tslib/tasks/public/sass.js +0 -27
  279. package/tslib/tasks/public/server.js +0 -129
  280. package/tslib/tasks/public/url.js +0 -35
  281. package/tslib/tasks/public/version.js +0 -27
  282. package/tslib/tasks/public/webpack.js +0 -41
  283. package/tslib/tasks/public/zip.js +0 -19
  284. package/tslib/utilities/address.js +0 -48
  285. package/tslib/utilities/cache-core.js +0 -57
  286. package/tslib/utilities/color.js +0 -33
  287. package/tslib/utilities/compiling.js +0 -16
  288. package/tslib/utilities/detect-port.js +0 -91
  289. package/tslib/utilities/escape-string-regexp.js +0 -7
  290. package/tslib/utilities/file.js +0 -78
  291. package/tslib/utilities/index.js +0 -8
  292. package/tslib/utilities/loading.js +0 -25
  293. package/tslib/utilities/logger.js +0 -92
  294. package/tslib/utilities/merge-stream.js +0 -34
  295. package/tslib/utilities/namespace.js +0 -12
  296. package/tslib/utilities/public-url.js +0 -31
  297. package/tslib/utilities/replacestream.js +0 -112
  298. package/tslib/utilities/typeof.js +0 -8
  299. package/tslib/utilities/utils.js +0 -38
package/lib/balm.js DELETED
@@ -1,49 +0,0 @@
1
- function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
2
- function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
3
- function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
4
- function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
5
- function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
6
- import './config/index.js';
7
- import './utilities/index.js';
8
- import './plugins/index.js';
9
- import registerTasks from './tasks/index.js';
10
- import { setConfig, setTask } from './bootstrap/index.js';
11
- import loading from './utilities/loading.js';
12
- var _config = /*#__PURE__*/new WeakMap();
13
- class Balm {
14
- constructor() {
15
- _classPrivateFieldInitSpec(this, _config, void 0);
16
- BalmJS.loading = false;
17
- loading.succeed();
18
- _classPrivateFieldSet(_config, this, setConfig({}));
19
- }
20
- get config() {
21
- return _classPrivateFieldGet(_config, this);
22
- }
23
- set config(value) {
24
- _classPrivateFieldSet(_config, this, setConfig(value));
25
- BalmJS.config = _classPrivateFieldGet(_config, this);
26
- }
27
- set beforeTask(name) {
28
- BalmJS.beforeTask = setTask(name);
29
- }
30
- set afterTask(name) {
31
- BalmJS.afterTask = setTask(name);
32
- }
33
- go(recipe = NOOP) {
34
- if (BalmJS.utils.isFunction(recipe)) {
35
- registerTasks(recipe);
36
- } else {
37
- BalmJS.logger.error('initialization', 'BalmJS API: `balm.go(mix => {});`');
38
- }
39
- }
40
- reset() {
41
- BalmJS.tasks = new Map();
42
- BalmJS.recipes = [];
43
- BalmJS.recipeIndex = 0;
44
- BalmJS.beforeTask = undefined;
45
- BalmJS.afterTask = undefined;
46
- BalmJS.config.useDefaults = true;
47
- }
48
- }
49
- export default Balm;
@@ -1,43 +0,0 @@
1
- import { DOMAIN } from '../config/constants.js';
2
- const docsBaseURL = `${DOMAIN}/docs/config`;
3
- function upgradeGuide(key, value, message) {
4
- const page = key === 'scripts' ? 'scripts-webpack' : key.toLowerCase();
5
- return `${message} See ${docsBaseURL}/${page}.html#${key}-${value.toLowerCase()}`;
6
- }
7
- function upgradeRenamed(version, configCategory, from, to) {
8
- if (BalmJS.config[configCategory][from]) {
9
- BalmJS.logger.warn(`balm@${version}+ config`, upgradeGuide(configCategory, to, `'${configCategory}.${from}' was renamed to '${configCategory}.${to}'.`));
10
- }
11
- }
12
- function upgradeMigrated(version, configName, from, to) {
13
- if (BalmJS.config[from][configName]) {
14
- BalmJS.logger.warn(`balm@${version}+ config`, upgradeGuide(to, configName, `'${from}.${configName}' was migrated to '${to}.${configName}'.`));
15
- }
16
- }
17
- function upgradeDeprecated(version, configCategory, configName) {
18
- if (BalmJS.config[configCategory][configName]) {
19
- BalmJS.logger.warn(`balm@${version}+ config`, `'${configCategory}.${configName}' was deprecated.`);
20
- }
21
- }
22
-
23
- // Compatibility for upgrade balm
24
- function checkConfig() {
25
- // For v2
26
- upgradeRenamed('2.5.0', 'scripts', 'disableDefaultLoaders', 'defaultLoaders');
27
- upgradeMigrated('2.11.0', 'postcssLoaderOptions', 'styles', 'scripts');
28
- upgradeRenamed('2.22.0', 'images', 'defaultPlugins', 'plugins');
29
-
30
- // For v3
31
- upgradeRenamed('3.0.0', 'styles', 'minified', 'minify');
32
- upgradeRenamed('3.9.0', 'scripts', 'options', 'minifyOptions');
33
- upgradeRenamed('3.16.0', 'scripts', 'inject', 'useCache');
34
- upgradeDeprecated('3.17.0', 'styles', 'darkSass');
35
- upgradeDeprecated('3.19.0', 'scripts', 'useCache');
36
-
37
- // For v4
38
- upgradeDeprecated('4.0.0', 'scripts', 'libraryTarget');
39
- upgradeDeprecated('4.5.0', 'scripts', 'excludeUrlResource');
40
- upgradeDeprecated('4.5.0', 'scripts', 'urlLoaderOptions');
41
- upgradeRenamed('4.29.0', 'server', 'proxyConfig', 'proxyOptions');
42
- }
43
- export default checkConfig;
@@ -1,87 +0,0 @@
1
- import checkConfig from './check_config.js';
2
- import { ASSETS_TYPES } from '../config/constants.js';
3
- function createQuickPath(config, rootKey) {
4
- const result = {};
5
- const rootValue = config.roots[rootKey];
6
- for (const pathKey of Object.keys(config.paths[rootKey])) {
7
- const pathValue = config.paths[rootKey][pathKey];
8
- result[pathKey] = rootKey === 'target' && ASSETS_TYPES.includes(pathKey) ? node.path.join(rootValue, BalmJS.config.assets.virtualDir, BalmJS.file.assetsSuffixPath, pathValue) : node.path.join(rootValue, pathValue);
9
- }
10
- return rootKey === 'source' ? result : result;
11
- }
12
- function ready(config) {
13
- // Create local quick directories
14
- config.src = createQuickPath(config, 'source');
15
- config.dest = createQuickPath(config, config.env.isProd || !config.inFrontend ? 'target' : 'tmp');
16
- config.dest.static = node.path.join(config.dest.base, BalmJS.config.assets.virtualDir, BalmJS.file.assetsSuffixPath);
17
-
18
- // Create remote quick directories
19
- config.assets.static = node.path.join(config.assets.root, config.assets.mainDir, BalmJS.file.assetsSuffixPath);
20
- for (const assetType of ASSETS_TYPES) {
21
- config.assets[assetType] = node.path.join(config.assets.static, config.paths.target[assetType]);
22
- }
23
-
24
- // Set HMR flag
25
- const HMR_ENV = config.useDefaults && config.env.isDev && !config.env.inSSR && !config.env.isMP;
26
- const HMR_Enabling = config.scripts.bundler === BalmJS.Bundler.webpack && !config.scripts.ie8;
27
- config.server.useHMR = HMR_ENV && HMR_Enabling;
28
-
29
- // Set desktop app flag
30
- if (/^electron-.*/.test(config.scripts.target)) {
31
- config.env.inDesktopApp = true;
32
- }
33
-
34
- // Set use cache for webpack
35
- config.scripts.useCache = config.env.isProd && config.assets.cache && config.scripts.injectHtml;
36
- return config;
37
- }
38
- function resetConfig() {
39
- BalmJS.config.roots.target = 'dist';
40
- BalmJS.config.roots.tmp = '.tmp';
41
- return BalmJS.config;
42
- }
43
- function setConfig(customConfig) {
44
- const defaultConfig = resetConfig();
45
-
46
- // 1. Overwrite config
47
- const newConfig = BalmJS.utils.deepMerge(defaultConfig, customConfig);
48
- checkConfig();
49
-
50
- // 2. Copy `config.paths.target` to `config.paths.tmp`
51
- let config = BalmJS.utils.deepMerge(newConfig, {
52
- paths: {
53
- tmp: newConfig.paths.target
54
- }
55
- });
56
-
57
- // 3. For the dynamic project
58
- if (!config.inFrontend) {
59
- if (config.roots.target === 'dist') {
60
- config.roots.target = config.assets.mainDir; // NOTE: `BalmJS.config.roots.target = 'public'` for back-end project
61
- }
62
- config.roots.tmp = config.roots.target;
63
- }
64
-
65
- // 4. Before created
66
- config = ready(config);
67
- BalmJS.logger.success('balm configuration', config, {
68
- pre: true
69
- });
70
- return config;
71
- }
72
- function setTask(name) {
73
- let result = undefined;
74
- if (BalmJS.utils.isFunction(name)) {
75
- result = name;
76
- } else if (BalmJS.utils.isString(name)) {
77
- if (gulp.tree().nodes.includes(name)) {
78
- result = name;
79
- } else {
80
- BalmJS.logger.error('before/end task', 'Invalid gulp task name');
81
- }
82
- } else {
83
- BalmJS.logger.error('before/end task', 'Task must be a string (gulp task name) or function');
84
- }
85
- return result;
86
- }
87
- export { setConfig, setTask };
@@ -1,26 +0,0 @@
1
- import { build } from 'esbuild';
2
- import { minifyOptions } from './options.js';
3
- const esBuild = (entryPoints, output, customBuildOptions, callback) => {
4
- const defaultBuildOptions = {
5
- entryPoints: BalmJS.file.absPaths(entryPoints),
6
- outdir: BalmJS.file.absPath(output),
7
- bundle: BalmJS.config.env.isProd
8
- };
9
- const buildOptions = BalmJS.config.env.isProd ? Object.assign(defaultBuildOptions, minifyOptions) : defaultBuildOptions;
10
- const options = Object.assign(buildOptions, BalmJS.config.scripts.buildOptions, customBuildOptions);
11
- BalmJS.logger.debug('esbuild bundler - build', {
12
- input: options.entryPoints,
13
- output: options.outdir
14
- }, {
15
- pre: true
16
- });
17
- BalmJS.logger.success('esbuild options', options, {
18
- pre: true
19
- });
20
- build(options).catch(error => {
21
- BalmJS.logger.error('esbuild', error.message);
22
- }).finally(() => {
23
- callback();
24
- });
25
- };
26
- export default esBuild;
@@ -1,7 +0,0 @@
1
- import build from './build.js';
2
- import transform from './transform.js';
3
- const esbuild = (input, output, customOptions, callback) => {
4
- const entryPoints = BalmJS.utils.isString(input) ? [input] : input;
5
- BalmJS.config.scripts.useTransform ? transform(entryPoints, output, customOptions, callback) : build(entryPoints, output, customOptions, callback);
6
- };
7
- export default esbuild;
@@ -1,7 +0,0 @@
1
- const minifyOptions = {
2
- minify: true,
3
- minifyWhitespace: true,
4
- minifyIdentifiers: true,
5
- minifySyntax: true
6
- };
7
- export { minifyOptions };
@@ -1,36 +0,0 @@
1
- import { transform } from 'esbuild';
2
- import { minifyOptions } from './options.js';
3
- const esTransform = (entryPoints, output, customTransformOptions, callback) => {
4
- const build = {
5
- output: BalmJS.file.absPath(output)
6
- };
7
- const transformOptions = BalmJS.config.env.isProd ? Object.assign({}, minifyOptions) : {};
8
- const options = Object.assign(transformOptions, BalmJS.config.scripts.transformOptions, customTransformOptions);
9
- (async () => {
10
- try {
11
- for await (const entryPoint of entryPoints) {
12
- build.input = BalmJS.file.absPath(entryPoint);
13
- BalmJS.logger.debug('esbuild bundler - transform', {
14
- input: build.input,
15
- output: build.output
16
- }, {
17
- pre: true
18
- });
19
- const filename = entryPoint.split('/').pop();
20
- if (filename && node.fs.existsSync(build.input)) {
21
- const inputCode = node.fs.readFileSync(build.input, 'utf8');
22
- const result = await transform(inputCode, options);
23
- node.fs.mkdirSync(build.output, {
24
- recursive: true
25
- });
26
- node.fs.writeFileSync(node.path.join(build.output, filename), result.code);
27
- } else {
28
- BalmJS.logger.warn('esbuild', `Invalid entry point: ${entryPoint}`);
29
- }
30
- }
31
- } finally {
32
- callback();
33
- }
34
- })();
35
- };
36
- export default esTransform;
@@ -1,52 +0,0 @@
1
- const build = async (bundle, outputOptions) => {
2
- const {
3
- output
4
- } = await bundle.generate(outputOptions);
5
- for (const chunkOrAsset of output) {
6
- if (chunkOrAsset.type === 'asset') {
7
- // For assets, this contains
8
- // {
9
- // fileName: string, // the asset file name
10
- // source: string | Uint8Array // the asset source
11
- // type: 'asset' // signifies that this is an asset
12
- // }
13
- BalmJS.logger.debug('rollup bundler - Asset', chunkOrAsset, {
14
- pre: true
15
- });
16
- } else {
17
- // For chunks, this contains
18
- // {
19
- // code: string, // the generated JS code
20
- // dynamicImports: string[], // external modules imported dynamically by the chunk
21
- // exports: string[], // exported variable names
22
- // facadeModuleId: string | null, // the id of a module that this chunk corresponds to
23
- // fileName: string, // the chunk file name
24
- // implicitlyLoadedBefore: string[]; // entries that should only be loaded after this chunk
25
- // imports: string[], // external modules imported statically by the chunk
26
- // importedBindings: {[imported: string]: string[]} // imported bindings per dependency
27
- // isDynamicEntry: boolean, // is this chunk a dynamic entry point
28
- // isEntry: boolean, // is this chunk a static entry point
29
- // isImplicitEntry: boolean, // should this chunk only be loaded after other chunks
30
- // map: string | null, // sourcemaps if present
31
- // modules: { // information about the modules in this chunk
32
- // [id: string]: {
33
- // renderedExports: string[]; // exported variable names that were included
34
- // removedExports: string[]; // exported variable names that were removed
35
- // renderedLength: number; // the length of the remaining code in this module
36
- // originalLength: number; // the original length of the code in this module
37
- // };
38
- // },
39
- // name: string // the name of this chunk as used in naming patterns
40
- // referencedFiles: string[] // files referenced via import.meta.ROLLUP_FILE_URL_<id>
41
- // type: 'chunk', // signifies that this is a chunk
42
- // }
43
- BalmJS.logger.debug('rollup bundler - Chunk', chunkOrAsset.modules, {
44
- pre: true
45
- });
46
- }
47
- }
48
-
49
- // or write the bundle to disk
50
- return await bundle.write(outputOptions);
51
- };
52
- export default build;
@@ -1,28 +0,0 @@
1
- import { getInputPlugins } from './plugins.js';
2
- function getEntry(inputOptions) {
3
- // Set plugins
4
- const inputPlugins = getInputPlugins(inputOptions);
5
- const options = Object.assign({}, BalmJS.config.scripts.inputOptions, inputOptions);
6
- options.plugins = inputPlugins;
7
-
8
- // Set entry points
9
- const {
10
- input
11
- } = options;
12
- let rollupEntries = input;
13
- if (BalmJS.utils.isObject(input)) {
14
- const entries = input;
15
- Object.keys(entries).forEach(entryAlias => {
16
- entries[entryAlias] = BalmJS.file.absPath(entries[entryAlias]);
17
- });
18
- rollupEntries = entries;
19
- } else {
20
- rollupEntries = BalmJS.file.absPaths(input);
21
- }
22
- options.input = rollupEntries;
23
- BalmJS.logger.debug('rollup input options', options, {
24
- pre: true
25
- });
26
- return options;
27
- }
28
- export default getEntry;
@@ -1,20 +0,0 @@
1
- import { rollup } from 'rollup';
2
- import getEntry from './entry.js';
3
- import getOutput from './output.js';
4
- import build from './build.js';
5
- const buildLibrary = async (inputOptions, outputOptions) => {
6
- inputOptions = getEntry(inputOptions);
7
- outputOptions = getOutput(outputOptions);
8
- const rollupOptions = Object.assign({}, inputOptions, {
9
- output: outputOptions
10
- });
11
- const bundle = await rollup(rollupOptions);
12
- if (Array.isArray(outputOptions)) {
13
- for await (const outputOption of outputOptions) {
14
- await build(bundle, outputOption);
15
- }
16
- } else {
17
- await build(bundle, outputOptions);
18
- }
19
- };
20
- export default buildLibrary;
@@ -1,20 +0,0 @@
1
- import { getOutputPlugins } from './plugins.js';
2
- function setOutput(outputOptions) {
3
- const outputPlugins = getOutputPlugins(outputOptions);
4
- outputOptions = Object.assign({}, BalmJS.config.scripts.outputOptions, outputOptions);
5
- outputOptions.plugins = outputPlugins;
6
- if (outputOptions.dir) {
7
- outputOptions.dir = BalmJS.file.absPath(outputOptions.dir);
8
- } else {
9
- outputOptions.file = BalmJS.file.absPath(outputOptions.file);
10
- }
11
- return outputOptions;
12
- }
13
- function getOutput(outputOptions) {
14
- const options = Array.isArray(outputOptions) ? outputOptions.map(outputOption => setOutput(outputOption)) : setOutput(outputOptions);
15
- BalmJS.logger.debug('rollup output options', options, {
16
- pre: true
17
- });
18
- return options;
19
- }
20
- export default getOutput;
@@ -1,31 +0,0 @@
1
- import terser from '@rollup/plugin-terser';
2
- function getInputPlugins(customInputOptions) {
3
- const {
4
- inputOptions
5
- } = BalmJS.config.scripts;
6
- const inputPlugins = [];
7
- if (inputOptions.plugins) {
8
- inputPlugins.push(...inputOptions.plugins);
9
- }
10
- if (customInputOptions.plugins) {
11
- inputPlugins.push(...customInputOptions.plugins);
12
- }
13
- return inputPlugins;
14
- }
15
- function getOutputPlugins(customOutputOptions) {
16
- const {
17
- outputOptions
18
- } = BalmJS.config.scripts;
19
- const outputPlugins = [];
20
- if (outputOptions.plugins) {
21
- outputPlugins.push(...outputOptions.plugins);
22
- }
23
- if (BalmJS.config.env.isProd) {
24
- outputPlugins.push(terser(BalmJS.config.scripts.minifyOptions));
25
- }
26
- if (customOutputOptions.plugins) {
27
- outputPlugins.push(...customOutputOptions.plugins);
28
- }
29
- return outputPlugins;
30
- }
31
- export { getInputPlugins, getOutputPlugins };
@@ -1,135 +0,0 @@
1
- import HtmlWebpackPlugin from 'html-webpack-plugin';
2
- import getLoaders from '../loaders.js';
3
- import { CHUNK } from '../../../config/constants.js';
4
- import getClientEnvironment from './env.js';
5
- function getDefaultPlugins(webpack, scripts) {
6
- // We will provide `BalmJS.file.publicUrlOrPath` to our app
7
- // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
8
- // Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
9
- // Get environment variables to inject into our app.
10
- const env = getClientEnvironment(BalmJS.file.publicUrlOrPath.slice(0, -1));
11
- const plugins = [
12
- // Makes some environment variables available to the JS code, for example:
13
- // if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
14
- // It is absolutely essential that NODE_ENV is set to production
15
- // during a production build.
16
- // Otherwise webapp will be compiled in the very slow development mode.
17
- new webpack.DefinePlugin(env.stringified),
18
- // Moment.js is an extremely popular library that bundles large locale files
19
- // by default due to how webpack interprets its code. This is a practical
20
- // solution that requires the user to opt into importing specific locales.
21
- // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
22
- // You can remove this if you don't use Moment.js:
23
- new webpack.IgnorePlugin({
24
- resourceRegExp: /^\.\/locale$/,
25
- contextRegExp: /moment$/
26
- })];
27
- if (scripts.injectHtml) {
28
- const isSPA = BalmJS.entries.length < 2;
29
- const titles = scripts.htmlPluginOptions.title || ['BalmJS App'];
30
- if (!BalmJS.entries.length) {
31
- BalmJS.entries.push({
32
- key: 'main',
33
- value: `./${BalmJS.file.defaultEntry}`
34
- });
35
- }
36
- BalmJS.entries.forEach((entry, index) => {
37
- const entryName = isSPA ? 'index' : entry.key;
38
- const chunks = isSPA ? 'all' : [entryName];
39
- const title = titles[index];
40
- const options = Object.assign({
41
- filename: BalmJS.file.absPath(`${BalmJS.config.src.base}/${entryName}.html`),
42
- chunks
43
- }, scripts.htmlPluginOptions, {
44
- title
45
- });
46
- plugins.push(new HtmlWebpackPlugin(options));
47
- });
48
- }
49
- return plugins;
50
- }
51
- function getSplitChunks() {
52
- const scripts = BalmJS.config.scripts;
53
- const jsFolder = BalmJS.config.paths.target.js;
54
- let cacheGroups = {};
55
- if (scripts.extractAllVendors) {
56
- // All vendors
57
- const vendorsFilename = scripts.useCache ? `${scripts.vendorName}.${CHUNK.hash}.js` : `${scripts.vendorName}.js`;
58
- cacheGroups = {
59
- allVendors: {
60
- name: 'vendors',
61
- chunks: 'initial',
62
- test: /[\\/](node_modules|bower_components)[\\/]/,
63
- filename: BalmJS.file.assetsPath(`${jsFolder}/${vendorsFilename}`) // Output: `js/vendors.js`
64
- }
65
- };
66
- } else if (BalmJS.vendors.length) {
67
- // Custom vendors
68
- cacheGroups = {};
69
- for (const vendor of BalmJS.vendors) {
70
- const name = vendor.key;
71
- const cacheGroupModules = vendor.value.join('|');
72
- const vendorFilename = scripts.useCache ? `${name}.${CHUNK.hash}.js` : `${name}.js`;
73
- cacheGroups[`${name}Scripts`] = {
74
- name,
75
- chunks: 'initial',
76
- test: new RegExp(`[\\\\/](${cacheGroupModules})[\\\\/].*(?<!\\.css)$`),
77
- filename: BalmJS.file.assetsPath(`${jsFolder}/${scripts.vendorName}/${vendorFilename}`),
78
- // Output: `js/vendor/customVendorName.js`
79
- enforce: true
80
- };
81
- }
82
- }
83
- if (BalmJS.config.env.isProd && BalmJS.config.scripts.extractCss) {
84
- // Custom styles in scripts
85
- for (const entry of BalmJS.entries) {
86
- const name = entry.key;
87
- cacheGroups[`${name}Styles`] = {
88
- type: 'css/mini-extract',
89
- name,
90
- chunks: chunk => chunk.name === name,
91
- enforce: true
92
- };
93
- }
94
- }
95
- return Object.keys(cacheGroups).length ? {
96
- cacheGroups
97
- } : false;
98
- }
99
- function getCommonConfig(webpack, scripts) {
100
- const splitChunks = getSplitChunks();
101
- const optimization = splitChunks ? BalmJS.utils.deepMerge({
102
- splitChunks: splitChunks
103
- }, scripts.optimization) : scripts.optimization;
104
- return {
105
- context: BalmJS.config.workspace,
106
- mode: 'none',
107
- // Stop compilation early in production
108
- bail: BalmJS.config.env.isProd,
109
- module: {
110
- strictExportPresence: true,
111
- rules: getLoaders(scripts.loaders)
112
- },
113
- resolve: {
114
- // (was split into `root`, `modulesDirectories` and `fallback` in the old options)
115
- // In which folders the resolver look for modules
116
- // relative paths are looked up in every parent folder (like node_modules)
117
- // absolute paths are looked up directly
118
- // the order is respected
119
- modules: ['node_modules', 'bower_components', BalmJS.file.absPath(BalmJS.config.src.base)],
120
- // These extensions are tried when resolving a file
121
- extensions: ['.wasm', '.mjs', '.js', '.json', '.jsx', '.ts', '.tsx', '.vue', ...scripts.extensions],
122
- // These aliasing is used when trying to resolve a module
123
- alias: scripts.alias,
124
- // These JSON files are read in directories
125
- descriptionFiles: ['package.json', 'bower.json'],
126
- // These fields in the description files are looked up when trying to resolve the package directory
127
- mainFields: ['browser', 'module', 'main']
128
- },
129
- optimization,
130
- plugins: [...getDefaultPlugins(webpack, scripts), ...scripts.plugins],
131
- target: scripts.target,
132
- stats: scripts.stats
133
- };
134
- }
135
- export default getCommonConfig;
@@ -1,12 +0,0 @@
1
- import { merge } from 'webpack-merge';
2
- import getCommonConfig from './common.js';
3
- function getDevConfig(webpack, scripts) {
4
- return merge(getCommonConfig(webpack, scripts), {
5
- mode: 'development',
6
- plugins: [
7
- // This is necessary to emit hot updates
8
- new webpack.HotModuleReplacementPlugin()],
9
- devtool: scripts.sourceMap ? scripts.sourceMap : 'eval-cheap-module-source-map'
10
- });
11
- }
12
- export default getDevConfig;
@@ -1,67 +0,0 @@
1
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
4
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
- import dotenv from 'dotenv';
7
- import dotenvExpand from 'dotenv-expand';
8
- const NODE_ENV = process.env.NODE_ENV;
9
- if (!NODE_ENV) {
10
- throw new Error('The NODE_ENV environment variable is required but was not specified.');
11
- }
12
- const dotenvFile = BalmJS.file.resolveApp('.env');
13
-
14
- // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
15
- const dotenvFiles = [`${dotenvFile}.${NODE_ENV}.local`,
16
- // Don't include `.env.local` for `test` environment
17
- // since normally you expect tests to produce the same
18
- // results for everyone
19
- NODE_ENV !== 'test' && `${dotenvFile}.local`, `${dotenvFile}.${NODE_ENV}`, dotenvFile].filter(Boolean);
20
-
21
- // Load environment variables from .env* files. Suppress warnings using silent
22
- // if this file is missing. dotenv will never modify any environment variables
23
- // that have already been set. Variable expansion is supported in .env files.
24
- // https://github.com/motdotla/dotenv
25
- // https://github.com/motdotla/dotenv-expand
26
- dotenvFiles.forEach(dotenvFile => {
27
- if (node.fs.existsSync(dotenvFile)) {
28
- dotenvExpand.expand(dotenv.config({
29
- path: dotenvFile
30
- }));
31
- }
32
- });
33
-
34
- // Grab NODE_ENV and BALM_APP_* environment variables and prepare them to be
35
- // injected into the application via DefinePlugin in webpack configuration.
36
- const BALM_APP = /^BALM_APP_/i;
37
- function getClientEnvironment(publicUrl) {
38
- const raw = Object.keys(process.env).filter(key => BALM_APP.test(key)).reduce((env, key) => {
39
- env[key] = process.env[key];
40
- return env;
41
- }, _objectSpread({
42
- // Useful for determining whether we’re running in production mode.
43
- // Most importantly, it switches webapp into the correct mode.
44
- NODE_ENV: process.env.NODE_ENV || 'development',
45
- // Useful for resolving the correct path to static assets in `public`.
46
- // For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
47
- // This should only be used as an escape hatch. Normally you would put
48
- // images into the `src` and `import` them in code to get their paths.
49
- PUBLIC_URL: publicUrl
50
- }, BalmJS.config.scripts.nodeEnv));
51
-
52
- // Stringify all values so we can feed into webpack DefinePlugin
53
- const stringified = {
54
- 'process.env': Object.keys(raw).reduce((env, key) => {
55
- env[key] = JSON.stringify(raw[key]);
56
- return env;
57
- }, {})
58
- };
59
- BalmJS.logger.debug('webpack .env', stringified, {
60
- pre: true
61
- });
62
- return {
63
- raw,
64
- stringified
65
- };
66
- }
67
- export default getClientEnvironment;
@@ -1,6 +0,0 @@
1
- import getDevConfig from './dev.js';
2
- import getProdConfig from './prod.js';
3
- function getDefaultConfig(webpack, scripts) {
4
- return BalmJS.config.env.isProd || scripts.minify || scripts.ie8 ? getProdConfig(webpack, scripts) : getDevConfig(webpack, scripts);
5
- }
6
- export default getDefaultConfig;