-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
120 lines (116 loc) · 3.83 KB
/
webpack.common.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
const fs = require("fs");
const path = require("path");
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
function createHtmlWebpackPluginsForTutorialPages(folderName) {
const htmlPlugins = [];
fs.readdirSync(`./pages/${folderName}`).forEach(pageName => {
const htmlPlugin = new HtmlWebpackPlugin({
template: path.resolve(__dirname, "pages", folderName, pageName, "index.ejs"),
filename: `${folderName}/${pageName}/index.html`,
chunks: ["style", "common", "tutorial"],
inject: true
});
htmlPlugins.push(htmlPlugin);
});
return htmlPlugins;
}
const tutorialPages = createHtmlWebpackPluginsForTutorialPages("tutorial");
const otherTutorialPages = createHtmlWebpackPluginsForTutorialPages("dalsi-tutorialy");
module.exports = {
entry: {
style: './less/main.less',
icons: './icons/main.js',
common: './ts/common/main.ts',
tutorial: './ts/tutorial-page/main.ts'
},
output: {
clean: true
},
module: {
rules: [
{
test: /\.ejs$/i,
use: [{
loader: 'html-loader',
options: {
sources: false
}
}, 'template-ejs-loader']
},
{
test: /(\.ts|\.d.ts)$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.svg$/,
exclude: /css-images/,
use: [
{
loader: 'svg-sprite-loader',
options: {
extract: true,
spriteFilename: "static/icon-sprite.svg"
}
},
{
loader: 'svgo-loader',
options: {
plugins: [
{
name: 'removeAttrs',
params: {
attrs: ['*:fill:(none|black)', '*:stroke:(none|black)']
}
}
]
}
}
]
}
]
},
resolve: {
extensions: ['.ts', '.js']
},
optimization: {
splitChunks: {
chunks: "all"
}
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "pages", "index.ejs"),
chunks: ["style", "common"],
inject: true
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "pages", "popis-zdrojoveho-kodu-projektu", "index.ejs"),
filename: "popis-zdrojoveho-kodu-projektu/index.html",
chunks: ["style", "common", "tutorial"],
inject: true
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "pages", "obsah", "index.ejs"),
filename: "obsah/index.html",
chunks: ["style", "common"],
inject: true
}),
...tutorialPages,
...otherTutorialPages,
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, "static").replace(/\\/g, "/"),
to: path.resolve(__dirname, "dist", "static"),
noErrorOnMissing: true
}
]
}),
new RemoveEmptyScriptsPlugin(),
new SpriteLoaderPlugin()
]
}