Skip to content
This repository was archived by the owner on Sep 14, 2022. It is now read-only.

Commit ffa5bc9

Browse files
committed
feat: setup webpack
1 parent 9db37b4 commit ffa5bc9

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

webpack.base.config.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
11
const path = require("path");
22
const HtmlPlugin = require("html-webpack-plugin");
3+
const webpack = require("webpack");
4+
5+
function reolveToDir(relPath) {
6+
return path.resolve(__dirname, relPath);
7+
}
38

49
module.exports = {
510
module: {
611
rules: [
712
{
8-
test: /\.(js|jsx|ts|tsx)$/,
9-
exclude: /node_modules/,
13+
test: /\.(jsx|ts|tsx)$/,
1014
use: {
1115
loader: "babel-loader",
1216
},
1317
},
18+
{
19+
test: [
20+
/\/eslint\/.*\/rule-tester/,
21+
/\/eslint\/.*\/cli-engine/,
22+
/\/resolve-from\/*/,
23+
/\/\@eslint\/.*\/config-array-factory/,
24+
/\/\@eslint\/.*\/relative-module-resolver/,
25+
/\/eslint\/eslint\.js/,
26+
// /\/@typescript-eslint\/experimental-utils\/dist\/ts-eslint/,
27+
/\/@typescript-eslint\/experimental-utils\/dist\/ts-eslint\/RuleTester.js/,
28+
/\/@typescript-eslint\/experimental-utils\/dist\/eslint-utils\/RuleTester.js/,
29+
/\/@typescript-eslint\/.*\/CLIEngine/,
30+
// /\/@typescript-eslint\/.*\/globby/,
31+
/\/@typescript-eslint\/.*\/create-program\/createWatchProgram.js/,
32+
/\.d\.ts$/,
33+
],
34+
use: "null-loader",
35+
},
1436
{
1537
test: /\.html$/,
1638
use: [
@@ -20,6 +42,10 @@ module.exports = {
2042
},
2143
],
2244
},
45+
{
46+
test: /\.css$/,
47+
use: ["style-loader", "css-loader"],
48+
},
2349
],
2450
},
2551
resolve: {
@@ -33,12 +59,26 @@ module.exports = {
3359
extensions: [".tsx", ".ts", ".js", ".jsx"],
3460
},
3561
plugins: [
62+
new webpack.NormalModuleReplacementPlugin(
63+
/resolve\-from/,
64+
path.resolve(__dirname, "./src/modules/resolve-from.js")
65+
),
66+
new webpack.NormalModuleReplacementPlugin(
67+
/esquery/,
68+
path.resolve(__dirname, "./node_modules/esquery/dist/esquery.js")
69+
),
70+
new webpack.NormalModuleReplacementPlugin(
71+
/globby/,
72+
path.resolve(__dirname, "./src/modules/globby.js")
73+
),
3674
new HtmlPlugin({
3775
template: "./src/index.html",
3876
filename: "./index.html",
3977
}),
4078
],
4179
output: {
80+
filename: "[name].[hash].js",
81+
chunkFilename: "[name].[hash].js",
4282
publicPath: "/",
4383
},
4484
};

webpack.prod.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const { merge } = require("lodash");
22
const baseConfig = require("./webpack.base.config");
3+
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
4+
.BundleAnalyzerPlugin;
35
const TerserPlugin = require("terser-webpack-plugin");
46

57
module.exports = merge(baseConfig, {
@@ -8,8 +10,26 @@ module.exports = merge(baseConfig, {
810
minimize: true,
911
minimizer: [
1012
new TerserPlugin({
13+
terserOptions: {
14+
comments: false,
15+
},
1116
extractComments: false,
1217
}),
1318
],
19+
splitChunks: {
20+
chunks: "all",
21+
maxInitialRequests: Infinity,
22+
minSize: 0,
23+
cacheGroups: {
24+
vendor: {
25+
test: /[\\/]node_modules[\\/]/,
26+
},
27+
},
28+
},
29+
},
30+
plugins: [new BundleAnalyzerPlugin()],
31+
output: {
32+
filename: "[name].[hash].js",
33+
publicPath: "./",
1434
},
1535
});

0 commit comments

Comments
 (0)