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.
- package/dist/index.cjs +2191 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +559 -0
- package/dist/index.d.ts +559 -0
- package/dist/index.js +2098 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -123
- package/src/balm.ts +103 -0
- package/src/bundler/esbuild.ts +47 -0
- package/src/bundler/index.ts +3 -0
- package/src/bundler/rollup.ts +39 -0
- package/src/bundler/webpack.ts +82 -0
- package/src/config/constants.ts +12 -0
- package/src/config/defaults.ts +209 -0
- package/src/config/index.ts +112 -0
- package/src/hooks/index.ts +192 -0
- package/src/index.ts +16 -0
- package/src/pipeline/file.ts +69 -0
- package/src/pipeline/index.ts +10 -0
- package/src/pipeline/pipeline.ts +132 -0
- package/src/pipeline/transforms/cache.ts +96 -0
- package/src/pipeline/transforms/htmlmin.ts +18 -0
- package/src/pipeline/transforms/less.ts +75 -0
- package/src/pipeline/transforms/postcss.ts +43 -0
- package/src/pipeline/transforms/rename.ts +37 -0
- package/src/pipeline/transforms/replace.ts +30 -0
- package/src/pipeline/transforms/sass.ts +106 -0
- package/src/pipeline/transforms/terser.ts +20 -0
- package/src/runner/dag.ts +77 -0
- package/src/runner/task.ts +38 -0
- package/src/shims.d.ts +5 -0
- package/src/tasks/cache.ts +58 -0
- package/src/tasks/clean.ts +21 -0
- package/src/tasks/copy.ts +36 -0
- package/src/tasks/ftp.ts +90 -0
- package/src/tasks/html.ts +78 -0
- package/src/tasks/index.ts +13 -0
- package/src/tasks/publish.ts +71 -0
- package/src/tasks/pwa.ts +49 -0
- package/src/tasks/remove.ts +24 -0
- package/src/tasks/replace.ts +34 -0
- package/src/tasks/script.ts +28 -0
- package/src/tasks/server.ts +89 -0
- package/src/tasks/style.ts +57 -0
- package/src/tasks/zip.ts +65 -0
- package/src/types/index.ts +200 -0
- package/src/utilities/file.ts +120 -0
- package/src/utilities/logger.ts +63 -0
- package/src/utilities/utils.ts +46 -0
- package/src/utilities/workspace.ts +38 -0
- package/src/watcher/index.ts +100 -0
- package/tsconfig.json +8 -0
- package/tsup.config.ts +12 -0
- package/README.md +0 -196
- package/index.d.ts +0 -360
- package/lib/balm.js +0 -49
- package/lib/bootstrap/check_config.js +0 -43
- package/lib/bootstrap/index.js +0 -87
- package/lib/bundler/esbuild/build.js +0 -26
- package/lib/bundler/esbuild/index.js +0 -7
- package/lib/bundler/esbuild/options.js +0 -7
- package/lib/bundler/esbuild/transform.js +0 -36
- package/lib/bundler/rollup/build.js +0 -52
- package/lib/bundler/rollup/entry.js +0 -28
- package/lib/bundler/rollup/index.js +0 -20
- package/lib/bundler/rollup/output.js +0 -20
- package/lib/bundler/rollup/plugins.js +0 -31
- package/lib/bundler/webpack/config/common.js +0 -135
- package/lib/bundler/webpack/config/dev.js +0 -12
- package/lib/bundler/webpack/config/env.js +0 -67
- package/lib/bundler/webpack/config/index.js +0 -6
- package/lib/bundler/webpack/config/prod.js +0 -39
- package/lib/bundler/webpack/config/regex.js +0 -10
- package/lib/bundler/webpack/entry.js +0 -65
- package/lib/bundler/webpack/index.js +0 -32
- package/lib/bundler/webpack/loaders.js +0 -50
- package/lib/bundler/webpack/output.js +0 -41
- package/lib/bundler/webpack/rules/asset.js +0 -33
- package/lib/bundler/webpack/rules/babel.js +0 -19
- package/lib/bundler/webpack/rules/css.js +0 -109
- package/lib/bundler/webpack/rules/html.js +0 -15
- package/lib/bundler/webpack/rules/index.js +0 -10
- package/lib/config/assets.js +0 -30
- package/lib/config/constants.js +0 -14
- package/lib/config/env.js +0 -35
- package/lib/config/extras.js +0 -6
- package/lib/config/ftp.js +0 -6
- package/lib/config/globals.js +0 -43
- package/lib/config/html.js +0 -22
- package/lib/config/images.js +0 -4
- package/lib/config/index.js +0 -63
- package/lib/config/logs.js +0 -11
- package/lib/config/paths.js +0 -46
- package/lib/config/pwa.js +0 -24
- package/lib/config/roots.js +0 -9
- package/lib/config/scripts.js +0 -162
- package/lib/config/server.js +0 -84
- package/lib/config/spinner.js +0 -9
- package/lib/config/styles.js +0 -67
- package/lib/hello.js +0 -19
- package/lib/hooks/index.js +0 -94
- package/lib/hooks/maker.js +0 -59
- package/lib/index.js +0 -5
- package/lib/middlewares/history.js +0 -6
- package/lib/middlewares/index.js +0 -11
- package/lib/middlewares/proxy.js +0 -28
- package/lib/middlewares/webpack.js +0 -26
- package/lib/plugins/htmlmin.js +0 -39
- package/lib/plugins/imagemin.js +0 -95
- package/lib/plugins/index.js +0 -27
- package/lib/plugins/jsmin.js +0 -37
- package/lib/plugins/less.js +0 -97
- package/lib/plugins/plumber.js +0 -87
- package/lib/plugins/postcss-plugins.js +0 -13
- package/lib/plugins/postcss.js +0 -117
- package/lib/plugins/rename.js +0 -51
- package/lib/plugins/replace.js +0 -91
- package/lib/plugins/sass-legacy.js +0 -131
- package/lib/plugins/sass.js +0 -134
- package/lib/plugins/sftp.js +0 -288
- package/lib/tasks/default.js +0 -46
- package/lib/tasks/foundation/balm.js +0 -72
- package/lib/tasks/foundation/balm_style.js +0 -65
- package/lib/tasks/foundation/index.js +0 -10
- package/lib/tasks/index.js +0 -48
- package/lib/tasks/private/build.js +0 -18
- package/lib/tasks/private/cache.js +0 -31
- package/lib/tasks/private/clean.js +0 -69
- package/lib/tasks/private/end.js +0 -24
- package/lib/tasks/private/extra.js +0 -35
- package/lib/tasks/private/font.js +0 -15
- package/lib/tasks/private/image.js +0 -37
- package/lib/tasks/private/index.js +0 -34
- package/lib/tasks/private/lint.js +0 -20
- package/lib/tasks/private/media.js +0 -15
- package/lib/tasks/private/modernizr.js +0 -59
- package/lib/tasks/private/pwa-cache.js +0 -32
- package/lib/tasks/private/script.js +0 -9
- package/lib/tasks/private/sprite.js +0 -105
- package/lib/tasks/private/start.js +0 -16
- package/lib/tasks/private/style.js +0 -9
- package/lib/tasks/private/workbox-sw.js +0 -15
- package/lib/tasks/public/copy.js +0 -16
- package/lib/tasks/public/esbuild.js +0 -18
- package/lib/tasks/public/ftp.js +0 -39
- package/lib/tasks/public/html.js +0 -65
- package/lib/tasks/public/index.js +0 -38
- package/lib/tasks/public/jsmin.js +0 -23
- package/lib/tasks/public/less.js +0 -21
- package/lib/tasks/public/postcss.js +0 -16
- package/lib/tasks/public/publish.js +0 -51
- package/lib/tasks/public/pwa.js +0 -84
- package/lib/tasks/public/remove.js +0 -46
- package/lib/tasks/public/replace.js +0 -26
- package/lib/tasks/public/rollup.js +0 -17
- package/lib/tasks/public/sass.js +0 -27
- package/lib/tasks/public/server.js +0 -130
- package/lib/tasks/public/url.js +0 -35
- package/lib/tasks/public/version.js +0 -23
- package/lib/tasks/public/webpack.js +0 -39
- package/lib/tasks/public/zip.js +0 -19
- package/lib/utilities/address.js +0 -55
- package/lib/utilities/cache-core.js +0 -66
- package/lib/utilities/color.js +0 -27
- package/lib/utilities/compiling.js +0 -24
- package/lib/utilities/detect-port.js +0 -100
- package/lib/utilities/escape-string-regexp.js +0 -10
- package/lib/utilities/file.js +0 -70
- package/lib/utilities/index.js +0 -8
- package/lib/utilities/loading.js +0 -37
- package/lib/utilities/logger.js +0 -99
- package/lib/utilities/merge-stream.js +0 -38
- package/lib/utilities/namespace.js +0 -11
- package/lib/utilities/public-url.js +0 -37
- package/lib/utilities/replacestream.js +0 -106
- package/lib/utilities/typeof.js +0 -5
- package/lib/utilities/utils.js +0 -43
- package/tslib/balm.js +0 -44
- package/tslib/bootstrap/check_config.js +0 -36
- package/tslib/bootstrap/index.js +0 -82
- package/tslib/bundler/esbuild/build.js +0 -30
- package/tslib/bundler/esbuild/index.js +0 -11
- package/tslib/bundler/esbuild/options.js +0 -7
- package/tslib/bundler/esbuild/transform.js +0 -38
- package/tslib/bundler/rollup/build.js +0 -17
- package/tslib/bundler/rollup/entry.js +0 -24
- package/tslib/bundler/rollup/index.js +0 -21
- package/tslib/bundler/rollup/output.js +0 -23
- package/tslib/bundler/rollup/plugins.js +0 -27
- package/tslib/bundler/webpack/config/common.js +0 -130
- package/tslib/bundler/webpack/config/dev.js +0 -14
- package/tslib/bundler/webpack/config/env.js +0 -44
- package/tslib/bundler/webpack/config/index.js +0 -8
- package/tslib/bundler/webpack/config/prod.js +0 -43
- package/tslib/bundler/webpack/config/regex.js +0 -10
- package/tslib/bundler/webpack/entry.js +0 -68
- package/tslib/bundler/webpack/index.js +0 -30
- package/tslib/bundler/webpack/loaders.js +0 -51
- package/tslib/bundler/webpack/output.js +0 -41
- package/tslib/bundler/webpack/rules/asset.js +0 -33
- package/tslib/bundler/webpack/rules/babel.js +0 -16
- package/tslib/bundler/webpack/rules/css.js +0 -95
- package/tslib/bundler/webpack/rules/html.js +0 -15
- package/tslib/bundler/webpack/rules/index.js +0 -10
- package/tslib/config/assets.js +0 -24
- package/tslib/config/constants.js +0 -14
- package/tslib/config/env.js +0 -43
- package/tslib/config/extras.js +0 -6
- package/tslib/config/ftp.js +0 -6
- package/tslib/config/globals.js +0 -47
- package/tslib/config/html.js +0 -17
- package/tslib/config/images.js +0 -4
- package/tslib/config/index.js +0 -56
- package/tslib/config/logs.js +0 -6
- package/tslib/config/paths.js +0 -30
- package/tslib/config/pwa.js +0 -18
- package/tslib/config/roots.js +0 -8
- package/tslib/config/scripts.js +0 -93
- package/tslib/config/server.js +0 -33
- package/tslib/config/spinner.js +0 -10
- package/tslib/config/styles.js +0 -37
- package/tslib/hello.js +0 -19
- package/tslib/hooks/index.js +0 -75
- package/tslib/hooks/maker.js +0 -66
- package/tslib/index.js +0 -5
- package/tslib/middlewares/history.js +0 -12
- package/tslib/middlewares/index.js +0 -18
- package/tslib/middlewares/proxy.js +0 -27
- package/tslib/middlewares/webpack.js +0 -29
- package/tslib/plugins/htmlmin.js +0 -38
- package/tslib/plugins/imagemin.js +0 -97
- package/tslib/plugins/index.js +0 -27
- package/tslib/plugins/jsmin.js +0 -39
- package/tslib/plugins/less.js +0 -90
- package/tslib/plugins/plumber.js +0 -81
- package/tslib/plugins/postcss-plugins.js +0 -24
- package/tslib/plugins/postcss.js +0 -111
- package/tslib/plugins/rename.js +0 -51
- package/tslib/plugins/replace.js +0 -72
- package/tslib/plugins/sass-legacy.js +0 -95
- package/tslib/plugins/sass.js +0 -109
- package/tslib/plugins/sftp.js +0 -258
- package/tslib/tasks/default.js +0 -59
- package/tslib/tasks/foundation/balm.js +0 -75
- package/tslib/tasks/foundation/balm_style.js +0 -68
- package/tslib/tasks/foundation/index.js +0 -10
- package/tslib/tasks/index.js +0 -43
- package/tslib/tasks/private/build.js +0 -15
- package/tslib/tasks/private/cache.js +0 -48
- package/tslib/tasks/private/clean.js +0 -82
- package/tslib/tasks/private/end.js +0 -21
- package/tslib/tasks/private/extra.js +0 -34
- package/tslib/tasks/private/font.js +0 -12
- package/tslib/tasks/private/image.js +0 -42
- package/tslib/tasks/private/index.js +0 -34
- package/tslib/tasks/private/lint.js +0 -17
- package/tslib/tasks/private/media.js +0 -12
- package/tslib/tasks/private/modernizr.js +0 -54
- package/tslib/tasks/private/pwa-cache.js +0 -32
- package/tslib/tasks/private/script.js +0 -9
- package/tslib/tasks/private/sprite.js +0 -93
- package/tslib/tasks/private/start.js +0 -13
- package/tslib/tasks/private/style.js +0 -12
- package/tslib/tasks/private/workbox-sw.js +0 -15
- package/tslib/tasks/public/copy.js +0 -18
- package/tslib/tasks/public/esbuild.js +0 -18
- package/tslib/tasks/public/ftp.js +0 -39
- package/tslib/tasks/public/html.js +0 -75
- package/tslib/tasks/public/index.js +0 -38
- package/tslib/tasks/public/jsmin.js +0 -24
- package/tslib/tasks/public/less.js +0 -21
- package/tslib/tasks/public/postcss.js +0 -16
- package/tslib/tasks/public/publish.js +0 -50
- package/tslib/tasks/public/pwa.js +0 -87
- package/tslib/tasks/public/remove.js +0 -44
- package/tslib/tasks/public/replace.js +0 -27
- package/tslib/tasks/public/rollup.js +0 -17
- package/tslib/tasks/public/sass.js +0 -27
- package/tslib/tasks/public/server.js +0 -129
- package/tslib/tasks/public/url.js +0 -35
- package/tslib/tasks/public/version.js +0 -27
- package/tslib/tasks/public/webpack.js +0 -41
- package/tslib/tasks/public/zip.js +0 -19
- package/tslib/utilities/address.js +0 -48
- package/tslib/utilities/cache-core.js +0 -57
- package/tslib/utilities/color.js +0 -33
- package/tslib/utilities/compiling.js +0 -16
- package/tslib/utilities/detect-port.js +0 -91
- package/tslib/utilities/escape-string-regexp.js +0 -7
- package/tslib/utilities/file.js +0 -78
- package/tslib/utilities/index.js +0 -8
- package/tslib/utilities/loading.js +0 -25
- package/tslib/utilities/logger.js +0 -92
- package/tslib/utilities/merge-stream.js +0 -34
- package/tslib/utilities/namespace.js +0 -12
- package/tslib/utilities/public-url.js +0 -31
- package/tslib/utilities/replacestream.js +0 -112
- package/tslib/utilities/typeof.js +0 -8
- 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;
|
package/lib/bootstrap/index.js
DELETED
|
@@ -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,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;
|