@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.
@@ -1,21 +1,21 @@
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';
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
- 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
- }
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
- 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 };
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
- filename: 'index.html',
60
- template: paths.appTemplate,
61
- inject: 'head',
62
- minify: { collapseWhitespace: true }
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
- htmlWebpackPluginOptions = _.extend({}, htmlWebpackPluginOptions, ssbConfig.htmlWebpackPluginOptions);
66
+ htmlWebpackPluginOptions = _.extend({}, htmlWebpackPluginOptions, ssbConfig.htmlWebpackPluginOptions);
67
67
  }
68
68
 
69
69
  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
- }),
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
- plugins.push(...ssbConfig.plugins);
80
+ plugins.push(...ssbConfig.plugins);
81
81
  }
82
82
 
83
83
  const copyPatterns = [];
84
84
 
85
85
  if(fs.existsSync(paths.publicDir)) {
86
- copyPatterns.push({
87
- from: paths.publicDir,
88
- to: paths.appBuild
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
- copyPatterns.push(...ssbConfig.copyPatterns);
93
+ copyPatterns.push(...ssbConfig.copyPatterns);
94
94
  }
95
95
 
96
96
  if(copyPatterns.length > 0) {
97
- plugins.push(new CopyPlugin({
98
- patterns: copyPatterns
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
- tsConfigPath = paths.resolveApp(ssbConfig.tsConfigPath);
105
+ tsConfigPath = paths.resolveApp(ssbConfig.tsConfigPath);
106
106
  }
107
107
 
108
108
  const resolvePlugins = [];
109
109
 
110
110
  if(fs.existsSync(tsConfigPath)) {
111
- resolvePlugins.push(new TsconfigPathsPlugin({ configFile: tsConfigPath }));
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
- appIndex = paths.resolveApp(appIndex);
117
+ appIndex = paths.resolveApp(appIndex);
118
118
  }
119
119
 
120
120
  const extraLoaders = [];
121
121
 
122
122
  if(ssbConfig.extraLoaders && _.isArray(ssbConfig.extraLoaders)) {
123
- extraLoaders.push(...ssbConfig.extraLoaders);
123
+ extraLoaders.push(...ssbConfig.extraLoaders);
124
124
  }
125
125
 
126
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
- ]
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
- plugins,
235
- performance: {
236
- hints: false,
237
- },
238
- });
231
+ }
232
+ ]
233
+ },
234
+ plugins,
235
+ performance: {
236
+ hints: false,
237
+ },
238
+ });