-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.samples.js
More file actions
138 lines (131 loc) · 3.64 KB
/
webpack.samples.js
File metadata and controls
138 lines (131 loc) · 3.64 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
const { mergeWithCustomize } = require('webpack-merge');
const common = require('./webpack.common.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackTagsPlugin = require('html-webpack-tags-plugin');
const { execSync } = require('child_process');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const rdfjsonVersion = execSync('pnpm view @entryscape/rdfjson version')
.toString()
.trim();
const examples = [1, 2, 3, 4, 5, 6, 7];
const getHTMLPlugins = () => {
return [
new HtmlWebpackPlugin({
filename: 'index.html',
template: __dirname + `/html/index.html`,
inject: true,
}),
...examples.map(
(exampleNumber) =>
new HtmlWebpackPlugin({
filename: `example${exampleNumber}/index.html`,
template: __dirname + `/html/example${exampleNumber}/index.html`,
inject: true,
})
),
// append assets for all examples
new HtmlWebpackTagsPlugin({
tags: [
{
path: 'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700',
type: 'css',
publicPath: false,
},
{
path: 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css',
type: 'css',
publicPath: false,
},
{
path: `https://unpkg.com/@entryscape/rdfjson@${rdfjsonVersion}/dist/rdfjson.js`,
type: 'js',
publicPath: false,
},
'styles.css',
],
append: true,
}), // append styles.css to all examples
// append examples' respective js for all html
...examples.map(
(number) =>
new HtmlWebpackTagsPlugin({
files: [`example${number}/**/*.html`],
publicPath: '.',
tags: [
{
path: 'init.js',
attributes: {
type: 'module',
},
},
],
append: true,
})
),
];
};
const getCopyPlugins = (type) =>
new CopyWebpackPlugin({
patterns: [
...examples.map((number) => ({
from: '**/*.js',
context: path.resolve(path.join(__dirname, 'html', `example${number}`)),
to: path.join(__dirname, 'samples', type, `example${number}`),
})),
{
from: path.resolve(path.join(__dirname, 'html', 'chooser')),
to: 'chooser',
},
{
from: path.resolve(path.join(__dirname, 'html', 'templates')),
to: 'templates',
},
{
from: path.resolve(path.join(__dirname, 'html', 'rdf.js')),
to: 'rdf.js',
},
// {
// from: path.resolve(path.join(__dirname, 'html', 'examples.html')),
// to: 'index.html',
// },
{
from: path.resolve(path.join(__dirname, 'html', 'styles.css')),
to: 'styles.css',
},
],
});
const variants = {
type: ['bootstrap', 'react'],
};
function createConfig(options) {
const devConfig = {
entry: `./renderers/${options.type}.js`,
output: {
path: path.join(__dirname, 'samples', options.type),
filename: 'rdforms.js',
clean: true,
},
mode: 'production',
plugins: [...getHTMLPlugins(), getCopyPlugins(options.type)],
resolve: {
fallback: {
fs: false,
},
},
};
// Customizing object behavior
return mergeWithCustomize({
customizeObject(a, b, key) {
if (key === 'entry') {
// Custom merging
return b;
}
// Fall back to default merging
return undefined;
},
})(common, devConfig);
}
module.exports = variants.type.map((variantType) =>
createConfig({ type: variantType })
);