Skip to content

Commit f044bef

Browse files
committed
Merge branch 'migration/esmodule' into develop
2 parents c79a343 + aed97ea commit f044bef

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

.eslintrc.cjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ const jestConfig = {
8585
};
8686

8787
const specialConfig = {
88-
files: ['**/*.config.js', '**/*.config.*.js'],
88+
files: [
89+
'**/*.config.js',
90+
'**/*.config.cjs',
91+
'**/*.config.*.js',
92+
'**/*.config.*.cjs',
93+
],
8994
rules: {
9095
...baseConfig.rules,
9196
'import/no-extraneous-dependencies': 'off',

CHANGELOG_V4+.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- `jest.config.js` & `webpack.config.js` are no longer ignored by ESLint.
2525
- Improved the readability of `webpack.config.js` by migrating to `webpack-merge`
2626
from using `lodash.deepClone()` for merging configuration objects.
27+
- Configured Node to resolve JavaScript files as ES modules (`"type": "module"`
28+
in `package.json`).
29+
- Refactored Jest and Webpack config files as ES modules.
2730

2831
### Fixed
2932
- Module import order warnings in most modules.

jest.config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
const { pathsToModuleNameMapper } = require('ts-jest');
1+
import { createRequire } from 'module';
2+
import { pathsToModuleNameMapper } from 'ts-jest';
3+
4+
const require = createRequire(import.meta.url);
25
const { compilerOptions } = require('./tsconfig.json');
36

4-
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
5-
module.exports = {
7+
export default {
68
testEnvironment: 'node',
79
globals: {
810
'ts-jest': {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "electron-react-typescript-webpack-boilerplate",
33
"version": "4.0.0",
44
"description": "Pre-configured boilerplate for Electron + React + TypeScript",
5+
"type": "module",
56
"main": "./dist/main.bundle.js",
67
"scripts": {
78
"start": "electron ./dist/main.bundle.js",

tsconfig.eslint.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"tests/**/*",
99
".eslintrc.cjs",
1010
"**/*.config.js",
11+
"**/*.config.cjs",
1112
"**/*.config.*.js",
13+
"**/*.config.*.cjs"
1214
]
1315
}

webpack.config.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
const path = require('path');
2-
const CopyPlugin = require('copy-webpack-plugin');
3-
const HtmlWebpackPlugin = require('html-webpack-plugin');
4-
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
5-
const { merge } = require('webpack-merge');
1+
import path from 'path';
2+
import { fileURLToPath } from 'url';
3+
import CopyPlugin from 'copy-webpack-plugin';
4+
import HtmlWebpackPlugin from 'html-webpack-plugin';
5+
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
6+
import { merge } from 'webpack-merge';
67

7-
function srcPaths(src) {
8-
return path.join(__dirname, src);
9-
}
8+
/* eslint-disable no-underscore-dangle */
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = path.dirname(__filename);
11+
/* eslint-enable */
1012

1113
const isEnvProduction = process.env.NODE_ENV === 'production';
1214
const isEnvDevelopment = process.env.NODE_ENV === 'development';
1315

1416
const commonConfig = {
1517
devtool: isEnvDevelopment ? 'source-map' : false,
1618
mode: isEnvProduction ? 'production' : 'development',
17-
output: { path: srcPaths('dist') },
19+
output: { path: path.join(__dirname, 'dist') },
1820
node: { __dirname: false, __filename: false },
1921
resolve: {
2022
extensions: ['.js', '.json', '.ts', '.tsx'],
@@ -59,6 +61,7 @@ const mainConfig = merge(commonConfig, {
5961
const jsonContent = JSON.parse(content);
6062
const electronVersion = jsonContent.devDependencies.electron;
6163

64+
delete jsonContent.type;
6265
delete jsonContent.devDependencies;
6366
delete jsonContent.optionalDependencies;
6467
delete jsonContent.scripts;
@@ -93,4 +96,4 @@ const rendererConfig = merge(commonConfig, {
9396
],
9497
});
9598

96-
module.exports = [mainConfig, preloadConfig, rendererConfig];
99+
export default [mainConfig, preloadConfig, rendererConfig];

0 commit comments

Comments
 (0)