balm-core 4.5.2 → 4.5.5
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/index.d.ts +1 -0
- package/lib/bootstrap/check_config.js +0 -1
- package/lib/bundler/webpack/config/common.js +18 -17
- package/lib/bundler/webpack/config/prod.js +12 -16
- package/lib/bundler/webpack/rules/css.js +7 -10
- package/lib/config/globals.js +1 -1
- package/lib/config/scripts.js +3 -3
- package/package.json +4 -6
- package/tslib/bootstrap/check_config.js +0 -1
- package/tslib/bundler/webpack/config/common.js +17 -6
- package/tslib/bundler/webpack/config/prod.js +14 -1
- package/tslib/bundler/webpack/rules/css.js +9 -1
- package/tslib/config/globals.js +1 -1
- package/tslib/config/scripts.js +2 -0
package/index.d.ts
CHANGED
|
@@ -98,6 +98,7 @@ export interface BalmScripts {
|
|
|
98
98
|
plugins: object[];
|
|
99
99
|
injectHtml: boolean;
|
|
100
100
|
htmlPluginOptions: object;
|
|
101
|
+
extractCss: boolean;
|
|
101
102
|
sourceMap: string | boolean;
|
|
102
103
|
target: string | string[] | false;
|
|
103
104
|
externals: string | string[] | object | Function | RegExp;
|
|
@@ -50,7 +50,7 @@ function getSplitChunks() {
|
|
|
50
50
|
// All vendors
|
|
51
51
|
const vendorsFilename = scripts.useCache ? `${scripts.vendorName}.${CHUNK.hash}.js` : `${scripts.vendorName}.js`;
|
|
52
52
|
cacheGroups = {
|
|
53
|
-
|
|
53
|
+
allVendors: {
|
|
54
54
|
name: 'vendors',
|
|
55
55
|
chunks: 'all',
|
|
56
56
|
test: /[\\/](node_modules|bower_components)[\\/]/,
|
|
@@ -63,11 +63,11 @@ function getSplitChunks() {
|
|
|
63
63
|
cacheGroups = {};
|
|
64
64
|
|
|
65
65
|
for (const vendor of BalmJS.vendors) {
|
|
66
|
-
const
|
|
66
|
+
const name = vendor.key;
|
|
67
67
|
const cacheGroupModules = vendor.value.join('|');
|
|
68
|
-
const vendorFilename = scripts.useCache ? `${
|
|
69
|
-
cacheGroups[
|
|
70
|
-
name
|
|
68
|
+
const vendorFilename = scripts.useCache ? `${name}.${CHUNK.hash}.js` : `${name}.js`;
|
|
69
|
+
cacheGroups[`${name}Scripts`] = {
|
|
70
|
+
name,
|
|
71
71
|
chunks: 'initial',
|
|
72
72
|
test: new RegExp(`[\\\\/](${cacheGroupModules})[\\\\/].*(?<!\\.css)$`),
|
|
73
73
|
filename: BalmJS.file.assetsPath(`${jsFolder}/${scripts.vendorName}/${vendorFilename}`),
|
|
@@ -75,19 +75,20 @@ function getSplitChunks() {
|
|
|
75
75
|
enforce: true
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
-
}
|
|
79
|
-
// // Custom styles in scripts
|
|
80
|
-
// for (const entry of BalmJS.entries) {
|
|
81
|
-
// const name = entry.key;
|
|
82
|
-
// cacheGroups[`${name}Styles`] = {
|
|
83
|
-
// type: 'css/mini-extract',
|
|
84
|
-
// name,
|
|
85
|
-
// chunks: (chunk: { name: string }) => chunk.name === name,
|
|
86
|
-
// enforce: true
|
|
87
|
-
// };
|
|
88
|
-
// }
|
|
89
|
-
// }
|
|
78
|
+
}
|
|
90
79
|
|
|
80
|
+
if (BalmJS.config.env.isProd && BalmJS.config.scripts.extractCss) {
|
|
81
|
+
// Custom styles in scripts
|
|
82
|
+
for (const entry of BalmJS.entries) {
|
|
83
|
+
const name = entry.key;
|
|
84
|
+
cacheGroups[`${name}Styles`] = {
|
|
85
|
+
type: 'css/mini-extract',
|
|
86
|
+
name,
|
|
87
|
+
chunks: chunk => chunk.name === name,
|
|
88
|
+
enforce: true
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
91
92
|
|
|
92
93
|
return Object.keys(cacheGroups).length ? {
|
|
93
94
|
cacheGroups
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import TerserPlugin from 'terser-webpack-plugin';
|
|
2
|
-
|
|
2
|
+
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
3
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
3
4
|
import webpackBundleAnalyzer from 'webpack-bundle-analyzer';
|
|
4
5
|
import { merge } from 'webpack-merge';
|
|
5
|
-
import getCommonConfig from './common.js';
|
|
6
|
-
|
|
6
|
+
import getCommonConfig from './common.js';
|
|
7
|
+
import { CHUNK } from '../../../config/constants.js';
|
|
7
8
|
// Run the build command with an extra argument to
|
|
8
9
|
// View the bundle analyzer report after build finishes:
|
|
9
10
|
// `npm run prod --report`
|
|
10
11
|
// Set to `true` or `false` to always turn it on or off
|
|
11
|
-
const bundleAnalyzerReport = process.env.npm_config_report || false;
|
|
12
|
-
|
|
12
|
+
const bundleAnalyzerReport = process.env.npm_config_report || false;
|
|
13
|
+
|
|
14
|
+
const getCssFilename = () => `${BalmJS.config.paths.target.css}/${CHUNK.dir}/[name].${CHUNK.hash}.css`;
|
|
13
15
|
|
|
14
16
|
function getProdConfig(webpack, scripts) {
|
|
15
17
|
const shouldUseSourceMap = scripts.sourceMap;
|
|
@@ -25,21 +27,15 @@ function getProdConfig(webpack, scripts) {
|
|
|
25
27
|
minimizer: [new TerserPlugin({
|
|
26
28
|
terserOptions,
|
|
27
29
|
extractComments: false
|
|
28
|
-
})
|
|
29
|
-
]
|
|
30
|
+
}), new CssMinimizerPlugin()]
|
|
30
31
|
},
|
|
31
32
|
plugins: [new webpack.DefinePlugin({
|
|
32
33
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production')
|
|
33
34
|
}), // Extract css into its own file
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// chunkFilename: BalmJS.file.assetsPath(getCssFilename())
|
|
39
|
-
// })
|
|
40
|
-
// ]
|
|
41
|
-
// : []),
|
|
42
|
-
// View the bundle analyzer report
|
|
35
|
+
...(scripts.extractCss ? [new MiniCssExtractPlugin({
|
|
36
|
+
filename: BalmJS.file.assetsPath(getCssFilename()),
|
|
37
|
+
chunkFilename: BalmJS.file.assetsPath(getCssFilename())
|
|
38
|
+
})] : []), // View the bundle analyzer report
|
|
43
39
|
...(bundleAnalyzerReport ? [new webpackBundleAnalyzer.BundleAnalyzerPlugin()] : [])],
|
|
44
40
|
devtool: shouldUseSourceMap ? 'source-map' : false
|
|
45
41
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
2
2
|
import { cssRegex, cssModuleRegex, sassRegex, sassModuleRegex } from '../config/regex.js';
|
|
3
3
|
|
|
4
4
|
// common function to get style loaders
|
|
@@ -6,15 +6,12 @@ function getStyleLoaders(styleLoader, cssOptions, preProcessor = '', sassOptions
|
|
|
6
6
|
const {
|
|
7
7
|
sourceMap
|
|
8
8
|
} = cssOptions;
|
|
9
|
-
const loaders = [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// }
|
|
16
|
-
// : styleLoader,
|
|
17
|
-
styleLoader, {
|
|
9
|
+
const loaders = [BalmJS.config.env.isProd && BalmJS.config.scripts.extractCss ? {
|
|
10
|
+
loader: MiniCssExtractPlugin.loader,
|
|
11
|
+
options: {
|
|
12
|
+
esModule: BalmJS.config.scripts.useEsModule
|
|
13
|
+
}
|
|
14
|
+
} : styleLoader, {
|
|
18
15
|
loader: requireModule.resolve('css-loader'),
|
|
19
16
|
options: cssOptions
|
|
20
17
|
}, {
|
package/lib/config/globals.js
CHANGED
|
@@ -6,7 +6,7 @@ import through2 from 'through2';
|
|
|
6
6
|
import PluginError from 'plugin-error'; // Set env var for ORIGINAL cwd before anything touches it
|
|
7
7
|
|
|
8
8
|
process.env.BALM_CWD = process.env.INIT_CWD || process.cwd();
|
|
9
|
-
const gulpModule = path.join(process.env.
|
|
9
|
+
const gulpModule = path.join(process.env.BALM_ROOT || process.env.BALM_CWD, 'node_modules', 'gulp', 'index.js');
|
|
10
10
|
|
|
11
11
|
if (fs.existsSync(gulpModule)) {
|
|
12
12
|
// Chdir before requiring balm config to make sure
|
package/lib/config/scripts.js
CHANGED
|
@@ -80,8 +80,8 @@ const alias = {}; // Plugins
|
|
|
80
80
|
|
|
81
81
|
const plugins = [];
|
|
82
82
|
const injectHtml = false;
|
|
83
|
-
const htmlPluginOptions = {};
|
|
84
|
-
// Devtool
|
|
83
|
+
const htmlPluginOptions = {};
|
|
84
|
+
const extractCss = false; // Devtool
|
|
85
85
|
|
|
86
86
|
const sourceMap = false; // Target
|
|
87
87
|
|
|
@@ -152,7 +152,7 @@ export default {
|
|
|
152
152
|
plugins,
|
|
153
153
|
injectHtml,
|
|
154
154
|
htmlPluginOptions,
|
|
155
|
-
|
|
155
|
+
extractCss,
|
|
156
156
|
sourceMap,
|
|
157
157
|
target,
|
|
158
158
|
externals,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "balm-core",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.5",
|
|
4
4
|
"description": "BalmJS compiler core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"balm",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"imagemin": "^8.0.1",
|
|
70
70
|
"istextorbinary": "^6.0.0",
|
|
71
71
|
"less": "^4.1.2",
|
|
72
|
+
"mini-css-extract-plugin": "2.5.2",
|
|
72
73
|
"modernizr": "^3.12.0",
|
|
73
74
|
"parents": "^1.0.1",
|
|
74
75
|
"plugin-error": "^1.0.1",
|
|
@@ -94,7 +95,7 @@
|
|
|
94
95
|
"through2-concurrent": "^2.0.0",
|
|
95
96
|
"tslib": "^2.3.1",
|
|
96
97
|
"vinyl-sourcemaps-apply": "^0.2.1",
|
|
97
|
-
"webpack": "^5.
|
|
98
|
+
"webpack": "^5.72.0",
|
|
98
99
|
"webpack-bundle-analyzer": "^4.5.0",
|
|
99
100
|
"webpack-dev-middleware": "^5.3.1",
|
|
100
101
|
"webpack-hot-middleware": "^2.25.1",
|
|
@@ -114,11 +115,8 @@
|
|
|
114
115
|
"imagemin-optipng": "^8.0.0",
|
|
115
116
|
"imagemin-svgo": "^9.0.0"
|
|
116
117
|
},
|
|
117
|
-
"resolutions": {
|
|
118
|
-
"ajv": "^8.0.0"
|
|
119
|
-
},
|
|
120
118
|
"engines": {
|
|
121
119
|
"node": ">=12.13.0"
|
|
122
120
|
},
|
|
123
|
-
"gitHead": "
|
|
121
|
+
"gitHead": "182ee55022c6194293195631a91a14bd22cacace"
|
|
124
122
|
}
|
|
@@ -30,6 +30,5 @@ function checkConfig() {
|
|
|
30
30
|
upgradeDeprecated('3.19.0', 'scripts', 'useCache');
|
|
31
31
|
upgradeDeprecated('4.5.0', 'scripts', 'excludeUrlResource');
|
|
32
32
|
upgradeDeprecated('4.5.0', 'scripts', 'urlLoaderOptions');
|
|
33
|
-
upgradeDeprecated('4.5.0', 'scripts', 'extractCss');
|
|
34
33
|
}
|
|
35
34
|
export default checkConfig;
|
|
@@ -41,7 +41,7 @@ function getSplitChunks() {
|
|
|
41
41
|
? `${scripts.vendorName}.${CHUNK.hash}.js`
|
|
42
42
|
: `${scripts.vendorName}.js`;
|
|
43
43
|
cacheGroups = {
|
|
44
|
-
|
|
44
|
+
allVendors: {
|
|
45
45
|
name: 'vendors',
|
|
46
46
|
chunks: 'all',
|
|
47
47
|
test: /[\\/](node_modules|bower_components)[\\/]/,
|
|
@@ -52,13 +52,13 @@ function getSplitChunks() {
|
|
|
52
52
|
else if (BalmJS.vendors.length) {
|
|
53
53
|
cacheGroups = {};
|
|
54
54
|
for (const vendor of BalmJS.vendors) {
|
|
55
|
-
const
|
|
55
|
+
const name = vendor.key;
|
|
56
56
|
const cacheGroupModules = vendor.value.join('|');
|
|
57
57
|
const vendorFilename = scripts.useCache
|
|
58
|
-
? `${
|
|
59
|
-
: `${
|
|
60
|
-
cacheGroups[
|
|
61
|
-
name
|
|
58
|
+
? `${name}.${CHUNK.hash}.js`
|
|
59
|
+
: `${name}.js`;
|
|
60
|
+
cacheGroups[`${name}Scripts`] = {
|
|
61
|
+
name,
|
|
62
62
|
chunks: 'initial',
|
|
63
63
|
test: new RegExp(`[\\\\/](${cacheGroupModules})[\\\\/].*(?<!\\.css)$`),
|
|
64
64
|
filename: BalmJS.file.assetsPath(`${jsFolder}/${scripts.vendorName}/${vendorFilename}`),
|
|
@@ -66,6 +66,17 @@ function getSplitChunks() {
|
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
+
if (BalmJS.config.env.isProd && BalmJS.config.scripts.extractCss) {
|
|
70
|
+
for (const entry of BalmJS.entries) {
|
|
71
|
+
const name = entry.key;
|
|
72
|
+
cacheGroups[`${name}Styles`] = {
|
|
73
|
+
type: 'css/mini-extract',
|
|
74
|
+
name,
|
|
75
|
+
chunks: (chunk) => chunk.name === name,
|
|
76
|
+
enforce: true
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
69
80
|
return Object.keys(cacheGroups).length ? { cacheGroups } : false;
|
|
70
81
|
}
|
|
71
82
|
function getCommonConfig(webpack, scripts) {
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import TerserPlugin from 'terser-webpack-plugin';
|
|
2
|
+
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
3
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
2
4
|
import webpackBundleAnalyzer from 'webpack-bundle-analyzer';
|
|
3
5
|
import { merge } from 'webpack-merge';
|
|
4
6
|
import getCommonConfig from './common.js';
|
|
7
|
+
import { CHUNK } from '../../../config/constants.js';
|
|
5
8
|
const bundleAnalyzerReport = process.env.npm_config_report || false;
|
|
9
|
+
const getCssFilename = () => `${BalmJS.config.paths.target.css}/${CHUNK.dir}/[name].${CHUNK.hash}.css`;
|
|
6
10
|
function getProdConfig(webpack, scripts) {
|
|
7
11
|
const shouldUseSourceMap = scripts.sourceMap;
|
|
8
12
|
const terserOptions = scripts.minifyOptions;
|
|
@@ -16,13 +20,22 @@ function getProdConfig(webpack, scripts) {
|
|
|
16
20
|
new TerserPlugin({
|
|
17
21
|
terserOptions,
|
|
18
22
|
extractComments: false
|
|
19
|
-
})
|
|
23
|
+
}),
|
|
24
|
+
new CssMinimizerPlugin()
|
|
20
25
|
]
|
|
21
26
|
},
|
|
22
27
|
plugins: [
|
|
23
28
|
new webpack.DefinePlugin({
|
|
24
29
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production')
|
|
25
30
|
}),
|
|
31
|
+
...(scripts.extractCss
|
|
32
|
+
? [
|
|
33
|
+
new MiniCssExtractPlugin({
|
|
34
|
+
filename: BalmJS.file.assetsPath(getCssFilename()),
|
|
35
|
+
chunkFilename: BalmJS.file.assetsPath(getCssFilename())
|
|
36
|
+
})
|
|
37
|
+
]
|
|
38
|
+
: []),
|
|
26
39
|
...(bundleAnalyzerReport
|
|
27
40
|
? [new webpackBundleAnalyzer.BundleAnalyzerPlugin()]
|
|
28
41
|
: [])
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
1
2
|
import { cssRegex, cssModuleRegex, sassRegex, sassModuleRegex } from '../config/regex.js';
|
|
2
3
|
function getStyleLoaders(styleLoader, cssOptions, preProcessor = '', sassOptions = {}) {
|
|
3
4
|
const { sourceMap } = cssOptions;
|
|
4
5
|
const loaders = [
|
|
5
|
-
|
|
6
|
+
BalmJS.config.env.isProd && BalmJS.config.scripts.extractCss
|
|
7
|
+
? {
|
|
8
|
+
loader: MiniCssExtractPlugin.loader,
|
|
9
|
+
options: {
|
|
10
|
+
esModule: BalmJS.config.scripts.useEsModule
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
: styleLoader,
|
|
6
14
|
{
|
|
7
15
|
loader: requireModule.resolve('css-loader'),
|
|
8
16
|
options: cssOptions
|
package/tslib/config/globals.js
CHANGED
|
@@ -5,7 +5,7 @@ import { create } from 'browser-sync';
|
|
|
5
5
|
import through2 from 'through2';
|
|
6
6
|
import PluginError from 'plugin-error';
|
|
7
7
|
process.env.BALM_CWD = process.env.INIT_CWD || process.cwd();
|
|
8
|
-
const gulpModule = path.join(process.env.
|
|
8
|
+
const gulpModule = path.join(process.env.BALM_ROOT || process.env.BALM_CWD, 'node_modules', 'gulp', 'index.js');
|
|
9
9
|
if (fs.existsSync(gulpModule)) {
|
|
10
10
|
if (process.cwd() !== process.env.BALM_CWD) {
|
|
11
11
|
process.chdir(process.env.BALM_CWD);
|
package/tslib/config/scripts.js
CHANGED
|
@@ -32,6 +32,7 @@ const alias = {};
|
|
|
32
32
|
const plugins = [];
|
|
33
33
|
const injectHtml = false;
|
|
34
34
|
const htmlPluginOptions = {};
|
|
35
|
+
const extractCss = false;
|
|
35
36
|
const sourceMap = false;
|
|
36
37
|
const target = ['web', 'es5'];
|
|
37
38
|
const externals = '';
|
|
@@ -72,6 +73,7 @@ export default {
|
|
|
72
73
|
plugins,
|
|
73
74
|
injectHtml,
|
|
74
75
|
htmlPluginOptions,
|
|
76
|
+
extractCss,
|
|
75
77
|
sourceMap,
|
|
76
78
|
target,
|
|
77
79
|
externals,
|