@henderea/static-site-builder 1.9.6 → 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 +37 -31
- package/config/cache-config.js +99 -99
- package/config/env.js +15 -14
- package/config/paths.js +58 -54
- package/config/webpack.config.dev.js +172 -169
- package/config/webpack.config.prod.js +259 -255
- package/package.json +43 -30
- package/scripts/build.js +90 -90
- package/scripts/watch.js +83 -83
- package/utils/FileSizeReporter.js +27 -27
- package/utils/checkRequiredFiles.js +5 -7
- package/utils/formatWebpackMessages.js +13 -15
- package/utils/printBuildError.js +5 -5
- package/utils/workspaceUtils.js +16 -14
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import webpack from 'webpack';
|
|
4
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
5
|
+
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
|
|
6
|
+
import { WebpackManifestPlugin } from 'webpack-manifest-plugin';
|
|
7
|
+
import CopyPlugin from 'copy-webpack-plugin';
|
|
8
|
+
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
|
|
9
|
+
import getClientEnvironment from './env.js';
|
|
10
|
+
import * as paths from './paths.js';
|
|
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.
|
|
15
18
|
const publicPath = paths.servedPath;
|
|
16
19
|
// Some apps do not use client-side routing with pushState.
|
|
17
20
|
// For these, "homepage" can be set to "." to enable relative asset paths.
|
|
18
|
-
const shouldUseRelativeAssetPaths = publicPath === './';
|
|
21
|
+
// const shouldUseRelativeAssetPaths = publicPath === './';
|
|
19
22
|
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
|
20
23
|
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
|
21
24
|
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
|
@@ -26,213 +29,213 @@ let env = getClientEnvironment(publicUrl);
|
|
|
26
29
|
let ssbConfig = {};
|
|
27
30
|
|
|
28
31
|
if(fs.existsSync(paths.ssbConfig)) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
32
|
+
let ssbConfigObj = require(paths.ssbConfig);
|
|
33
|
+
if(ssbConfigObj) {
|
|
34
|
+
if(_.isFunction(ssbConfigObj)) {
|
|
35
|
+
ssbConfig = ssbConfigObj(env.raw, 'development', { publicUrl, ...paths });
|
|
36
|
+
} else if(_.isPlainObject(ssbConfigObj)) {
|
|
37
|
+
if(_.has(ssbConfigObj, 'dev')) {
|
|
38
|
+
ssbConfig = _.get(ssbConfigObj, 'dev');
|
|
39
|
+
} else if(_.has(ssbConfigObj, 'development')) {
|
|
40
|
+
ssbConfig = _.get(ssbConfigObj, 'development');
|
|
41
|
+
} else {
|
|
42
|
+
ssbConfig = ssbConfigObj;
|
|
43
|
+
}
|
|
42
44
|
}
|
|
45
|
+
}
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
ssbConfig = ssbConfig || {};
|
|
46
49
|
|
|
47
50
|
if(ssbConfig.env && _.isPlainObject(ssbConfig.env)) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
const raw = _.extend({}, env.raw, ssbConfig.env);
|
|
52
|
+
const stringified = {
|
|
53
|
+
'process.env': Object.keys(raw).reduce((env, key) => {
|
|
54
|
+
env[key] = JSON.stringify(raw[key]);
|
|
55
|
+
return env;
|
|
56
|
+
}, {}),
|
|
57
|
+
};
|
|
58
|
+
env = { raw, stringified };
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
let htmlWebpackPluginOptions = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
filename: 'index.html',
|
|
63
|
+
template: paths.appTemplate,
|
|
64
|
+
inject: 'head',
|
|
65
|
+
minify: { collapseWhitespace: true }
|
|
63
66
|
};
|
|
64
67
|
|
|
65
68
|
if(ssbConfig.htmlWebpackPluginOptions && _.isPlainObject(ssbConfig.htmlWebpackPluginOptions)) {
|
|
66
|
-
|
|
69
|
+
htmlWebpackPluginOptions = _.extend({}, htmlWebpackPluginOptions, ssbConfig.htmlWebpackPluginOptions);
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
const plugins = [
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
new webpack.DefinePlugin(env.stringified),
|
|
74
|
+
new HtmlWebpackPlugin(htmlWebpackPluginOptions),
|
|
75
|
+
new CaseSensitivePathsPlugin(),
|
|
76
|
+
new WebpackManifestPlugin({
|
|
77
|
+
fileName: 'asset-manifest.json',
|
|
78
|
+
publicPath: publicPath
|
|
79
|
+
}),
|
|
77
80
|
];
|
|
78
81
|
|
|
79
82
|
if(ssbConfig.plugins && _.isArray(ssbConfig.plugins)) {
|
|
80
|
-
|
|
83
|
+
plugins.push(...ssbConfig.plugins);
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
const copyPatterns = [];
|
|
84
87
|
|
|
85
88
|
if(fs.existsSync(paths.publicDir)) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
copyPatterns.push({
|
|
90
|
+
from: paths.publicDir,
|
|
91
|
+
to: paths.appBuild
|
|
92
|
+
});
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
if(ssbConfig.copyPatterns && _.isArray(ssbConfig.copyPatterns)) {
|
|
93
|
-
|
|
96
|
+
copyPatterns.push(...ssbConfig.copyPatterns);
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
if(copyPatterns.length > 0) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
plugins.push(new CopyPlugin({
|
|
101
|
+
patterns: copyPatterns
|
|
102
|
+
}));
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
let tsConfigPath = paths.tsConfig;
|
|
103
106
|
|
|
104
107
|
if(ssbConfig.tsConfigPath && fs.existsSync(paths.resolveApp(ssbConfig.tsConfigPath))) {
|
|
105
|
-
|
|
108
|
+
tsConfigPath = paths.resolveApp(ssbConfig.tsConfigPath);
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
const resolvePlugins = [];
|
|
109
112
|
|
|
110
113
|
if(fs.existsSync(tsConfigPath)) {
|
|
111
|
-
|
|
114
|
+
resolvePlugins.push(new TsconfigPathsPlugin({ configFile: tsConfigPath }));
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
let appIndex = paths.appIndex;
|
|
115
118
|
|
|
116
119
|
if(ssbConfig.appIndex && fs.existsSync(paths.resolveApp(appIndex))) {
|
|
117
|
-
|
|
120
|
+
appIndex = paths.resolveApp(appIndex);
|
|
118
121
|
}
|
|
119
122
|
|
|
120
123
|
const extraLoaders = [];
|
|
121
124
|
|
|
122
125
|
if(ssbConfig.extraLoaders && _.isArray(ssbConfig.extraLoaders)) {
|
|
123
|
-
|
|
126
|
+
extraLoaders.push(...ssbConfig.extraLoaders);
|
|
124
127
|
}
|
|
125
128
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
]
|
|
129
|
+
export default _.defaultsDeep({}, ssbConfig.webpack || {}, {
|
|
130
|
+
mode: 'development',
|
|
131
|
+
entry: {
|
|
132
|
+
index: appIndex
|
|
133
|
+
},
|
|
134
|
+
devtool: 'source-map',
|
|
135
|
+
output: {
|
|
136
|
+
pathinfo: true,
|
|
137
|
+
path: paths.appBuild,
|
|
138
|
+
publicPath: publicPath
|
|
139
|
+
},
|
|
140
|
+
resolve: {
|
|
141
|
+
modules: ['node_modules'].concat(
|
|
142
|
+
// It is guaranteed to exist because we tweak it in `env.js`
|
|
143
|
+
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
|
144
|
+
),
|
|
145
|
+
extensions: ['.js', '.ts', '.json'],
|
|
146
|
+
plugins: resolvePlugins,
|
|
147
|
+
roots: [paths.appPath, paths.publicDir],
|
|
148
|
+
},
|
|
149
|
+
module: {
|
|
150
|
+
strictExportPresence: true,
|
|
151
|
+
rules: [
|
|
152
|
+
{
|
|
153
|
+
test: /\.[tj]s$/,
|
|
154
|
+
parser: { requireEnsure: false }
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
oneOf: [
|
|
158
|
+
...extraLoaders,
|
|
159
|
+
{
|
|
160
|
+
test: /\.ts$/,
|
|
161
|
+
exclude: [/[/\\\\]node_modules[/\\\\]/],
|
|
162
|
+
use: [
|
|
163
|
+
{
|
|
164
|
+
loader: require.resolve('ts-loader'),
|
|
165
|
+
options: {
|
|
166
|
+
configFile: tsConfigPath
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
]
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
test: /\.js$/,
|
|
173
|
+
exclude: [/[/\\\\]node_modules[/\\\\]/],
|
|
174
|
+
use: [
|
|
175
|
+
require.resolve('thread-loader'),
|
|
176
|
+
{
|
|
177
|
+
loader: require.resolve('babel-loader'),
|
|
178
|
+
options: {
|
|
179
|
+
babelrc: false,
|
|
180
|
+
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
|
181
|
+
// It enables caching results in ./node_modules/.cache/babel-loader/
|
|
182
|
+
// directory for faster rebuilds.
|
|
183
|
+
cacheDirectory: true,
|
|
184
|
+
highlightCode: true,
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
]
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
test: /\.js$/,
|
|
191
|
+
use: [
|
|
192
|
+
require.resolve('thread-loader'),
|
|
193
|
+
{
|
|
194
|
+
loader: require.resolve('babel-loader'),
|
|
195
|
+
options: {
|
|
196
|
+
babelrc: false,
|
|
197
|
+
compact: false,
|
|
198
|
+
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
|
199
|
+
// It enables caching results in ./node_modules/.cache/babel-loader/
|
|
200
|
+
// directory for faster rebuilds.
|
|
201
|
+
cacheDirectory: true,
|
|
202
|
+
highlightCode: true,
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
]
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
test: /\.css$/,
|
|
209
|
+
use: [
|
|
210
|
+
'style-loader',
|
|
211
|
+
'css-loader'
|
|
212
|
+
]
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
test: /\.scss$/,
|
|
216
|
+
use: [
|
|
217
|
+
'style-loader',
|
|
218
|
+
'css-loader',
|
|
219
|
+
'sass-loader'
|
|
220
|
+
]
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
loader: require.resolve('file-loader'),
|
|
224
|
+
// Exclude `js` files to keep "css" loader working as it injects
|
|
225
|
+
// its runtime that would otherwise processed through "file" loader.
|
|
226
|
+
// Also exclude `html` and `json` extensions so they get processed
|
|
227
|
+
// by webpack's internal loaders.
|
|
228
|
+
exclude: [/\.js$/, /\.ts$/, /\.svg$/, /\.html$/, /\.ejs$/, /\.hbs$/, /\.json$/],
|
|
229
|
+
options: {
|
|
230
|
+
name: '[name].[ext]'
|
|
231
231
|
}
|
|
232
|
+
}
|
|
232
233
|
]
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
234
|
+
}
|
|
235
|
+
]
|
|
236
|
+
},
|
|
237
|
+
plugins,
|
|
238
|
+
performance: {
|
|
239
|
+
hints: false,
|
|
240
|
+
},
|
|
241
|
+
});
|