balm-core 4.5.4 → 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 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;
@@ -39,7 +39,6 @@ function checkConfig() {
39
39
 
40
40
  upgradeDeprecated('4.5.0', 'scripts', 'excludeUrlResource');
41
41
  upgradeDeprecated('4.5.0', 'scripts', 'urlLoaderOptions');
42
- upgradeDeprecated('4.5.0', 'scripts', 'extractCss');
43
42
  }
44
43
 
45
44
  export default checkConfig;
@@ -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
- defaultVendors: {
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 cacheGroupKey = vendor.key;
66
+ const name = vendor.key;
67
67
  const cacheGroupModules = vendor.value.join('|');
68
- const vendorFilename = scripts.useCache ? `${cacheGroupKey}.${CHUNK.hash}.js` : `${cacheGroupKey}.js`;
69
- cacheGroups[cacheGroupKey] = {
70
- name: cacheGroupKey,
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
- } // if (BalmJS.config.env.isProd && BalmJS.config.scripts.extractCss) {
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
- // import MiniCssExtractPlugin from 'mini-css-extract-plugin';
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'; // import { CHUNK } from '../../../config/constants.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; // const getCssFilename = (): string =>
12
- // `${BalmJS.config.paths.target.css}/${CHUNK.dir}/[name].${CHUNK.hash}.css`;
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
- }) // new CssMinimizerPlugin()
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
- // ...(scripts.extractCss
35
- // ? [
36
- // new MiniCssExtractPlugin({
37
- // filename: BalmJS.file.assetsPath(getCssFilename()),
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
- // import MiniCssExtractPlugin from 'mini-css-extract-plugin';
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 = [// BalmJS.config.env.isProd && BalmJS.config.scripts.extractCss
10
- // ? {
11
- // loader: MiniCssExtractPlugin.loader,
12
- // options: {
13
- // esModule: BalmJS.config.scripts.useEsModule
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
  }, {
@@ -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.BALM || process.env.BALM_CWD, 'node_modules', 'gulp', 'index.js');
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
@@ -80,8 +80,8 @@ const alias = {}; // Plugins
80
80
 
81
81
  const plugins = [];
82
82
  const injectHtml = false;
83
- const htmlPluginOptions = {}; // const extractCss = false;
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
- // extractCss,
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.4",
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",
@@ -117,5 +118,5 @@
117
118
  "engines": {
118
119
  "node": ">=12.13.0"
119
120
  },
120
- "gitHead": "d2febf04626afb74e03159a62d279ac6bd630461"
121
+ "gitHead": "182ee55022c6194293195631a91a14bd22cacace"
121
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
- defaultVendors: {
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 cacheGroupKey = vendor.key;
55
+ const name = vendor.key;
56
56
  const cacheGroupModules = vendor.value.join('|');
57
57
  const vendorFilename = scripts.useCache
58
- ? `${cacheGroupKey}.${CHUNK.hash}.js`
59
- : `${cacheGroupKey}.js`;
60
- cacheGroups[cacheGroupKey] = {
61
- name: cacheGroupKey,
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
- styleLoader,
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
@@ -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.BALM || process.env.BALM_CWD, 'node_modules', 'gulp', 'index.js');
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);
@@ -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,