forked from henryzt/Rhythm-Plus-Music-Game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
111 lines (109 loc) · 2.76 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
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const VueLoaderPlugin = require("vue-loader/lib/plugin");
const CopyPlugin = require("copy-webpack-plugin");
const packageJson = require("./package.json");
const version = packageJson.version || 0; //TODO change to ?? once netlify resolves their issue
const versionPrefix = "alpha";
const commitHash = require("child_process")
.execSync("git rev-parse --short HEAD")
.toString()
.trim();
const isProduction = () => process.env.NODE_ENV === "production";
module.exports = {
entry: ["babel-polyfill", path.resolve(__dirname, "src", "main.js")],
mode: "development",
devtool: "source-map",
resolve: { extensions: ["*", ".js"] },
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].[contenthash].bundle.js",
publicPath: "/",
},
devServer: {
contentBase: path.resolve(__dirname, "public"),
host: "0.0.0.0",
port: 3000,
hotOnly: true,
historyApiFallback: true,
clientLogLevel: "warn",
},
optimization: isProduction()
? {
concatenateModules: true,
mergeDuplicateChunks: true,
minimize: true,
nodeEnv: "production",
providedExports: true,
removeAvailableModules: true,
removeEmptyChunks: true,
sideEffects: true,
usedExports: true,
}
: {},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
},
},
},
{
test: /\.vue$/,
loader: "vue-loader",
},
{
test: /\.css$/,
use: [
"vue-style-loader",
{
loader: "css-loader",
options: { importLoaders: 1 },
},
],
},
{
test: /\.(png|jpg|gif)$/i,
use: [
{
loader: "url-loader",
options: {
limit: 8192,
},
},
],
},
{
test: /\.less$/,
use: ["vue-style-loader", "css-loader", "less-loader"],
},
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
VERSION_PREFIX: `"${versionPrefix}"`,
APP_VERSION: `"${version}"`,
COMMIT_HASH: `"${commitHash}"`,
},
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "public", "index.html"),
inject: "body",
}),
new VueLoaderPlugin(),
new CopyPlugin([
{
from: path.resolve(__dirname, "public"),
},
]),
],
};