Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
243 lines (237 loc) · 8.83 KB
/
Copy pathwebpack.config.js
File metadata and controls
243 lines (237 loc) · 8.83 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
const path = require("path");
const webpack = require("webpack");
const merge = require("webpack-merge");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HTMLWebpackPlugin = require("html-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const StringReplacePlugin = require("string-replace-webpack-plugin");
// to extract the css as a separate file
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const PROD_API_URL = "https://api.vivadoc.io:8888/api"
var MODE =
process.env.npm_lifecycle_event === "prod" ? "production" : "development";
var filename = MODE == "production" ? "[name]-[hash].js" : "index.js";
var common = {
mode: MODE,
entry: "./src/index.js",
output: {
path: path.join(__dirname, "dist"),
publicPath: "/",
// webpack -p automatically adds hash when building for production
filename: filename
},
plugins: [
new HTMLWebpackPlugin({
// Use this template to get basic responsive meta tags
template: "src/index.html",
// inject details of output file at end of body
inject: "body"
}),
new StringReplacePlugin()
],
resolve: {
modules: [path.join(__dirname, "src"), "node_modules"],
extensions: [".js", ".elm", ".scss", ".png"]
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.scss$/,
exclude: [/elm-stuff/, /node_modules/],
// see https://github.com/webpack-contrib/css-loader#url
loaders: ["style-loader", "css-loader?url=false", "sass-loader"]
},
{
test: /\.css$/,
exclude: [/elm-stuff/, /node_modules/],
loaders: ["style-loader", "css-loader?url=false"]
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
exclude: [/elm-stuff/, /node_modules/],
loader: "url-loader",
options: {
limit: 10000,
mimetype: "application/font-woff"
}
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
exclude: [/elm-stuff/, /node_modules/],
loader: "file-loader"
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
exclude: [/elm-stuff/, /node_modules/],
loader: "file-loader"
}
]
}
};
if (MODE === "development") {
console.log("Building for dev...");
module.exports = merge(common, {
plugins: [
// Suggested for hot-loading
new webpack.NamedModulesPlugin(),
// Prevents compilation errors causing the hot loader to lose state
new webpack.NoEmitOnErrorsPlugin()
],
module: {
rules: [
{
test: /\.elm$/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /__WEBPACK_CONSTANT_API_BASE_URL__/g,
replacement: function (match, p1, offset, string) {
return "http://localhost:3001/api";
}
},
{
pattern: /__WEBPACK_CONSTANT_OAUTH_CLIENT_ID__/g,
replacement: function(match, p1, offset, string) {
return "Iv1.aca2ea3b5a164445";
}
},
{
pattern: /__WEBPACK_CONSTANT_GITHUB_APP_NAME__/g,
replacement: function(match, p1, offset, string) {
return "vivadocdev"
}
},
{
pattern: /__WEBPACK_CONSTANT_REDIRECT_URI__/g,
replacement: function(match, p1, offset, string) {
return "http://localhost:8080/oauth_redirect";
}
}
]
})
},
{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
use: [
{ loader: "elm-hot-webpack-loader" },
{
loader: "elm-webpack-loader",
options: {
// add Elm's debug overlay to output
debug: true,
forceWatch: true
}
}
]
}
]
},
devServer: {
inline: true,
stats: "errors-only",
contentBase: path.join(__dirname, "src"),
historyApiFallback: true,
// feel free to delete this section if you don't need anything like this
before(app) {
// on port 3000
app.get("/test", function(req, res) {
res.json({ result: "OK" });
});
}
}
});
}
if (MODE === "production") {
console.log("Building for Production...");
module.exports = merge(common, {
plugins: [
// Delete everything from /dist directory and report to user
new CleanWebpackPlugin(["dist"], {
root: __dirname,
exclude: [],
verbose: true,
dry: false
}),
// Copy static assets
new CopyWebpackPlugin([
{ from: "src/assets", to: "assets/" },
{ from: "src/ace", to: "ace" }
]),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: "[name]-[hash].css"
})
],
module: {
rules: [
{
test: /\.elm$/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /__WEBPACK_CONSTANT_API_BASE_URL__/g,
replacement: function (match, p1, offset, string) {
return PROD_API_URL;
}
},
{
pattern: /__WEBPACK_CONSTANT_OAUTH_CLIENT_ID__/g,
replacement: function(match, p1, offset, string) {
return "Iv1.5f4d835ee23e3947";
}
},
{
pattern: /__WEBPACK_CONSTANT_GITHUB_APP_NAME__/g,
replacement: function(match, p1, offset, string) {
return "vivadoc"
}
},
{
pattern: /__WEBPACK_CONSTANT_REDIRECT_URI__/g,
replacement: function(match, p1, offset, string) {
return "https://www.vivadoc.io/oauth_redirect";
}
}
]
})
},
{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
use: {
loader: "elm-webpack-loader",
options: {
optimize: true
}
}
},
{
test: /\.css$/,
exclude: [/elm-stuff/, /node_modules/],
loaders: [
MiniCssExtractPlugin.loader,
"css-loader?url=false"
]
},
{
test: /\.scss$/,
exclude: [/elm-stuff/, /node_modules/],
loaders: [
MiniCssExtractPlugin.loader,
"css-loader?url=false",
"sass-loader"
]
}
]
}
});
}