Skip to content

Commit eecc5ab

Browse files
committed
Fix webpack compile error
- Configured `NormalModuleReplacementPlugin` to remove `.js` extension from relative imports in source code for Webpack to compile.
1 parent e48ad97 commit eecc5ab

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

webpack.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { fileURLToPath } from 'url';
33
import CopyPlugin from 'copy-webpack-plugin';
44
import HtmlWebpackPlugin from 'html-webpack-plugin';
55
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
6+
import webpack from 'webpack';
67
import { merge } from 'webpack-merge';
78

89
/* eslint-disable no-underscore-dangle */
@@ -18,6 +19,12 @@ const commonConfig = {
1819
mode: isEnvProduction ? 'production' : 'development',
1920
output: { path: path.join(__dirname, 'dist') },
2021
node: { __dirname: false, __filename: false },
22+
plugins: [
23+
new webpack.NormalModuleReplacementPlugin(/.*\/+.+\.js$/, (resource) => {
24+
// eslint-disable-next-line no-param-reassign
25+
resource.request = resource.request.replace(/\.js$/, '');
26+
}),
27+
],
2128
resolve: {
2229
extensions: ['.js', '.json', '.ts', '.tsx'],
2330
plugins: [new TsconfigPathsPlugin({

0 commit comments

Comments
 (0)