@lipemat/js-boilerplate 10.2.0 → 10.3.0-beta.1
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/README.md +3 -2
- package/config/webpack.dev.js +5 -5
- package/config/webpack.dist.js +37 -19
- package/helpers/config.js +40 -10
- package/helpers/package-config.js +1 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -38,8 +38,9 @@ Add the following to your package.json. (this may also be found in the `template
|
|
|
38
38
|
```
|
|
39
39
|
**_You may adjust things as needed but be sure to leave the `scripts` as is._**
|
|
40
40
|
|
|
41
|
-
* `
|
|
42
|
-
* `
|
|
41
|
+
* `brotliFiles : {bool}` Enabled generating pre-compressed .br files for CSS and JS.
|
|
42
|
+
* `shortCssClasses : {bool}` Enable short 1-2 character CSS classes. Recommended if you're not running multiple instances of this package on the same site.
|
|
43
|
+
* `jsPath : {string}` Path of JS application relative to `package.json`. If `package.json` is in same directory as the JS application, this may be omitted.
|
|
43
44
|
|
|
44
45
|
## Code Completion In PHPStorm
|
|
45
46
|
Some `@types` have been specified in this library to assist with code completion and allow using the built-in TypeScript support. Unfortunately, some typescripts still send errors to PHPStorm like "Default export is not declared in an imported module". I've found that it's easier to just remove this warning by un-checking `Editor -> Inspections -> JavaScript -> General -> Validate Imports`. (this may not need to be un-checked if you enable the built-in TypeScript support).
|
package/config/webpack.dev.js
CHANGED
|
@@ -4,7 +4,7 @@ const path = require( 'path' );
|
|
|
4
4
|
const ForkTsCheckerWebpackPlugin = require( 'fork-ts-checker-webpack-plugin' );
|
|
5
5
|
const config = require( '../helpers/package-config' );
|
|
6
6
|
const {getEntries} = require( '../helpers/entries' );
|
|
7
|
-
const {getConfig,
|
|
7
|
+
const {getConfig, getTsConfigFile} = require( '../helpers/config' );
|
|
8
8
|
|
|
9
9
|
const postcssOptions = getConfig( 'postcss.config.js' );
|
|
10
10
|
const babelOptions = getConfig( 'babel.config.js' );
|
|
@@ -24,14 +24,14 @@ const plugins = [
|
|
|
24
24
|
new ReactRefreshWebpackPlugin(),
|
|
25
25
|
];
|
|
26
26
|
|
|
27
|
-
// Loads a thread, which verifies any TypeScripts on changes
|
|
28
|
-
//
|
|
29
|
-
if (
|
|
27
|
+
// Loads a thread, which verifies any TypeScripts on changes if the
|
|
28
|
+
// project has a "tsconfig.json" file.
|
|
29
|
+
if ( '' !== getTsConfigFile() ) {
|
|
30
30
|
plugins.push( new ForkTsCheckerWebpackPlugin( {
|
|
31
31
|
devServer: false,
|
|
32
32
|
formatter: 'basic',
|
|
33
33
|
typescript: {
|
|
34
|
-
configFile:
|
|
34
|
+
configFile: getTsConfigFile(),
|
|
35
35
|
},
|
|
36
36
|
} ) );
|
|
37
37
|
}
|
package/config/webpack.dist.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const webpack = require( 'webpack' );
|
|
2
2
|
const path = require( 'path' );
|
|
3
|
+
const CompressionPlugin = require( 'compression-webpack-plugin' );
|
|
3
4
|
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
|
|
4
5
|
const {CleanWebpackPlugin} = require( 'clean-webpack-plugin' );
|
|
5
6
|
const WebpackAssetsManifest = require( 'webpack-assets-manifest' );
|
|
@@ -21,6 +22,41 @@ const ManifestPlugin = new WebpackAssetsManifest( {
|
|
|
21
22
|
output: 'manifest.json',
|
|
22
23
|
} );
|
|
23
24
|
|
|
25
|
+
const plugins = [
|
|
26
|
+
new webpack.ProvidePlugin( {
|
|
27
|
+
jQuery: 'jquery',
|
|
28
|
+
$: 'jquery',
|
|
29
|
+
} ),
|
|
30
|
+
new MiniCssExtractPlugin( {
|
|
31
|
+
filename: '[name].css',
|
|
32
|
+
chunkFilename: '[name].[contenthash].css',
|
|
33
|
+
} ),
|
|
34
|
+
new CleanWebpackPlugin( {
|
|
35
|
+
// Remove all files except the `.running` file created by "Start".
|
|
36
|
+
cleanOnceBeforeBuildPatterns: [ '**/*', '!.running' ],
|
|
37
|
+
} ),
|
|
38
|
+
new SubresourceIntegrityPlugin( {
|
|
39
|
+
hashFuncNames: [ 'sha384' ],
|
|
40
|
+
} ),
|
|
41
|
+
new WebpackAssetsHash( ManifestPlugin ),
|
|
42
|
+
ManifestPlugin,
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Generate .br files if enabled.
|
|
47
|
+
*
|
|
48
|
+
* @note Will only generate files if 20% or more size is gained.
|
|
49
|
+
* @see https://webpack.js.org/plugins/compression-webpack-plugin/#using-brotli
|
|
50
|
+
*/
|
|
51
|
+
if ( config.brotliFiles ) {
|
|
52
|
+
plugins.push( new CompressionPlugin( {
|
|
53
|
+
algorithm: 'brotliCompress',
|
|
54
|
+
deleteOriginalAssets: false,
|
|
55
|
+
test: /\.(js|css)$/,
|
|
56
|
+
} ) );
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
24
60
|
module.exports = {
|
|
25
61
|
devtool: false,
|
|
26
62
|
entry: getEntries(),
|
|
@@ -68,25 +104,7 @@ module.exports = {
|
|
|
68
104
|
'node_modules',
|
|
69
105
|
],
|
|
70
106
|
},
|
|
71
|
-
plugins
|
|
72
|
-
new webpack.ProvidePlugin( {
|
|
73
|
-
jQuery: 'jquery',
|
|
74
|
-
$: 'jquery',
|
|
75
|
-
} ),
|
|
76
|
-
new MiniCssExtractPlugin( {
|
|
77
|
-
filename: '[name].css',
|
|
78
|
-
chunkFilename: '[name].[contenthash].css',
|
|
79
|
-
} ),
|
|
80
|
-
new CleanWebpackPlugin( {
|
|
81
|
-
// Remove all files except the `.running` file created by "Start".
|
|
82
|
-
cleanOnceBeforeBuildPatterns: [ '**/*', '!.running' ],
|
|
83
|
-
} ),
|
|
84
|
-
new SubresourceIntegrityPlugin( {
|
|
85
|
-
hashFuncNames: [ 'sha384' ],
|
|
86
|
-
} ),
|
|
87
|
-
new WebpackAssetsHash( ManifestPlugin ),
|
|
88
|
-
ManifestPlugin,
|
|
89
|
-
],
|
|
107
|
+
plugins,
|
|
90
108
|
module: {
|
|
91
109
|
rules: [
|
|
92
110
|
{
|
package/helpers/config.js
CHANGED
|
@@ -2,6 +2,8 @@ const packageConfig = require( './package-config' );
|
|
|
2
2
|
const path = require( 'path' );
|
|
3
3
|
const once = require( 'lodash/once' );
|
|
4
4
|
const browserslist = require( 'browserslist' );
|
|
5
|
+
const fs = require( 'fs' );
|
|
6
|
+
const config = require( './package-config' );
|
|
5
7
|
|
|
6
8
|
const extensions = [
|
|
7
9
|
...Object.keys( packageConfig.dependencies ?? {} ).filter( name => name.includes( 'js-boilerplate-' ) ),
|
|
@@ -16,7 +18,7 @@ const extensions = [
|
|
|
16
18
|
*
|
|
17
19
|
* @return {boolean}
|
|
18
20
|
*/
|
|
19
|
-
function hasLocalOverride( fileName, inWorkingDirectory = false ) {
|
|
21
|
+
function hasLocalOverride( fileName, inWorkingDirectory = false, ) {
|
|
20
22
|
let hasLocal = false;
|
|
21
23
|
try {
|
|
22
24
|
if ( inWorkingDirectory ) {
|
|
@@ -61,18 +63,18 @@ function hasLocalOverride( fileName, inWorkingDirectory = false ) {
|
|
|
61
63
|
* @return {Object}
|
|
62
64
|
*/
|
|
63
65
|
function getConfig( fileName ) {
|
|
64
|
-
let
|
|
65
|
-
|
|
66
|
+
let mergedConfig = require( '../config/' + fileName );
|
|
67
|
+
mergedConfig = {...mergedConfig, ...getExtensionsConfig( fileName, mergedConfig )};
|
|
66
68
|
try {
|
|
67
69
|
const localConfig = require( path.resolve( packageConfig.packageDirectory + '/config', fileName ) );
|
|
68
70
|
if ( 'function' === typeof localConfig ) {
|
|
69
|
-
|
|
71
|
+
mergedConfig = {...mergedConfig, ...localConfig( mergedConfig )};
|
|
70
72
|
} else {
|
|
71
|
-
|
|
73
|
+
mergedConfig = {...mergedConfig, ...localConfig};
|
|
72
74
|
}
|
|
73
75
|
} catch ( e ) {
|
|
74
76
|
}
|
|
75
|
-
return
|
|
77
|
+
return mergedConfig;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
/**
|
|
@@ -88,22 +90,49 @@ function getConfig( fileName ) {
|
|
|
88
90
|
* @return {Object}
|
|
89
91
|
*/
|
|
90
92
|
function getExtensionsConfig( fileName, defaultConfig ) {
|
|
91
|
-
let
|
|
93
|
+
let mergedConfig = {};
|
|
92
94
|
extensions.forEach( extension => {
|
|
93
95
|
try {
|
|
94
96
|
const extensionConfig = require( extension + '/config/' + fileName );
|
|
95
97
|
if ( 'function' === typeof extensionConfig ) {
|
|
96
|
-
|
|
98
|
+
mergedConfig = {...mergedConfig, ...extensionConfig( {...defaultConfig, ...mergedConfig} )};
|
|
97
99
|
} else {
|
|
98
|
-
|
|
100
|
+
mergedConfig = {...mergedConfig, ...extensionConfig};
|
|
99
101
|
}
|
|
100
102
|
} catch ( e ) {
|
|
101
103
|
}
|
|
102
104
|
} );
|
|
103
105
|
|
|
104
|
-
return
|
|
106
|
+
return mergedConfig;
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Get the path to the "tsconfig.json" file if it exists.
|
|
111
|
+
*
|
|
112
|
+
* 1. The working directory.
|
|
113
|
+
* 2. The package directory.
|
|
114
|
+
*
|
|
115
|
+
* The package directory takes priority over the working directory.
|
|
116
|
+
*
|
|
117
|
+
*
|
|
118
|
+
* @return {string}
|
|
119
|
+
*/
|
|
120
|
+
function getTsConfigFile() {
|
|
121
|
+
const possibles = [
|
|
122
|
+
// Backward compatible for before @lipemat/eslint-config version 3.
|
|
123
|
+
path.resolve( config.workingDirectory + '/tsconfig.json' ),
|
|
124
|
+
path.resolve( config.packageDirectory + '/tsconfig.json' ),
|
|
125
|
+
];
|
|
126
|
+
let tsConfig = '';
|
|
127
|
+
possibles.forEach( filePath => {
|
|
128
|
+
if ( fs.existsSync( filePath ) ) {
|
|
129
|
+
tsConfig = filePath;
|
|
130
|
+
}
|
|
131
|
+
} );
|
|
132
|
+
return tsConfig;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
107
136
|
/**
|
|
108
137
|
* If browserslist is not specified, we fall back to WordPress defaults
|
|
109
138
|
* except for > 1% we don't support by default.
|
|
@@ -134,5 +163,6 @@ module.exports = {
|
|
|
134
163
|
getConfig,
|
|
135
164
|
getDefaultBrowsersList,
|
|
136
165
|
getExtensionsConfig,
|
|
166
|
+
getTsConfigFile,
|
|
137
167
|
hasLocalOverride,
|
|
138
168
|
};
|
|
@@ -3,6 +3,7 @@ const fs = require( 'fs' );
|
|
|
3
3
|
|
|
4
4
|
const workingDirectory = fs.realpathSync( process.cwd() );
|
|
5
5
|
let packageConfig = require( path.resolve( workingDirectory, 'package.json' ) );
|
|
6
|
+
packageConfig.brotliFiles ||= false;
|
|
6
7
|
packageConfig.es6Modules ||= [];
|
|
7
8
|
packageConfig.jsPath ||= '';
|
|
8
9
|
// Path of the package.json file (root).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lipemat/js-boilerplate",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.3.0-beta.1",
|
|
4
4
|
"description": "Dependencies and scripts for a no config JavaScript app",
|
|
5
5
|
"author": "Mat Lipe",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,13 +45,14 @@
|
|
|
45
45
|
"@lipemat/css-mqpacker": "^9.0.0",
|
|
46
46
|
"@lipemat/eslint-config": "^3.0.1",
|
|
47
47
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
|
|
48
|
-
"@wordpress/browserslist-config": "^
|
|
48
|
+
"@wordpress/browserslist-config": "^5.19.0",
|
|
49
49
|
"are-you-es5": "^2.1.1",
|
|
50
50
|
"babel-jest": "^29.0.0",
|
|
51
51
|
"babel-loader": "^9.1.2",
|
|
52
52
|
"browserslist": "^4.17.0",
|
|
53
53
|
"clean-css": "^5.3.0",
|
|
54
54
|
"clean-webpack-plugin": "^4.0.0",
|
|
55
|
+
"compression-webpack-plugin": "^10.0.0",
|
|
55
56
|
"core-js": "^3.8.3",
|
|
56
57
|
"cross-spawn": "^6.0.5",
|
|
57
58
|
"css-loader": "6.7.1",
|
|
@@ -66,7 +67,7 @@
|
|
|
66
67
|
"postcss": "^8.4.13",
|
|
67
68
|
"postcss-color-mod-function": "^3.0.3",
|
|
68
69
|
"postcss-custom-media": "^8.0.1",
|
|
69
|
-
"postcss-import": "^
|
|
70
|
+
"postcss-import": "^15.1.0",
|
|
70
71
|
"postcss-loader": "^6.2.1",
|
|
71
72
|
"postcss-nested": "^5.0.6",
|
|
72
73
|
"postcss-preset-env": "^7.5.0",
|