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