@henderea/static-site-builder 1.9.10 → 1.10.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/bin/static-site-builder.js +10 -3
- package/config/env.js +6 -4
- package/config/paths.js +27 -28
- package/config/webpack.config.dev.js +7 -4
- package/config/webpack.config.prod.js +9 -5
- package/package.json +1 -1
- package/scripts/build.js +7 -7
- package/scripts/watch.js +7 -7
- package/utils/FileSizeReporter.js +3 -3
- package/utils/workspaceUtils.js +5 -2
|
@@ -15,8 +15,13 @@ process.on('unhandledRejection', (err) => {
|
|
|
15
15
|
throw err;
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
import
|
|
18
|
+
import { spawnSync } from 'child_process';
|
|
19
19
|
const args = process.argv.slice(2);
|
|
20
|
+
import _ from 'lodash';
|
|
21
|
+
|
|
22
|
+
import { createRequire } from 'module';
|
|
23
|
+
|
|
24
|
+
const require = createRequire(import.meta.url);
|
|
20
25
|
|
|
21
26
|
const scriptIndex = args.findIndex(
|
|
22
27
|
(x) => x === 'build' || x === 'watch'
|
|
@@ -27,12 +32,13 @@ const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
|
|
|
27
32
|
switch(script) {
|
|
28
33
|
case 'build':
|
|
29
34
|
case 'watch': {
|
|
30
|
-
const
|
|
35
|
+
const nodeEnv = script == 'build' ? 'production' : 'development';
|
|
36
|
+
const result = spawnSync(
|
|
31
37
|
'node',
|
|
32
38
|
nodeArgs
|
|
33
39
|
.concat(require.resolve('../scripts/' + script))
|
|
34
40
|
.concat(args.slice(scriptIndex + 1)),
|
|
35
|
-
{ stdio: 'inherit' }
|
|
41
|
+
{ stdio: 'inherit', env: _.extend({}, process.env, { NODE_ENV: nodeEnv, BABEL_ENV: nodeEnv }) }
|
|
36
42
|
);
|
|
37
43
|
if(result.signal) {
|
|
38
44
|
if(result.signal === 'SIGKILL') {
|
|
@@ -52,6 +58,7 @@ case 'watch': {
|
|
|
52
58
|
}
|
|
53
59
|
process.exit(result.status);
|
|
54
60
|
}
|
|
61
|
+
// eslint-disable-next-line no-fallthrough
|
|
55
62
|
default:
|
|
56
63
|
console.log('Unknown script "' + script + '".');
|
|
57
64
|
console.log('Perhaps you need to update static-site-builder?');
|
package/config/env.js
CHANGED
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import fs from 'fs';
|
|
8
8
|
import path from 'path';
|
|
9
|
-
import paths from './paths';
|
|
9
|
+
import * as paths from './paths.js';
|
|
10
|
+
import dotenvExpand from 'dotenv-expand';
|
|
11
|
+
import dotenv from 'dotenv';
|
|
10
12
|
|
|
11
13
|
// Make sure that including paths.js after env.js will read .env variables.
|
|
12
|
-
delete require.cache[require.resolve('./paths')];
|
|
14
|
+
// delete require.cache[require.resolve('./paths')];
|
|
13
15
|
|
|
14
16
|
const NODE_ENV = process.env.NODE_ENV;
|
|
15
17
|
if(!NODE_ENV) {
|
|
@@ -36,8 +38,8 @@ var dotenvFiles = [
|
|
|
36
38
|
// https://github.com/motdotla/dotenv-expand
|
|
37
39
|
dotenvFiles.forEach((dotenvFile) => {
|
|
38
40
|
if(fs.existsSync(dotenvFile)) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
dotenvExpand(
|
|
42
|
+
dotenv.config({
|
|
41
43
|
path: dotenvFile,
|
|
42
44
|
})
|
|
43
45
|
);
|
package/config/paths.js
CHANGED
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
import path from 'path';
|
|
10
10
|
import fs from 'fs';
|
|
11
11
|
import url from 'url';
|
|
12
|
-
import { findMonorepo } from '../utils/workspaceUtils';
|
|
12
|
+
import { findMonorepo } from '../utils/workspaceUtils.js';
|
|
13
|
+
import { fileURLToPath } from 'url';
|
|
14
|
+
|
|
15
|
+
const dirname = fileURLToPath(import.meta.url);
|
|
13
16
|
|
|
14
17
|
// Make sure any symlinks in the project folder are resolved:
|
|
15
18
|
// https://github.com/facebookincubator/create-react-app/issues/637
|
|
@@ -34,7 +37,7 @@ function ensureSlash(path, needsSlash) {
|
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
const getPublicUrl = (appPackageJson) =>
|
|
37
|
-
envPublicUrl ||
|
|
40
|
+
envPublicUrl || JSON.parse(fs.readFileSync(appPackageJson)).homepage;
|
|
38
41
|
|
|
39
42
|
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
|
|
40
43
|
// "public path" at which the app is served.
|
|
@@ -49,37 +52,29 @@ function getServedPath(appPackageJson) {
|
|
|
49
52
|
return ensureSlash(servedUrl, true);
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
const resolveOwn = (relativePath) => path.resolve(
|
|
55
|
+
const resolveOwn = (relativePath) => path.resolve(dirname, '..', relativePath);
|
|
53
56
|
|
|
54
57
|
export const dotenv = resolveApp('.env');
|
|
55
58
|
export const ssbConfig = resolveApp('static-site-builder.config.js');
|
|
56
59
|
export const publicDir = resolveApp('public');
|
|
57
|
-
export const tsConfig= resolveApp('tsconfig.json');
|
|
58
|
-
export const appPath= resolveApp('.');
|
|
59
|
-
export const appBuild= resolveApp('build');
|
|
60
|
-
export const appDist= resolveApp('dist');
|
|
61
|
-
export const appTemplate= resolveAppFirst('src/index.html', 'src/index.ejs', 'src/index.hbs');
|
|
62
|
-
export const appIndex= resolveAppFirst('src/index.js', 'src/index.ts');
|
|
63
|
-
export const appPackageJson= resolveApp('package.json');
|
|
64
|
-
export const appSrc= resolveApp('src');
|
|
65
|
-
export const testsSetup= resolveApp('src/setupTests.js');
|
|
66
|
-
export const appNodeModules= resolveApp('node_modules');
|
|
67
|
-
export const publicUrl= getPublicUrl(resolveApp('package.json'));
|
|
68
|
-
export const servedPath= getServedPath(resolveApp('package.json'));
|
|
69
|
-
export const ownPath= resolveOwn('.');
|
|
70
|
-
export const ownNodeModules= resolveOwn('node_modules');
|
|
71
|
-
|
|
72
|
-
resolveApp,
|
|
73
|
-
resolveAppFirst,
|
|
74
|
-
resolveOwn,
|
|
75
|
-
ensureSlash
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const srcPaths = [module.exports.appSrc];
|
|
60
|
+
export const tsConfig = resolveApp('tsconfig.json');
|
|
61
|
+
export const appPath = resolveApp('.');
|
|
62
|
+
export const appBuild = resolveApp('build');
|
|
63
|
+
export const appDist = resolveApp('dist');
|
|
64
|
+
export const appTemplate = resolveAppFirst('src/index.html', 'src/index.ejs', 'src/index.hbs');
|
|
65
|
+
export const appIndex = resolveAppFirst('src/index.js', 'src/index.ts');
|
|
66
|
+
export const appPackageJson = resolveApp('package.json');
|
|
67
|
+
export const appSrc = resolveApp('src');
|
|
68
|
+
export const testsSetup = resolveApp('src/setupTests.js');
|
|
69
|
+
export const appNodeModules = resolveApp('node_modules');
|
|
70
|
+
export const publicUrl = getPublicUrl(resolveApp('package.json'));
|
|
71
|
+
export const servedPath = getServedPath(resolveApp('package.json'));
|
|
72
|
+
export const ownPath = resolveOwn('.');
|
|
73
|
+
export const ownNodeModules = resolveOwn('node_modules');
|
|
74
|
+
const srcPaths = [appSrc];
|
|
80
75
|
|
|
81
76
|
let useYarn = fs.existsSync(
|
|
82
|
-
path.join(
|
|
77
|
+
path.join(appPath, 'yarn.lock')
|
|
83
78
|
);
|
|
84
79
|
|
|
85
80
|
let checkForMonorepo = true;
|
|
@@ -91,10 +86,14 @@ if(checkForMonorepo) {
|
|
|
91
86
|
if(mono.isAppIncluded) {
|
|
92
87
|
Array.prototype.push.apply(srcPaths, mono.pkgs);
|
|
93
88
|
}
|
|
94
|
-
useYarn =
|
|
89
|
+
useYarn = useYarn || mono.isYarnWs;
|
|
95
90
|
}
|
|
96
91
|
|
|
97
92
|
export {
|
|
93
|
+
resolveApp,
|
|
94
|
+
resolveAppFirst,
|
|
95
|
+
resolveOwn,
|
|
96
|
+
ensureSlash,
|
|
98
97
|
srcPaths,
|
|
99
98
|
useYarn
|
|
100
99
|
};
|
|
@@ -6,9 +6,12 @@ import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
|
|
|
6
6
|
import { WebpackManifestPlugin } from 'webpack-manifest-plugin';
|
|
7
7
|
import CopyPlugin from 'copy-webpack-plugin';
|
|
8
8
|
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
|
|
9
|
-
import getClientEnvironment from './env';
|
|
10
|
-
import * as paths from './paths';
|
|
9
|
+
import getClientEnvironment from './env.js';
|
|
10
|
+
import * as paths from './paths.js';
|
|
11
11
|
import _ from 'lodash';
|
|
12
|
+
import { createRequire } from 'module';
|
|
13
|
+
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
12
15
|
|
|
13
16
|
// Webpack uses `publicPath` to determine where the app is being served from.
|
|
14
17
|
// It requires a trailing slash, or the file assets will get an incorrect path.
|
|
@@ -123,7 +126,7 @@ if(ssbConfig.extraLoaders && _.isArray(ssbConfig.extraLoaders)) {
|
|
|
123
126
|
extraLoaders.push(...ssbConfig.extraLoaders);
|
|
124
127
|
}
|
|
125
128
|
|
|
126
|
-
|
|
129
|
+
export default _.defaultsDeep({}, ssbConfig.webpack || {}, {
|
|
127
130
|
mode: 'development',
|
|
128
131
|
entry: {
|
|
129
132
|
index: appIndex
|
|
@@ -222,7 +225,7 @@ module.exports = _.defaultsDeep({}, ssbConfig.webpack || {}, {
|
|
|
222
225
|
// its runtime that would otherwise processed through "file" loader.
|
|
223
226
|
// Also exclude `html` and `json` extensions so they get processed
|
|
224
227
|
// by webpack's internal loaders.
|
|
225
|
-
exclude: [/\.js$/, /\.ts$/, /\.html$/, /\.ejs$/, /\.hbs$/, /\.json$/],
|
|
228
|
+
exclude: [/\.js$/, /\.ts$/, /\.svg$/, /\.html$/, /\.ejs$/, /\.hbs$/, /\.json$/],
|
|
226
229
|
options: {
|
|
227
230
|
name: '[name].[ext]'
|
|
228
231
|
}
|
|
@@ -9,11 +9,14 @@ import CopyPlugin from 'copy-webpack-plugin';
|
|
|
9
9
|
import { GenerateSW } from 'workbox-webpack-plugin';
|
|
10
10
|
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
|
|
11
11
|
import MomentLocalesPlugin from 'moment-locales-webpack-plugin';
|
|
12
|
-
import getClientEnvironment from './env';
|
|
13
|
-
import * as paths from './paths';
|
|
12
|
+
import getClientEnvironment from './env.js';
|
|
13
|
+
import * as paths from './paths.js';
|
|
14
14
|
import _ from 'lodash';
|
|
15
15
|
import crypto from 'crypto';
|
|
16
16
|
import { globbySync } from 'globby';
|
|
17
|
+
import { createRequire } from 'module';
|
|
18
|
+
|
|
19
|
+
const require = createRequire(import.meta.url);
|
|
17
20
|
|
|
18
21
|
// Webpack uses `publicPath` to determine where the app is being served from.
|
|
19
22
|
// It requires a trailing slash, or the file assets will get an incorrect path.
|
|
@@ -74,7 +77,8 @@ if(ssbConfig.additionalManifestEntries && _.isArray(ssbConfig.additionalManifest
|
|
|
74
77
|
additionalManifestEntries.push(...ssbConfig.additionalManifestEntries);
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
import runtimeCachingTmp from './cache-config.js';
|
|
81
|
+
let runtimeCaching = runtimeCachingTmp;
|
|
78
82
|
|
|
79
83
|
if(ssbConfig.runtimeCaching && _.isArray(ssbConfig.runtimeCaching)) {
|
|
80
84
|
runtimeCaching = ssbConfig.runtimeCaching;
|
|
@@ -230,7 +234,7 @@ if(ssbConfig.extraLoaders && _.isArray(ssbConfig.extraLoaders)) {
|
|
|
230
234
|
extraLoaders.push(...ssbConfig.extraLoaders);
|
|
231
235
|
}
|
|
232
236
|
|
|
233
|
-
|
|
237
|
+
export default _.defaultsDeep({}, ssbConfig.webpack || {}, {
|
|
234
238
|
mode: 'production',
|
|
235
239
|
entry: {
|
|
236
240
|
index: appIndex
|
|
@@ -354,7 +358,7 @@ module.exports = _.defaultsDeep({}, ssbConfig.webpack || {}, {
|
|
|
354
358
|
// its runtime that would otherwise processed through "file" loader.
|
|
355
359
|
// Also exclude `html` and `json` extensions so they get processed
|
|
356
360
|
// by webpack's internal loaders.
|
|
357
|
-
exclude: [/\.js$/, /\.ts$/, /\.html$/, /\.ejs$/, /\.hbs$/, /\.json$/],
|
|
361
|
+
exclude: [/\.js$/, /\.ts$/, /\.svg$/, /\.html$/, /\.ejs$/, /\.hbs$/, /\.json$/],
|
|
358
362
|
options: {
|
|
359
363
|
name: '[name].[ext]'
|
|
360
364
|
}
|
package/package.json
CHANGED
package/scripts/build.js
CHANGED
|
@@ -11,18 +11,18 @@ process.on('unhandledRejection', (err) => {
|
|
|
11
11
|
throw err;
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
import '../config/env.js';
|
|
15
15
|
|
|
16
16
|
// import path from 'path';
|
|
17
17
|
import chalk from 'chalk';
|
|
18
18
|
import fs from 'fs-extra';
|
|
19
19
|
import webpack from 'webpack';
|
|
20
|
-
import config from '../config/webpack.config.prod';
|
|
21
|
-
import * as paths from '../config/paths';
|
|
22
|
-
import checkRequiredFiles from '../utils/checkRequiredFiles';
|
|
23
|
-
import formatWebpackMessages from '../utils/formatWebpackMessages';
|
|
24
|
-
import FileSizeReporter from '../utils/FileSizeReporter';
|
|
25
|
-
import printBuildError from '../utils/printBuildError';
|
|
20
|
+
import config from '../config/webpack.config.prod.js';
|
|
21
|
+
import * as paths from '../config/paths.js';
|
|
22
|
+
import checkRequiredFiles from '../utils/checkRequiredFiles.js';
|
|
23
|
+
import formatWebpackMessages from '../utils/formatWebpackMessages.js';
|
|
24
|
+
import * as FileSizeReporter from '../utils/FileSizeReporter.js';
|
|
25
|
+
import printBuildError from '../utils/printBuildError.js';
|
|
26
26
|
|
|
27
27
|
const measureFileSizesBeforeBuild =
|
|
28
28
|
FileSizeReporter.measureFileSizesBeforeBuild;
|
package/scripts/watch.js
CHANGED
|
@@ -11,18 +11,18 @@ process.on('unhandledRejection', (err) => {
|
|
|
11
11
|
throw err;
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
import '../config/env.js';
|
|
15
15
|
|
|
16
16
|
// import path from 'path';
|
|
17
17
|
import chalk from 'chalk';
|
|
18
18
|
import fs from 'fs-extra';
|
|
19
19
|
import webpack from 'webpack';
|
|
20
|
-
import config from '../config/webpack.config.dev';
|
|
21
|
-
import * as paths from '../config/paths';
|
|
22
|
-
import checkRequiredFiles from '../utils/checkRequiredFiles';
|
|
23
|
-
import formatWebpackMessages from '../utils/formatWebpackMessages';
|
|
24
|
-
import FileSizeReporter from '../utils/FileSizeReporter';
|
|
25
|
-
import printBuildError from '../utils/printBuildError';
|
|
20
|
+
import config from '../config/webpack.config.dev.js';
|
|
21
|
+
import * as paths from '../config/paths.js';
|
|
22
|
+
import checkRequiredFiles from '../utils/checkRequiredFiles.js';
|
|
23
|
+
import formatWebpackMessages from '../utils/formatWebpackMessages.js';
|
|
24
|
+
import * as FileSizeReporter from '../utils/FileSizeReporter.js';
|
|
25
|
+
import printBuildError from '../utils/printBuildError.js';
|
|
26
26
|
|
|
27
27
|
const measureFileSizesBeforeBuild =
|
|
28
28
|
FileSizeReporter.measureFileSizesBeforeBuild;
|
|
@@ -13,7 +13,7 @@ import chalk from 'chalk';
|
|
|
13
13
|
import filesize from 'filesize';
|
|
14
14
|
import recursive from 'recursive-readdir';
|
|
15
15
|
import stripAnsi from 'strip-ansi';
|
|
16
|
-
import {
|
|
16
|
+
import { gzipSizeSync } from 'gzip-size';
|
|
17
17
|
|
|
18
18
|
// Prints a detailed summary of build files.
|
|
19
19
|
function printFileSizesAfterBuild(
|
|
@@ -32,7 +32,7 @@ function printFileSizesAfterBuild(
|
|
|
32
32
|
.assets.filter((asset) => /\.(js|css)$/.test(asset.name))
|
|
33
33
|
.map((asset) => {
|
|
34
34
|
var fileContents = fs.readFileSync(path.join(root, asset.name));
|
|
35
|
-
var size =
|
|
35
|
+
var size = gzipSizeSync(fileContents);
|
|
36
36
|
var previousSize = sizes[removeFileNameHash(root, asset.name)];
|
|
37
37
|
var difference = getDifferenceLabel(size, previousSize);
|
|
38
38
|
return {
|
|
@@ -132,7 +132,7 @@ function measureFileSizesBeforeBuild(buildFolder) {
|
|
|
132
132
|
.reduce((memo, fileName) => {
|
|
133
133
|
var contents = fs.readFileSync(fileName);
|
|
134
134
|
var key = removeFileNameHash(buildFolder, fileName);
|
|
135
|
-
memo[key] =
|
|
135
|
+
memo[key] = gzipSizeSync(contents);
|
|
136
136
|
return memo;
|
|
137
137
|
}, {});
|
|
138
138
|
}
|
package/utils/workspaceUtils.js
CHANGED
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
import fs from 'fs';
|
|
9
9
|
import path from 'path';
|
|
10
10
|
import findPkg from 'find-pkg';
|
|
11
|
-
import
|
|
11
|
+
import { globbySync } from 'globby';
|
|
12
|
+
import { createRequire } from 'module';
|
|
13
|
+
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
12
15
|
|
|
13
16
|
const findPkgs = (rootPath, globPatterns) => {
|
|
14
17
|
if(!globPatterns) {
|
|
@@ -22,7 +25,7 @@ const findPkgs = (rootPath, globPatterns) => {
|
|
|
22
25
|
return globPatterns
|
|
23
26
|
.reduce(
|
|
24
27
|
(pkgs, pattern) =>
|
|
25
|
-
pkgs.concat(
|
|
28
|
+
pkgs.concat(globbySync(path.join(pattern, 'package.json'), globOpts)),
|
|
26
29
|
[]
|
|
27
30
|
)
|
|
28
31
|
.map((f) => path.dirname(path.normalize(f)));
|