balm-core 4.0.0-canary.e34d3bf4.0 → 4.0.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/README.md +1 -1
- package/index.d.ts +4 -3
- package/lib/balm.js +5 -1
- package/lib/bootstrap/check_config.js +11 -3
- package/lib/bootstrap/index.js +3 -1
- package/lib/bundler/webpack/config/common.js +18 -8
- package/lib/bundler/webpack/config/dev.js +3 -1
- package/lib/bundler/webpack/config/prod.js +7 -35
- package/lib/bundler/webpack/config/regex.js +3 -1
- package/lib/bundler/webpack/output.js +15 -15
- package/lib/bundler/webpack/rules/css.js +66 -26
- package/lib/bundler/webpack/rules/url.js +2 -2
- package/lib/config/constants.js +3 -2
- package/lib/config/globals.js +2 -2
- package/lib/config/scripts.js +4 -8
- package/lib/hello.js +4 -3
- package/lib/middlewares/proxy.js +4 -1
- package/lib/plugins/plumber.js +1 -1
- package/lib/plugins/postcss.js +1 -1
- package/lib/plugins/rename.js +1 -1
- package/lib/plugins/replace.js +1 -1
- package/lib/tasks/index.js +4 -1
- package/lib/tasks/private/clean.js +5 -1
- package/lib/tasks/private/modernizr.js +7 -3
- package/lib/tasks/private/sprite.js +6 -2
- package/lib/tasks/public/ftp.js +4 -1
- package/lib/tasks/public/html.js +6 -2
- package/lib/tasks/public/publish.js +5 -1
- package/lib/tasks/public/remove.js +5 -1
- package/lib/tasks/public/server.js +10 -3
- package/lib/tasks/public/url.js +5 -1
- package/lib/utilities/address.js +1 -1
- package/lib/utilities/cache-core.js +8 -7
- package/lib/utilities/compiling.js +5 -1
- package/lib/utilities/detect-port.js +1 -1
- package/lib/utilities/file.js +2 -1
- package/lib/utilities/loading.js +7 -3
- package/lib/utilities/logger.js +6 -2
- package/lib/utilities/merge-stream.js +1 -1
- package/lib/utilities/public-url.js +1 -1
- package/package.json +39 -37
- package/tslib/balm.js +7 -7
- package/tslib/bootstrap/check_config.js +10 -3
- package/tslib/bootstrap/index.js +2 -0
- package/tslib/bundler/webpack/config/common.js +15 -8
- package/tslib/bundler/webpack/config/dev.js +3 -0
- package/tslib/bundler/webpack/config/prod.js +7 -27
- package/tslib/bundler/webpack/config/regex.js +3 -1
- package/tslib/bundler/webpack/output.js +8 -21
- package/tslib/bundler/webpack/rules/css.js +64 -35
- package/tslib/bundler/webpack/rules/url.js +2 -2
- package/tslib/config/constants.js +3 -2
- package/tslib/config/globals.js +2 -2
- package/tslib/config/scripts.js +0 -4
- package/tslib/hello.js +4 -3
- package/tslib/middlewares/proxy.js +2 -1
- package/tslib/plugins/imagemin.js +3 -1
- package/tslib/plugins/plumber.js +1 -1
- package/tslib/plugins/postcss.js +1 -1
- package/tslib/plugins/rename.js +1 -1
- package/tslib/plugins/replace.js +1 -1
- package/tslib/tasks/index.js +2 -1
- package/tslib/tasks/private/clean.js +5 -5
- package/tslib/tasks/private/modernizr.js +8 -8
- package/tslib/tasks/private/sprite.js +7 -7
- package/tslib/tasks/public/ftp.js +2 -1
- package/tslib/tasks/public/html.js +9 -9
- package/tslib/tasks/public/publish.js +5 -5
- package/tslib/tasks/public/remove.js +4 -4
- package/tslib/tasks/public/server.js +13 -12
- package/tslib/tasks/public/url.js +5 -5
- package/tslib/utilities/address.js +1 -1
- package/tslib/utilities/cache-core.js +6 -5
- package/tslib/utilities/compiling.js +6 -6
- package/tslib/utilities/detect-port.js +1 -1
- package/tslib/utilities/loading.js +11 -10
- package/tslib/utilities/logger.js +9 -9
- package/tslib/utilities/merge-stream.js +1 -1
- package/tslib/utilities/public-url.js +1 -1
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ You need to set up your development environment before you can do anything.
|
|
|
69
69
|
|
|
70
70
|
Install [Node.js® and npm](https://nodejs.org/en/download/) if they are not already on your machine.
|
|
71
71
|
|
|
72
|
-
> **Verify that you are running at least node `12.
|
|
72
|
+
> **Verify that you are running at least node `12.13.0` and npm `5.2.0`** by running `node -v` and `npm -v` in a terminal/console window. Older versions maybe produce errors, but newer versions are fine.
|
|
73
73
|
|
|
74
74
|
You develop apps in the context of an [Balm workspace](https://balm.js.org/docs/guide/structure.html).
|
|
75
75
|
|
package/index.d.ts
CHANGED
|
@@ -86,7 +86,6 @@ export interface BalmScripts {
|
|
|
86
86
|
lint: boolean;
|
|
87
87
|
// webpack
|
|
88
88
|
library: string | object;
|
|
89
|
-
libraryTarget: string;
|
|
90
89
|
loaders: RuleSetRule[];
|
|
91
90
|
defaultLoaders: Partial<BalmLoaders>;
|
|
92
91
|
includeJsResource: string[];
|
|
@@ -110,16 +109,17 @@ export interface BalmScripts {
|
|
|
110
109
|
extractAllVendors: boolean;
|
|
111
110
|
vendorName: string;
|
|
112
111
|
extractCss: boolean;
|
|
113
|
-
useCache: boolean;
|
|
114
112
|
ie8: boolean;
|
|
115
113
|
// rollup
|
|
116
|
-
inputOptions: InputOptions
|
|
114
|
+
inputOptions: Omit<InputOptions, 'acorn'>; // incompatible
|
|
117
115
|
outputOptions: OutputOptions;
|
|
118
116
|
watchOptions: WatcherOptions;
|
|
119
117
|
// esbuild
|
|
120
118
|
buildOptions: BuildOptions;
|
|
121
119
|
useTransform: boolean;
|
|
122
120
|
transformOptions: TransformOptions;
|
|
121
|
+
// extra
|
|
122
|
+
useCache?: boolean;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
export interface BalmImagesPlugins {
|
|
@@ -169,6 +169,7 @@ interface BalmServer {
|
|
|
169
169
|
historyOptions: boolean | object;
|
|
170
170
|
middlewares: Function[] | object[];
|
|
171
171
|
extraWatchFiles: string[];
|
|
172
|
+
// extra
|
|
172
173
|
useHMR?: boolean;
|
|
173
174
|
}
|
|
174
175
|
|
package/lib/balm.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
2
|
+
|
|
3
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
4
|
+
|
|
1
5
|
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
2
6
|
|
|
3
7
|
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
@@ -19,7 +23,7 @@ var _config = /*#__PURE__*/new WeakMap();
|
|
|
19
23
|
|
|
20
24
|
class Balm {
|
|
21
25
|
constructor() {
|
|
22
|
-
|
|
26
|
+
_classPrivateFieldInitSpec(this, _config, {
|
|
23
27
|
writable: true,
|
|
24
28
|
value: void 0
|
|
25
29
|
});
|
|
@@ -12,9 +12,15 @@ function upgradeRenamed(version, configCategory, from, to) {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function upgradeMigrated(version,
|
|
16
|
-
if (BalmJS.config[from][
|
|
17
|
-
BalmJS.logger.warn(`balm@${version}+ config`, upgradeGuide(to,
|
|
15
|
+
function upgradeMigrated(version, configName, from, to) {
|
|
16
|
+
if (BalmJS.config[from][configName]) {
|
|
17
|
+
BalmJS.logger.warn(`balm@${version}+ config`, upgradeGuide(to, configName, `'${from}.${configName}' was migrated to '${to}.${configName}'.`));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function upgradeDeprecated(version, configCategory, configName) {
|
|
22
|
+
if (BalmJS.config[configCategory][configName]) {
|
|
23
|
+
BalmJS.logger.warn(`balm@${version}+ config`, `'${configCategory}.${configName}' was deprecated.`);
|
|
18
24
|
}
|
|
19
25
|
} // Compatibility for upgrade balm
|
|
20
26
|
|
|
@@ -28,6 +34,8 @@ function checkConfig() {
|
|
|
28
34
|
upgradeRenamed('3.0.0', 'styles', 'minified', 'minify');
|
|
29
35
|
upgradeRenamed('3.9.0', 'scripts', 'options', 'minifyOptions');
|
|
30
36
|
upgradeRenamed('3.16.0', 'scripts', 'inject', 'useCache');
|
|
37
|
+
upgradeDeprecated('3.17.0', 'styles', 'darkSass');
|
|
38
|
+
upgradeDeprecated('3.19.0', 'scripts', 'useCache');
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
export default checkConfig;
|
package/lib/bootstrap/index.js
CHANGED
|
@@ -32,8 +32,10 @@ function ready(config) {
|
|
|
32
32
|
|
|
33
33
|
if (/^electron-.*/.test(config.scripts.target)) {
|
|
34
34
|
config.env.inDesktopApp = true;
|
|
35
|
-
}
|
|
35
|
+
} // Set use cache for webpack
|
|
36
|
+
|
|
36
37
|
|
|
38
|
+
config.scripts.useCache = config.env.isProd && config.assets.cache && config.scripts.injectHtml;
|
|
37
39
|
return config;
|
|
38
40
|
}
|
|
39
41
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
2
2
|
import getLoaders from '../loaders.js';
|
|
3
|
-
import {
|
|
3
|
+
import { HASH_NAME_PROD } 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
|
|
@@ -14,8 +14,16 @@ function getDefaultPlugins(webpack, scripts) {
|
|
|
14
14
|
})];
|
|
15
15
|
|
|
16
16
|
if (scripts.injectHtml) {
|
|
17
|
-
const isSPA = BalmJS.entries.length
|
|
17
|
+
const isSPA = BalmJS.entries.length < 2;
|
|
18
18
|
const titles = scripts.htmlPluginOptions.title || ['BalmJS App'];
|
|
19
|
+
|
|
20
|
+
if (!BalmJS.entries.length) {
|
|
21
|
+
BalmJS.entries.push({
|
|
22
|
+
key: 'main',
|
|
23
|
+
value: `./${BalmJS.file.defaultEntry}`
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
19
27
|
BalmJS.entries.forEach((entry, index) => {
|
|
20
28
|
const entryName = isSPA ? 'index' : entry.key;
|
|
21
29
|
const chunks = isSPA ? '?' : [entryName];
|
|
@@ -40,7 +48,7 @@ function getSplitChunks() {
|
|
|
40
48
|
|
|
41
49
|
if (scripts.extractAllVendors) {
|
|
42
50
|
// All vendors
|
|
43
|
-
const jsFilename = scripts.useCache ? `${scripts.vendorName}.${
|
|
51
|
+
const jsFilename = scripts.useCache ? `${scripts.vendorName}.${HASH_NAME_PROD}.js` : `${scripts.vendorName}.js`;
|
|
44
52
|
cacheGroups = {
|
|
45
53
|
defaultVendors: {
|
|
46
54
|
name: 'vendors',
|
|
@@ -57,7 +65,7 @@ function getSplitChunks() {
|
|
|
57
65
|
for (const vendor of BalmJS.vendors) {
|
|
58
66
|
const cacheGroupKey = vendor.key;
|
|
59
67
|
const cacheGroupModules = vendor.value.join('|');
|
|
60
|
-
const jsFilename = scripts.useCache ? `${cacheGroupKey}.${
|
|
68
|
+
const jsFilename = scripts.useCache ? `${cacheGroupKey}.${HASH_NAME_PROD}.js` : `${cacheGroupKey}.js`;
|
|
61
69
|
cacheGroups[cacheGroupKey] = {
|
|
62
70
|
name: cacheGroupKey,
|
|
63
71
|
chunks: 'initial',
|
|
@@ -87,14 +95,16 @@ function getSplitChunks() {
|
|
|
87
95
|
function getCommonConfig(webpack, scripts) {
|
|
88
96
|
const splitChunks = getSplitChunks();
|
|
89
97
|
const optimization = splitChunks ? BalmJS.utils.deepMerge({
|
|
90
|
-
splitChunks
|
|
98
|
+
splitChunks: splitChunks
|
|
91
99
|
}, scripts.optimization) : scripts.optimization;
|
|
92
100
|
return {
|
|
93
101
|
context: BalmJS.config.workspace,
|
|
94
102
|
mode: 'none',
|
|
103
|
+
// Stop compilation early in production
|
|
104
|
+
bail: BalmJS.config.env.isProd,
|
|
95
105
|
module: {
|
|
96
|
-
|
|
97
|
-
|
|
106
|
+
strictExportPresence: true,
|
|
107
|
+
rules: getLoaders(scripts.loaders)
|
|
98
108
|
},
|
|
99
109
|
resolve: {
|
|
100
110
|
// (was split into `root`, `modulesDirectories` and `fallback` in the old options)
|
|
@@ -110,7 +120,7 @@ function getCommonConfig(webpack, scripts) {
|
|
|
110
120
|
// These JSON files are read in directories
|
|
111
121
|
descriptionFiles: ['package.json', 'bower.json'],
|
|
112
122
|
// These fields in the description files are looked up when trying to resolve the package directory
|
|
113
|
-
mainFields: ['
|
|
123
|
+
mainFields: ['browser', 'module', 'main']
|
|
114
124
|
},
|
|
115
125
|
optimization,
|
|
116
126
|
plugins: [...getDefaultPlugins(webpack, scripts), ...scripts.plugins],
|
|
@@ -4,7 +4,9 @@ import getCommonConfig from './common.js';
|
|
|
4
4
|
function getDevConfig(webpack, scripts) {
|
|
5
5
|
return merge(getCommonConfig(webpack, scripts), {
|
|
6
6
|
mode: 'development',
|
|
7
|
-
plugins: [
|
|
7
|
+
plugins: [new webpack.DefinePlugin({
|
|
8
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
|
|
9
|
+
}), // This is necessary to emit hot updates
|
|
8
10
|
new webpack.HotModuleReplacementPlugin()],
|
|
9
11
|
devtool: scripts.sourceMap ? scripts.sourceMap : 'eval-cheap-module-source-map'
|
|
10
12
|
});
|
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
import TerserPlugin from 'terser-webpack-plugin';
|
|
2
2
|
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
3
|
-
import safePostCssParser from 'postcss-safe-parser';
|
|
4
3
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
5
4
|
import webpackBundleAnalyzer from 'webpack-bundle-analyzer';
|
|
6
5
|
import { merge } from 'webpack-merge';
|
|
7
6
|
import getCommonConfig from './common.js';
|
|
8
|
-
import { ASYNC_SCRIPTS,
|
|
7
|
+
import { ASYNC_SCRIPTS, HASH_NAME_PROD } from '../../../config/constants.js';
|
|
9
8
|
// Run the build command with an extra argument to
|
|
10
9
|
// View the bundle analyzer report after build finishes:
|
|
11
10
|
// `npm run prod --report`
|
|
12
11
|
// Set to `true` or `false` to always turn it on or off
|
|
13
12
|
const bundleAnalyzerReport = process.env.npm_config_report || false;
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
let filename;
|
|
17
|
-
|
|
18
|
-
if (isChunk) {
|
|
19
|
-
filename = BalmJS.config.env.isProd ? `[id].${HASH_NAME}` : '[id]';
|
|
20
|
-
} else {
|
|
21
|
-
filename = BalmJS.config.env.isProd ? `[name].${HASH_NAME}` : '[name]';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return `${BalmJS.config.paths.target.css}/${ASYNC_SCRIPTS}/${filename}.css`;
|
|
25
|
-
}
|
|
14
|
+
const getCssFilename = () => `${BalmJS.config.paths.target.css}/${ASYNC_SCRIPTS}/[name].${HASH_NAME_PROD}.css`;
|
|
26
15
|
|
|
27
16
|
function getProdConfig(webpack, scripts) {
|
|
28
17
|
const shouldUseSourceMap = scripts.sourceMap;
|
|
@@ -38,31 +27,14 @@ function getProdConfig(webpack, scripts) {
|
|
|
38
27
|
minimizer: [new TerserPlugin({
|
|
39
28
|
terserOptions,
|
|
40
29
|
extractComments: false
|
|
41
|
-
}), new CssMinimizerPlugin(
|
|
42
|
-
minimizerOptions: {
|
|
43
|
-
preset: ['default', {
|
|
44
|
-
minifyFontValues: {
|
|
45
|
-
removeQuotes: false
|
|
46
|
-
}
|
|
47
|
-
}],
|
|
48
|
-
processorOptions: {
|
|
49
|
-
parser: safePostCssParser,
|
|
50
|
-
map: shouldUseSourceMap ? {
|
|
51
|
-
// `inline: false` forces the sourcemap to be output into a
|
|
52
|
-
// separate file
|
|
53
|
-
inline: false,
|
|
54
|
-
// `annotation: true` appends the sourceMappingURL to the end of
|
|
55
|
-
// the css file, helping the browser find the sourcemap
|
|
56
|
-
annotation: true
|
|
57
|
-
} : false
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
})]
|
|
30
|
+
}), new CssMinimizerPlugin()]
|
|
61
31
|
},
|
|
62
|
-
plugins: [
|
|
32
|
+
plugins: [new webpack.DefinePlugin({
|
|
33
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production')
|
|
34
|
+
}), // Extract css into its own file
|
|
63
35
|
...(scripts.extractCss ? [new MiniCssExtractPlugin({
|
|
64
36
|
filename: BalmJS.file.assetsPath(getCssFilename()),
|
|
65
|
-
chunkFilename: BalmJS.file.assetsPath(getCssFilename(
|
|
37
|
+
chunkFilename: BalmJS.file.assetsPath(getCssFilename())
|
|
66
38
|
})] : []), // View the bundle analyzer report
|
|
67
39
|
...(bundleAnalyzerReport ? [new webpackBundleAnalyzer.BundleAnalyzerPlugin()] : [])],
|
|
68
40
|
devtool: shouldUseSourceMap ? 'source-map' : false
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const htmlRegex = /\.html$/;
|
|
2
2
|
const cssRegex = /\.css$/;
|
|
3
3
|
const cssModuleRegex = /\.module\.css$/;
|
|
4
|
+
const sassRegex = /\.(scss|sass)$/;
|
|
5
|
+
const sassModuleRegex = /\.module\.(scss|sass)$/;
|
|
4
6
|
const jsRegex = /\.(js|mjs|jsx|ts|tsx)$/;
|
|
5
7
|
const imgRegex = /\.(bmp|gif|jpe?g|png|svg)(\?.*)?$/;
|
|
6
8
|
const fontRegex = /\.(woff2?|eot|ttf|otf)(\?.*)?$/;
|
|
7
9
|
const mediaRegex = /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/;
|
|
8
|
-
export { htmlRegex, cssRegex, cssModuleRegex, jsRegex, imgRegex, fontRegex, mediaRegex };
|
|
10
|
+
export { htmlRegex, cssRegex, cssModuleRegex, sassRegex, sassModuleRegex, jsRegex, imgRegex, fontRegex, mediaRegex };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ASYNC_SCRIPTS,
|
|
1
|
+
import { ASYNC_SCRIPTS, HASH_NAME_PROD, MP_ASSETS } from '../../config/constants.js';
|
|
2
2
|
|
|
3
3
|
function getFilename(scripts, isChunk = false) {
|
|
4
4
|
let filename;
|
|
5
5
|
|
|
6
6
|
if (isChunk) {
|
|
7
|
-
filename = BalmJS.config.env.isProd ?
|
|
7
|
+
filename = BalmJS.config.env.isProd ? `[name].${HASH_NAME_PROD}` : '[name]';
|
|
8
8
|
} else {
|
|
9
|
-
filename = scripts.useCache ? `[name].${
|
|
9
|
+
filename = scripts.useCache ? `[name].${HASH_NAME_PROD}` : '[name]';
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
return `${filename}.js`;
|
|
@@ -18,16 +18,9 @@ function getOutput(output, scripts, isHook = false) {
|
|
|
18
18
|
const jsFolder = BalmJS.config.paths.target.js;
|
|
19
19
|
const jsFilename = getFilename(scripts);
|
|
20
20
|
const jsChunkFilename = getFilename(scripts, true);
|
|
21
|
-
const customLibraryConfig =
|
|
22
|
-
library:
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
} : {
|
|
26
|
-
library: {
|
|
27
|
-
name: scripts.library || 'MyLibrary',
|
|
28
|
-
type: scripts.libraryTarget
|
|
29
|
-
}
|
|
30
|
-
};
|
|
21
|
+
const customLibraryConfig = scripts.library ? {
|
|
22
|
+
library: scripts.library
|
|
23
|
+
} : {};
|
|
31
24
|
const miniprogramConfig = BalmJS.config.env.isMP ? {
|
|
32
25
|
path: BalmJS.file.absPath(node.path.join(BalmJS.config.dest.base, MP_ASSETS)),
|
|
33
26
|
library: {
|
|
@@ -37,10 +30,17 @@ function getOutput(output, scripts, isHook = false) {
|
|
|
37
30
|
}
|
|
38
31
|
} : {};
|
|
39
32
|
return Object.assign({
|
|
33
|
+
// The build folder.
|
|
40
34
|
path: BalmJS.file.absPath(outputPath),
|
|
35
|
+
// There will be one main bundle, and one file per asynchronous chunk.
|
|
36
|
+
// In development, it does not produce real files.
|
|
41
37
|
filename: isHook ? jsFilename : BalmJS.file.assetsPath(`${jsFolder}/${jsFilename}`),
|
|
42
|
-
|
|
43
|
-
chunkFilename: isHook ? jsChunkFilename : BalmJS.file.assetsPath(`${jsFolder}/${ASYNC_SCRIPTS}/${jsChunkFilename}`)
|
|
38
|
+
// There are also additional JS chunk files if you use code splitting.
|
|
39
|
+
chunkFilename: isHook ? jsChunkFilename : BalmJS.file.assetsPath(`${jsFolder}/${ASYNC_SCRIPTS}/${jsChunkFilename}`),
|
|
40
|
+
// webpack uses `publicPath` to determine where the app is being served from.
|
|
41
|
+
// It requires a trailing slash, or the file assets will get an incorrect path.
|
|
42
|
+
// We inferred the "public path" (such as / or /my-project) from homepage.
|
|
43
|
+
publicPath: BalmJS.file.publicUrlOrPath
|
|
44
44
|
}, customLibraryConfig, miniprogramConfig);
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
2
|
-
import { cssRegex, cssModuleRegex } from '../config/regex.js';
|
|
2
|
+
import { cssRegex, cssModuleRegex, sassRegex, sassModuleRegex } from '../config/regex.js';
|
|
3
|
+
|
|
4
|
+
// common function to get style loaders
|
|
5
|
+
const getStyleLoaders = (styleLoader, cssOptions, preProcessor = '', sassOptions = {}) => {
|
|
6
|
+
const {
|
|
7
|
+
sourceMap
|
|
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, {
|
|
15
|
+
loader: requireModule.resolve('css-loader'),
|
|
16
|
+
options: cssOptions
|
|
17
|
+
}, {
|
|
18
|
+
loader: requireModule.resolve('postcss-loader'),
|
|
19
|
+
options: Object.assign({
|
|
20
|
+
postcssOptions: {
|
|
21
|
+
plugins: BalmJS.plugins.postcssPlugins(true)
|
|
22
|
+
},
|
|
23
|
+
sourceMap
|
|
24
|
+
}, BalmJS.config.scripts.postcssLoaderOptions)
|
|
25
|
+
}].filter(Boolean);
|
|
26
|
+
|
|
27
|
+
if (preProcessor) {
|
|
28
|
+
loaders.push({
|
|
29
|
+
loader: requireModule.resolve(preProcessor),
|
|
30
|
+
options: Object.assign({
|
|
31
|
+
sourceMap: true
|
|
32
|
+
}, sassOptions)
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return loaders;
|
|
37
|
+
};
|
|
3
38
|
|
|
4
39
|
function cssLoader() {
|
|
5
40
|
let styleLoader = {
|
|
@@ -28,39 +63,44 @@ function cssLoader() {
|
|
|
28
63
|
// of CSS.
|
|
29
64
|
// By default we support CSS Modules with the extension .module.css
|
|
30
65
|
|
|
31
|
-
return {
|
|
66
|
+
return [{
|
|
32
67
|
test: cssRegex,
|
|
33
68
|
exclude: cssModuleRegex,
|
|
34
|
-
use:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
69
|
+
use: getStyleLoaders(styleLoader, {
|
|
70
|
+
importLoaders: 1,
|
|
71
|
+
sourceMap,
|
|
72
|
+
modules: {
|
|
73
|
+
mode: 'icss'
|
|
74
|
+
},
|
|
75
|
+
esModule: BalmJS.config.scripts.useEsModule
|
|
76
|
+
}),
|
|
77
|
+
// Don't consider CSS imports dead code even if the
|
|
78
|
+
// containing package claims to have no side effects.
|
|
79
|
+
// Remove this when webpack adds a warning or an error for this.
|
|
80
|
+
// See https://github.com/webpack/webpack/issues/6571
|
|
81
|
+
sideEffects: true
|
|
82
|
+
}, // Opt-in support for SASS (using .scss or .sass extensions).
|
|
83
|
+
// By default we support SASS Modules with the
|
|
84
|
+
// extensions .module.scss or .module.sass
|
|
85
|
+
{
|
|
86
|
+
test: sassRegex,
|
|
87
|
+
exclude: sassModuleRegex,
|
|
88
|
+
use: getStyleLoaders(styleLoader, {
|
|
89
|
+
importLoaders: 3,
|
|
90
|
+
sourceMap,
|
|
91
|
+
modules: {
|
|
92
|
+
mode: 'icss'
|
|
48
93
|
}
|
|
49
|
-
}, {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
plugins: BalmJS.plugins.postcssPlugins(true)
|
|
54
|
-
},
|
|
55
|
-
sourceMap
|
|
56
|
-
}, BalmJS.config.scripts.postcssLoaderOptions)
|
|
57
|
-
}],
|
|
94
|
+
}, 'sass-loader', {
|
|
95
|
+
// Prefer `dart-sass`
|
|
96
|
+
implementation: requireModule.resolve('sass')
|
|
97
|
+
}),
|
|
58
98
|
// Don't consider CSS imports dead code even if the
|
|
59
99
|
// containing package claims to have no side effects.
|
|
60
100
|
// Remove this when webpack adds a warning or an error for this.
|
|
61
101
|
// See https://github.com/webpack/webpack/issues/6571
|
|
62
102
|
sideEffects: true
|
|
63
|
-
};
|
|
103
|
+
}];
|
|
64
104
|
}
|
|
65
105
|
|
|
66
106
|
export default cssLoader;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { STATIC_ASSETS } from '../../../config/constants.js';
|
|
1
|
+
import { STATIC_ASSETS, HASH_NAME_DEV } from '../../../config/constants.js';
|
|
2
2
|
import { imgRegex, fontRegex, mediaRegex } from '../config/regex.js';
|
|
3
3
|
const imageInlineSizeLimit = parseInt(process.env.IMAGE_INLINE_SIZE_LIMIT || '10000');
|
|
4
4
|
|
|
5
5
|
function urlLoader() {
|
|
6
6
|
const PATHNAME = `${BalmJS.config.paths.target.js}/${STATIC_ASSETS}/`;
|
|
7
|
-
const FILENAME =
|
|
7
|
+
const FILENAME = `[name].${HASH_NAME_DEV}[ext]`;
|
|
8
8
|
const options = Object.assign({
|
|
9
9
|
limit: imageInlineSizeLimit,
|
|
10
10
|
// Loads files as `base64` encoded URL
|
package/lib/config/constants.js
CHANGED
|
@@ -3,7 +3,8 @@ const PUBLIC_URL = '%PUBLIC_URL%';
|
|
|
3
3
|
const ASSETS_KEYS = ['css', 'js', 'img', 'font', 'media'];
|
|
4
4
|
const ASYNC_SCRIPTS = 'async';
|
|
5
5
|
const STATIC_ASSETS = 'assets';
|
|
6
|
-
const
|
|
6
|
+
const HASH_NAME_PROD = '[contenthash:8]';
|
|
7
|
+
const HASH_NAME_DEV = '[hash:8]';
|
|
7
8
|
const HMR_PATH = '/__balm_hmr';
|
|
8
9
|
const MP_ASSETS = 'common';
|
|
9
|
-
export { DOMAIN, PUBLIC_URL, ASSETS_KEYS, ASYNC_SCRIPTS, STATIC_ASSETS,
|
|
10
|
+
export { DOMAIN, PUBLIC_URL, ASSETS_KEYS, ASYNC_SCRIPTS, STATIC_ASSETS, HASH_NAME_PROD, HASH_NAME_DEV, HMR_PATH, MP_ASSETS };
|
package/lib/config/globals.js
CHANGED
package/lib/config/scripts.js
CHANGED
|
@@ -11,7 +11,7 @@ const minifyOptions = {
|
|
|
11
11
|
ecma: 5,
|
|
12
12
|
parse: {
|
|
13
13
|
// We want terser to parse ecma 8 code. However, we don't want it
|
|
14
|
-
// to apply any
|
|
14
|
+
// to apply any minification steps that turns valid ecma 5 code
|
|
15
15
|
// into invalid ecma 5 code. This is why the 'compress' and 'output'
|
|
16
16
|
// sections only apply transformations that are ecma 5 safe
|
|
17
17
|
// https://github.com/facebook/create-react-app/pull/4234
|
|
@@ -25,7 +25,7 @@ const minifyOptions = {
|
|
|
25
25
|
comparisons: false,
|
|
26
26
|
// Disabled because of an issue with Terser breaking valid code:
|
|
27
27
|
// https://github.com/facebook/create-react-app/issues/5250
|
|
28
|
-
// Pending
|
|
28
|
+
// Pending further investigation:
|
|
29
29
|
// https://github.com/terser-js/terser/issues/120
|
|
30
30
|
inline: 2
|
|
31
31
|
},
|
|
@@ -47,8 +47,7 @@ const lint = false;
|
|
|
47
47
|
*/
|
|
48
48
|
// Output
|
|
49
49
|
|
|
50
|
-
const library = '';
|
|
51
|
-
const libraryTarget = 'var'; // Module
|
|
50
|
+
const library = ''; // Module
|
|
52
51
|
|
|
53
52
|
const loaders = [];
|
|
54
53
|
const defaultLoaders = {};
|
|
@@ -123,8 +122,7 @@ const optimization = {};
|
|
|
123
122
|
const extractAllVendors = false; // Extract all vendors (all in one)
|
|
124
123
|
|
|
125
124
|
const vendorName = 'vendor'; // AllInOne vendor filename or Vendors folder name
|
|
126
|
-
|
|
127
|
-
const useCache = false; // IE8 compatibility
|
|
125
|
+
// IE8 compatibility
|
|
128
126
|
|
|
129
127
|
const ie8 = false;
|
|
130
128
|
/**
|
|
@@ -150,7 +148,6 @@ export default {
|
|
|
150
148
|
lint,
|
|
151
149
|
// webpack
|
|
152
150
|
library,
|
|
153
|
-
libraryTarget,
|
|
154
151
|
loaders,
|
|
155
152
|
defaultLoaders,
|
|
156
153
|
includeJsResource,
|
|
@@ -174,7 +171,6 @@ export default {
|
|
|
174
171
|
optimization,
|
|
175
172
|
extractAllVendors,
|
|
176
173
|
vendorName,
|
|
177
|
-
useCache,
|
|
178
174
|
ie8,
|
|
179
175
|
// rollup
|
|
180
176
|
inputOptions,
|
package/lib/hello.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { createRequire } from 'module';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { URL } from 'node:url';
|
|
4
|
+
import { EventEmitter } from 'node:events';
|
|
4
5
|
import cacheBalmCore from './utilities/cache-core.js';
|
|
5
6
|
const requireModule = createRequire(import.meta.url);
|
|
6
7
|
const balmCorePkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
package/lib/middlewares/proxy.js
CHANGED
package/lib/plugins/plumber.js
CHANGED
package/lib/plugins/postcss.js
CHANGED
package/lib/plugins/rename.js
CHANGED
package/lib/plugins/replace.js
CHANGED
|
@@ -5,7 +5,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
5
5
|
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
6
|
|
|
7
7
|
// Reference `gulp-replace@1.1.3`
|
|
8
|
-
import { Transform } from 'stream';
|
|
8
|
+
import { Transform } from 'node:stream';
|
|
9
9
|
import { isText } from 'istextorbinary';
|
|
10
10
|
import rs from '../utilities/replacestream.js';
|
|
11
11
|
const defaultOptions = {
|
package/lib/tasks/index.js
CHANGED
|
@@ -31,7 +31,10 @@ function registerTasks(recipe) {
|
|
|
31
31
|
try {
|
|
32
32
|
recipe(new BalmHooks());
|
|
33
33
|
} catch (error) {
|
|
34
|
-
|
|
34
|
+
const {
|
|
35
|
+
message
|
|
36
|
+
} = error;
|
|
37
|
+
BalmJS.logger.error('balm hook', message);
|
|
35
38
|
} // 3. Register balm default task
|
|
36
39
|
|
|
37
40
|
|
|
@@ -1,5 +1,9 @@
|
|
|
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
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
4
|
+
|
|
5
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
6
|
+
|
|
3
7
|
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
4
8
|
|
|
5
9
|
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
@@ -29,7 +33,7 @@ class CleanTask extends BalmJS.BalmTask {
|
|
|
29
33
|
constructor() {
|
|
30
34
|
super('clean');
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
_classPrivateFieldInitSpec(this, _getAssetsDir, {
|
|
33
37
|
writable: true,
|
|
34
38
|
value: (rootKey = 'assets') => {
|
|
35
39
|
return unique(ASSETS_KEYS.map(assetKey => BalmJS.config[rootKey][assetKey]));
|
|
@@ -1,5 +1,9 @@
|
|
|
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
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
4
|
+
|
|
5
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
6
|
+
|
|
3
7
|
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
4
8
|
|
|
5
9
|
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
@@ -18,7 +22,7 @@ class ModernizrTask extends BalmJS.BalmTask {
|
|
|
18
22
|
constructor() {
|
|
19
23
|
super('modernizr');
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
_classPrivateFieldInitSpec(this, _readConfig, {
|
|
22
26
|
writable: true,
|
|
23
27
|
value: () => {
|
|
24
28
|
return new Promise((resolve, reject) => {
|
|
@@ -30,7 +34,7 @@ class ModernizrTask extends BalmJS.BalmTask {
|
|
|
30
34
|
}
|
|
31
35
|
});
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
_classPrivateFieldInitSpec(this, _createDir, {
|
|
34
38
|
writable: true,
|
|
35
39
|
value: () => {
|
|
36
40
|
return new Promise((resolve, reject) => {
|
|
@@ -44,7 +48,7 @@ class ModernizrTask extends BalmJS.BalmTask {
|
|
|
44
48
|
}
|
|
45
49
|
});
|
|
46
50
|
|
|
47
|
-
|
|
51
|
+
_classPrivateFieldInitSpec(this, _generateScript, {
|
|
48
52
|
writable: true,
|
|
49
53
|
value: config => {
|
|
50
54
|
return new Promise((resolve, reject) => {
|