-
Notifications
You must be signed in to change notification settings - Fork 416
/
Copy pathwebpack.config.js
177 lines (171 loc) · 5.83 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright (c) 2018-present, GM Cruise LLC
//
// This source code is licensed under the Apache License, Version 2.0,
// found in the LICENSE file in the root directory of this source tree.
// You may not use this file except in compliance with the License.
const rehypePrism = require("@mapbox/rehype-prism");
const CaseSensitivePathsPlugin = require("case-sensitive-paths-webpack-plugin");
const { spawnSync } = require("child_process");
const path = require("path");
const retext = require("retext");
const retextSmartypants = require("retext-smartypants");
const TerserPlugin = require("terser-webpack-plugin");
const visit = require("unist-util-visit");
const webpack = require("webpack");
// Enable smart quotes:
// https://github.com/mdx-js/mdx/blob/ad58be384c07672dc415b3d9d9f45dcebbfd2eb8/docs/advanced/retext-plugins.md
const smartypantsProcessor = retext().use(retextSmartypants);
function remarkSmartypants() {
function transformer(tree) {
visit(tree, "text", (node) => {
node.value = String(smartypantsProcessor.processSync(node.value));
});
}
return transformer;
}
const config = {
ravenUrl: undefined,
currentVersion: "0.0.1",
minimumChromeVersion: parseInt(process.env.MINIMUM_CHROME_VERSION) || 68,
};
const gitInfo = (() => {
const revParse = spawnSync("git", ["rev-parse", "--short", "HEAD"], { timeout: 5000 });
const diffIndex = spawnSync("git", ["diff-index", "--quiet", "HEAD", "--"], { timeout: 5000 });
if (revParse.error) {
console.log("Error getting git commit hash:", revParse.error); // eslint-disable-line no-console
return undefined;
}
if (diffIndex.error) {
console.log("Error getting git status:", diffIndex.error); // eslint-disable-line no-console
}
return {
hash: revParse.status === 0 && revParse.stdout.toString().trim(),
dirty: diffIndex.status && diffIndex.status !== 0,
};
})();
module.exports = {
devtool: "cheap-module-eval-source-map",
entry: {
docs: "./docs/src/index.js",
webvizCoreBundle: "./packages/webviz-core/src/index.js",
},
output: {
path: path.resolve(`${__dirname}/docs/public/dist`),
publicPath: "/dist/",
pathinfo: true,
filename: "[name].js",
devtoolModuleFilenameTemplate: (info) => path.resolve(info.absoluteResourcePath),
},
resolve: {
modules: [path.resolve("."), path.resolve(`${__dirname}/packages`), "node_modules"],
extensions: [".js"],
// Doesn't work properly with linked packages, see
// https://webpack.js.org/configuration/resolve/#resolve-symlinks
// and https://github.com/webpack/webpack/issues/1866
symlinks: false,
},
module: {
strictExportPresence: true,
rules: [
{
test: /\.worker\.js$/,
use: {
loader: "worker-loader",
options: { name: "[name].[ext]?[hash]" },
},
},
{
test: /\.js$/,
exclude: /node_modules/,
use: { loader: "babel-loader?cacheDirectory" },
},
{
test: /\.mdx$/,
use: [
"babel-loader?cacheDirectory",
{
loader: "@mdx-js/loader",
options: {
hastPlugins: [rehypePrism],
mdPlugins: [remarkSmartypants],
},
},
],
},
{ test: /\.md$/, loader: "raw-loader" },
{ test: /\.svg$/, loader: "react-svg-loader" },
{ test: /\.ne$/, loader: "nearley-loader" },
{ test: /\.(png|jpg|gif)$/i, use: [{ loader: "url-loader", options: { limit: 8192 } }] },
{ test: /\.s?css$/, loader: "style-loader", options: { singleton: true } },
{
test: /\.s?css$/,
oneOf: [
{
test: /\.module\./,
loader: "css-loader",
options: { localIdentName: "[path][name]-[sha512:hash:base32:5]--[local]", modules: true, sourceMap: true },
},
{ loader: "css-loader", options: { sourceMap: true } },
],
},
{
test: /\.s?css$/,
loader: "postcss-loader",
options: {
ident: "postcss",
sourceMap: true,
plugins: () => [
require("postcss-flexbugs-fixes"),
require("autoprefixer")({
browsers: [">1%", "last 4 versions", "Firefox ESR", "not ie < 9"],
flexbox: "no-2009",
}),
],
},
},
{ test: /\.scss$/, loader: "sass-loader", options: { sourceMap: true } },
{ test: /\.woff2?$/, loader: "url-loader" },
{ test: /\.(glb|bag)$/, loader: "file-loader" },
],
},
optimization: {
// use Terser instead of Uglify for async iteration (`for await`) support
minimizer: [
new TerserPlugin({
terserOptions: {
mangle: false, // make error stack traces easier to read in production
},
}),
],
},
plugins: [
new webpack.DefinePlugin({
RAVEN_URL: JSON.stringify(config.ravenUrl),
GIT_INFO: JSON.stringify(gitInfo),
CURRENT_VERSION: JSON.stringify(config.currentVersion),
MINIMUM_CHROME_VERSION: JSON.stringify(config.minimumChromeVersion),
}),
new CaseSensitivePathsPlugin(),
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
],
node: {
fs: "empty",
__filename: true,
},
performance: { hints: false },
devServer: {
contentBase: path.resolve(`${__dirname}/docs/public`),
hot: true,
open: true,
},
};
if (process.env.NODE_ENV === "production") {
module.exports.mode = "production";
module.exports.devtool = "source-map";
} else {
module.exports.mode = "development";
module.exports.entry.docs = [module.exports.entry.docs, "webpack-hot-middleware/client"];
module.exports.plugins.push(new webpack.HotModuleReplacementPlugin());
module.exports.output.globalObject = "this"; // Workaround for https://github.com/webpack/webpack/issues/6642#issuecomment-370222543
}