-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
131 lines (127 loc) · 3.59 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
const path = require("path");
const fs = require("fs");
const lessToJs = require("less-vars-to-js");
const themeVariables = lessToJs(fs.readFileSync(path.join(__dirname, "./src/app/ant-theme-vars.less"), "utf8"));
//Webpack Plugins
const webpack = require("webpack");
const htmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const compressionPlugin = require("compression-webpack-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const autoprefixer = require("autoprefixer");
const Dotenv = require("dotenv-webpack");
const WorkboxPlugin = require("workbox-webpack-plugin");
const WebpackPwaManifest = require("webpack-pwa-manifest");
const isDevelopment = process.env.NODE_ENV === "development" ? true : false;
const postcssLoader = {
loader: "postcss-loader",
options: {
ident: "postcss",
sourceMap: true,
plugins: () => [
autoprefixer()
]
}
};
module.exports = {
entry: path.resolve(__dirname, "src/index.js"),
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: "babel-loader",
options: {
plugins: [["import", { libraryName: "antd", style: true }]]
}
},
{
test: [/\.svg$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: "file-loader"
},
{
test: /\.(eot|otf|woff|woff2|ttf)(\?\S*)?$/,
loader: "url-loader"
},
{
test: /\.less$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" },
{
loader: "less-loader",
options: {
modifyVars: themeVariables,
javascriptEnabled: true
}
}
]
},
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: "css-loader", options: { modules: true, localIdentName: "[name]__[local]___[hash:base64:5]", camelCase: true } },
"sass-loader",
postcssLoader
]
}
]
},
devtool: "source-map",
plugins: [
new htmlWebpackPlugin({ template: path.resolve(__dirname, "./src/index.html"), meta: { "theme-color": "#a574ff" } }),
new MiniCssExtractPlugin({
filename: "spotify-style.css",
chunkFilename: "[id].css"
}),
new webpack.HotModuleReplacementPlugin(),
new CleanWebpackPlugin(),
new Dotenv(),
new WorkboxPlugin.GenerateSW({
clientsClaim: true,
skipWaiting: true
}),
new WebpackPwaManifest({
filename: "manifest.json",
name: "Spotify Music App",
short_name: "SpotifyMini",
description: "My Spotify-music app based on spotify-web-api and react.js",
background_color: "#a574ff",
crossorigin: "use-credentials",
icons: [
{
src: path.resolve("static/logo.png"),
sizes: [96, 128, 192, 256, 384, 512]
}
]
})
],
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true
}),
new OptimizeCSSAssetsPlugin({})
]
},
output: {
path: path.resolve(__dirname, "build"),
publicPath: "/",
filename: "spotify-bundle.js"
},
mode: process.env.NODE_ENV,
devServer:
process.env.NODE_ENV === "development"
? {
contentBase: path.join(__dirname, "build"),
hot: true,
compress: true,
historyApiFallback: true,
port: 4000
}
: {}
};