This repository has been archived by the owner on May 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathwebpack.server.js
128 lines (102 loc) · 4.02 KB
/
webpack.server.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
let Fs = require("fs")
let Path = require("path")
let {assoc, map, reduce} = require("ramda")
let {Base64} = require("js-base64")
let Webpack = require("webpack")
let {NODE_MODULES_DIR, COMMON_DIR, FRONTEND_DIR, BACKEND_DIR, PUBLIC_DIR} = require("common/constants")
// Paths to minified library distributions relative to the root node_modules
const MINIFIED_DEPS = [
"moment/min/moment.min.js",
]
const API_AUTH = process.env.hasOwnProperty("API_USER_NAME") && process.env.hasOwnProperty("API_USER_PASS")
? "Basic " + Base64.encode(process.env.API_USER_NAME + ":" + process.env.API_USER_PASS)
: undefined
const DEFINE = {
"process.env": {
"NODE_ENV": JSON.stringify(process.env.NODE_ENV),
},
"config": {
"api-auth": JSON.stringify(API_AUTH),
},
}
module.exports = {
// http://webpack.github.io/docs/configuration.html#target
target: "web",
// http://webpack.github.io/docs/configuration.html#entry
entry: {
bundle: "./frontend/app",
},
// http://webpack.github.io/docs/configuration.html#output
output: {
// http://webpack.github.io/docs/configuration.html#output-path
path: PUBLIC_DIR,
// http://webpack.github.io/docs/configuration.html#output-filename
filename: "[name].js",
// http://webpack.github.io/docs/configuration.html#output-publicpath
publicPath: "http://localhost:2992/public/",
// http://webpack.github.io/docs/configuration.html#output-pathinfo
pathinfo: true,
},
// http://webpack.github.io/docs/configuration.html#debug
debug: true,
// http://webpack.github.io/docs/configuration.html#devtool
devtool: null,
// http://webpack.github.io/docs/configuration.html#profile
profile: false,
// http://webpack.github.io/docs/configuration.html#module
module: {
noParse: map(dep => {
return Path.resolve(NODE_MODULES_DIR, dep)
}, MINIFIED_DEPS),
// http://webpack.github.io/docs/loaders.html
loaders: [
// https://github.com/babel/babel-loader
{test: /\.(js(\?.*)?)$/, loaders: ["babel-loader"], exclude: /node_modules/},
// https://github.com/webpack/json-loader
{test: /\.(json(\?.*)?)$/, loaders: ["json"]},
{test: /\.(json5(\?.*)?)$/, loaders: ["json5"]},
// https://github.com/webpack/css-loader
{test: /\.(css(\?.*)?)$/, loaders: ["style", "css?sourceMap"]},
// https://github.com/webpack/less-loader
{test: /\.(less(\?.*)?)$/, loaders: ["style", "css?sourceMap", "less?sourceMap"]},
// https://github.com/webpack/url-loader
{test: /\.(jpg(\?.*)?)$/, loaders: ["url?limit=10000"]},
{test: /\.(jpeg(\?.*)?)$/, loaders: ["url?limit=10000"]},
{test: /\.(png(\?.*)?)$/, loaders: ["url?limit=10000"]},
{test: /\.(gif(\?.*)?)$/, loaders: ["url?limit=10000"]},
{test: /\.(svg(\?.*)?)$/, loaders: ["url?limit=10000"]},
{test: /\.(woff(\?.*)?)$/, loaders: ["url?limit=100000"]},
{test: /\.(woff2(\?.*)?)$/, loaders: ["url?limit=100000"]},
// https://github.com/webpack/file-loader
{test: /\.(ttf(\?.*)?)$/, loaders: ["file"]},
{test: /\.(eot(\?.*)?)$/, loaders: ["file"]},
{test: /\.(wav(\?.*)?)$/, loaders: ["file"]},
{test: /\.(mp3(\?.*)?)$/, loaders: ["file"]},
// https://github.com/webpack/raw-loader
{test: /\.(txt(\?.*)?)$/, loaders: ["raw"]},
],
},
// http://webpack.github.io/docs/configuration.html#resolve
resolve: {
root: FRONTEND_DIR,
modulesDirectories: ["web_modules", "node_modules"],
alias: reduce((memo, dep) => {
let depPath = Path.resolve(NODE_MODULES_DIR, dep)
return assoc(dep.split(Path.sep)[0], depPath, memo)
}, {}, MINIFIED_DEPS),
},
// http://webpack.github.io/docs/configuration.html#resolveloader
resolveLoader: {
root: NODE_MODULES_DIR,
},
// http://webpack.github.io/docs/list-of-plugins.html
plugins: [
new Webpack.NoErrorsPlugin(),
new Webpack.IgnorePlugin(/^vertx$/),
new Webpack.DefinePlugin(DEFINE),
new Webpack.optimize.DedupePlugin(),
],
devServer: {
headers: {"Access-Control-Allow-Origin": "*"},
}
}