/
modules.ts
88 lines (87 loc) · 2.58 KB
/
modules.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import hash from "hash-it";
import { Configuration } from "webpack";
import babelCore from "@babel/core/package.json";
import babelLoader from "babel-loader/package.json";
import { Target, BabelConfigs, Mode } from "../../../types";
export default ({
target,
babel,
mode
}: {
target: Target;
babel: BabelConfigs;
mode: Mode;
}): Configuration["module"] => {
const config: Configuration["module"] = {
rules: [
{
// Support for js, jsx, ts and tsx files.
test: /\.(j|t)sx?$/,
use: {
loader: "babel-loader",
options: {
// Don't use the babelrc file of the root.
babelrc: false,
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
// A unique hash using @babel/core's version, the babel-loader's version,
// and the contents of babel.
cacheIdentifier: hash({
babelCoreVersion: babelCore.version,
babelLoaderVersion: babelLoader.version,
babel: babel
}),
// Instead, use the babel options directly from our babel object.
...babel[target]
}
}
},
{
test: /\.(png|jpe?g|gif|svg)$/,
use: [
{
loader: "file-loader",
options: {
name: (file: string): string => {
const filename = /([^/\\]+)\.(?:png|jpe?g|gif|svg)$/.exec(
file
) || ["", "image"];
return mode === "development"
? `${filename[1]}.[ext]`
: `${filename[1]}-[hash].[ext]`;
},
outputPath: "images",
emitFile: target !== "server"
}
}
]
},
{
test: /\.css$/,
use: "raw-loader"
},
{
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
use: {
loader: "url-loader",
options: {
name: (file: string): string => {
const filename = /([^/\\]+)\.(?:woff(2)?|ttf|eot)$/.exec(
file
) || ["", "font"];
return mode === "development"
? `${filename[1]}.[ext]`
: `${filename[1]}-[hash].[ext]`;
},
outputPath: "fonts",
limit: 25000,
emitFile: target !== "server"
}
}
}
]
};
return config;
};