balm-core 4.4.3 → 4.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/index.d.ts +3 -6
  2. package/lib/balm.js +1 -1
  3. package/lib/bootstrap/check_config.js +5 -1
  4. package/lib/bootstrap/index.js +4 -4
  5. package/lib/bundler/webpack/config/common.js +17 -15
  6. package/lib/bundler/webpack/config/prod.js +16 -12
  7. package/lib/bundler/webpack/loaders.js +3 -3
  8. package/lib/bundler/webpack/output.js +11 -12
  9. package/lib/bundler/webpack/rules/asset.js +29 -0
  10. package/lib/bundler/webpack/rules/css.js +12 -9
  11. package/lib/bundler/webpack/rules/index.js +6 -6
  12. package/lib/config/constants.js +12 -8
  13. package/lib/config/env.js +8 -6
  14. package/lib/config/scripts.js +3 -13
  15. package/lib/plugins/postcss-plugins.js +4 -3
  16. package/lib/tasks/foundation/balm_style.js +2 -2
  17. package/lib/tasks/private/cache.js +3 -3
  18. package/lib/tasks/private/clean.js +2 -2
  19. package/lib/utilities/file.js +1 -2
  20. package/package.json +15 -14
  21. package/tslib/balm.js +1 -1
  22. package/tslib/bootstrap/check_config.js +3 -0
  23. package/tslib/bootstrap/index.js +4 -4
  24. package/tslib/bundler/webpack/config/common.js +7 -15
  25. package/tslib/bundler/webpack/config/prod.js +1 -14
  26. package/tslib/bundler/webpack/loaders.js +3 -3
  27. package/tslib/bundler/webpack/output.js +13 -13
  28. package/tslib/bundler/webpack/rules/asset.js +28 -0
  29. package/tslib/bundler/webpack/rules/css.js +3 -11
  30. package/tslib/bundler/webpack/rules/index.js +6 -6
  31. package/tslib/config/constants.js +12 -8
  32. package/tslib/config/env.js +16 -16
  33. package/tslib/config/scripts.js +0 -6
  34. package/tslib/plugins/postcss-plugins.js +5 -3
  35. package/tslib/tasks/foundation/balm_style.js +2 -2
  36. package/tslib/tasks/private/cache.js +5 -6
  37. package/tslib/tasks/private/clean.js +2 -2
  38. package/tslib/utilities/file.js +2 -1
  39. package/lib/bundler/webpack/rules/url.js +0 -33
  40. package/tslib/bundler/webpack/rules/url.js +0 -31
package/index.d.ts CHANGED
@@ -46,10 +46,10 @@ export type Configuration = import('webpack').Configuration;
46
46
  export type RuleSetRule = import('webpack').RuleSetRule;
47
47
 
48
48
  export interface BalmLoaders {
49
- html: boolean;
50
- css: boolean;
51
49
  js: boolean;
52
- url: boolean;
50
+ css: boolean;
51
+ html: boolean;
52
+ asset: boolean;
53
53
  }
54
54
  export interface PostcssLoaderOptions {
55
55
  exec?: boolean;
@@ -89,9 +89,7 @@ export interface BalmScripts {
89
89
  loaders: RuleSetRule[];
90
90
  defaultLoaders: Partial<BalmLoaders>;
91
91
  includeJsResource: string[];
92
- excludeUrlResource: string[];
93
92
  useEsModule: boolean;
94
- urlLoaderOptions: object;
95
93
  babelLoaderOptions: object;
96
94
  postcssLoaderOptions: Partial<PostcssLoaderOptions>;
97
95
  htmlLoaderOptions: object;
@@ -108,7 +106,6 @@ export interface BalmScripts {
108
106
  optimization: object;
109
107
  extractAllVendors: boolean;
110
108
  vendorName: string;
111
- extractCss: boolean;
112
109
  ie8: boolean;
113
110
  // rollup
114
111
  inputOptions: Omit<InputOptions, 'acorn'>; // incompatible
package/lib/balm.js CHANGED
@@ -56,7 +56,7 @@ class Balm {
56
56
  if (BalmJS.utils.isFunction(recipe)) {
57
57
  registerTasks(recipe);
58
58
  } else {
59
- BalmJS.logger.error('initialization', 'BalmJS API: `balm.go(function(mix) {});`');
59
+ BalmJS.logger.error('initialization', 'BalmJS API: `balm.go(mix => {});`');
60
60
  }
61
61
  }
62
62
 
@@ -35,7 +35,11 @@ function checkConfig() {
35
35
  upgradeRenamed('3.9.0', 'scripts', 'options', 'minifyOptions');
36
36
  upgradeRenamed('3.16.0', 'scripts', 'inject', 'useCache');
37
37
  upgradeDeprecated('3.17.0', 'styles', 'darkSass');
38
- upgradeDeprecated('3.19.0', 'scripts', 'useCache');
38
+ upgradeDeprecated('3.19.0', 'scripts', 'useCache'); // For v4
39
+
40
+ upgradeDeprecated('4.5.0', 'scripts', 'excludeUrlResource');
41
+ upgradeDeprecated('4.5.0', 'scripts', 'urlLoaderOptions');
42
+ upgradeDeprecated('4.5.0', 'scripts', 'extractCss');
39
43
  }
40
44
 
41
45
  export default checkConfig;
@@ -1,5 +1,5 @@
1
1
  import checkConfig from './check_config.js';
2
- import { ASSETS_KEYS } from '../config/constants.js';
2
+ import { ASSETS_TYPES } from '../config/constants.js';
3
3
 
4
4
  function createQuickPath(config, rootKey) {
5
5
  const result = {};
@@ -7,7 +7,7 @@ function createQuickPath(config, rootKey) {
7
7
 
8
8
  for (const pathKey of Object.keys(config.paths[rootKey])) {
9
9
  const pathValue = config.paths[rootKey][pathKey];
10
- result[pathKey] = rootKey === 'target' && ASSETS_KEYS.includes(pathKey) ? node.path.join(rootValue, BalmJS.config.assets.virtualDir, BalmJS.file.assetsSuffixPath, pathValue) : node.path.join(rootValue, pathValue);
10
+ 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
11
  }
12
12
 
13
13
  return rootKey === 'source' ? result : result;
@@ -21,8 +21,8 @@ function ready(config) {
21
21
 
22
22
  config.assets.static = node.path.join(config.assets.root, config.assets.mainDir, BalmJS.file.assetsSuffixPath);
23
23
 
24
- for (const assetKey of ASSETS_KEYS) {
25
- config.assets[assetKey] = node.path.join(config.assets.static, config.paths.target[assetKey]);
24
+ for (const assetType of ASSETS_TYPES) {
25
+ config.assets[assetType] = node.path.join(config.assets.static, config.paths.target[assetType]);
26
26
  } // Set HMR flag
27
27
 
28
28
 
@@ -1,6 +1,6 @@
1
1
  import HtmlWebpackPlugin from 'html-webpack-plugin';
2
2
  import getLoaders from '../loaders.js';
3
- import { HASH_NAME_PROD } from '../../../config/constants.js';
3
+ import { CHUNK } from '../../../config/constants.js';
4
4
 
5
5
  function getDefaultPlugins(webpack, scripts) {
6
6
  const plugins = [// Moment.js is an extremely popular library that bundles large locale files
@@ -48,13 +48,13 @@ function getSplitChunks() {
48
48
 
49
49
  if (scripts.extractAllVendors) {
50
50
  // All vendors
51
- const jsFilename = scripts.useCache ? `${scripts.vendorName}.${HASH_NAME_PROD}.js` : `${scripts.vendorName}.js`;
51
+ const vendorsFilename = scripts.useCache ? `${scripts.vendorName}.${CHUNK.hash}.js` : `${scripts.vendorName}.js`;
52
52
  cacheGroups = {
53
53
  defaultVendors: {
54
54
  name: 'vendors',
55
55
  chunks: 'all',
56
56
  test: /[\\/](node_modules|bower_components)[\\/]/,
57
- filename: BalmJS.file.assetsPath(`${jsFolder}/${jsFilename}`) // Output: `js/vendors.js`
57
+ filename: BalmJS.file.assetsPath(`${jsFolder}/${vendorsFilename}`) // Output: `js/vendors.js`
58
58
 
59
59
  }
60
60
  };
@@ -65,27 +65,29 @@ function getSplitChunks() {
65
65
  for (const vendor of BalmJS.vendors) {
66
66
  const cacheGroupKey = vendor.key;
67
67
  const cacheGroupModules = vendor.value.join('|');
68
- const jsFilename = scripts.useCache ? `${cacheGroupKey}.${HASH_NAME_PROD}.js` : `${cacheGroupKey}.js`;
68
+ const vendorFilename = scripts.useCache ? `${cacheGroupKey}.${CHUNK.hash}.js` : `${cacheGroupKey}.js`;
69
69
  cacheGroups[cacheGroupKey] = {
70
70
  name: cacheGroupKey,
71
71
  chunks: 'initial',
72
72
  test: new RegExp(`[\\\\/](${cacheGroupModules})[\\\\/].*(?<!\\.css)$`),
73
- filename: BalmJS.file.assetsPath(`${jsFolder}/${scripts.vendorName}/${jsFilename}`),
73
+ filename: BalmJS.file.assetsPath(`${jsFolder}/${scripts.vendorName}/${vendorFilename}`),
74
74
  // Output: `js/vendor/customVendorName.js`
75
75
  enforce: true
76
76
  };
77
77
  }
78
- }
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
+ // }
79
90
 
80
- if (BalmJS.config.env.isProd && BalmJS.config.scripts.extractCss) {
81
- // Custom styles in scripts
82
- cacheGroups.css = {
83
- name: 'css',
84
- chunks: 'all',
85
- test: /\.css$/,
86
- enforce: true
87
- };
88
- }
89
91
 
90
92
  return Object.keys(cacheGroups).length ? {
91
93
  cacheGroups
@@ -1,17 +1,15 @@
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
+ // import MiniCssExtractPlugin from 'mini-css-extract-plugin';
4
3
  import webpackBundleAnalyzer from 'webpack-bundle-analyzer';
5
4
  import { merge } from 'webpack-merge';
6
- import getCommonConfig from './common.js';
7
- import { ASYNC_SCRIPTS, HASH_NAME_PROD } from '../../../config/constants.js';
5
+ import getCommonConfig from './common.js'; // import { CHUNK } from '../../../config/constants.js';
6
+
8
7
  // Run the build command with an extra argument to
9
8
  // View the bundle analyzer report after build finishes:
10
9
  // `npm run prod --report`
11
10
  // Set to `true` or `false` to always turn it on or off
12
- const bundleAnalyzerReport = process.env.npm_config_report || false;
13
-
14
- const getCssFilename = () => `${BalmJS.config.paths.target.css}/${ASYNC_SCRIPTS}/[name].${HASH_NAME_PROD}.css`;
11
+ const bundleAnalyzerReport = process.env.npm_config_report || false; // const getCssFilename = (): string =>
12
+ // `${BalmJS.config.paths.target.css}/${CHUNK.dir}/[name].${CHUNK.hash}.css`;
15
13
 
16
14
  function getProdConfig(webpack, scripts) {
17
15
  const shouldUseSourceMap = scripts.sourceMap;
@@ -27,15 +25,21 @@ function getProdConfig(webpack, scripts) {
27
25
  minimizer: [new TerserPlugin({
28
26
  terserOptions,
29
27
  extractComments: false
30
- }), new CssMinimizerPlugin()]
28
+ }) // new CssMinimizerPlugin()
29
+ ]
31
30
  },
32
31
  plugins: [new webpack.DefinePlugin({
33
32
  'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production')
34
33
  }), // Extract css into its own file
35
- ...(scripts.extractCss ? [new MiniCssExtractPlugin({
36
- filename: BalmJS.file.assetsPath(getCssFilename()),
37
- chunkFilename: BalmJS.file.assetsPath(getCssFilename())
38
- })] : []), // View the bundle analyzer report
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
39
43
  ...(bundleAnalyzerReport ? [new webpackBundleAnalyzer.BundleAnalyzerPlugin()] : [])],
40
44
  devtool: shouldUseSourceMap ? 'source-map' : false
41
45
  });
@@ -3,10 +3,10 @@ import LOADERS from './rules/index.js';
3
3
 
4
4
  function getLoaders(customLoaders) {
5
5
  const enableDefaultLoaders = Object.assign({
6
- html: true,
7
- css: true,
8
6
  js: true,
9
- url: true
7
+ css: true,
8
+ html: true,
9
+ asset: true
10
10
  }, BalmJS.config.scripts.defaultLoaders);
11
11
  const useDefaultLoaders = Object.values(enableDefaultLoaders).some(value => value);
12
12
  let defaultLoaders = [];
@@ -1,28 +1,27 @@
1
- import { ASYNC_SCRIPTS, HASH_NAME_PROD, MP_ASSETS } from '../../config/constants.js';
1
+ import { CHUNK, ASSET } from '../../config/constants.js';
2
2
 
3
- function getFilename(scripts, isChunk = false) {
3
+ function getJsFilename(scripts, isChunk = false) {
4
4
  let filename;
5
5
 
6
6
  if (isChunk) {
7
- filename = BalmJS.config.env.isProd ? `[name].${HASH_NAME_PROD}` : '[name]';
7
+ filename = BalmJS.config.env.isProd ? `[name].${CHUNK.hash}` : '[name]';
8
8
  } else {
9
- filename = scripts.useCache ? `[name].${HASH_NAME_PROD}` : '[name]';
9
+ filename = scripts.useCache ? `[name].${CHUNK.hash}` : '[name]';
10
10
  }
11
11
 
12
12
  return `${filename}.js`;
13
13
  }
14
14
 
15
15
  function getOutput(output, scripts, isHook = false) {
16
- const outputPath = output || BalmJS.config.dest.base; // Absolute path
17
-
16
+ const outputDirectory = output || BalmJS.config.dest.base;
18
17
  const jsFolder = BalmJS.config.paths.target.js;
19
- const jsFilename = getFilename(scripts);
20
- const jsChunkFilename = getFilename(scripts, true);
18
+ const bundleFilename = getJsFilename(scripts);
19
+ const chunkFilename = getJsFilename(scripts, true);
21
20
  const customLibraryConfig = scripts.library ? {
22
21
  library: scripts.library
23
22
  } : {};
24
23
  const miniprogramConfig = BalmJS.config.env.isMP ? {
25
- path: BalmJS.file.absPath(node.path.join(BalmJS.config.dest.base, MP_ASSETS)),
24
+ path: BalmJS.file.absPath(node.path.join(BalmJS.config.dest.base, ASSET.mpDir)),
26
25
  library: {
27
26
  name: 'createApp',
28
27
  type: 'window',
@@ -31,12 +30,12 @@ function getOutput(output, scripts, isHook = false) {
31
30
  } : {};
32
31
  return Object.assign({
33
32
  // The build folder.
34
- path: BalmJS.file.absPath(outputPath),
33
+ path: BalmJS.file.absPath(outputDirectory),
35
34
  // There will be one main bundle, and one file per asynchronous chunk.
36
35
  // In development, it does not produce real files.
37
- filename: isHook ? jsFilename : BalmJS.file.assetsPath(`${jsFolder}/${jsFilename}`),
36
+ filename: isHook ? bundleFilename : BalmJS.file.assetsPath(`${jsFolder}/${bundleFilename}`),
38
37
  // There are also additional JS chunk files if you use code splitting.
39
- chunkFilename: isHook ? jsChunkFilename : BalmJS.file.assetsPath(`${jsFolder}/${ASYNC_SCRIPTS}/${jsChunkFilename}`),
38
+ chunkFilename: isHook ? chunkFilename : BalmJS.file.assetsPath(`${jsFolder}/${CHUNK.dir}/${chunkFilename}`),
40
39
  // webpack uses `publicPath` to determine where the app is being served from.
41
40
  // It requires a trailing slash, or the file assets will get an incorrect path.
42
41
  // We inferred the "public path" (such as / or /my-project) from homepage.
@@ -0,0 +1,29 @@
1
+ import { imgRegex, fontRegex, mediaRegex } from '../config/regex.js';
2
+ import { ASSET } from '../../../config/constants.js';
3
+
4
+ function assetLoader() {
5
+ return [// "url" loader works like "file" loader except that it embeds assets
6
+ // smaller than specified limit in bytes as data URLs to avoid requests.
7
+ // A missing `test` is equivalent to a match.
8
+ {
9
+ test: imgRegex,
10
+ type: 'asset/resource',
11
+ generator: {
12
+ filename: BalmJS.file.assetsPath(`${ASSET.dir}/${BalmJS.config.paths.target.img}/[name].${ASSET.hash}[ext]`)
13
+ }
14
+ }, {
15
+ test: fontRegex,
16
+ type: 'asset/resource',
17
+ generator: {
18
+ filename: BalmJS.file.assetsPath(`${ASSET.dir}/${BalmJS.config.paths.target.font}/[name].${ASSET.hash}[ext]`)
19
+ }
20
+ }, {
21
+ test: mediaRegex,
22
+ type: 'asset/resource',
23
+ generator: {
24
+ filename: BalmJS.file.assetsPath(`${ASSET.dir}/${BalmJS.config.paths.target.media}/[name].${ASSET.hash}[ext]`)
25
+ }
26
+ }];
27
+ }
28
+
29
+ export default assetLoader;
@@ -1,17 +1,20 @@
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
5
- const getStyleLoaders = (styleLoader, cssOptions, preProcessor = '', sassOptions = {}) => {
5
+ 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
- loader: MiniCssExtractPlugin.loader,
11
- options: {
12
- esModule: BalmJS.config.scripts.useEsModule
13
- }
14
- } : styleLoader, {
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, {
15
18
  loader: requireModule.resolve('css-loader'),
16
19
  options: cssOptions
17
20
  }, {
@@ -34,7 +37,7 @@ const getStyleLoaders = (styleLoader, cssOptions, preProcessor = '', sassOptions
34
37
  }
35
38
 
36
39
  return loaders;
37
- };
40
+ }
38
41
 
39
42
  function cssLoader() {
40
43
  let styleLoader = {
@@ -1,10 +1,10 @@
1
- import htmlLoader from './html.js';
2
- import babelLoader from './babel.js';
1
+ import jsLoader from './babel.js';
3
2
  import cssLoader from './css.js';
4
- import urlLoader from './url.js';
3
+ import htmlLoader from './html.js';
4
+ import assetLoader from './asset.js';
5
5
  export default {
6
- htmlLoader,
7
- babelLoader,
6
+ jsLoader,
8
7
  cssLoader,
9
- urlLoader
8
+ htmlLoader,
9
+ assetLoader
10
10
  };
@@ -1,10 +1,14 @@
1
1
  const DOMAIN = 'https://balm.js.org';
2
- const PUBLIC_URL = '%PUBLIC_URL%';
3
- const ASSETS_KEYS = ['css', 'js', 'img', 'font', 'media'];
4
- const ASYNC_SCRIPTS = 'async';
5
- const STATIC_ASSETS = 'assets';
6
- const HASH_NAME_PROD = '[contenthash:8]';
7
- const HASH_NAME_DEV = '[hash:8]';
8
2
  const HMR_PATH = '/__balm_hmr';
9
- const MP_ASSETS = 'common';
10
- export { DOMAIN, PUBLIC_URL, ASSETS_KEYS, ASYNC_SCRIPTS, STATIC_ASSETS, HASH_NAME_PROD, HASH_NAME_DEV, HMR_PATH, MP_ASSETS };
3
+ const PUBLIC_URL = '%PUBLIC_URL%';
4
+ const ASSETS_TYPES = ['css', 'js', 'img', 'font', 'media'];
5
+ const CHUNK = {
6
+ dir: 'chunk',
7
+ hash: '[contenthash:8]'
8
+ };
9
+ const ASSET = {
10
+ dir: 'asset',
11
+ hash: '[hash:8]',
12
+ mpDir: 'common'
13
+ };
14
+ export { DOMAIN, HMR_PATH, PUBLIC_URL, ASSETS_TYPES, CHUNK, ASSET };
package/lib/config/env.js CHANGED
@@ -1,3 +1,5 @@
1
+ const NODE_ENV = process.env.NODE_ENV;
2
+ const argv = process.argv;
1
3
  const ENV = {
2
4
  // standard
3
5
  PROD: 'production',
@@ -8,11 +10,11 @@ const ENV = {
8
10
  MP: 'miniprogram',
9
11
  DESKTOP_APP: 'desktop-app'
10
12
  };
11
- const isProd = process.env.NODE_ENV === ENV.PROD || process.argv.includes(`--${ENV.PROD}`) || process.argv.includes('-p');
12
- const isTest = process.env.NODE_ENV === ENV.TEST || process.argv.includes(`--${ENV.TEST}`) || process.argv.includes('-t');
13
+ const isProd = NODE_ENV === ENV.PROD || argv.includes(`--${ENV.PROD}`) || argv.includes('-p');
14
+ const isTest = NODE_ENV === ENV.TEST || argv.includes(`--${ENV.TEST}`) || argv.includes('-t');
13
15
  const isDev = !isProd && !isTest;
14
16
 
15
- if (!process.env.NODE_ENV) {
17
+ if (!NODE_ENV) {
16
18
  if (isProd) {
17
19
  process.env.NODE_ENV = ENV.PROD;
18
20
  } else if (isTest) {
@@ -22,9 +24,9 @@ if (!process.env.NODE_ENV) {
22
24
  }
23
25
  }
24
26
 
25
- const inSSR = process.env.NODE_ENV === ENV.SSR || process.argv.includes(`--${ENV.SSR}`) || process.argv.includes('-ssr');
26
- const isMP = process.env.NODE_ENV === ENV.MP || process.argv.includes(`--${ENV.MP}`) || process.argv.includes('-mp');
27
- const inDesktopApp = process.env.NODE_ENV === ENV.DESKTOP_APP || process.argv.includes(`--${ENV.DESKTOP_APP}`) || process.argv.includes('-electron');
27
+ const inSSR = NODE_ENV === ENV.SSR || argv.includes(`--${ENV.SSR}`) || argv.includes('-ssr');
28
+ const isMP = NODE_ENV === ENV.MP || argv.includes(`--${ENV.MP}`) || argv.includes('-mp');
29
+ const inDesktopApp = NODE_ENV === ENV.DESKTOP_APP || argv.includes(`--${ENV.DESKTOP_APP}`) || argv.includes('-electron');
28
30
  export default {
29
31
  isProd,
30
32
  isTest,
@@ -52,15 +52,7 @@ const library = ''; // Module
52
52
  const loaders = [];
53
53
  const defaultLoaders = {};
54
54
  const includeJsResource = [];
55
- const excludeUrlResource = [];
56
55
  const useEsModule = true;
57
- /**
58
- * Files: url-loader options
59
- *
60
- * @reference https://github.com/webpack-contrib/url-loader#options
61
- */
62
-
63
- const urlLoaderOptions = {};
64
56
  /**
65
57
  * Scripts: babel-loader options
66
58
  *
@@ -88,8 +80,8 @@ const alias = {}; // Plugins
88
80
 
89
81
  const plugins = [];
90
82
  const injectHtml = false;
91
- const htmlPluginOptions = {};
92
- const extractCss = false; // Devtool
83
+ const htmlPluginOptions = {}; // const extractCss = false;
84
+ // Devtool
93
85
 
94
86
  const sourceMap = false; // Target
95
87
 
@@ -151,9 +143,7 @@ export default {
151
143
  loaders,
152
144
  defaultLoaders,
153
145
  includeJsResource,
154
- excludeUrlResource,
155
146
  useEsModule,
156
- urlLoaderOptions,
157
147
  babelLoaderOptions,
158
148
  postcssLoaderOptions,
159
149
  htmlLoaderOptions,
@@ -162,7 +152,7 @@ export default {
162
152
  plugins,
163
153
  injectHtml,
164
154
  htmlPluginOptions,
165
- extractCss,
155
+ // extractCss,
166
156
  sourceMap,
167
157
  target,
168
158
  externals,
@@ -1,12 +1,13 @@
1
- import postcssPresetEnv from 'postcss-preset-env';
2
1
  import atImport from 'postcss-import';
2
+ import postcssFlexbugsFixes from 'postcss-flexbugs-fixes';
3
+ import postcssPresetEnv from 'postcss-preset-env';
3
4
  import autoprefixer from 'autoprefixer';
4
5
  import cssnano from 'cssnano';
5
6
 
6
7
  function getDefaultPostcssPlugins(isPostCSS = false) {
7
- const defaultPostcssPlugins = isPostCSS || BalmJS.config.styles.extname === 'css' ? [postcssPresetEnv(BalmJS.config.styles.postcssEnvOptions), atImport({
8
+ const defaultPostcssPlugins = isPostCSS || BalmJS.config.styles.extname === 'css' ? [atImport({
8
9
  path: BalmJS.file.stylePaths
9
- })] : [];
10
+ }), postcssFlexbugsFixes(), postcssPresetEnv(BalmJS.config.styles.postcssEnvOptions)] : [];
10
11
  const cssnanoPlugin = BalmJS.config.env.isProd || BalmJS.config.styles.minify ? [cssnano(Object.assign(BalmJS.config.styles.options, {
11
12
  autoprefixer: false
12
13
  }))] : [];
@@ -1,5 +1,5 @@
1
1
  import BalmTask from './balm.js';
2
- import { MP_ASSETS } from '../../config/constants.js';
2
+ import { ASSET } from '../../config/constants.js';
3
3
 
4
4
  class BalmStyleTask extends BalmTask {
5
5
  constructor(name) {
@@ -20,7 +20,7 @@ class BalmStyleTask extends BalmTask {
20
20
  }
21
21
 
22
22
  this.defaultInput = node.path.join(BalmJS.config.src.css, '**', `!(_*).${extname}`);
23
- this.defaultOutput = BalmJS.config.env.isMP ? node.path.join(BalmJS.config.dest.base, MP_ASSETS, BalmJS.config.paths.target.css) : BalmJS.config.dest.css;
23
+ this.defaultOutput = BalmJS.config.env.isMP ? node.path.join(BalmJS.config.dest.base, ASSET.mpDir, BalmJS.config.paths.target.css) : BalmJS.config.dest.css;
24
24
  }
25
25
 
26
26
  handleStyle(style, output, options) {
@@ -1,6 +1,6 @@
1
1
  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; }
2
2
 
3
- import { ASSETS_KEYS, ASYNC_SCRIPTS, STATIC_ASSETS } from '../../config/constants.js';
3
+ import { ASSETS_TYPES, CHUNK, ASSET } from '../../config/constants.js';
4
4
 
5
5
  class CacheTask extends BalmJS.BalmTask {
6
6
  constructor() {
@@ -11,8 +11,8 @@ class CacheTask extends BalmJS.BalmTask {
11
11
  return this.src.pipe($.revAll.revision(BalmJS.config.assets.options)).pipe($.if(/\.html$/, BalmJS.file.setPublicPath())).pipe(gulp.dest(this.output)).pipe($.revDeleteOriginal()).pipe($.revAll.manifestFile()).pipe(gulp.dest(this.output));
12
12
  });
13
13
 
14
- const defaultIncludes = BalmJS.config.scripts.useCache ? ASSETS_KEYS.filter(assetKey => assetKey !== 'js').map(assetKey => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetKey])) : ASSETS_KEYS.map(assetKey => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetKey]));
15
- const defaultExcludes = [node.path.join(`!${BalmJS.config.dest.js}`, ASYNC_SCRIPTS, '*'), node.path.join(`!${BalmJS.config.dest.js}`, STATIC_ASSETS, '*'), node.path.join(`!${BalmJS.config.dest.css}`, ASYNC_SCRIPTS, '*'), node.path.join(`!${BalmJS.config.dest.base}`, BalmJS.config.pwa.manifest)];
14
+ const defaultIncludes = BalmJS.config.scripts.useCache ? ASSETS_TYPES.filter(assetType => assetType !== 'js').map(assetType => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetType])) : ASSETS_TYPES.map(assetType => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetType]));
15
+ const defaultExcludes = [node.path.join(`!${BalmJS.config.dest.js}`, CHUNK.dir, '*'), node.path.join(`!${BalmJS.config.dest.js}`, ASSET.dir, '*'), node.path.join(`!${BalmJS.config.dest.base}`, BalmJS.config.pwa.manifest)];
16
16
  const customIncludes = BalmJS.config.assets.includes;
17
17
  const customExcludes = BalmJS.config.assets.excludes.map(filename => {
18
18
  return `!${filename}`;
@@ -11,7 +11,7 @@ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!priva
11
11
  function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
12
12
 
13
13
  import del from 'del';
14
- import { ASSETS_KEYS } from '../../config/constants.js';
14
+ import { ASSETS_TYPES } from '../../config/constants.js';
15
15
 
16
16
  function unique(arr) {
17
17
  const obj = {};
@@ -36,7 +36,7 @@ class CleanTask extends BalmJS.BalmTask {
36
36
  _classPrivateFieldInitSpec(this, _getAssetsDir, {
37
37
  writable: true,
38
38
  value: (rootKey = 'assets') => {
39
- return unique(ASSETS_KEYS.map(assetKey => BalmJS.config[rootKey][assetKey]));
39
+ return unique(ASSETS_TYPES.map(assetType => BalmJS.config[rootKey][assetType]));
40
40
  }
41
41
  });
42
42
 
@@ -13,8 +13,7 @@ class File {
13
13
  // single-page apps that may serve index.html for nested URLs like /todos/42.
14
14
  // We can't use a relative path in HTML because we don't want to load something
15
15
  // like /todos/42/static/js/bundle.7289d.js. We have to know the root.
16
- return getPublicUrlOrPath( // eslint-disable-next-line @typescript-eslint/no-var-requires
17
- requireModule(resolveApp('package.json')).homepage, process.env.PUBLIC_URL);
16
+ return getPublicUrlOrPath(requireModule(resolveApp('package.json')).homepage, process.env.PUBLIC_URL);
18
17
  }
19
18
 
20
19
  get stylePaths() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "balm-core",
3
- "version": "4.4.3",
3
+ "version": "4.5.2",
4
4
  "description": "BalmJS compiler core",
5
5
  "keywords": [
6
6
  "balm",
@@ -49,11 +49,10 @@
49
49
  "connect-history-api-fallback": "^1.6.0",
50
50
  "css-loader": "^6.7.1",
51
51
  "css-minimizer-webpack-plugin": "^3.4.1",
52
- "cssnano": "^5.1.5",
52
+ "cssnano": "^5.1.7",
53
53
  "del": "^6.0.0",
54
- "esbuild": "^0.14",
54
+ "esbuild": "^0.14.0",
55
55
  "fancy-log": "^2.0.0",
56
- "file-loader": "^6.2.0",
57
56
  "gulp-eslint": "^6.0.0",
58
57
  "gulp-if": "^3.0.0",
59
58
  "gulp-load-plugins": "^2.0.7",
@@ -70,13 +69,13 @@
70
69
  "imagemin": "^8.0.1",
71
70
  "istextorbinary": "^6.0.0",
72
71
  "less": "^4.1.2",
73
- "mini-css-extract-plugin": "2.4.5",
74
72
  "modernizr": "^3.12.0",
75
73
  "parents": "^1.0.1",
76
74
  "plugin-error": "^1.0.1",
77
75
  "postcss": "^8.4.12",
76
+ "postcss-flexbugs-fixes": "^5.0.2",
78
77
  "postcss-import": "^14.1.0",
79
- "postcss-load-config": "^3.1.3",
78
+ "postcss-load-config": "^3.1.4",
80
79
  "postcss-loader": "6.2.1",
81
80
  "postcss-preset-env": "^7.4.3",
82
81
  "pretty-bytes": "^6.0.0",
@@ -84,9 +83,9 @@
84
83
  "replace-ext": "^2.0.0",
85
84
  "rollup": "^2.70.1",
86
85
  "rollup-plugin-terser": "^7.0.2",
87
- "sass": "^1.49.9",
86
+ "sass": "^1.50.0",
88
87
  "sass-loader": "^12.6.0",
89
- "ssh2": "^1.7.0",
88
+ "ssh2": "^1.9.0",
90
89
  "strip-ansi": "^7.0.1",
91
90
  "style-loader": "^3.3.1",
92
91
  "terser": "^5.12.1",
@@ -94,19 +93,18 @@
94
93
  "through2": "^4.0.2",
95
94
  "through2-concurrent": "^2.0.0",
96
95
  "tslib": "^2.3.1",
97
- "url-loader": "^4.1.1",
98
96
  "vinyl-sourcemaps-apply": "^0.2.1",
99
- "webpack": "^5.70.0",
97
+ "webpack": "^5.71.0",
100
98
  "webpack-bundle-analyzer": "^4.5.0",
101
99
  "webpack-dev-middleware": "^5.3.1",
102
100
  "webpack-hot-middleware": "^2.25.1",
103
101
  "webpack-merge": "^5.8.0",
104
- "workbox-build": "^6.5.1"
102
+ "workbox-build": "^6.5.2"
105
103
  },
106
104
  "devDependencies": {
107
- "@swc/core": "^1.2",
105
+ "@swc/core": "^1.2.0",
108
106
  "@types/express": "^4.17.13",
109
- "@types/node": "^17.0.22",
107
+ "@types/node": "^17.0.23",
110
108
  "@types/uglify-js": "^3.13.1",
111
109
  "@types/webpack": "^5.28.0"
112
110
  },
@@ -116,8 +114,11 @@
116
114
  "imagemin-optipng": "^8.0.0",
117
115
  "imagemin-svgo": "^9.0.0"
118
116
  },
117
+ "resolutions": {
118
+ "ajv": "^8.0.0"
119
+ },
119
120
  "engines": {
120
121
  "node": ">=12.13.0"
121
122
  },
122
- "gitHead": "e7d55837b2f75da51169f028516a1748ce6a543b"
123
+ "gitHead": "3f7e99d1cafc6868d2437975e1817c8ba26de24e"
123
124
  }
package/tslib/balm.js CHANGED
@@ -31,7 +31,7 @@ class Balm {
31
31
  registerTasks(recipe);
32
32
  }
33
33
  else {
34
- BalmJS.logger.error('initialization', 'BalmJS API: `balm.go(function(mix) {});`');
34
+ BalmJS.logger.error('initialization', 'BalmJS API: `balm.go(mix => {});`');
35
35
  }
36
36
  }
37
37
  reset() {
@@ -28,5 +28,8 @@ function checkConfig() {
28
28
  upgradeRenamed('3.16.0', 'scripts', 'inject', 'useCache');
29
29
  upgradeDeprecated('3.17.0', 'styles', 'darkSass');
30
30
  upgradeDeprecated('3.19.0', 'scripts', 'useCache');
31
+ upgradeDeprecated('4.5.0', 'scripts', 'excludeUrlResource');
32
+ upgradeDeprecated('4.5.0', 'scripts', 'urlLoaderOptions');
33
+ upgradeDeprecated('4.5.0', 'scripts', 'extractCss');
31
34
  }
32
35
  export default checkConfig;
@@ -1,12 +1,12 @@
1
1
  import checkConfig from './check_config.js';
2
- import { ASSETS_KEYS } from '../config/constants.js';
2
+ import { ASSETS_TYPES } from '../config/constants.js';
3
3
  function createQuickPath(config, rootKey) {
4
4
  const result = {};
5
5
  const rootValue = config.roots[rootKey];
6
6
  for (const pathKey of Object.keys(config.paths[rootKey])) {
7
7
  const pathValue = config.paths[rootKey][pathKey];
8
8
  result[pathKey] =
9
- rootKey === 'target' && ASSETS_KEYS.includes(pathKey)
9
+ rootKey === 'target' && ASSETS_TYPES.includes(pathKey)
10
10
  ? node.path.join(rootValue, BalmJS.config.assets.virtualDir, BalmJS.file.assetsSuffixPath, pathValue)
11
11
  : node.path.join(rootValue, pathValue);
12
12
  }
@@ -19,8 +19,8 @@ function ready(config) {
19
19
  config.dest = createQuickPath(config, config.env.isProd || !config.inFrontend ? 'target' : 'tmp');
20
20
  config.dest.static = node.path.join(config.dest.base, BalmJS.config.assets.virtualDir, BalmJS.file.assetsSuffixPath);
21
21
  config.assets.static = node.path.join(config.assets.root, config.assets.mainDir, BalmJS.file.assetsSuffixPath);
22
- for (const assetKey of ASSETS_KEYS) {
23
- config.assets[assetKey] = node.path.join(config.assets.static, config.paths.target[assetKey]);
22
+ for (const assetType of ASSETS_TYPES) {
23
+ config.assets[assetType] = node.path.join(config.assets.static, config.paths.target[assetType]);
24
24
  }
25
25
  const HMR_ENV = config.useDefaults &&
26
26
  config.env.isDev &&
@@ -1,6 +1,6 @@
1
1
  import HtmlWebpackPlugin from 'html-webpack-plugin';
2
2
  import getLoaders from '../loaders.js';
3
- import { HASH_NAME_PROD } from '../../../config/constants.js';
3
+ import { CHUNK } from '../../../config/constants.js';
4
4
  function getDefaultPlugins(webpack, scripts) {
5
5
  const plugins = [
6
6
  new webpack.IgnorePlugin({
@@ -37,15 +37,15 @@ function getSplitChunks() {
37
37
  const jsFolder = BalmJS.config.paths.target.js;
38
38
  let cacheGroups = {};
39
39
  if (scripts.extractAllVendors) {
40
- const jsFilename = scripts.useCache
41
- ? `${scripts.vendorName}.${HASH_NAME_PROD}.js`
40
+ const vendorsFilename = scripts.useCache
41
+ ? `${scripts.vendorName}.${CHUNK.hash}.js`
42
42
  : `${scripts.vendorName}.js`;
43
43
  cacheGroups = {
44
44
  defaultVendors: {
45
45
  name: 'vendors',
46
46
  chunks: 'all',
47
47
  test: /[\\/](node_modules|bower_components)[\\/]/,
48
- filename: BalmJS.file.assetsPath(`${jsFolder}/${jsFilename}`)
48
+ filename: BalmJS.file.assetsPath(`${jsFolder}/${vendorsFilename}`)
49
49
  }
50
50
  };
51
51
  }
@@ -54,26 +54,18 @@ function getSplitChunks() {
54
54
  for (const vendor of BalmJS.vendors) {
55
55
  const cacheGroupKey = vendor.key;
56
56
  const cacheGroupModules = vendor.value.join('|');
57
- const jsFilename = scripts.useCache
58
- ? `${cacheGroupKey}.${HASH_NAME_PROD}.js`
57
+ const vendorFilename = scripts.useCache
58
+ ? `${cacheGroupKey}.${CHUNK.hash}.js`
59
59
  : `${cacheGroupKey}.js`;
60
60
  cacheGroups[cacheGroupKey] = {
61
61
  name: cacheGroupKey,
62
62
  chunks: 'initial',
63
63
  test: new RegExp(`[\\\\/](${cacheGroupModules})[\\\\/].*(?<!\\.css)$`),
64
- filename: BalmJS.file.assetsPath(`${jsFolder}/${scripts.vendorName}/${jsFilename}`),
64
+ filename: BalmJS.file.assetsPath(`${jsFolder}/${scripts.vendorName}/${vendorFilename}`),
65
65
  enforce: true
66
66
  };
67
67
  }
68
68
  }
69
- if (BalmJS.config.env.isProd && BalmJS.config.scripts.extractCss) {
70
- cacheGroups.css = {
71
- name: 'css',
72
- chunks: 'all',
73
- test: /\.css$/,
74
- enforce: true
75
- };
76
- }
77
69
  return Object.keys(cacheGroups).length ? { cacheGroups } : false;
78
70
  }
79
71
  function getCommonConfig(webpack, scripts) {
@@ -1,12 +1,8 @@
1
1
  import TerserPlugin from 'terser-webpack-plugin';
2
- import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
3
- import MiniCssExtractPlugin from 'mini-css-extract-plugin';
4
2
  import webpackBundleAnalyzer from 'webpack-bundle-analyzer';
5
3
  import { merge } from 'webpack-merge';
6
4
  import getCommonConfig from './common.js';
7
- import { ASYNC_SCRIPTS, HASH_NAME_PROD } from '../../../config/constants.js';
8
5
  const bundleAnalyzerReport = process.env.npm_config_report || false;
9
- const getCssFilename = () => `${BalmJS.config.paths.target.css}/${ASYNC_SCRIPTS}/[name].${HASH_NAME_PROD}.css`;
10
6
  function getProdConfig(webpack, scripts) {
11
7
  const shouldUseSourceMap = scripts.sourceMap;
12
8
  const terserOptions = scripts.minifyOptions;
@@ -20,22 +16,13 @@ function getProdConfig(webpack, scripts) {
20
16
  new TerserPlugin({
21
17
  terserOptions,
22
18
  extractComments: false
23
- }),
24
- new CssMinimizerPlugin()
19
+ })
25
20
  ]
26
21
  },
27
22
  plugins: [
28
23
  new webpack.DefinePlugin({
29
24
  'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production')
30
25
  }),
31
- ...(scripts.extractCss
32
- ? [
33
- new MiniCssExtractPlugin({
34
- filename: BalmJS.file.assetsPath(getCssFilename()),
35
- chunkFilename: BalmJS.file.assetsPath(getCssFilename())
36
- })
37
- ]
38
- : []),
39
26
  ...(bundleAnalyzerReport
40
27
  ? [new webpackBundleAnalyzer.BundleAnalyzerPlugin()]
41
28
  : [])
@@ -2,10 +2,10 @@ import { mergeWithRules, CustomizeRule } from 'webpack-merge';
2
2
  import LOADERS from './rules/index.js';
3
3
  function getLoaders(customLoaders) {
4
4
  const enableDefaultLoaders = Object.assign({
5
- html: true,
6
- css: true,
7
5
  js: true,
8
- url: true
6
+ css: true,
7
+ html: true,
8
+ asset: true
9
9
  }, BalmJS.config.scripts.defaultLoaders);
10
10
  const useDefaultLoaders = Object.values(enableDefaultLoaders).some((value) => value);
11
11
  let defaultLoaders = [];
@@ -1,25 +1,25 @@
1
- import { ASYNC_SCRIPTS, HASH_NAME_PROD, MP_ASSETS } from '../../config/constants.js';
2
- function getFilename(scripts, isChunk = false) {
1
+ import { CHUNK, ASSET } from '../../config/constants.js';
2
+ function getJsFilename(scripts, isChunk = false) {
3
3
  let filename;
4
4
  if (isChunk) {
5
- filename = BalmJS.config.env.isProd ? `[name].${HASH_NAME_PROD}` : '[name]';
5
+ filename = BalmJS.config.env.isProd ? `[name].${CHUNK.hash}` : '[name]';
6
6
  }
7
7
  else {
8
- filename = scripts.useCache ? `[name].${HASH_NAME_PROD}` : '[name]';
8
+ filename = scripts.useCache ? `[name].${CHUNK.hash}` : '[name]';
9
9
  }
10
10
  return `${filename}.js`;
11
11
  }
12
12
  function getOutput(output, scripts, isHook = false) {
13
- const outputPath = output || BalmJS.config.dest.base;
13
+ const outputDirectory = output || BalmJS.config.dest.base;
14
14
  const jsFolder = BalmJS.config.paths.target.js;
15
- const jsFilename = getFilename(scripts);
16
- const jsChunkFilename = getFilename(scripts, true);
15
+ const bundleFilename = getJsFilename(scripts);
16
+ const chunkFilename = getJsFilename(scripts, true);
17
17
  const customLibraryConfig = scripts.library
18
18
  ? { library: scripts.library }
19
19
  : {};
20
20
  const miniprogramConfig = BalmJS.config.env.isMP
21
21
  ? {
22
- path: BalmJS.file.absPath(node.path.join(BalmJS.config.dest.base, MP_ASSETS)),
22
+ path: BalmJS.file.absPath(node.path.join(BalmJS.config.dest.base, ASSET.mpDir)),
23
23
  library: {
24
24
  name: 'createApp',
25
25
  type: 'window',
@@ -28,13 +28,13 @@ function getOutput(output, scripts, isHook = false) {
28
28
  }
29
29
  : {};
30
30
  return Object.assign({
31
- path: BalmJS.file.absPath(outputPath),
31
+ path: BalmJS.file.absPath(outputDirectory),
32
32
  filename: isHook
33
- ? jsFilename
34
- : BalmJS.file.assetsPath(`${jsFolder}/${jsFilename}`),
33
+ ? bundleFilename
34
+ : BalmJS.file.assetsPath(`${jsFolder}/${bundleFilename}`),
35
35
  chunkFilename: isHook
36
- ? jsChunkFilename
37
- : BalmJS.file.assetsPath(`${jsFolder}/${ASYNC_SCRIPTS}/${jsChunkFilename}`),
36
+ ? chunkFilename
37
+ : BalmJS.file.assetsPath(`${jsFolder}/${CHUNK.dir}/${chunkFilename}`),
38
38
  publicPath: BalmJS.file.publicUrlOrPath
39
39
  }, customLibraryConfig, miniprogramConfig);
40
40
  }
@@ -0,0 +1,28 @@
1
+ import { imgRegex, fontRegex, mediaRegex } from '../config/regex.js';
2
+ import { ASSET } from '../../../config/constants.js';
3
+ function assetLoader() {
4
+ return [
5
+ {
6
+ test: imgRegex,
7
+ type: 'asset/resource',
8
+ generator: {
9
+ filename: BalmJS.file.assetsPath(`${ASSET.dir}/${BalmJS.config.paths.target.img}/[name].${ASSET.hash}[ext]`)
10
+ }
11
+ },
12
+ {
13
+ test: fontRegex,
14
+ type: 'asset/resource',
15
+ generator: {
16
+ filename: BalmJS.file.assetsPath(`${ASSET.dir}/${BalmJS.config.paths.target.font}/[name].${ASSET.hash}[ext]`)
17
+ }
18
+ },
19
+ {
20
+ test: mediaRegex,
21
+ type: 'asset/resource',
22
+ generator: {
23
+ filename: BalmJS.file.assetsPath(`${ASSET.dir}/${BalmJS.config.paths.target.media}/[name].${ASSET.hash}[ext]`)
24
+ }
25
+ }
26
+ ];
27
+ }
28
+ export default assetLoader;
@@ -1,16 +1,8 @@
1
- import MiniCssExtractPlugin from 'mini-css-extract-plugin';
2
1
  import { cssRegex, cssModuleRegex, sassRegex, sassModuleRegex } from '../config/regex.js';
3
- const getStyleLoaders = (styleLoader, cssOptions, preProcessor = '', sassOptions = {}) => {
2
+ function getStyleLoaders(styleLoader, cssOptions, preProcessor = '', sassOptions = {}) {
4
3
  const { sourceMap } = cssOptions;
5
4
  const loaders = [
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,
5
+ styleLoader,
14
6
  {
15
7
  loader: requireModule.resolve('css-loader'),
16
8
  options: cssOptions
@@ -34,7 +26,7 @@ const getStyleLoaders = (styleLoader, cssOptions, preProcessor = '', sassOptions
34
26
  });
35
27
  }
36
28
  return loaders;
37
- };
29
+ }
38
30
  function cssLoader() {
39
31
  let styleLoader = {
40
32
  loader: requireModule.resolve('style-loader'),
@@ -1,10 +1,10 @@
1
- import htmlLoader from './html.js';
2
- import babelLoader from './babel.js';
1
+ import jsLoader from './babel.js';
3
2
  import cssLoader from './css.js';
4
- import urlLoader from './url.js';
3
+ import htmlLoader from './html.js';
4
+ import assetLoader from './asset.js';
5
5
  export default {
6
- htmlLoader,
7
- babelLoader,
6
+ jsLoader,
8
7
  cssLoader,
9
- urlLoader
8
+ htmlLoader,
9
+ assetLoader
10
10
  };
@@ -1,10 +1,14 @@
1
1
  const DOMAIN = 'https://balm.js.org';
2
- const PUBLIC_URL = '%PUBLIC_URL%';
3
- const ASSETS_KEYS = ['css', 'js', 'img', 'font', 'media'];
4
- const ASYNC_SCRIPTS = 'async';
5
- const STATIC_ASSETS = 'assets';
6
- const HASH_NAME_PROD = '[contenthash:8]';
7
- const HASH_NAME_DEV = '[hash:8]';
8
2
  const HMR_PATH = '/__balm_hmr';
9
- const MP_ASSETS = 'common';
10
- export { DOMAIN, PUBLIC_URL, ASSETS_KEYS, ASYNC_SCRIPTS, STATIC_ASSETS, HASH_NAME_PROD, HASH_NAME_DEV, HMR_PATH, MP_ASSETS };
3
+ const PUBLIC_URL = '%PUBLIC_URL%';
4
+ const ASSETS_TYPES = ['css', 'js', 'img', 'font', 'media'];
5
+ const CHUNK = {
6
+ dir: 'chunk',
7
+ hash: '[contenthash:8]'
8
+ };
9
+ const ASSET = {
10
+ dir: 'asset',
11
+ hash: '[hash:8]',
12
+ mpDir: 'common'
13
+ };
14
+ export { DOMAIN, HMR_PATH, PUBLIC_URL, ASSETS_TYPES, CHUNK, ASSET };
@@ -1,3 +1,5 @@
1
+ const NODE_ENV = process.env.NODE_ENV;
2
+ const argv = process.argv;
1
3
  const ENV = {
2
4
  PROD: 'production',
3
5
  TEST: 'test',
@@ -6,14 +8,14 @@ const ENV = {
6
8
  MP: 'miniprogram',
7
9
  DESKTOP_APP: 'desktop-app'
8
10
  };
9
- const isProd = process.env.NODE_ENV === ENV.PROD ||
10
- process.argv.includes(`--${ENV.PROD}`) ||
11
- process.argv.includes('-p');
12
- const isTest = process.env.NODE_ENV === ENV.TEST ||
13
- process.argv.includes(`--${ENV.TEST}`) ||
14
- process.argv.includes('-t');
11
+ const isProd = NODE_ENV === ENV.PROD ||
12
+ argv.includes(`--${ENV.PROD}`) ||
13
+ argv.includes('-p');
14
+ const isTest = NODE_ENV === ENV.TEST ||
15
+ argv.includes(`--${ENV.TEST}`) ||
16
+ argv.includes('-t');
15
17
  const isDev = !isProd && !isTest;
16
- if (!process.env.NODE_ENV) {
18
+ if (!NODE_ENV) {
17
19
  if (isProd) {
18
20
  process.env.NODE_ENV = ENV.PROD;
19
21
  }
@@ -24,15 +26,13 @@ if (!process.env.NODE_ENV) {
24
26
  process.env.NODE_ENV = ENV.DEV;
25
27
  }
26
28
  }
27
- const inSSR = process.env.NODE_ENV === ENV.SSR ||
28
- process.argv.includes(`--${ENV.SSR}`) ||
29
- process.argv.includes('-ssr');
30
- const isMP = process.env.NODE_ENV === ENV.MP ||
31
- process.argv.includes(`--${ENV.MP}`) ||
32
- process.argv.includes('-mp');
33
- const inDesktopApp = process.env.NODE_ENV === ENV.DESKTOP_APP ||
34
- process.argv.includes(`--${ENV.DESKTOP_APP}`) ||
35
- process.argv.includes('-electron');
29
+ const inSSR = NODE_ENV === ENV.SSR ||
30
+ argv.includes(`--${ENV.SSR}`) ||
31
+ argv.includes('-ssr');
32
+ const isMP = NODE_ENV === ENV.MP || argv.includes(`--${ENV.MP}`) || argv.includes('-mp');
33
+ const inDesktopApp = NODE_ENV === ENV.DESKTOP_APP ||
34
+ argv.includes(`--${ENV.DESKTOP_APP}`) ||
35
+ argv.includes('-electron');
36
36
  export default {
37
37
  isProd,
38
38
  isTest,
@@ -23,9 +23,7 @@ const library = '';
23
23
  const loaders = [];
24
24
  const defaultLoaders = {};
25
25
  const includeJsResource = [];
26
- const excludeUrlResource = [];
27
26
  const useEsModule = true;
28
- const urlLoaderOptions = {};
29
27
  const babelLoaderOptions = {};
30
28
  const postcssLoaderOptions = {};
31
29
  const htmlLoaderOptions = {};
@@ -34,7 +32,6 @@ const alias = {};
34
32
  const plugins = [];
35
33
  const injectHtml = false;
36
34
  const htmlPluginOptions = {};
37
- const extractCss = false;
38
35
  const sourceMap = false;
39
36
  const target = ['web', 'es5'];
40
37
  const externals = '';
@@ -66,9 +63,7 @@ export default {
66
63
  loaders,
67
64
  defaultLoaders,
68
65
  includeJsResource,
69
- excludeUrlResource,
70
66
  useEsModule,
71
- urlLoaderOptions,
72
67
  babelLoaderOptions,
73
68
  postcssLoaderOptions,
74
69
  htmlLoaderOptions,
@@ -77,7 +72,6 @@ export default {
77
72
  plugins,
78
73
  injectHtml,
79
74
  htmlPluginOptions,
80
- extractCss,
81
75
  sourceMap,
82
76
  target,
83
77
  externals,
@@ -1,12 +1,14 @@
1
- import postcssPresetEnv from 'postcss-preset-env';
2
1
  import atImport from 'postcss-import';
2
+ import postcssFlexbugsFixes from 'postcss-flexbugs-fixes';
3
+ import postcssPresetEnv from 'postcss-preset-env';
3
4
  import autoprefixer from 'autoprefixer';
4
5
  import cssnano from 'cssnano';
5
6
  function getDefaultPostcssPlugins(isPostCSS = false) {
6
7
  const defaultPostcssPlugins = isPostCSS || BalmJS.config.styles.extname === 'css'
7
8
  ? [
8
- postcssPresetEnv(BalmJS.config.styles.postcssEnvOptions),
9
- atImport({ path: BalmJS.file.stylePaths })
9
+ atImport({ path: BalmJS.file.stylePaths }),
10
+ postcssFlexbugsFixes(),
11
+ postcssPresetEnv(BalmJS.config.styles.postcssEnvOptions)
10
12
  ]
11
13
  : [];
12
14
  const cssnanoPlugin = BalmJS.config.env.isProd || BalmJS.config.styles.minify
@@ -1,5 +1,5 @@
1
1
  import BalmTask from './balm.js';
2
- import { MP_ASSETS } from '../../config/constants.js';
2
+ import { ASSET } from '../../config/constants.js';
3
3
  class BalmStyleTask extends BalmTask {
4
4
  constructor(name) {
5
5
  super(name);
@@ -16,7 +16,7 @@ class BalmStyleTask extends BalmTask {
16
16
  }
17
17
  this.defaultInput = node.path.join(BalmJS.config.src.css, '**', `!(_*).${extname}`);
18
18
  this.defaultOutput = BalmJS.config.env.isMP
19
- ? node.path.join(BalmJS.config.dest.base, MP_ASSETS, BalmJS.config.paths.target.css)
19
+ ? node.path.join(BalmJS.config.dest.base, ASSET.mpDir, BalmJS.config.paths.target.css)
20
20
  : BalmJS.config.dest.css;
21
21
  }
22
22
  handleStyle(style, output, options) {
@@ -1,4 +1,4 @@
1
- import { ASSETS_KEYS, ASYNC_SCRIPTS, STATIC_ASSETS } from '../../config/constants.js';
1
+ import { ASSETS_TYPES, CHUNK, ASSET } from '../../config/constants.js';
2
2
  class CacheTask extends BalmJS.BalmTask {
3
3
  constructor() {
4
4
  super('cache');
@@ -13,12 +13,11 @@ class CacheTask extends BalmJS.BalmTask {
13
13
  .pipe(gulp.dest(this.output));
14
14
  };
15
15
  const defaultIncludes = BalmJS.config.scripts.useCache
16
- ? ASSETS_KEYS.filter((assetKey) => assetKey !== 'js').map((assetKey) => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetKey]))
17
- : ASSETS_KEYS.map((assetKey) => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetKey]));
16
+ ? ASSETS_TYPES.filter((assetType) => assetType !== 'js').map((assetType) => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetType]))
17
+ : ASSETS_TYPES.map((assetType) => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetType]));
18
18
  const defaultExcludes = [
19
- node.path.join(`!${BalmJS.config.dest.js}`, ASYNC_SCRIPTS, '*'),
20
- node.path.join(`!${BalmJS.config.dest.js}`, STATIC_ASSETS, '*'),
21
- node.path.join(`!${BalmJS.config.dest.css}`, ASYNC_SCRIPTS, '*'),
19
+ node.path.join(`!${BalmJS.config.dest.js}`, CHUNK.dir, '*'),
20
+ node.path.join(`!${BalmJS.config.dest.js}`, ASSET.dir, '*'),
22
21
  node.path.join(`!${BalmJS.config.dest.base}`, BalmJS.config.pwa.manifest)
23
22
  ];
24
23
  const customIncludes = BalmJS.config.assets.includes;
@@ -1,7 +1,7 @@
1
1
  var _CleanTask_getAssetsDir;
2
2
  import { __classPrivateFieldGet } from "tslib";
3
3
  import del from 'del';
4
- import { ASSETS_KEYS } from '../../config/constants.js';
4
+ import { ASSETS_TYPES } from '../../config/constants.js';
5
5
  function unique(arr) {
6
6
  const obj = {};
7
7
  const result = [];
@@ -17,7 +17,7 @@ class CleanTask extends BalmJS.BalmTask {
17
17
  constructor() {
18
18
  super('clean');
19
19
  _CleanTask_getAssetsDir.set(this, (rootKey = 'assets') => {
20
- return unique(ASSETS_KEYS.map((assetKey) => BalmJS.config[rootKey][assetKey]));
20
+ return unique(ASSETS_TYPES.map((assetType) => BalmJS.config[rootKey][assetType]));
21
21
  });
22
22
  this.fn = async (callback) => {
23
23
  const taskName = `${this.name} task`;
@@ -4,7 +4,8 @@ const appDirectory = node.fs.realpathSync(process.cwd());
4
4
  const resolveApp = (relativePath) => node.path.resolve(appDirectory, relativePath);
5
5
  class File {
6
6
  get publicUrlOrPath() {
7
- return getPublicUrlOrPath(requireModule(resolveApp('package.json')).homepage, process.env.PUBLIC_URL);
7
+ return getPublicUrlOrPath(requireModule(resolveApp('package.json'))
8
+ .homepage, process.env.PUBLIC_URL);
8
9
  }
9
10
  get stylePaths() {
10
11
  return [
@@ -1,33 +0,0 @@
1
- import { STATIC_ASSETS, HASH_NAME_DEV } from '../../../config/constants.js';
2
- import { imgRegex, fontRegex, mediaRegex } from '../config/regex.js';
3
- const imageInlineSizeLimit = parseInt(process.env.IMAGE_INLINE_SIZE_LIMIT || '10000');
4
-
5
- function urlLoader() {
6
- const PATHNAME = `${BalmJS.config.paths.target.js}/${STATIC_ASSETS}/`;
7
- const FILENAME = `[name].${HASH_NAME_DEV}.[ext]`;
8
- const options = Object.assign({
9
- limit: imageInlineSizeLimit,
10
- // Loads files as `base64` encoded URL
11
- name: BalmJS.file.assetsPath(`${PATHNAME}${FILENAME}`),
12
- esModule: BalmJS.config.scripts.useEsModule
13
- }, BalmJS.config.scripts.urlLoaderOptions);
14
- return [// "url" loader works like "file" loader except that it embeds assets
15
- // smaller than specified limit in bytes as data URLs to avoid requests.
16
- // A missing `test` is equivalent to a match.
17
- {
18
- test: imgRegex,
19
- loader: requireModule.resolve('url-loader'),
20
- exclude: BalmJS.config.scripts.excludeUrlResource,
21
- options
22
- }, {
23
- test: mediaRegex,
24
- loader: requireModule.resolve('url-loader'),
25
- options
26
- }, {
27
- test: fontRegex,
28
- loader: requireModule.resolve('url-loader'),
29
- options
30
- }];
31
- }
32
-
33
- export default urlLoader;
@@ -1,31 +0,0 @@
1
- import { STATIC_ASSETS, HASH_NAME_DEV } from '../../../config/constants.js';
2
- import { imgRegex, fontRegex, mediaRegex } from '../config/regex.js';
3
- const imageInlineSizeLimit = parseInt(process.env.IMAGE_INLINE_SIZE_LIMIT || '10000');
4
- function urlLoader() {
5
- const PATHNAME = `${BalmJS.config.paths.target.js}/${STATIC_ASSETS}/`;
6
- const FILENAME = `[name].${HASH_NAME_DEV}.[ext]`;
7
- const options = Object.assign({
8
- limit: imageInlineSizeLimit,
9
- name: BalmJS.file.assetsPath(`${PATHNAME}${FILENAME}`),
10
- esModule: BalmJS.config.scripts.useEsModule
11
- }, BalmJS.config.scripts.urlLoaderOptions);
12
- return [
13
- {
14
- test: imgRegex,
15
- loader: requireModule.resolve('url-loader'),
16
- exclude: BalmJS.config.scripts.excludeUrlResource,
17
- options
18
- },
19
- {
20
- test: mediaRegex,
21
- loader: requireModule.resolve('url-loader'),
22
- options
23
- },
24
- {
25
- test: fontRegex,
26
- loader: requireModule.resolve('url-loader'),
27
- options
28
- }
29
- ];
30
- }
31
- export default urlLoader;