-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
86 lines (80 loc) · 1.92 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
"use strict";
const path = require("path");
const { VueLoaderPlugin } = require("vue-loader");
const dataObj = require("./data/data.json");
module.exports = {
entry: {
app: ["babel-polyfill", "./src/app.js"],
},
output: {
path: path.resolve(__dirname, "./dist"),
publicPath: "/dist/",
filename: "bundle.js",
},
module: {
rules: [
{
test: /\.vue$/,
use: "vue-loader",
},
{
test: /\.scss$/,
use: ["vue-style-loader", "css-loader", "sass-loader"],
},
{
test: /\.(ttf|eot|woff|woff2)$/,
use: {
loader: "url-loader",
options: {
name: "[name].[ext]",
},
},
},
{
test: /\.(png|jpe?g|gif|svg)$/,
use: [
{
loader: "url-loader",
options: {
name: "[name].[contenthash].[ext]",
esModule: false,
},
},
],
},
],
},
plugins: [new VueLoaderPlugin()],
resolve: {
alias: {
fonts: path.resolve(__dirname, "src/assets/fonts"),
},
},
devServer: {
historyApiFallback: true,
contentBase: path.join(__dirname, "public"),
port: 9000,
before: function(app, server, compiler) {
app.get("/api/categories", function(req, res) {
res.json(dataObj.categories);
});
app.get("/api/category/*", function(req, res) {
res.json(dataObj.articles);
});
app.get("/api/author/*", function(req, res) {
let author = {};
const authorId = req.params["0"];
for (let index = 0; index < dataObj.authors.length; index++) {
if (dataObj.authors[index].id === authorId) {
author = dataObj.authors[index];
break;
}
}
res.json(author);
});
app.get("/api/search/*", function(req, res) {
res.json(dataObj.articles);
});
},
},
};