This repository has been archived by the owner on Feb 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
97 lines (93 loc) · 2.55 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
"use strict";
var path = require("path");
var webpack = require("webpack");
var LodashModuleReplacementPlugin = require("lodash-webpack-plugin");
var aliases = require("./util/aliases");
var SRC = path.resolve("src");
var TEST = path.resolve("test");
var PERF = path.resolve("perf");
// **Little Hacky**: Infer the filename and library name from the package name.
//
// Assumptions:
// - `package.json`'s `name` field is name of dist files.
// - PascalCased version of that name is exported class name.
var PKG = require(path.resolve("package.json"));
var libPath = (PKG.name || "").toLowerCase();
if (!libPath) { throw new Error("Need package.json:name field"); }
// PascalCase (with first character capitalized).
var libName = libPath
.replace(/^\s+|\s+$/g, "")
.replace(/(^|[-_ ])+(.)/g, function (match, first, second) {
// Second match group is the character we want to change. Throw away first.
return second.toUpperCase();
});
module.exports = {
cache: true,
context: SRC,
entry: "./index",
externals: [
{
"react": {
root: "React",
commonjs2: "react",
commonjs: "react",
amd: "react"
}
},
{
"prop-types": {
root: "PropTypes",
commonjs2: "prop-types",
commonjs: "prop-types",
amd: "prop-types"
}
}
],
output: {
path: path.resolve("dist"),
filename: libPath + ".min.js",
library: libName,
libraryTarget: "umd"
},
resolve: {
alias: aliases.pkgs
},
module: {
rules: [
{
// Transform source
test: /\.js$/,
// Use include specifically of our sources.
// Do _not_ use an `exclude` here.
include: [SRC, TEST, PERF],
// **Note**: Cannot use shorthand `"babel-loader"` or `"babel"` when
// we are playing around with `NODE_PATH` in builder. Manually
// resolve path.
loader: require.resolve("babel-loader")
}
]
},
plugins: [
new LodashModuleReplacementPlugin({
"currying": true,
"flattening": true,
"paths": true,
"placeholders": true,
"shorthands": true
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.DefinePlugin({
// Signal production, so that webpack removes non-production code that
// is in condtionals like: `if (process.env.NODE_ENV === "production")`
"process.env.NODE_ENV": JSON.stringify("production")
}),
new webpack.SourceMapDevToolPlugin({
filename: "[file].map"
})
]
};