-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.browser.config.js
More file actions
117 lines (116 loc) · 3.18 KB
/
webpack.browser.config.js
File metadata and controls
117 lines (116 loc) · 3.18 KB
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
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { StatsWriterPlugin } = require("webpack-stats-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const globImporter = require("node-sass-glob-importer");
const isOffline = !!process.env.IS_OFFLINE;
module.exports = {
entry: {
main: path.join(__dirname, "src/browser/index.jsx"),
},
target: "web",
mode: isOffline ? "development" : "production",
devServer: {
contentBase: path.join(__dirname, "public"),
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization",
},
},
performance: {
// Turn off size warnings for entry points
hints: false,
},
devtool: "nosources-source-map",
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: isOffline ? "index.css" : "index.[contenthash:8].css",
}),
new StatsWriterPlugin({
transform(data, opts) {
const assets = data.assetsByChunkName.main;
const stats = JSON.stringify(
{
main: assets.find((path) => path.endsWith(".js")),
css: assets.find((path) => path.endsWith(".css")),
},
null,
2,
);
console.log("ASSETS =>", assets);
console.log("STATS =>", stats);
return stats;
},
}),
],
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/, // we shouldn't need processing `node_modules`
use: [
{
loader: "babel-loader",
options: {
// Don't use .babelrc here but web browser optimized settings
presets: [
[
"@babel/preset-env",
{
targets: { browsers: ["last 2 versions"] },
// debug: isOffline,
},
],
"@babel/preset-react",
],
},
},
],
},
{
test: /(\.css|\.scss)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
sourceMap: true,
},
},
{
loader: "postcss-loader",
options: {
plugins: () => [require("autoprefixer")],
sourceMap: true,
},
},
{
loader: "sass-loader",
options: {
includePaths: [path.resolve(__dirname, "./src/browser", "scss")],
sourceMap: true,
importer: globImporter(),
},
},
],
},
{
test: /\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$/,
use: "url-loader",
},
{
test: /\.svg$/,
use: ["@svgr/webpack"],
},
],
},
resolve: {
extensions: [".js", ".jsx"],
},
output: {
path: path.join(__dirname, "dist"),
filename: isOffline ? "index.js" : "index.[contenthash:8].js",
},
};