forked from jakeNiemiec/react-floorplanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
150 lines (142 loc) · 3.72 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const webpack = require("webpack");
const path = require("path");
const OpenBrowserPlugin = require("open-browser-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
const fs = require("fs");
const gitRev = require("git-rev-sync");
const Path = require("path");
const getGitLong = () => {
try {
return fs.readFileSync("./REVISION", "utf8").trim();
} catch (e) {
return gitRev.long() || "error";
}
};
/**
* --env.port port
*/
const PAGE_TITLE = "React Planner";
const VENDORS_LIBRARIES = [
"immutable",
"react",
"react-dom",
"react-redux",
"redux",
"three",
];
module.exports = function (env) {
let isProduction = process.env.NODE_ENV === "production";
let isQuiet = env && env.hasOwnProperty("quiet");
let port = env && env.hasOwnProperty("port") ? env.port : 8080;
if (isProduction) console.info("Webpack: Production mode");
else console.info("Webpack: Development mode");
let config = {
context: path.resolve(__dirname),
entry: {
app: path.join(__dirname, "./src/demo/src/renderer.jsx"),
vendor: VENDORS_LIBRARIES,
},
output: {
path: path.join(__dirname, "dist"),
filename: "[chunkhash].[name].js",
},
performance: {
hints: isProduction ? "warning" : false,
},
devtool: isProduction ? "source-map" : "eval",
devServer: {
port: port,
contentBase: path.join(__dirname, "./dist"),
overlay: {
warnings: true,
errors: true,
},
inline: true,
},
resolve: {
extensions: [".js", ".jsx"],
},
module: {
rules: [
{
test: /\.js$|jsx/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
compact: false,
plugins: ["transform-object-rest-spread"],
presets: ["react"],
},
},
],
},
{
test: /\.jpe?g|png|gif|mtl|obj$/i,
use: [
{
loader: "file-loader",
options: {
hash: "sha512",
digest: "hex",
name: "[path][name].[ext]",
context: "demo/src",
},
},
],
},
{
test: /\.ttf|eot|svg|woff(2?)\?[a-z0-9=&.]+?$/,
include: [Path.join(__dirname, "src/assets")],
loader: "file-loader?name=assets/[name].[ext]",
},
],
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: "vendor",
chunks: ["vendor", "app"],
minChunks: 2,
}),
new webpack.optimize.CommonsChunkPlugin({
names: "app",
chunks: ["app"],
minChunks: 2,
}),
new webpack.optimize.CommonsChunkPlugin({
names: ["manifest"],
}),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV || "development"),
},
defineREV: JSON.stringify(getGitLong()),
defineVersion: JSON.stringify(require("./package.json").version),
}),
new HtmlWebpackPlugin({
title: PAGE_TITLE,
template: "./src/demo/src/index.html.ejs",
filename: "index.html",
inject: "body",
}),
],
};
if (isProduction) {
config.plugins.push(
new UglifyJSPlugin({
sourceMap:
config.devtool &&
(config.devtool.indexOf("sourcemap") >= 0 ||
config.devtool.indexOf("source-map") >= 0),
})
);
}
if (!isProduction) {
config.plugins.push(
new OpenBrowserPlugin({ url: `http://localhost:${port}` })
);
}
return config;
};