-
Notifications
You must be signed in to change notification settings - Fork 301
/
webpack.config.js
116 lines (109 loc) · 2.91 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
require("dotenv/config");
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const workbox = require("workbox-webpack-plugin");
const webpack = require("webpack");
const buildTarget = process.env.BUILD_TARGET || "web";
const isProduction = process.env.NODE_ENV === "production";
const isWeb = buildTarget === "web";
const version = require("./package.json").version;
const config = {
entry: {
polyfills: "./src/polyfills.ts",
main: ["normalize.css", "./src/styles.sass", "./src/main.tsx"],
},
output: {
path: path.resolve("dist", buildTarget),
publicPath: "/",
filename: isWeb ? "[name].[contenthash:12].js" : "[name].js",
},
mode: isProduction ? "production" : "development",
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
module: {
rules: [
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
{
test: /\.(gif|jpe?g|png)$/,
loader: "url-loader",
options: {
limit: 10000,
name: isWeb ? "[name].[contenthash:12].[ext]" : "[name].[ext]",
},
},
{
test: /\.sass$/,
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
},
{
test: /\.svg$/,
loader: "raw-loader",
},
{
test: /\.(ts|tsx)$/,
include: path.resolve("./src"),
loader: "ts-loader",
},
],
},
plugins: [
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{ from: "target/shared" },
{
from: `target/${buildTarget}`,
filter: (path) => !path.includes("index.html"),
},
],
}),
new HtmlWebpackPlugin({
template: `./target/${buildTarget}/index.html`,
}),
new MiniCssExtractPlugin({
filename: isWeb ? "[name].[contenthash:12].css" : "[name].css",
}),
new webpack.DefinePlugin({
BUILD_TARGET: JSON.stringify(buildTarget),
DEV: JSON.stringify(!isProduction),
GIPHY_API_KEY: JSON.stringify(process.env.GIPHY_API_KEY),
VERSION: JSON.stringify(version),
UNSPLASH_API_KEY: JSON.stringify(process.env.UNSPLASH_API_KEY),
}),
],
devtool: isWeb || !isProduction ? "source-map" : false,
stats: {
warnings: false,
},
};
if (isProduction) {
config.plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
}),
);
}
if (!isWeb) {
config.plugins.push(
new webpack.ProvidePlugin({
browser: "webextension-polyfill",
}),
);
}
if (isWeb && isProduction) {
config.plugins.push(
new workbox.GenerateSW({
cacheId: "tabliss-cache",
dontCacheBustURLsMatching: /\.\w{12}\./,
}),
);
}
module.exports = config;