-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.dev.js
94 lines (89 loc) · 3.16 KB
/
webpack.config.dev.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
process.env.NODE_ENV = "development";
process.env.NODE_PATH = ".";
const _ = require("lodash");
const path = require("path");
const webpack = require("webpack");
const glob = require("glob");
const entry = {};
const files = glob.sync("server/web/views/react/*/index.js");
_.each(files, (file) => {
const splitFile = file.split("/");
try {
entry[splitFile[4]] = path.join(__dirname, "/", file);
} catch (err) {
console.error(err); // eslint-disable-line
}
});
// Webpack uses `publicPath` to determine where the app is being served from.
// It requires a trailing slash, or the file assets will get an incorrect path.
const publicPath = "/";
// This is the production configuration.
// It compiles slowly and is focused on producing a fast and minimal bundle.
// The development configuration is different and lives in a separate file.
module.exports = {
mode: "development",
// Don't attempt to continue if there are any errors.
bail: true,
// This is a default provided by running webpack in development mode,
// but we're setting it explicitly here to make it more clear what
// source map tool we're using.
devtool: "eval",
// Add your new react files here
entry,
output: {
path: path.join(__dirname, "/server/web/public/js/react"),
filename: "[name].js", // [name] is the key of the entry point up above
chunkFilename: "[name].[chunkhash:8].chunk.js",
publicPath,
// Point sourcemap entries to original disk location (format as URL on Windows)
// devtoolModuleFilenameTemplate: (info) => {
// return path
// .relative(paths.appSrc, info.absoluteResourcePath)
// .replace(/\\/g, '/');
// },
},
resolve: {
extensions: [".js", ".json", ".jsx"],
},
module: {
strictExportPresence: true,
rules: [
{
test: /\.(js|jsx)$/,
include: path.join(__dirname, "/server"),
exclude: [/node_modules/, /__tests__/],
loader: require.resolve("babel-loader"),
options: {
presets: ["react-app"],
plugins: [
"transform-flow-strip-types",
"transform-es2015-modules-commonjs",
"transform-object-rest-spread",
"transform-decorators-legacy",
],
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
},
},
],
},
plugins: [
// Moment.js is an extremely popular library that bundles large locale files
// by default due to how Webpack interprets its code. This is a practical
// solution that requires the user to opt into importing specific locales.
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
// You can remove this if you don't use Moment.js:
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
dgram: "empty",
fs: "empty",
net: "empty",
tls: "empty",
child_process: "empty",
},
};