-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
116 lines (110 loc) · 3.71 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
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
import path from 'path';
import CopyPlugin from 'copy-webpack-plugin';
import HandlebarsHelpers from 'handlebars-helpers';
import HandlebarsPlugin from 'handlebars-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import SitemapPluginModule from 'sitemap-webpack-plugin';
import SpriteLoaderPlugin from 'svg-sprite-loader/plugin.js';
import RemoveEmptyScriptsPlugin from 'webpack-remove-empty-scripts';
const SitemapPlugin = SitemapPluginModule.default;
// Update this with the list of html files in /pages/en directory
const paths = [
'index.html'
];
const buildpath = {
main: './public',
js: './public/js',
css: './public/css',
images: './public/images/'
};
const webpackCommonConfig = {
entry: {
scripts: './src/assets/js/main.js',
'style-ltr': './src/assets/sass/style-ltr.scss',
'style-rtl': './src/assets/sass/style-rtl.scss'
},
output: {
filename: './src/js/[name].js',
path: path.resolve(buildpath.main),
publicPath: path.resolve('./public')
},
module: {
rules: [
{
test: /\.js?$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.svg$/,
use: [
{
loader: 'svg-sprite-loader',
options: {
extract: true,
spriteFilename: './images/icons.svg'
}
},
'svgo-loader'
]
},
{
test: /\.scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '/'
}
},
'css-loader',
'postcss-loader',
'sass-loader'
]
}
]
},
plugins: [
new CopyPlugin({
patterns: [
{ from: 'src/assets/robots.txt', to: buildpath.main },
{ from: 'src/assets/static', to: buildpath.main },
{ from: 'src/assets/images', to: buildpath.images }
]
}),
new HandlebarsPlugin({
entry: path.join(process.cwd(), 'src', 'pages', '**', '*.html'),
output: path.join(process.cwd(), 'public', '[path]', '[name].html'),
data: './src/assets/data.json',
partials: [
path.join(process.cwd(), 'src', 'partials', '**', '*.html')
],
getPartialId: (filePath) => filePath.match(`^${path.resolve('.')}/src/partials/(.+).html`).pop(),
helpers: {
...HandlebarsHelpers,
inlineArray: (...args) => args.slice(0, -1)
}
}),
new SpriteLoaderPlugin(),
new RemoveEmptyScriptsPlugin({
stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
}),
new MiniCssExtractPlugin({
filename: './src/css/[name].css'
}),
new SitemapPlugin({
base: 'https://prototype.net',
options: {
changefreq: 'weekly',
lastmod: new Date().toISOString().toString(),
priority: 1
},
paths: paths.map((pathItem) => ([
`./en/${pathItem.endsWith('index.html') ? '' : pathItem}`,
`./ar/${pathItem.endsWith('index.html') ? '' : pathItem}`
])).flat()
})
]
};
// eslint-disable-next-line import/no-unused-modules
export default webpackCommonConfig;