-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
127 lines (121 loc) · 3.12 KB
/
webpack.config.js
File metadata and controls
127 lines (121 loc) · 3.12 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
const path = require('path');
const fs = require("fs");
const webpack = require('webpack');
const NunjucksWebpackPlugin = require("nunjucks-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
let data = JSON.parse(fs.readFileSync(path.join(__dirname, 'data.json'), 'utf8'));
let projects_raw = JSON.parse(JSON.stringify(data.projects))
let prodect_id_map = {}
projects_raw.forEach(proj => {
const {project_id, ...new_obj} = proj
prodect_id_map[project_id] = new_obj
})
data.projects.forEach((item, index) => {
data.projects[index].related_proj = item.related_proj.map(rel => { return data.projects[rel] });
})
let proj_ids = data.projects.map(item => {
return {
from: "./src/html/project.html",
to: `projects/${item.project_id}.html`,
context: {ctx :item, isProject: true},
};
});
let entry_points = { index: './src/js/index.js', published: './src/js/published.js', }
data.projects.forEach(item => entry_points[item.project_id] = "./src/js/project.js");
module.exports = {
entry: entry_points,
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
publicPath: "/"
},
devServer: {
static: [
{
directory: path.join(__dirname, 'dist'),
},
{
directory: path.join(__dirname),
publicPath: '/',
}
],
watchFiles: ['src/**/*', 'data.json']
},
module: {
rules: [
{
test: /\.jsx?/,
exclude: "/node_modules",
use: {loader: 'babel-loader'}
},
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
{loader:"css-loader",
options: {
url: false
},
},
{
loader: 'resolve-url-loader',
// options: {...}
},
{
// Compiles Sass to CSS
loader: 'sass-loader',
options: {
sourceMap: true, // <-- !!IMPORTANT!!
},
}
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'assets/fonts/[name].[ext]',
}
}
]
},
// {
// test: /\.(jpe?g|png|gif|svg)$/i,
// loader: 'file-loader',
// options: {
// name: 'assets/images/[name].[ext]'
// }
// },
// {test: /\.(png|jpg|svg)$/, loader: 'url-loader?limit=8192'},
],
},
node: {
fs: "empty"
},
plugins: [
new NunjucksWebpackPlugin({
templates: [
{
from: "./src/html/index.html",
to: "index.html",
context: data,
},
{
from: "./src/html/published.html",
to: "published.html",
context: data,
},
...proj_ids
],
}),
// Removed data bundling - data is now loaded dynamically via dataService
new CopyWebpackPlugin([
{from:'src/assets/',to:'assets/'},
{from:'data.json',to:'data.json'}
]),
]
};