@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.
@@ -1,21 +1,24 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
- const webpack = require('webpack');
4
- const HtmlWebpackPlugin = require('html-webpack-plugin');
5
- const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
6
- const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
7
- const CopyPlugin = require('copy-webpack-plugin');
8
- const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
9
- const getClientEnvironment = require('./env');
10
- const paths = require('./paths');
11
- const _ = require('lodash');
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
- 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
- }
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
- 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 };
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
- filename: 'index.html',
60
- template: paths.appTemplate,
61
- inject: 'head',
62
- minify: { collapseWhitespace: true }
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
- htmlWebpackPluginOptions = _.extend({}, htmlWebpackPluginOptions, ssbConfig.htmlWebpackPluginOptions);
69
+ htmlWebpackPluginOptions = _.extend({}, htmlWebpackPluginOptions, ssbConfig.htmlWebpackPluginOptions);
67
70
  }
68
71
 
69
72
  const plugins = [
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
- }),
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
- plugins.push(...ssbConfig.plugins);
83
+ plugins.push(...ssbConfig.plugins);
81
84
  }
82
85
 
83
86
  const copyPatterns = [];
84
87
 
85
88
  if(fs.existsSync(paths.publicDir)) {
86
- copyPatterns.push({
87
- from: paths.publicDir,
88
- to: paths.appBuild
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
- copyPatterns.push(...ssbConfig.copyPatterns);
96
+ copyPatterns.push(...ssbConfig.copyPatterns);
94
97
  }
95
98
 
96
99
  if(copyPatterns.length > 0) {
97
- plugins.push(new CopyPlugin({
98
- patterns: copyPatterns
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
- tsConfigPath = paths.resolveApp(ssbConfig.tsConfigPath);
108
+ tsConfigPath = paths.resolveApp(ssbConfig.tsConfigPath);
106
109
  }
107
110
 
108
111
  const resolvePlugins = [];
109
112
 
110
113
  if(fs.existsSync(tsConfigPath)) {
111
- resolvePlugins.push(new TsconfigPathsPlugin({ configFile: tsConfigPath }));
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
- appIndex = paths.resolveApp(appIndex);
120
+ appIndex = paths.resolveApp(appIndex);
118
121
  }
119
122
 
120
123
  const extraLoaders = [];
121
124
 
122
125
  if(ssbConfig.extraLoaders && _.isArray(ssbConfig.extraLoaders)) {
123
- extraLoaders.push(...ssbConfig.extraLoaders);
126
+ extraLoaders.push(...ssbConfig.extraLoaders);
124
127
  }
125
128
 
126
- module.exports = _.defaultsDeep({}, ssbConfig.webpack || {}, {
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]'
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
- plugins,
235
- performance: {
236
- hints: false,
237
- },
238
- });
234
+ }
235
+ ]
236
+ },
237
+ plugins,
238
+ performance: {
239
+ hints: false,
240
+ },
241
+ });