forked from joelshepherd/tabliss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
113 lines (107 loc) · 2.79 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
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 SWPrecacheWebpackPlugin = require('sw-precache-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: {
main: ['normalize.css', './src/styles.sass', './src/main.tsx'],
},
output: {
path: path.resolve('./dist'),
publicPath: '/',
filename: isWeb ? '[name].[hash: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].[hash:12].[ext]' : '[name].[ext]',
},
},
{
// Thanks, `react-intl`
test: /\.mjs$/,
type: 'javascript/auto',
},
{
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}` }],
}),
new HtmlWebpackPlugin({
template: `./target/${buildTarget}/index.html`,
}),
new MiniCssExtractPlugin({
filename: isWeb ? '[name].[hash:12].css' : '[name].css',
}),
new webpack.EnvironmentPlugin({
BUILD_TARGET: 'web',
API_ENDPOINT: 'https://api.tabliss.io/v1',
SENTRY_PUBLIC_DSN: null,
GIPHY_API_KEY: null,
UNSPLASH_API_KEY: null,
VERSION: version,
}),
],
devServer: {
overlay: true,
},
devtool: isWeb ? 'source-map' : false,
stats: {
warnings: false,
},
};
if (isProduction) {
config.plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
}),
);
}
if (isWeb) {
config.plugins.push(
new SWPrecacheWebpackPlugin({
cacheId: 'tabliss-cache',
dontCacheBustUrlsMatching: /\.\w{12}\./,
filename: 'service-worker.js',
minify: true,
staticFileGlobsIgnorePatterns: [/\.map$/],
}),
);
}
module.exports = config;