balm-core 4.11.0 → 4.13.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/lib/balm.js +0 -20
- package/lib/bootstrap/check_config.js +6 -9
- package/lib/bootstrap/index.js +16 -22
- package/lib/bundler/esbuild/build.js +0 -2
- package/lib/bundler/esbuild/index.js +0 -2
- package/lib/bundler/esbuild/transform.js +0 -4
- package/lib/bundler/rollup/build.js +2 -4
- package/lib/bundler/rollup/entry.js +2 -5
- package/lib/bundler/rollup/index.js +0 -3
- package/lib/bundler/rollup/output.js +0 -5
- package/lib/bundler/rollup/plugins.js +0 -10
- package/lib/bundler/webpack/config/common.js +4 -15
- package/lib/bundler/webpack/config/dev.js +2 -3
- package/lib/bundler/webpack/config/env.js +12 -14
- package/lib/bundler/webpack/config/index.js +0 -2
- package/lib/bundler/webpack/config/prod.js +4 -7
- package/lib/bundler/webpack/entry.js +8 -12
- package/lib/bundler/webpack/index.js +2 -5
- package/lib/bundler/webpack/loaders.js +0 -6
- package/lib/bundler/webpack/output.js +0 -5
- package/lib/bundler/webpack/rules/asset.js +2 -3
- package/lib/bundler/webpack/rules/babel.js +3 -4
- package/lib/bundler/webpack/rules/css.js +4 -10
- package/lib/bundler/webpack/rules/html.js +0 -2
- package/lib/config/assets.js +0 -5
- package/lib/config/env.js +0 -2
- package/lib/config/globals.js +2 -5
- package/lib/config/index.js +0 -5
- package/lib/config/logs.js +0 -1
- package/lib/config/paths.js +3 -3
- package/lib/config/pwa.js +0 -3
- package/lib/config/roots.js +0 -2
- package/lib/config/scripts.js +20 -28
- package/lib/config/server.js +4 -10
- package/lib/config/styles.js +2 -10
- package/lib/hello.js +0 -2
- package/lib/hooks/index.js +18 -35
- package/lib/hooks/maker.js +0 -14
- package/lib/middlewares/history.js +0 -2
- package/lib/middlewares/index.js +0 -4
- package/lib/middlewares/proxy.js +0 -6
- package/lib/middlewares/webpack.js +0 -5
- package/lib/plugins/htmlmin.js +1 -7
- package/lib/plugins/imagemin.js +1 -18
- package/lib/plugins/jsmin.js +0 -10
- package/lib/plugins/less.js +7 -14
- package/lib/plugins/plumber.js +4 -21
- package/lib/plugins/postcss-plugins.js +0 -2
- package/lib/plugins/postcss.js +8 -21
- package/lib/plugins/rename.js +2 -13
- package/lib/plugins/replace.js +4 -22
- package/lib/plugins/sass.js +30 -39
- package/lib/plugins/sftp.js +33 -62
- package/lib/tasks/default.js +10 -19
- package/lib/tasks/foundation/balm.js +0 -25
- package/lib/tasks/foundation/balm_style.js +2 -15
- package/lib/tasks/foundation/index.js +0 -2
- package/lib/tasks/index.js +8 -7
- package/lib/tasks/private/build.js +0 -5
- package/lib/tasks/private/cache.js +0 -6
- package/lib/tasks/private/clean.js +0 -20
- package/lib/tasks/private/end.js +0 -6
- package/lib/tasks/private/extra.js +4 -11
- package/lib/tasks/private/font.js +0 -5
- package/lib/tasks/private/image.js +0 -11
- package/lib/tasks/private/lint.js +0 -5
- package/lib/tasks/private/media.js +0 -5
- package/lib/tasks/private/modernizr.js +0 -19
- package/lib/tasks/private/pwa-cache.js +0 -7
- package/lib/tasks/private/script.js +0 -3
- package/lib/tasks/private/sprite.js +3 -25
- package/lib/tasks/private/start.js +0 -6
- package/lib/tasks/private/style.js +0 -3
- package/lib/tasks/private/workbox-sw.js +0 -5
- package/lib/tasks/public/copy.js +0 -5
- package/lib/tasks/public/esbuild.js +0 -6
- package/lib/tasks/public/ftp.js +0 -11
- package/lib/tasks/public/html.js +0 -20
- package/lib/tasks/public/jsmin.js +0 -6
- package/lib/tasks/public/less.js +0 -6
- package/lib/tasks/public/postcss.js +0 -5
- package/lib/tasks/public/publish.js +3 -15
- package/lib/tasks/public/pwa.js +0 -13
- package/lib/tasks/public/remove.js +2 -18
- package/lib/tasks/public/replace.js +0 -7
- package/lib/tasks/public/rollup.js +0 -6
- package/lib/tasks/public/sass.js +0 -6
- package/lib/tasks/public/server.js +4 -32
- package/lib/tasks/public/url.js +0 -13
- package/lib/tasks/public/version.js +0 -6
- package/lib/tasks/public/webpack.js +2 -12
- package/lib/tasks/public/zip.js +0 -5
- package/lib/utilities/address.js +5 -16
- package/lib/utilities/cache-core.js +5 -13
- package/lib/utilities/color.js +0 -5
- package/lib/utilities/compiling.js +0 -14
- package/lib/utilities/detect-port.js +6 -22
- package/lib/utilities/escape-string-regexp.js +3 -4
- package/lib/utilities/file.js +2 -18
- package/lib/utilities/loading.js +0 -23
- package/lib/utilities/logger.js +0 -19
- package/lib/utilities/merge-stream.js +0 -8
- package/lib/utilities/namespace.js +0 -4
- package/lib/utilities/public-url.js +10 -10
- package/lib/utilities/replacestream.js +5 -27
- package/lib/utilities/typeof.js +0 -2
- package/lib/utilities/utils.js +2 -9
- package/package.json +31 -31
package/lib/balm.js
CHANGED
|
@@ -1,57 +1,40 @@
|
|
|
1
1
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
2
|
-
|
|
3
2
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
4
|
-
|
|
5
3
|
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
6
|
-
|
|
7
4
|
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
8
|
-
|
|
9
5
|
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
|
|
10
|
-
|
|
11
6
|
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
12
|
-
|
|
13
7
|
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
|
|
14
|
-
|
|
15
8
|
import './config/index.js';
|
|
16
9
|
import './utilities/index.js';
|
|
17
10
|
import './plugins/index.js';
|
|
18
11
|
import registerTasks from './tasks/index.js';
|
|
19
12
|
import { setConfig, setTask } from './bootstrap/index.js';
|
|
20
13
|
import loading from './utilities/loading.js';
|
|
21
|
-
|
|
22
14
|
var _config = /*#__PURE__*/new WeakMap();
|
|
23
|
-
|
|
24
15
|
class Balm {
|
|
25
16
|
constructor() {
|
|
26
17
|
_classPrivateFieldInitSpec(this, _config, {
|
|
27
18
|
writable: true,
|
|
28
19
|
value: void 0
|
|
29
20
|
});
|
|
30
|
-
|
|
31
21
|
BalmJS.loading = false;
|
|
32
22
|
loading.succeed();
|
|
33
|
-
|
|
34
23
|
_classPrivateFieldSet(this, _config, setConfig({}));
|
|
35
24
|
}
|
|
36
|
-
|
|
37
25
|
get config() {
|
|
38
26
|
return _classPrivateFieldGet(this, _config);
|
|
39
27
|
}
|
|
40
|
-
|
|
41
28
|
set config(value) {
|
|
42
29
|
_classPrivateFieldSet(this, _config, setConfig(value));
|
|
43
|
-
|
|
44
30
|
BalmJS.config = _classPrivateFieldGet(this, _config);
|
|
45
31
|
}
|
|
46
|
-
|
|
47
32
|
set beforeTask(name) {
|
|
48
33
|
BalmJS.beforeTask = setTask(name);
|
|
49
34
|
}
|
|
50
|
-
|
|
51
35
|
set afterTask(name) {
|
|
52
36
|
BalmJS.afterTask = setTask(name);
|
|
53
37
|
}
|
|
54
|
-
|
|
55
38
|
go(recipe = NOOP) {
|
|
56
39
|
if (BalmJS.utils.isFunction(recipe)) {
|
|
57
40
|
registerTasks(recipe);
|
|
@@ -59,7 +42,6 @@ class Balm {
|
|
|
59
42
|
BalmJS.logger.error('initialization', 'BalmJS API: `balm.go(mix => {});`');
|
|
60
43
|
}
|
|
61
44
|
}
|
|
62
|
-
|
|
63
45
|
reset() {
|
|
64
46
|
BalmJS.tasks = new Map();
|
|
65
47
|
BalmJS.recipes = [];
|
|
@@ -68,7 +50,5 @@ class Balm {
|
|
|
68
50
|
BalmJS.afterTask = undefined;
|
|
69
51
|
BalmJS.config.useDefaults = true;
|
|
70
52
|
}
|
|
71
|
-
|
|
72
53
|
}
|
|
73
|
-
|
|
74
54
|
export default Balm;
|
|
@@ -1,45 +1,42 @@
|
|
|
1
1
|
import { DOMAIN } from '../config/constants.js';
|
|
2
2
|
const docsBaseURL = `${DOMAIN}/docs/config`;
|
|
3
|
-
|
|
4
3
|
function upgradeGuide(key, value, message) {
|
|
5
4
|
const page = key === 'scripts' ? 'scripts-webpack' : key.toLowerCase();
|
|
6
5
|
return `${message} See ${docsBaseURL}/${page}.html#${key}-${value.toLowerCase()}`;
|
|
7
6
|
}
|
|
8
|
-
|
|
9
7
|
function upgradeRenamed(version, configCategory, from, to) {
|
|
10
8
|
if (BalmJS.config[configCategory][from]) {
|
|
11
9
|
BalmJS.logger.warn(`balm@${version}+ config`, upgradeGuide(configCategory, to, `'${configCategory}.${from}' was renamed to '${configCategory}.${to}'.`));
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
function upgradeMigrated(version, configName, from, to) {
|
|
16
13
|
if (BalmJS.config[from][configName]) {
|
|
17
14
|
BalmJS.logger.warn(`balm@${version}+ config`, upgradeGuide(to, configName, `'${from}.${configName}' was migrated to '${to}.${configName}'.`));
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
function upgradeDeprecated(version, configCategory, configName) {
|
|
22
18
|
if (BalmJS.config[configCategory][configName]) {
|
|
23
19
|
BalmJS.logger.warn(`balm@${version}+ config`, `'${configCategory}.${configName}' was deprecated.`);
|
|
24
20
|
}
|
|
25
|
-
}
|
|
26
|
-
|
|
21
|
+
}
|
|
27
22
|
|
|
23
|
+
// Compatibility for upgrade balm
|
|
28
24
|
function checkConfig() {
|
|
29
25
|
// For v2
|
|
30
26
|
upgradeRenamed('2.5.0', 'scripts', 'disableDefaultLoaders', 'defaultLoaders');
|
|
31
27
|
upgradeMigrated('2.11.0', 'postcssLoaderOptions', 'styles', 'scripts');
|
|
32
|
-
upgradeRenamed('2.22.0', 'images', 'defaultPlugins', 'plugins');
|
|
28
|
+
upgradeRenamed('2.22.0', 'images', 'defaultPlugins', 'plugins');
|
|
33
29
|
|
|
30
|
+
// For v3
|
|
34
31
|
upgradeRenamed('3.0.0', 'styles', 'minified', 'minify');
|
|
35
32
|
upgradeRenamed('3.9.0', 'scripts', 'options', 'minifyOptions');
|
|
36
33
|
upgradeRenamed('3.16.0', 'scripts', 'inject', 'useCache');
|
|
37
34
|
upgradeDeprecated('3.17.0', 'styles', 'darkSass');
|
|
38
|
-
upgradeDeprecated('3.19.0', 'scripts', 'useCache');
|
|
35
|
+
upgradeDeprecated('3.19.0', 'scripts', 'useCache');
|
|
39
36
|
|
|
37
|
+
// For v4
|
|
40
38
|
upgradeDeprecated('4.0.0', 'scripts', 'libraryTarget');
|
|
41
39
|
upgradeDeprecated('4.5.0', 'scripts', 'excludeUrlResource');
|
|
42
40
|
upgradeDeprecated('4.5.0', 'scripts', 'urlLoaderOptions');
|
|
43
41
|
}
|
|
44
|
-
|
|
45
42
|
export default checkConfig;
|
package/lib/bootstrap/index.js
CHANGED
|
@@ -1,81 +1,77 @@
|
|
|
1
1
|
import checkConfig from './check_config.js';
|
|
2
2
|
import { ASSETS_TYPES } from '../config/constants.js';
|
|
3
|
-
|
|
4
3
|
function createQuickPath(config, rootKey) {
|
|
5
4
|
const result = {};
|
|
6
5
|
const rootValue = config.roots[rootKey];
|
|
7
|
-
|
|
8
6
|
for (const pathKey of Object.keys(config.paths[rootKey])) {
|
|
9
7
|
const pathValue = config.paths[rootKey][pathKey];
|
|
10
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);
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
return rootKey === 'source' ? result : result;
|
|
14
11
|
}
|
|
15
|
-
|
|
16
12
|
function ready(config) {
|
|
17
13
|
// Create local quick directories
|
|
18
14
|
config.src = createQuickPath(config, 'source');
|
|
19
15
|
config.dest = createQuickPath(config, config.env.isProd || !config.inFrontend ? 'target' : 'tmp');
|
|
20
|
-
config.dest.static = node.path.join(config.dest.base, BalmJS.config.assets.virtualDir, BalmJS.file.assetsSuffixPath);
|
|
16
|
+
config.dest.static = node.path.join(config.dest.base, BalmJS.config.assets.virtualDir, BalmJS.file.assetsSuffixPath);
|
|
21
17
|
|
|
18
|
+
// Create remote quick directories
|
|
22
19
|
config.assets.static = node.path.join(config.assets.root, config.assets.mainDir, BalmJS.file.assetsSuffixPath);
|
|
23
|
-
|
|
24
20
|
for (const assetType of ASSETS_TYPES) {
|
|
25
21
|
config.assets[assetType] = node.path.join(config.assets.static, config.paths.target[assetType]);
|
|
26
|
-
}
|
|
27
|
-
|
|
22
|
+
}
|
|
28
23
|
|
|
24
|
+
// Set HMR flag
|
|
29
25
|
const HMR_ENV = config.useDefaults && config.env.isDev && !config.env.inSSR && !config.env.isMP;
|
|
30
26
|
const HMR_Enabling = config.scripts.bundler === BalmJS.Bundler.webpack && !config.scripts.ie8;
|
|
31
|
-
config.server.useHMR = HMR_ENV && HMR_Enabling;
|
|
27
|
+
config.server.useHMR = HMR_ENV && HMR_Enabling;
|
|
32
28
|
|
|
29
|
+
// Set desktop app flag
|
|
33
30
|
if (/^electron-.*/.test(config.scripts.target)) {
|
|
34
31
|
config.env.inDesktopApp = true;
|
|
35
|
-
}
|
|
36
|
-
|
|
32
|
+
}
|
|
37
33
|
|
|
34
|
+
// Set use cache for webpack
|
|
38
35
|
config.scripts.useCache = config.env.isProd && config.assets.cache && config.scripts.injectHtml;
|
|
39
36
|
return config;
|
|
40
37
|
}
|
|
41
|
-
|
|
42
38
|
function resetConfig() {
|
|
43
39
|
BalmJS.config.roots.target = 'dist';
|
|
44
40
|
BalmJS.config.roots.tmp = '.tmp';
|
|
45
41
|
return BalmJS.config;
|
|
46
42
|
}
|
|
47
|
-
|
|
48
43
|
function setConfig(customConfig) {
|
|
49
|
-
const defaultConfig = resetConfig();
|
|
44
|
+
const defaultConfig = resetConfig();
|
|
50
45
|
|
|
46
|
+
// 1. Overwrite config
|
|
51
47
|
const newConfig = BalmJS.utils.deepMerge(defaultConfig, customConfig);
|
|
52
|
-
checkConfig();
|
|
48
|
+
checkConfig();
|
|
53
49
|
|
|
50
|
+
// 2. Copy `config.paths.target` to `config.paths.tmp`
|
|
54
51
|
let config = BalmJS.utils.deepMerge(newConfig, {
|
|
55
52
|
paths: {
|
|
56
53
|
tmp: newConfig.paths.target
|
|
57
54
|
}
|
|
58
|
-
});
|
|
55
|
+
});
|
|
59
56
|
|
|
57
|
+
// 3. For the dynamic project
|
|
60
58
|
if (!config.inFrontend) {
|
|
61
59
|
if (config.roots.target === 'dist') {
|
|
62
60
|
config.roots.target = config.assets.mainDir; // NOTE: `BalmJS.config.roots.target = 'public'` for back-end project
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
config.roots.tmp = config.roots.target;
|
|
66
|
-
}
|
|
67
|
-
|
|
64
|
+
}
|
|
68
65
|
|
|
66
|
+
// 4. Before created
|
|
69
67
|
config = ready(config);
|
|
70
68
|
BalmJS.logger.success('balm configuration', config, {
|
|
71
69
|
pre: true
|
|
72
70
|
});
|
|
73
71
|
return config;
|
|
74
72
|
}
|
|
75
|
-
|
|
76
73
|
function setTask(name) {
|
|
77
74
|
let result = undefined;
|
|
78
|
-
|
|
79
75
|
if (BalmJS.utils.isFunction(name)) {
|
|
80
76
|
result = name;
|
|
81
77
|
} else if (BalmJS.utils.isString(name)) {
|
|
@@ -87,8 +83,6 @@ function setTask(name) {
|
|
|
87
83
|
} else {
|
|
88
84
|
BalmJS.logger.error('before/end task', 'Task must be a string (gulp task name) or function');
|
|
89
85
|
}
|
|
90
|
-
|
|
91
86
|
return result;
|
|
92
87
|
}
|
|
93
|
-
|
|
94
88
|
export { setConfig, setTask };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { build } from 'esbuild';
|
|
2
2
|
import { minifyOptions } from './options.js';
|
|
3
|
-
|
|
4
3
|
const esBuild = (entryPoints, output, customBuildOptions, callback) => {
|
|
5
4
|
const defaultBuildOptions = {
|
|
6
5
|
entryPoints: BalmJS.file.absPaths(entryPoints),
|
|
@@ -24,5 +23,4 @@ const esBuild = (entryPoints, output, customBuildOptions, callback) => {
|
|
|
24
23
|
callback();
|
|
25
24
|
});
|
|
26
25
|
};
|
|
27
|
-
|
|
28
26
|
export default esBuild;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import build from './build.js';
|
|
2
2
|
import transform from './transform.js';
|
|
3
|
-
|
|
4
3
|
const esbuild = (input, output, customOptions, callback) => {
|
|
5
4
|
const entryPoints = BalmJS.utils.isString(input) ? [input] : input;
|
|
6
5
|
BalmJS.config.scripts.useTransform ? transform(entryPoints, output, customOptions, callback) : build(entryPoints, output, customOptions, callback);
|
|
7
6
|
};
|
|
8
|
-
|
|
9
7
|
export default esbuild;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { transform } from 'esbuild';
|
|
2
2
|
import { minifyOptions } from './options.js';
|
|
3
|
-
|
|
4
3
|
const esTransform = (entryPoints, output, customTransformOptions, callback) => {
|
|
5
4
|
const build = {
|
|
6
5
|
output: BalmJS.file.absPath(output)
|
|
7
6
|
};
|
|
8
7
|
const transformOptions = BalmJS.config.env.isProd ? Object.assign({}, minifyOptions) : {};
|
|
9
8
|
const options = Object.assign(transformOptions, BalmJS.config.scripts.transformOptions, customTransformOptions);
|
|
10
|
-
|
|
11
9
|
(async () => {
|
|
12
10
|
try {
|
|
13
11
|
for await (const entryPoint of entryPoints) {
|
|
@@ -19,7 +17,6 @@ const esTransform = (entryPoints, output, customTransformOptions, callback) => {
|
|
|
19
17
|
pre: true
|
|
20
18
|
});
|
|
21
19
|
const filename = entryPoint.split('/').pop();
|
|
22
|
-
|
|
23
20
|
if (filename && node.fs.existsSync(build.input)) {
|
|
24
21
|
const inputCode = node.fs.readFileSync(build.input, 'utf8');
|
|
25
22
|
const result = await transform(inputCode, options);
|
|
@@ -36,5 +33,4 @@ const esTransform = (entryPoints, output, customTransformOptions, callback) => {
|
|
|
36
33
|
}
|
|
37
34
|
})();
|
|
38
35
|
};
|
|
39
|
-
|
|
40
36
|
export default esTransform;
|
|
@@ -2,7 +2,6 @@ const build = async (bundle, outputOptions) => {
|
|
|
2
2
|
const {
|
|
3
3
|
output
|
|
4
4
|
} = await bundle.generate(outputOptions);
|
|
5
|
-
|
|
6
5
|
for (const chunkOrAsset of output) {
|
|
7
6
|
if (chunkOrAsset.type === 'asset') {
|
|
8
7
|
// For assets, this contains
|
|
@@ -45,10 +44,9 @@ const build = async (bundle, outputOptions) => {
|
|
|
45
44
|
pre: true
|
|
46
45
|
});
|
|
47
46
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
47
|
+
}
|
|
50
48
|
|
|
49
|
+
// or write the bundle to disk
|
|
51
50
|
return await bundle.write(outputOptions);
|
|
52
51
|
};
|
|
53
|
-
|
|
54
52
|
export default build;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { getInputPlugins } from './plugins.js';
|
|
2
|
-
|
|
3
2
|
function getEntry(inputOptions) {
|
|
4
3
|
// Set plugins
|
|
5
4
|
const inputPlugins = getInputPlugins(inputOptions);
|
|
6
5
|
const options = Object.assign({}, BalmJS.config.scripts.inputOptions, inputOptions);
|
|
7
|
-
options.plugins = inputPlugins;
|
|
6
|
+
options.plugins = inputPlugins;
|
|
8
7
|
|
|
8
|
+
// Set entry points
|
|
9
9
|
const {
|
|
10
10
|
input
|
|
11
11
|
} = options;
|
|
12
12
|
let rollupEntries = input;
|
|
13
|
-
|
|
14
13
|
if (BalmJS.utils.isObject(input)) {
|
|
15
14
|
const entries = input;
|
|
16
15
|
Object.keys(entries).forEach(entryAlias => {
|
|
@@ -20,12 +19,10 @@ function getEntry(inputOptions) {
|
|
|
20
19
|
} else {
|
|
21
20
|
rollupEntries = BalmJS.file.absPaths(input);
|
|
22
21
|
}
|
|
23
|
-
|
|
24
22
|
options.input = rollupEntries;
|
|
25
23
|
BalmJS.logger.debug('rollup input options', options, {
|
|
26
24
|
pre: true
|
|
27
25
|
});
|
|
28
26
|
return options;
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
export default getEntry;
|
|
@@ -2,7 +2,6 @@ import { rollup } from 'rollup';
|
|
|
2
2
|
import getEntry from './entry.js';
|
|
3
3
|
import getOutput from './output.js';
|
|
4
4
|
import build from './build.js';
|
|
5
|
-
|
|
6
5
|
const buildLibrary = async (inputOptions, outputOptions) => {
|
|
7
6
|
inputOptions = getEntry(inputOptions);
|
|
8
7
|
outputOptions = getOutput(outputOptions);
|
|
@@ -10,7 +9,6 @@ const buildLibrary = async (inputOptions, outputOptions) => {
|
|
|
10
9
|
output: outputOptions
|
|
11
10
|
});
|
|
12
11
|
const bundle = await rollup(rollupOptions);
|
|
13
|
-
|
|
14
12
|
if (Array.isArray(outputOptions)) {
|
|
15
13
|
for await (const outputOption of outputOptions) {
|
|
16
14
|
await build(bundle, outputOption);
|
|
@@ -19,5 +17,4 @@ const buildLibrary = async (inputOptions, outputOptions) => {
|
|
|
19
17
|
await build(bundle, outputOptions);
|
|
20
18
|
}
|
|
21
19
|
};
|
|
22
|
-
|
|
23
20
|
export default buildLibrary;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { getOutputPlugins } from './plugins.js';
|
|
2
|
-
|
|
3
2
|
function setOutput(outputOptions) {
|
|
4
3
|
const outputPlugins = getOutputPlugins(outputOptions);
|
|
5
4
|
outputOptions = Object.assign({}, BalmJS.config.scripts.outputOptions, outputOptions);
|
|
6
5
|
outputOptions.plugins = outputPlugins;
|
|
7
|
-
|
|
8
6
|
if (outputOptions.dir) {
|
|
9
7
|
outputOptions.dir = BalmJS.file.absPath(outputOptions.dir);
|
|
10
8
|
} else {
|
|
11
9
|
outputOptions.file = BalmJS.file.absPath(outputOptions.file);
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
return outputOptions;
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
function getOutput(outputOptions) {
|
|
18
14
|
const options = Array.isArray(outputOptions) ? outputOptions.map(outputOption => setOutput(outputOption)) : setOutput(outputOptions);
|
|
19
15
|
BalmJS.logger.debug('rollup output options', options, {
|
|
@@ -21,5 +17,4 @@ function getOutput(outputOptions) {
|
|
|
21
17
|
});
|
|
22
18
|
return options;
|
|
23
19
|
}
|
|
24
|
-
|
|
25
20
|
export default getOutput;
|
|
@@ -1,41 +1,31 @@
|
|
|
1
1
|
import { terser } from 'rollup-plugin-terser';
|
|
2
|
-
|
|
3
2
|
function getInputPlugins(customInputOptions) {
|
|
4
3
|
const {
|
|
5
4
|
inputOptions
|
|
6
5
|
} = BalmJS.config.scripts;
|
|
7
6
|
const inputPlugins = [];
|
|
8
|
-
|
|
9
7
|
if (inputOptions.plugins) {
|
|
10
8
|
inputPlugins.push(...inputOptions.plugins);
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
if (customInputOptions.plugins) {
|
|
14
11
|
inputPlugins.push(...customInputOptions.plugins);
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
return inputPlugins;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
function getOutputPlugins(customOutputOptions) {
|
|
21
16
|
const {
|
|
22
17
|
outputOptions
|
|
23
18
|
} = BalmJS.config.scripts;
|
|
24
19
|
const outputPlugins = [];
|
|
25
|
-
|
|
26
20
|
if (outputOptions.plugins) {
|
|
27
21
|
outputPlugins.push(...outputOptions.plugins);
|
|
28
22
|
}
|
|
29
|
-
|
|
30
23
|
if (BalmJS.config.env.isProd) {
|
|
31
24
|
outputPlugins.push(terser(BalmJS.config.scripts.minifyOptions));
|
|
32
25
|
}
|
|
33
|
-
|
|
34
26
|
if (customOutputOptions.plugins) {
|
|
35
27
|
outputPlugins.push(...customOutputOptions.plugins);
|
|
36
28
|
}
|
|
37
|
-
|
|
38
29
|
return outputPlugins;
|
|
39
30
|
}
|
|
40
|
-
|
|
41
31
|
export { getInputPlugins, getOutputPlugins };
|
|
@@ -2,19 +2,20 @@ import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
|
2
2
|
import getLoaders from '../loaders.js';
|
|
3
3
|
import { CHUNK } from '../../../config/constants.js';
|
|
4
4
|
import getClientEnvironment from './env.js';
|
|
5
|
-
|
|
6
5
|
function getDefaultPlugins(webpack, scripts) {
|
|
7
6
|
// We will provide `BalmJS.file.publicUrlOrPath` to our app
|
|
8
7
|
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
|
9
8
|
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
|
10
9
|
// Get environment variables to inject into our app.
|
|
11
10
|
const env = getClientEnvironment(BalmJS.file.publicUrlOrPath.slice(0, -1));
|
|
12
|
-
const plugins = [
|
|
11
|
+
const plugins = [
|
|
12
|
+
// Makes some environment variables available to the JS code, for example:
|
|
13
13
|
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
|
14
14
|
// It is absolutely essential that NODE_ENV is set to production
|
|
15
15
|
// during a production build.
|
|
16
16
|
// Otherwise webapp will be compiled in the very slow development mode.
|
|
17
|
-
new webpack.DefinePlugin(env.stringified),
|
|
17
|
+
new webpack.DefinePlugin(env.stringified),
|
|
18
|
+
// Moment.js is an extremely popular library that bundles large locale files
|
|
18
19
|
// by default due to how webpack interprets its code. This is a practical
|
|
19
20
|
// solution that requires the user to opt into importing specific locales.
|
|
20
21
|
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
|
@@ -23,18 +24,15 @@ function getDefaultPlugins(webpack, scripts) {
|
|
|
23
24
|
resourceRegExp: /^\.\/locale$/,
|
|
24
25
|
contextRegExp: /moment$/
|
|
25
26
|
})];
|
|
26
|
-
|
|
27
27
|
if (scripts.injectHtml) {
|
|
28
28
|
const isSPA = BalmJS.entries.length < 2;
|
|
29
29
|
const titles = scripts.htmlPluginOptions.title || ['BalmJS App'];
|
|
30
|
-
|
|
31
30
|
if (!BalmJS.entries.length) {
|
|
32
31
|
BalmJS.entries.push({
|
|
33
32
|
key: 'main',
|
|
34
33
|
value: `./${BalmJS.file.defaultEntry}`
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
|
-
|
|
38
36
|
BalmJS.entries.forEach((entry, index) => {
|
|
39
37
|
const entryName = isSPA ? 'index' : entry.key;
|
|
40
38
|
const chunks = isSPA ? 'all' : [entryName];
|
|
@@ -48,15 +46,12 @@ function getDefaultPlugins(webpack, scripts) {
|
|
|
48
46
|
plugins.push(new HtmlWebpackPlugin(options));
|
|
49
47
|
});
|
|
50
48
|
}
|
|
51
|
-
|
|
52
49
|
return plugins;
|
|
53
50
|
}
|
|
54
|
-
|
|
55
51
|
function getSplitChunks() {
|
|
56
52
|
const scripts = BalmJS.config.scripts;
|
|
57
53
|
const jsFolder = BalmJS.config.paths.target.js;
|
|
58
54
|
let cacheGroups = {};
|
|
59
|
-
|
|
60
55
|
if (scripts.extractAllVendors) {
|
|
61
56
|
// All vendors
|
|
62
57
|
const vendorsFilename = scripts.useCache ? `${scripts.vendorName}.${CHUNK.hash}.js` : `${scripts.vendorName}.js`;
|
|
@@ -66,13 +61,11 @@ function getSplitChunks() {
|
|
|
66
61
|
chunks: 'initial',
|
|
67
62
|
test: /[\\/](node_modules|bower_components)[\\/]/,
|
|
68
63
|
filename: BalmJS.file.assetsPath(`${jsFolder}/${vendorsFilename}`) // Output: `js/vendors.js`
|
|
69
|
-
|
|
70
64
|
}
|
|
71
65
|
};
|
|
72
66
|
} else if (BalmJS.vendors.length) {
|
|
73
67
|
// Custom vendors
|
|
74
68
|
cacheGroups = {};
|
|
75
|
-
|
|
76
69
|
for (const vendor of BalmJS.vendors) {
|
|
77
70
|
const name = vendor.key;
|
|
78
71
|
const cacheGroupModules = vendor.value.join('|');
|
|
@@ -87,7 +80,6 @@ function getSplitChunks() {
|
|
|
87
80
|
};
|
|
88
81
|
}
|
|
89
82
|
}
|
|
90
|
-
|
|
91
83
|
if (BalmJS.config.env.isProd && BalmJS.config.scripts.extractCss) {
|
|
92
84
|
// Custom styles in scripts
|
|
93
85
|
for (const entry of BalmJS.entries) {
|
|
@@ -100,12 +92,10 @@ function getSplitChunks() {
|
|
|
100
92
|
};
|
|
101
93
|
}
|
|
102
94
|
}
|
|
103
|
-
|
|
104
95
|
return Object.keys(cacheGroups).length ? {
|
|
105
96
|
cacheGroups
|
|
106
97
|
} : false;
|
|
107
98
|
}
|
|
108
|
-
|
|
109
99
|
function getCommonConfig(webpack, scripts) {
|
|
110
100
|
const splitChunks = getSplitChunks();
|
|
111
101
|
const optimization = splitChunks ? BalmJS.utils.deepMerge({
|
|
@@ -142,5 +132,4 @@ function getCommonConfig(webpack, scripts) {
|
|
|
142
132
|
stats: scripts.stats
|
|
143
133
|
};
|
|
144
134
|
}
|
|
145
|
-
|
|
146
135
|
export default getCommonConfig;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { merge } from 'webpack-merge';
|
|
2
2
|
import getCommonConfig from './common.js';
|
|
3
|
-
|
|
4
3
|
function getDevConfig(webpack, scripts) {
|
|
5
4
|
return merge(getCommonConfig(webpack, scripts), {
|
|
6
5
|
mode: 'development',
|
|
7
|
-
plugins: [
|
|
6
|
+
plugins: [
|
|
7
|
+
// This is necessary to emit hot updates
|
|
8
8
|
new webpack.HotModuleReplacementPlugin()],
|
|
9
9
|
devtool: scripts.sourceMap ? scripts.sourceMap : 'eval-cheap-module-source-map'
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
|
|
13
12
|
export default getDevConfig;
|
|
@@ -1,39 +1,37 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
import dotenv from 'dotenv';
|
|
8
5
|
import dotenvExpand from 'dotenv-expand';
|
|
9
6
|
const NODE_ENV = process.env.NODE_ENV;
|
|
10
|
-
|
|
11
7
|
if (!NODE_ENV) {
|
|
12
8
|
throw new Error('The NODE_ENV environment variable is required but was not specified.');
|
|
13
9
|
}
|
|
10
|
+
const dotenvFile = BalmJS.file.resolveApp('.env');
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
|
13
|
+
const dotenvFiles = [`${dotenvFile}.${NODE_ENV}.local`,
|
|
14
|
+
// Don't include `.env.local` for `test` environment
|
|
18
15
|
// since normally you expect tests to produce the same
|
|
19
16
|
// results for everyone
|
|
20
|
-
NODE_ENV !== 'test' && `${dotenvFile}.local`, `${dotenvFile}.${NODE_ENV}`, dotenvFile].filter(Boolean);
|
|
17
|
+
NODE_ENV !== 'test' && `${dotenvFile}.local`, `${dotenvFile}.${NODE_ENV}`, dotenvFile].filter(Boolean);
|
|
18
|
+
|
|
19
|
+
// Load environment variables from .env* files. Suppress warnings using silent
|
|
21
20
|
// if this file is missing. dotenv will never modify any environment variables
|
|
22
21
|
// that have already been set. Variable expansion is supported in .env files.
|
|
23
22
|
// https://github.com/motdotla/dotenv
|
|
24
23
|
// https://github.com/motdotla/dotenv-expand
|
|
25
|
-
|
|
26
24
|
dotenvFiles.forEach(dotenvFile => {
|
|
27
25
|
if (node.fs.existsSync(dotenvFile)) {
|
|
28
26
|
dotenvExpand.expand(dotenv.config({
|
|
29
27
|
path: dotenvFile
|
|
30
28
|
}));
|
|
31
29
|
}
|
|
32
|
-
});
|
|
33
|
-
// injected into the application via DefinePlugin in webpack configuration.
|
|
30
|
+
});
|
|
34
31
|
|
|
32
|
+
// Grab NODE_ENV and BALM_APP_* environment variables and prepare them to be
|
|
33
|
+
// injected into the application via DefinePlugin in webpack configuration.
|
|
35
34
|
const BALM_APP = /^BALM_APP_/i;
|
|
36
|
-
|
|
37
35
|
function getClientEnvironment(publicUrl) {
|
|
38
36
|
const raw = Object.keys(process.env).filter(key => BALM_APP.test(key)).reduce((env, key) => {
|
|
39
37
|
env[key] = process.env[key];
|
|
@@ -47,8 +45,9 @@ function getClientEnvironment(publicUrl) {
|
|
|
47
45
|
// This should only be used as an escape hatch. Normally you would put
|
|
48
46
|
// images into the `src` and `import` them in code to get their paths.
|
|
49
47
|
PUBLIC_URL: publicUrl
|
|
50
|
-
}, BalmJS.config.scripts.nodeEnv));
|
|
48
|
+
}, BalmJS.config.scripts.nodeEnv));
|
|
51
49
|
|
|
50
|
+
// Stringify all values so we can feed into webpack DefinePlugin
|
|
52
51
|
const stringified = {
|
|
53
52
|
'process.env': Object.keys(raw).reduce((env, key) => {
|
|
54
53
|
env[key] = JSON.stringify(raw[key]);
|
|
@@ -63,5 +62,4 @@ function getClientEnvironment(publicUrl) {
|
|
|
63
62
|
stringified
|
|
64
63
|
};
|
|
65
64
|
}
|
|
66
|
-
|
|
67
65
|
export default getClientEnvironment;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import getDevConfig from './dev.js';
|
|
2
2
|
import getProdConfig from './prod.js';
|
|
3
|
-
|
|
4
3
|
function getDefaultConfig(webpack, scripts) {
|
|
5
4
|
return BalmJS.config.env.isProd || scripts.minify || scripts.ie8 ? getProdConfig(webpack, scripts) : getDevConfig(webpack, scripts);
|
|
6
5
|
}
|
|
7
|
-
|
|
8
6
|
export default getDefaultConfig;
|
|
@@ -10,17 +10,13 @@ import { CHUNK } from '../../../config/constants.js';
|
|
|
10
10
|
// `npm run prod --report`
|
|
11
11
|
// Set to `true` or `false` to always turn it on or off
|
|
12
12
|
const bundleAnalyzerReport = process.env.npm_config_report || false;
|
|
13
|
-
|
|
14
13
|
const getCssFilename = () => `${BalmJS.config.paths.target.css}/${CHUNK.dir}/[name].${CHUNK.hash}.css`;
|
|
15
|
-
|
|
16
14
|
function getProdConfig(webpack, scripts) {
|
|
17
15
|
const shouldUseSourceMap = scripts.sourceMap;
|
|
18
16
|
const terserOptions = scripts.minifyOptions;
|
|
19
|
-
|
|
20
17
|
if (scripts.ie8) {
|
|
21
18
|
terserOptions.ie8 = true;
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
return merge(getCommonConfig(webpack, scripts), {
|
|
25
21
|
mode: 'production',
|
|
26
22
|
optimization: {
|
|
@@ -29,14 +25,15 @@ function getProdConfig(webpack, scripts) {
|
|
|
29
25
|
extractComments: false
|
|
30
26
|
}), new CssMinimizerPlugin()]
|
|
31
27
|
},
|
|
32
|
-
plugins: [
|
|
28
|
+
plugins: [
|
|
29
|
+
// Extract css into its own file
|
|
33
30
|
...(scripts.extractCss ? [new MiniCssExtractPlugin({
|
|
34
31
|
filename: BalmJS.file.assetsPath(getCssFilename()),
|
|
35
32
|
chunkFilename: BalmJS.file.assetsPath(getCssFilename())
|
|
36
|
-
})] : []),
|
|
33
|
+
})] : []),
|
|
34
|
+
// View the bundle analyzer report
|
|
37
35
|
...(bundleAnalyzerReport ? [new webpackBundleAnalyzer.BundleAnalyzerPlugin()] : [])],
|
|
38
36
|
devtool: shouldUseSourceMap ? 'source-map' : false
|
|
39
37
|
});
|
|
40
38
|
}
|
|
41
|
-
|
|
42
39
|
export default getProdConfig;
|