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
@@ -1,130 +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
- const env = getClientEnvironment(BalmJS.file.publicUrlOrPath.slice(0, -1));
7
- const plugins = [
8
- new webpack.DefinePlugin(env.stringified),
9
- new webpack.IgnorePlugin({
10
- resourceRegExp: /^\.\/locale$/,
11
- contextRegExp: /moment$/
12
- })
13
- ];
14
- if (scripts.injectHtml) {
15
- const isSPA = BalmJS.entries.length < 2;
16
- const titles = scripts.htmlPluginOptions.title || ['BalmJS App'];
17
- if (!BalmJS.entries.length) {
18
- BalmJS.entries.push({
19
- key: 'main',
20
- value: `./${BalmJS.file.defaultEntry}`
21
- });
22
- }
23
- BalmJS.entries.forEach((entry, index) => {
24
- const entryName = isSPA ? 'index' : entry.key;
25
- const chunks = isSPA ? 'all' : [entryName];
26
- const title = titles[index];
27
- const options = Object.assign({
28
- filename: BalmJS.file.absPath(`${BalmJS.config.src.base}/${entryName}.html`),
29
- chunks
30
- }, scripts.htmlPluginOptions, {
31
- title
32
- });
33
- plugins.push(new HtmlWebpackPlugin(options));
34
- });
35
- }
36
- return plugins;
37
- }
38
- function getSplitChunks() {
39
- const scripts = BalmJS.config.scripts;
40
- const jsFolder = BalmJS.config.paths.target.js;
41
- let cacheGroups = {};
42
- if (scripts.extractAllVendors) {
43
- const vendorsFilename = scripts.useCache
44
- ? `${scripts.vendorName}.${CHUNK.hash}.js`
45
- : `${scripts.vendorName}.js`;
46
- cacheGroups = {
47
- allVendors: {
48
- name: 'vendors',
49
- chunks: 'initial',
50
- test: /[\\/](node_modules|bower_components)[\\/]/,
51
- filename: BalmJS.file.assetsPath(`${jsFolder}/${vendorsFilename}`)
52
- }
53
- };
54
- }
55
- else if (BalmJS.vendors.length) {
56
- cacheGroups = {};
57
- for (const vendor of BalmJS.vendors) {
58
- const name = vendor.key;
59
- const cacheGroupModules = vendor.value.join('|');
60
- const vendorFilename = scripts.useCache
61
- ? `${name}.${CHUNK.hash}.js`
62
- : `${name}.js`;
63
- cacheGroups[`${name}Scripts`] = {
64
- name,
65
- chunks: 'initial',
66
- test: new RegExp(`[\\\\/](${cacheGroupModules})[\\\\/].*(?<!\\.css)$`),
67
- filename: BalmJS.file.assetsPath(`${jsFolder}/${scripts.vendorName}/${vendorFilename}`),
68
- enforce: true
69
- };
70
- }
71
- }
72
- if (BalmJS.config.env.isProd && BalmJS.config.scripts.extractCss) {
73
- for (const entry of BalmJS.entries) {
74
- const name = entry.key;
75
- cacheGroups[`${name}Styles`] = {
76
- type: 'css/mini-extract',
77
- name,
78
- chunks: (chunk) => chunk.name === name,
79
- enforce: true
80
- };
81
- }
82
- }
83
- return Object.keys(cacheGroups).length ? { cacheGroups } : false;
84
- }
85
- function getCommonConfig(webpack, scripts) {
86
- const splitChunks = getSplitChunks();
87
- const optimization = splitChunks
88
- ? BalmJS.utils.deepMerge({
89
- splitChunks: splitChunks
90
- }, scripts.optimization)
91
- : scripts.optimization;
92
- return {
93
- context: BalmJS.config.workspace,
94
- mode: 'none',
95
- bail: BalmJS.config.env.isProd,
96
- module: {
97
- strictExportPresence: true,
98
- rules: getLoaders(scripts.loaders)
99
- },
100
- resolve: {
101
- modules: [
102
- 'node_modules',
103
- 'bower_components',
104
- BalmJS.file.absPath(BalmJS.config.src.base)
105
- ],
106
- extensions: [
107
- '.wasm',
108
- '.mjs',
109
- '.js',
110
- '.json',
111
- '.jsx',
112
- '.ts',
113
- '.tsx',
114
- '.vue',
115
- ...scripts.extensions
116
- ],
117
- alias: scripts.alias,
118
- descriptionFiles: ['package.json', 'bower.json'],
119
- mainFields: ['browser', 'module', 'main']
120
- },
121
- optimization,
122
- plugins: [
123
- ...getDefaultPlugins(webpack, scripts),
124
- ...scripts.plugins
125
- ],
126
- target: scripts.target,
127
- stats: scripts.stats
128
- };
129
- }
130
- export default getCommonConfig;
@@ -1,14 +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
- new webpack.HotModuleReplacementPlugin()
8
- ],
9
- devtool: scripts.sourceMap
10
- ? scripts.sourceMap
11
- : 'eval-cheap-module-source-map'
12
- });
13
- }
14
- export default getDevConfig;
@@ -1,44 +0,0 @@
1
- import dotenv from 'dotenv';
2
- import dotenvExpand from 'dotenv-expand';
3
- const NODE_ENV = process.env.NODE_ENV;
4
- if (!NODE_ENV) {
5
- throw new Error('The NODE_ENV environment variable is required but was not specified.');
6
- }
7
- const dotenvFile = BalmJS.file.resolveApp('.env');
8
- const dotenvFiles = [
9
- `${dotenvFile}.${NODE_ENV}.local`,
10
- NODE_ENV !== 'test' && `${dotenvFile}.local`,
11
- `${dotenvFile}.${NODE_ENV}`,
12
- dotenvFile
13
- ].filter(Boolean);
14
- dotenvFiles.forEach((dotenvFile) => {
15
- if (node.fs.existsSync(dotenvFile)) {
16
- dotenvExpand.expand(dotenv.config({
17
- path: dotenvFile
18
- }));
19
- }
20
- });
21
- const BALM_APP = /^BALM_APP_/i;
22
- function getClientEnvironment(publicUrl) {
23
- const raw = Object.keys(process.env)
24
- .filter((key) => BALM_APP.test(key))
25
- .reduce((env, key) => {
26
- env[key] = process.env[key];
27
- return env;
28
- }, {
29
- NODE_ENV: process.env.NODE_ENV || 'development',
30
- PUBLIC_URL: publicUrl,
31
- ...BalmJS.config.scripts.nodeEnv
32
- });
33
- const stringified = {
34
- 'process.env': Object.keys(raw).reduce((env, key) => {
35
- env[key] = JSON.stringify(raw[key]);
36
- return env;
37
- }, {})
38
- };
39
- BalmJS.logger.debug('webpack .env', stringified, {
40
- pre: true
41
- });
42
- return { raw, stringified };
43
- }
44
- export default getClientEnvironment;
@@ -1,8 +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
5
- ? getProdConfig(webpack, scripts)
6
- : getDevConfig(webpack, scripts);
7
- }
8
- export default getDefaultConfig;
@@ -1,43 +0,0 @@
1
- import TerserPlugin from 'terser-webpack-plugin';
2
- import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
3
- import MiniCssExtractPlugin from 'mini-css-extract-plugin';
4
- import webpackBundleAnalyzer from 'webpack-bundle-analyzer';
5
- import { merge } from 'webpack-merge';
6
- import getCommonConfig from './common.js';
7
- import { CHUNK } from '../../../config/constants.js';
8
- const bundleAnalyzerReport = process.env.npm_config_report || false;
9
- const getCssFilename = () => `${BalmJS.config.paths.target.css}/${CHUNK.dir}/[name].${CHUNK.hash}.css`;
10
- function getProdConfig(webpack, scripts) {
11
- const shouldUseSourceMap = scripts.sourceMap;
12
- const terserOptions = scripts.minifyOptions;
13
- if (scripts.ie8) {
14
- terserOptions.ie8 = true;
15
- }
16
- return merge(getCommonConfig(webpack, scripts), {
17
- mode: 'production',
18
- optimization: {
19
- minimizer: [
20
- new TerserPlugin({
21
- terserOptions,
22
- extractComments: false
23
- }),
24
- new CssMinimizerPlugin()
25
- ]
26
- },
27
- plugins: [
28
- ...(scripts.extractCss
29
- ? [
30
- new MiniCssExtractPlugin({
31
- filename: BalmJS.file.assetsPath(getCssFilename()),
32
- chunkFilename: BalmJS.file.assetsPath(getCssFilename())
33
- })
34
- ]
35
- : []),
36
- ...(bundleAnalyzerReport
37
- ? [new webpackBundleAnalyzer.BundleAnalyzerPlugin()]
38
- : [])
39
- ],
40
- devtool: shouldUseSourceMap ? 'source-map' : false
41
- });
42
- }
43
- export default getProdConfig;
@@ -1,10 +0,0 @@
1
- const htmlRegex = /\.html$/;
2
- const cssRegex = /\.css$/;
3
- const cssModuleRegex = /\.module\.css$/;
4
- const sassRegex = /\.(scss|sass)$/;
5
- const sassModuleRegex = /\.module\.(scss|sass)$/;
6
- const jsRegex = /\.(js|mjs|jsx|ts|tsx)$/;
7
- const imgRegex = /\.(bmp|gif|jpe?g|png|svg|webp)(\?.*)?$/;
8
- const fontRegex = /\.(woff2?|eot|ttf|otf)(\?.*)?$/;
9
- const mediaRegex = /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/;
10
- export { htmlRegex, cssRegex, cssModuleRegex, sassRegex, sassModuleRegex, jsRegex, imgRegex, fontRegex, mediaRegex };
@@ -1,68 +0,0 @@
1
- import { HMR_PATH } from '../../config/constants.js';
2
- const FILENAME_REGEX = new RegExp('[^/]+$', 'i');
3
- const HOT_CLIENT = 'webpack-hot-middleware/client';
4
- function initVendors(entries) {
5
- const jsVendors = [];
6
- const jsEntries = [];
7
- for (const [key, value] of Object.entries(entries)) {
8
- if (BalmJS.utils.isArray(value)) {
9
- jsVendors.push({
10
- key,
11
- value: value
12
- });
13
- }
14
- else {
15
- jsEntries.push({
16
- key,
17
- value: value
18
- });
19
- }
20
- }
21
- BalmJS.vendors = jsVendors;
22
- BalmJS.entries = jsEntries;
23
- }
24
- function getEntry(input, scripts) {
25
- let webpackEntries = {};
26
- const hotOptions = Object.assign({}, BalmJS.config.server.hotOptions, {
27
- path: HMR_PATH
28
- });
29
- const HMR = `${HOT_CLIENT}?` +
30
- Object.entries(hotOptions)
31
- .map((option) => option.join('='))
32
- .join('&');
33
- const useHMR = BalmJS.config.server.useHMR;
34
- if (BalmJS.utils.isObject(input)) {
35
- initVendors(input);
36
- for (const [key, value] of Object.entries(input)) {
37
- const isVendor = BalmJS.utils.isArray(value);
38
- const entryKey = isVendor
39
- ? node.path.join(scripts.vendorName, key)
40
- : node.path.join(key);
41
- const hotValue = BalmJS.utils.isString(value)
42
- ? [value, HMR]
43
- : [...value, HMR];
44
- const entryValue = useHMR ? hotValue : value;
45
- if (!isVendor) {
46
- webpackEntries[entryKey] = entryValue;
47
- }
48
- }
49
- }
50
- else if (BalmJS.utils.isArray(input) && input.length) {
51
- for (const value of input) {
52
- const matchResult = FILENAME_REGEX.exec(value)[0];
53
- const key = matchResult.split('.')[0];
54
- webpackEntries[key] = useHMR ? [value, HMR] : value;
55
- }
56
- }
57
- else if (BalmJS.utils.isString(input) && input.trim().length) {
58
- webpackEntries = useHMR ? [input, HMR] : input;
59
- }
60
- else {
61
- BalmJS.logger.warn('webpack entry', '`scripts.entry` must be `string | array | object`');
62
- }
63
- BalmJS.logger.debug('webpack entry', webpackEntries, {
64
- pre: true
65
- });
66
- return webpackEntries;
67
- }
68
- export default getEntry;
@@ -1,30 +0,0 @@
1
- import { merge } from 'webpack-merge';
2
- import getEntry from './entry.js';
3
- import getOutput from './output.js';
4
- import getDefaultConfig from './config/index.js';
5
- const webpackModule = process.env.WEBPACK || requireModule.resolve('webpack');
6
- const webpack = requireModule(webpackModule);
7
- function webpackConfig(input, output, customWebpackOptions = {}, isHook = false) {
8
- const scripts = BalmJS.config.scripts;
9
- const defaultEntry = `./${BalmJS.file.defaultEntry}`;
10
- const baseConfig = {
11
- entry: input ? getEntry(input, scripts) : defaultEntry,
12
- output: getOutput(output, scripts, isHook)
13
- };
14
- BalmJS.logger.debug('webpack bundler', {
15
- input: baseConfig.entry,
16
- output: baseConfig.output.path
17
- }, {
18
- pre: true
19
- });
20
- if (scripts.externals) {
21
- baseConfig.externals = scripts.externals;
22
- }
23
- const defaultConfig = getDefaultConfig(webpack, scripts);
24
- const configuration = merge(baseConfig, defaultConfig, scripts.webpackOptions, customWebpackOptions);
25
- BalmJS.logger.success('webpack configuration', configuration, {
26
- pre: true
27
- });
28
- return configuration;
29
- }
30
- export { webpack, webpackConfig };
@@ -1,51 +0,0 @@
1
- import { mergeWithRules, CustomizeRule } from 'webpack-merge';
2
- import LOADERS from './rules/index.js';
3
- function getLoaders(customLoaders) {
4
- const enableDefaultLoaders = Object.assign({
5
- js: true,
6
- css: true,
7
- html: true,
8
- asset: true
9
- }, BalmJS.config.scripts.defaultLoaders);
10
- const useDefaultLoaders = Object.values(enableDefaultLoaders).some((value) => value);
11
- let defaultLoaders = [];
12
- if (useDefaultLoaders) {
13
- Object.values(LOADERS).forEach((Loader) => {
14
- const key = Loader.name.replace('Loader', '');
15
- if (enableDefaultLoaders[key]) {
16
- const loader = Loader();
17
- if (BalmJS.utils.isArray(loader)) {
18
- defaultLoaders = defaultLoaders.concat(loader);
19
- }
20
- else {
21
- defaultLoaders.push(loader);
22
- }
23
- }
24
- });
25
- }
26
- const result = mergeWithRules({
27
- module: {
28
- rules: {
29
- test: CustomizeRule.Match,
30
- use: {
31
- loader: CustomizeRule.Match,
32
- options: CustomizeRule.Replace
33
- }
34
- }
35
- }
36
- })({
37
- module: {
38
- rules: defaultLoaders
39
- }
40
- }, {
41
- module: {
42
- rules: customLoaders
43
- }
44
- });
45
- const defaultModule = result.module;
46
- BalmJS.logger.debug('webpack loaders', defaultModule.rules, {
47
- pre: true
48
- });
49
- return defaultModule.rules;
50
- }
51
- export default getLoaders;
@@ -1,41 +0,0 @@
1
- import { CHUNK, ASSET } from '../../config/constants.js';
2
- function getJsFilename(scripts, isChunk = false) {
3
- let filename;
4
- if (isChunk) {
5
- filename = BalmJS.config.env.isProd ? `[name].${CHUNK.hash}` : '[name]';
6
- }
7
- else {
8
- filename = scripts.useCache ? `[name].${CHUNK.hash}` : '[name]';
9
- }
10
- return `${filename}.js`;
11
- }
12
- function getOutput(output, scripts, isHook = false) {
13
- const outputDirectory = output || BalmJS.config.dest.base;
14
- const jsFolder = BalmJS.config.paths.target.js;
15
- const bundleFilename = getJsFilename(scripts);
16
- const chunkFilename = getJsFilename(scripts, true);
17
- const customLibraryConfig = scripts.library
18
- ? { library: scripts.library }
19
- : {};
20
- const miniprogramConfig = BalmJS.config.env.isMP
21
- ? {
22
- path: BalmJS.file.absPath(node.path.join(BalmJS.config.dest.base, ASSET.mpDir)),
23
- library: {
24
- name: 'createApp',
25
- type: 'window',
26
- export: 'default'
27
- }
28
- }
29
- : {};
30
- return Object.assign({
31
- path: BalmJS.file.absPath(outputDirectory),
32
- filename: isHook
33
- ? bundleFilename
34
- : BalmJS.file.assetsPath(`${jsFolder}/${bundleFilename}`),
35
- chunkFilename: isHook
36
- ? chunkFilename
37
- : BalmJS.file.assetsPath(`${jsFolder}/${CHUNK.dir}/${chunkFilename}`),
38
- publicPath: BalmJS.file.publicUrlOrPath
39
- }, customLibraryConfig, miniprogramConfig);
40
- }
41
- export default getOutput;
@@ -1,33 +0,0 @@
1
- import { imgRegex, fontRegex, mediaRegex } from '../config/regex.js';
2
- import { ASSET } from '../../../config/constants.js';
3
- function assetLoader() {
4
- return [
5
- {
6
- test: imgRegex,
7
- type: BalmJS.config.scripts.imageAssetType,
8
- parser: {
9
- dataUrlCondition: {
10
- maxSize: BalmJS.config.scripts.imageInlineSizeLimit
11
- }
12
- },
13
- generator: {
14
- filename: BalmJS.file.assetsPath(`${ASSET.dir}/${BalmJS.config.paths.target.img}/[name].${ASSET.hash}[ext]`)
15
- }
16
- },
17
- {
18
- test: fontRegex,
19
- type: 'asset/resource',
20
- generator: {
21
- filename: BalmJS.file.assetsPath(`${ASSET.dir}/${BalmJS.config.paths.target.font}/[name].${ASSET.hash}[ext]`)
22
- }
23
- },
24
- {
25
- test: mediaRegex,
26
- type: 'asset/resource',
27
- generator: {
28
- filename: BalmJS.file.assetsPath(`${ASSET.dir}/${BalmJS.config.paths.target.media}/[name].${ASSET.hash}[ext]`)
29
- }
30
- }
31
- ];
32
- }
33
- export default assetLoader;
@@ -1,16 +0,0 @@
1
- import { jsRegex } from '../config/regex.js';
2
- function jsLoader() {
3
- const options = Object.assign({
4
- cacheDirectory: true
5
- }, BalmJS.config.scripts.babelLoaderOptions);
6
- return {
7
- test: jsRegex,
8
- include: [
9
- BalmJS.file.absPaths(BalmJS.config.src.js),
10
- ...BalmJS.config.scripts.includeJsResource
11
- ],
12
- loader: requireModule.resolve('babel-loader'),
13
- options
14
- };
15
- }
16
- export default jsLoader;
@@ -1,95 +0,0 @@
1
- import fs from 'node:fs';
2
- import MiniCssExtractPlugin from 'mini-css-extract-plugin';
3
- import { cssRegex, cssModuleRegex, sassRegex, sassModuleRegex } from '../config/regex.js';
4
- const useTailwind = fs.existsSync(node.path.join(BalmJS.config.workspace, 'tailwind.config.js'));
5
- function getStyleLoaders(styleLoader, cssOptions, preProcessor = '', sassOptions = {}) {
6
- const { sourceMap } = cssOptions;
7
- const loaders = [
8
- BalmJS.config.env.isProd && BalmJS.config.scripts.extractCss
9
- ? {
10
- loader: MiniCssExtractPlugin.loader,
11
- options: {
12
- esModule: BalmJS.config.scripts.useEsModule
13
- }
14
- }
15
- : styleLoader,
16
- {
17
- loader: requireModule.resolve('css-loader'),
18
- options: cssOptions
19
- },
20
- {
21
- loader: requireModule.resolve('postcss-loader'),
22
- options: Object.assign({
23
- postcssOptions: {
24
- plugins: BalmJS.plugins.postcssPlugins(true, useTailwind)
25
- },
26
- sourceMap
27
- }, BalmJS.config.scripts.postcssLoaderOptions)
28
- }
29
- ].filter(Boolean);
30
- if (preProcessor) {
31
- loaders.push({
32
- loader: requireModule.resolve(preProcessor),
33
- options: Object.assign({
34
- sourceMap: true
35
- }, sassOptions)
36
- });
37
- }
38
- return loaders;
39
- }
40
- function cssLoader() {
41
- let styleLoader = {
42
- loader: requireModule.resolve('style-loader'),
43
- options: {
44
- esModule: BalmJS.config.scripts.useEsModule
45
- }
46
- };
47
- if (BalmJS.config.env.inSSR) {
48
- const loadersCount = BalmJS.config.scripts.loaders.length;
49
- for (let i = 0; i < loadersCount; i++) {
50
- if (BalmJS.config.scripts.loaders[i].loader ===
51
- 'vue-loader') {
52
- styleLoader = 'vue-style-loader';
53
- break;
54
- }
55
- }
56
- }
57
- const sourceMap = BalmJS.config.env.isProd
58
- ? BalmJS.config.scripts.sourceMap
59
- : BalmJS.config.env.isDev;
60
- return [
61
- {
62
- test: cssRegex,
63
- exclude: cssModuleRegex,
64
- use: getStyleLoaders(styleLoader, {
65
- importLoaders: 1,
66
- sourceMap,
67
- modules: {
68
- mode: 'icss'
69
- },
70
- esModule: BalmJS.config.scripts.useEsModule
71
- }),
72
- sideEffects: true
73
- },
74
- {
75
- test: sassRegex,
76
- exclude: sassModuleRegex,
77
- use: getStyleLoaders(styleLoader, {
78
- importLoaders: 3,
79
- sourceMap,
80
- modules: {
81
- mode: 'icss'
82
- }
83
- }, 'sass-loader', {
84
- implementation: requireModule.resolve('sass'),
85
- sassOptions: Object.assign({
86
- loadPaths: BalmJS.file.stylePaths,
87
- sourceMap: true,
88
- quietDeps: BalmJS.config.logs.level < BalmJS.LogLevel.Warn
89
- }, BalmJS.config.styles.sassOptions)
90
- }),
91
- sideEffects: true
92
- }
93
- ];
94
- }
95
- export default cssLoader;
@@ -1,15 +0,0 @@
1
- import { htmlRegex } from '../config/regex.js';
2
- function htmlLoader() {
3
- const options = Object.assign({
4
- minimize: {
5
- removeAttributeQuotes: false
6
- },
7
- esModule: BalmJS.config.scripts.useEsModule
8
- }, BalmJS.config.scripts.htmlLoaderOptions);
9
- return {
10
- test: `${htmlRegex}i`,
11
- loader: requireModule.resolve('html-loader'),
12
- options
13
- };
14
- }
15
- export default htmlLoader;
@@ -1,10 +0,0 @@
1
- import jsLoader from './babel.js';
2
- import cssLoader from './css.js';
3
- import htmlLoader from './html.js';
4
- import assetLoader from './asset.js';
5
- export default {
6
- assetLoader,
7
- htmlLoader,
8
- jsLoader,
9
- cssLoader
10
- };
@@ -1,24 +0,0 @@
1
- const root = 'assets';
2
- const mainDir = 'public';
3
- const subDir = '';
4
- const buildDir = 'build';
5
- const virtualDir = '';
6
- const cache = false;
7
- const options = {
8
- fileNameManifest: 'rev-manifest.json',
9
- dontRenameFile: ['.html'],
10
- dontUpdateReference: ['.html']
11
- };
12
- const includes = [];
13
- const excludes = [];
14
- export default {
15
- root,
16
- mainDir,
17
- subDir,
18
- buildDir,
19
- virtualDir,
20
- cache,
21
- options,
22
- includes,
23
- excludes
24
- };
@@ -1,14 +0,0 @@
1
- const DOMAIN = 'https://balm.js.org';
2
- const HMR_PATH = '/__balm_hmr';
3
- const PUBLIC_URL = '%PUBLIC_URL%';
4
- const ASSETS_TYPES = ['css', 'js', 'img', 'font', 'media'];
5
- const CHUNK = {
6
- dir: 'chunk',
7
- hash: '[contenthash:8]'
8
- };
9
- const ASSET = {
10
- dir: 'asset',
11
- hash: '[hash:8]',
12
- mpDir: 'common'
13
- };
14
- export { DOMAIN, HMR_PATH, PUBLIC_URL, ASSETS_TYPES, CHUNK, ASSET };