@lipemat/js-boilerplate 10.6.0-beta.5 → 10.7.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/README.md +4 -8
- package/bin/lipemat-js-boilerplate.js +2 -0
- package/config/{babel.config.js → babel.config.ts} +19 -3
- package/config/webpack.dev.js +4 -4
- package/config/webpack.dist.js +3 -3
- package/helpers/config.d.ts +7 -0
- package/helpers/config.js +2 -0
- package/helpers/entries.js +1 -1
- package/package.json +4 -1
- package/scripts/analyze.ts +53 -0
- package/scripts/dist.js +1 -1
- package/scripts/lint.ts +10 -5
- package/scripts/start.js +2 -2
- package/scripts/validate-css-modules.ts +2 -2
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ Add the following to your package.json. (this may also be found in the `template
|
|
|
22
22
|
{
|
|
23
23
|
"jsPath": "./js",
|
|
24
24
|
"scripts": {
|
|
25
|
+
"analyze": "lipemat-js-boilerplate analyze",
|
|
25
26
|
"browserslist": "lipemat-js-boilerplate browserslist",
|
|
26
27
|
"dist": "lipemat-js-boilerplate dist",
|
|
27
28
|
"lint": "lipemat-js-boilerplate lint",
|
|
@@ -44,7 +45,7 @@ Add the following to your package.json. (this may also be found in the `template
|
|
|
44
45
|
* `cssTsFiles : {bool}` Enable auto generation of TypeScript definitions for CSS modules.
|
|
45
46
|
|
|
46
47
|
## Code Completion In PHPStorm
|
|
47
|
-
Some `@types` have been specified in this library to
|
|
48
|
+
Some `@types` have been specified in this library to help 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).
|
|
48
49
|
|
|
49
50
|
|
|
50
51
|
## ESLint
|
|
@@ -72,7 +73,7 @@ The console will display a list of browsers targeted by your [browserslist confi
|
|
|
72
73
|
To use the built-in TypeScript, copy the following items from `templates` into your project root:
|
|
73
74
|
1. `tsconfig.json`
|
|
74
75
|
|
|
75
|
-
TypeScript will run a validator during dev and output any errors in the console. These same errors will display within PHPStorm if you copied tsconfig.json file in step 1. You technically don't have to fix any issues to compile but it's recommended.
|
|
76
|
+
TypeScript will run a validator during dev and output any errors in the console. These same errors will display within PHPStorm if you copied tsconfig.json file in step 1. You technically don't have to fix any issues to compile, but it's recommended.
|
|
76
77
|
|
|
77
78
|
Babel will automatically compile TypeScript files into the finished javascript, and will ignore errors.
|
|
78
79
|
|
|
@@ -88,7 +89,7 @@ To create a package which extends any of the files within the `config` directory
|
|
|
88
89
|
This is useful when you have often reused overrides to support a particular library. [Here is an example](https://github.com/lipemat/js-boilerplate-gutenberg)
|
|
89
90
|
|
|
90
91
|
### Testing
|
|
91
|
-
To use the built
|
|
92
|
+
To use the built-in testing, copy the following items from `templates` into your project root:
|
|
92
93
|
1. `jest.config.js`
|
|
93
94
|
2. `tests`
|
|
94
95
|
|
|
@@ -103,11 +104,6 @@ Now you may write `jest` tests as desired and run them via `yarn run test`
|
|
|
103
104
|
|
|
104
105
|
## Legacy Browsers Support
|
|
105
106
|
|
|
106
|
-
#### IE11
|
|
107
|
-
|
|
108
|
-
By default, IE11 is disabled via an internal Browserslist configuration. If you would like to support IE11, add it
|
|
109
|
-
as a target to your project's Browserslist configuration and all tooling will automatically support it.
|
|
110
|
-
|
|
111
107
|
#### ES6 Modules
|
|
112
108
|
|
|
113
109
|
The app will automatically detect any packages in your `package.json` which do not support ES5 and add them to the list
|
|
@@ -17,12 +17,14 @@ const nodeArgs = scriptIndex > 0 ? args.slice( 0, scriptIndex ) : [];
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
const TS_CONVERTED_SCRIPTS = [
|
|
20
|
+
'analyze',
|
|
20
21
|
'test',
|
|
21
22
|
'lint',
|
|
22
23
|
'validate-css-modules',
|
|
23
24
|
];
|
|
24
25
|
|
|
25
26
|
switch ( script ) {
|
|
27
|
+
case 'analyze':
|
|
26
28
|
case 'browserslist':
|
|
27
29
|
case 'dist':
|
|
28
30
|
case 'fix-pnp':
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import {getBrowsersList} from '../helpers/config';
|
|
2
|
+
import type {TransformOptions} from '@babel/core';
|
|
3
|
+
import type {Options} from '@babel/preset-env';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @link https://webpack.js.org/loaders/babel-loader/#options
|
|
7
|
+
*/
|
|
8
|
+
export type BabelLoader = {
|
|
9
|
+
cacheDirectory?: boolean | string;
|
|
10
|
+
cacheIdentifier?: string;
|
|
11
|
+
cacheCompression?: boolean;
|
|
12
|
+
customize?: string;
|
|
13
|
+
metadataSubscribers?: string[];
|
|
14
|
+
}
|
|
2
15
|
|
|
3
16
|
/**
|
|
4
17
|
* Use Babel's preset-env to add support for target browsers.
|
|
@@ -7,11 +20,12 @@ const {getBrowsersList} = require( '../helpers/config' );
|
|
|
7
20
|
*
|
|
8
21
|
* @see https://babeljs.io/docs/en/babel-preset-env
|
|
9
22
|
*/
|
|
10
|
-
const presetEnv = {
|
|
23
|
+
const presetEnv: Options = {
|
|
11
24
|
bugfixes: true,
|
|
12
25
|
corejs: {
|
|
13
26
|
// Use the core-js version currently installed in the project.
|
|
14
27
|
version: require( 'core-js/package.json' ).version,
|
|
28
|
+
proposals: false,
|
|
15
29
|
},
|
|
16
30
|
// Enable the `debug` option to debug the included polyfills and plugins.
|
|
17
31
|
debug: false,
|
|
@@ -25,7 +39,7 @@ const presetEnv = {
|
|
|
25
39
|
};
|
|
26
40
|
|
|
27
41
|
|
|
28
|
-
|
|
42
|
+
const babelConfig: TransformOptions & BabelLoader = {
|
|
29
43
|
cacheDirectory: true,
|
|
30
44
|
presets: [
|
|
31
45
|
[ '@babel/preset-env', presetEnv ],
|
|
@@ -39,3 +53,5 @@ module.exports = {
|
|
|
39
53
|
'@babel/plugin-syntax-dynamic-import',
|
|
40
54
|
],
|
|
41
55
|
};
|
|
56
|
+
|
|
57
|
+
module.exports = babelConfig;
|
package/config/webpack.dev.js
CHANGED
|
@@ -6,10 +6,10 @@ const {getPackageConfig} = require( '../helpers/package-config' );
|
|
|
6
6
|
const {getEntries} = require( '../helpers/entries' );
|
|
7
7
|
const {getConfig, getTsConfigFile, getBrowsersList} = require( '../helpers/config' );
|
|
8
8
|
|
|
9
|
-
const postcssOptions = getConfig( 'postcss.config
|
|
10
|
-
const babelOptions = getConfig( 'babel.config
|
|
11
|
-
const cssLoaderOptions = getConfig( 'css-loader.config
|
|
12
|
-
const devServerOptions = getConfig( 'dev-server.config
|
|
9
|
+
const postcssOptions = getConfig( 'postcss.config' );
|
|
10
|
+
const babelOptions = getConfig( 'babel.config' );
|
|
11
|
+
const cssLoaderOptions = getConfig( 'css-loader.config' );
|
|
12
|
+
const devServerOptions = getConfig( 'dev-server.config' );
|
|
13
13
|
|
|
14
14
|
// To allow line numbers to show up in console errors. @see React Error Boundaries.
|
|
15
15
|
babelOptions.plugins.unshift( '@babel/plugin-transform-react-jsx-source' );
|
package/config/webpack.dist.js
CHANGED
|
@@ -14,9 +14,9 @@ const config = require( '../helpers/package-config' );
|
|
|
14
14
|
const {getEntries} = require( '../helpers/entries' );
|
|
15
15
|
const {getPackageConfig} = require( '../helpers/package-config' );
|
|
16
16
|
|
|
17
|
-
const postcssOptions = getConfig( 'postcss.config
|
|
18
|
-
const babelOptions = getConfig( 'babel.config
|
|
19
|
-
const cssLoaderOptions = getConfig( 'css-loader.config
|
|
17
|
+
const postcssOptions = getConfig( 'postcss.config' );
|
|
18
|
+
const babelOptions = getConfig( 'babel.config' );
|
|
19
|
+
const cssLoaderOptions = getConfig( 'css-loader.config' );
|
|
20
20
|
|
|
21
21
|
const ManifestPlugin = new WebpackAssetsManifest( {
|
|
22
22
|
integrity: true,
|
package/helpers/config.js
CHANGED
|
@@ -171,6 +171,8 @@ const getDefaultBrowsersList = () => {
|
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
173
|
* Adjust the browserslist to include our defaults.
|
|
174
|
+
*
|
|
175
|
+
* @todo Remove `not op_mini all` after 3/8/2024 if it does not creep back in to the defaults.
|
|
174
176
|
*/
|
|
175
177
|
function adjustBrowserslist( browserRules ) {
|
|
176
178
|
browserRules.push( 'not op_mini all' );
|
package/helpers/entries.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lipemat/js-boilerplate",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.7.0",
|
|
4
4
|
"description": "Dependencies and scripts for a no config JavaScript app",
|
|
5
5
|
"author": "Mat Lipe",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,13 +48,16 @@
|
|
|
48
48
|
"@lipemat/css-mqpacker": "^9.0.0",
|
|
49
49
|
"@lipemat/eslint-config": "^3.1.3",
|
|
50
50
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
|
|
51
|
+
"@statoscope/webpack-plugin": "^5.28.2",
|
|
51
52
|
"@teamsupercell/typings-for-css-modules-loader": "^2.5.2",
|
|
53
|
+
"@types/babel__preset-env": "^7.9.6",
|
|
52
54
|
"@types/node": "^16",
|
|
53
55
|
"@wordpress/browserslist-config": "^5.19.0",
|
|
54
56
|
"are-you-es5": "^2.1.1",
|
|
55
57
|
"babel-jest": "^29.0.0",
|
|
56
58
|
"babel-loader": "9.1.2",
|
|
57
59
|
"browserslist": "^4.21.9",
|
|
60
|
+
"chalk": "^4.0",
|
|
58
61
|
"clean-css": "^5.3.0",
|
|
59
62
|
"clean-webpack-plugin": "^4.0.0",
|
|
60
63
|
"compression-webpack-plugin": "^10.0.0",
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {getConfig} from '../helpers/config';
|
|
2
|
+
import webpack from 'webpack';
|
|
3
|
+
import StatoscopeWebpackPlugin from '@statoscope/webpack-plugin';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import minimist from 'minimist';
|
|
6
|
+
|
|
7
|
+
const help = `
|
|
8
|
+
Uses Statoscope to visualize the size of the project's output files.
|
|
9
|
+
|
|
10
|
+
Usage: lipemat-js-boilerplate analyze [--stats-only|--help]
|
|
11
|
+
|
|
12
|
+
--help, -h Show help menu.
|
|
13
|
+
--stats-only Generate stats.json file for use with https://statoscope.tech for comparing diffs between builds.
|
|
14
|
+
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// Command line arguments.
|
|
19
|
+
const flags = minimist( process.argv.slice( 2 ) );
|
|
20
|
+
const workingDirectory = fs.realpathSync( process.cwd() );
|
|
21
|
+
const statsDir = workingDirectory + '/node_modules/.cache/statoscope';
|
|
22
|
+
const webpackConfig = getConfig<webpack.Configuration>( 'webpack.dist' );
|
|
23
|
+
|
|
24
|
+
if ( true === flags.h || true === flags.help ) {
|
|
25
|
+
console.log( help );
|
|
26
|
+
process.exit( 0 );
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
function analyze() {
|
|
31
|
+
webpackConfig.plugins?.push( new StatoscopeWebpackPlugin( {
|
|
32
|
+
saveOnlyStats: true === ( flags[ 'stats-only' ] ?? false ),
|
|
33
|
+
saveStatsTo: statsDir + '/stats-[hash].json',
|
|
34
|
+
saveReportTo: statsDir + '/stats-[hash].html',
|
|
35
|
+
} ) );
|
|
36
|
+
|
|
37
|
+
// Use the default webpack stats configuration.
|
|
38
|
+
delete webpackConfig.stats;
|
|
39
|
+
|
|
40
|
+
webpack( webpackConfig ).run( ( err, stats ) => {
|
|
41
|
+
if ( err ) {
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
if ( 'undefined' === typeof stats ) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if ( stats.hasErrors() ) {
|
|
48
|
+
process.exit( 1 );
|
|
49
|
+
}
|
|
50
|
+
} );
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
analyze();
|
package/scripts/dist.js
CHANGED
|
@@ -2,7 +2,7 @@ process.env.BABEL_ENV = 'production';
|
|
|
2
2
|
process.env.NODE_ENV = 'production';
|
|
3
3
|
|
|
4
4
|
const webpack = require( 'webpack' );
|
|
5
|
-
const webpackConfig = require( '../helpers/config' ).getConfig( 'webpack.dist
|
|
5
|
+
const webpackConfig = require( '../helpers/config' ).getConfig( 'webpack.dist' );
|
|
6
6
|
|
|
7
7
|
async function build( config ) {
|
|
8
8
|
// Compiler Instance.
|
package/scripts/lint.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {ESLint} from 'eslint';
|
|
2
2
|
import minimist from 'minimist';
|
|
3
|
+
import chalk from 'chalk';
|
|
3
4
|
|
|
4
5
|
import packageConfig from '../helpers/package-config';
|
|
5
6
|
|
|
@@ -30,6 +31,8 @@ function errorOccurred( results: ESLint.LintResult[] ): boolean {
|
|
|
30
31
|
cacheStrategy: 'content',
|
|
31
32
|
} );
|
|
32
33
|
|
|
34
|
+
console.log( chalk.underline( 'Running "js-boilerplate:lint" (eslint) task' ) );
|
|
35
|
+
|
|
33
36
|
// 2. Lint files. This doesn't modify target files.
|
|
34
37
|
const results: ESLint.LintResult[] = await eslint.lintFiles( [
|
|
35
38
|
packageConfig.workingDirectory + '/src/**/*.{js,jsx,ts,tsx}',
|
|
@@ -43,13 +46,15 @@ function errorOccurred( results: ESLint.LintResult[] ): boolean {
|
|
|
43
46
|
const resultText = formatter.format( results );
|
|
44
47
|
|
|
45
48
|
// 5. Output it.
|
|
46
|
-
console.log( resultText );
|
|
47
49
|
if ( '' === resultText ) {
|
|
48
|
-
console.log(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
console.log( `>> Linted ${results.length} files without errors` );
|
|
51
|
+
} else {
|
|
52
|
+
console.log( resultText );
|
|
53
|
+
if ( errorOccurred( results ) ) {
|
|
54
|
+
process.exitCode = 1;
|
|
55
|
+
}
|
|
52
56
|
}
|
|
57
|
+
console.log( '' );
|
|
53
58
|
}() ).catch( error => {
|
|
54
59
|
process.exitCode = 1;
|
|
55
60
|
console.error( error );
|
package/scripts/start.js
CHANGED
|
@@ -7,8 +7,8 @@ const {unlinkSync, writeFile} = require( 'fs' );
|
|
|
7
7
|
const WebpackDevServer = require( 'webpack-dev-server' );
|
|
8
8
|
const configHelper = require( '../helpers/config' );
|
|
9
9
|
const path = require( 'path' );
|
|
10
|
-
const webpackConfig = configHelper.getConfig( 'webpack.dev
|
|
11
|
-
const devServerConfig = configHelper.getConfig( 'dev-server.config
|
|
10
|
+
const webpackConfig = configHelper.getConfig( 'webpack.dev' );
|
|
11
|
+
const devServerConfig = configHelper.getConfig( 'dev-server.config' );
|
|
12
12
|
|
|
13
13
|
const server = new WebpackDevServer( devServerConfig, webpack( webpackConfig ) );
|
|
14
14
|
|
|
@@ -14,7 +14,7 @@ Validate CSS modules using .d.ts definition files for each CSS module.
|
|
|
14
14
|
|
|
15
15
|
Usage: lipemat-js-boilerplate validate-css-modules
|
|
16
16
|
|
|
17
|
-
--help, -h
|
|
17
|
+
--help, -h Show help menu.`;
|
|
18
18
|
|
|
19
19
|
const args = process.argv.slice( 3 );
|
|
20
20
|
if ( '-h' === args[ 0 ] || '--help' === args[ 0 ] ) {
|
|
@@ -23,7 +23,7 @@ if ( '-h' === args[ 0 ] || '--help' === args[ 0 ] ) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
async function validate() {
|
|
26
|
-
let webpackConfig
|
|
26
|
+
let webpackConfig = getConfig<webpack.Configuration>( 'webpack.dist' );
|
|
27
27
|
webpackConfig.stats = 'errors-warnings';
|
|
28
28
|
|
|
29
29
|
// Add CSS module typings generation to webpack config.
|