-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
152 lines (145 loc) · 4.42 KB
/
webpack.config.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
"use strict";
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlReplaceWebpackPlugin = require("html-replace-webpack-plugin");
const GitRevPlugin = require("git-rev-webpack-plugin");
const version = require("./package.json").version;
const webpack = require("webpack");
const gitRevPlugin = new GitRevPlugin();
const appVersionInfo = `Version ${version} (${gitRevPlugin.hash()})`;
// DEPLOY_PATH is set by the s3-deploy-action its value will be:
// `branch/[branch-name]/` or `version/[tag-name]/`
const DEPLOY_PATH = process.env.DEPLOY_PATH;
module.exports = (env, argv) => {
const devMode = argv.mode !== "production";
return {
context: __dirname, // to automatically find tsconfig.json
devtool: "source-map",
entry: "./src/index.tsx",
mode: "development",
output: {
filename: "assets/index.[hash].js",
hashFunction: "sha512"
},
performance: { hints: false },
module: {
rules: [
{
test: /\.tsx?$/,
enforce: "pre",
use: [
{
loader: "eslint-loader",
options: {}
}
]
},
{
test: /\.tsx?$/,
loader: "ts-loader"
},
{
test: /\.(sa|sc|c)ss$/i,
use: [
devMode ? "style-loader" : MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
modules: {
// required for :import from scss files
// cf. https://github.com/webpack-contrib/css-loader#separating-interoperable-css-only-and-css-module-features
compileType: "icss"
}
}
},
"postcss-loader",
"sass-loader"
]
},
{
test: /\.(png|woff|woff2|eot|ttf)$/,
loader: "url-loader",
options: {
limit: 8192
}
},
{
test: /\.svg$/,
oneOf: [
{
// Do not apply SVGR import in CSS files.
issuer: /\.(css|scss|less)$/,
use: "url-loader"
},
{
issuer: /\.tsx?$/,
loader: "@svgr/webpack"
}
]
},
// This code coverage instrumentation should only be added when needed. It makes
// the code larger and slower
process.env.CODE_COVERAGE ? {
test: /\.[tj]sx?$/,
use: {
loader: "istanbul-instrumenter-loader",
options: { esModules: true },
},
enforce: "post",
// I"m not sure but I don"t think it is necessary to exclude the cypress and
// tests folder. I think Jest does its own loading of tests. And cypress does
// its own loading of cypress
exclude: /node_modules|\.spec\.js$/,
} : {}
]
},
resolve: {
extensions: [ ".ts", ".tsx", ".js" ],
fallback: {
"buffer": require.resolve("buffer/"),
"crypto": require.resolve("crypto-browserify"),
"querystring": require.resolve("querystring-es3"),
"stream": require.resolve("stream-browserify"),
"util": require.resolve("util")
},
alias: {
// this allows local npm link to work without causing duplicate react imports
react: path.resolve(__dirname, './node_modules/react')
},
},
stats: {
// suppress "export not found" warnings about re-exported types
warningsFilter: /export .* was not found in/
},
plugins: [
new MiniCssExtractPlugin({
filename: devMode ? "assets/index.css" : "assets/index.[hash].css"
}),
new HtmlWebpackPlugin({
filename: "index.html",
template: "src/index.html"
}),
...(DEPLOY_PATH ? [new HtmlWebpackPlugin({
filename: "index-top.html",
template: "src/index.html",
publicPath: DEPLOY_PATH,
})] : []),
new HtmlReplaceWebpackPlugin([
{
pattern: '__APP_VERSION_INFO__',
replacement: appVersionInfo
}
]),
new CopyWebpackPlugin({
patterns: [
{from: "src/public"}
]
}),
new webpack.ProvidePlugin({
process: "process/browser",
}),
]
};
};