-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
58 lines (55 loc) · 1.76 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
const CopyPlugin = require('copy-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const WebpackRTLPlugin = require('webpack-rtl-plugin')
const merge = require('webpack-merge')
// Common Webpack configuration.
const common = require('./webpack.common')
// Configuration for building a Hugo theme in dist/theme.
const build = {
output: {
filename: 'theme/static/[name].js'
},
module: {
rules: [
{
// When merged first, this loader should be the last one used
// to process Sass files.
test: /\.(?:css|scss|sass)$/i,
use: [MiniCssExtractPlugin.loader]
},
{
test: /\.woff2?$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'theme/static/fonts',
publicPath: './fonts/'
}
}
]
},
plugins: [
// Used to copy files into the dist/theme folder.
new CopyPlugin([
{ from: 'layouts', to: 'theme/layouts' },
{ from: 'i18n', to: 'theme/i18n' },
{ from: 'public', to: 'theme' }
]),
// Used to extract a CSS file.
new MiniCssExtractPlugin({
filename: "theme/static/[name].css"
}),
// Used to process an rtl CSS file.
new WebpackRTLPlugin()
]
}
// Merge the required configurations.
module.exports = env => {
// Short circuit check `env` to avoid errors.
if (env && env.prod) {
const prod = require('./webpack.prod')
return merge.smart(build, common, prod)
} else {
return merge.smart(build, common, { mode: 'development' })
}
}