forked from tailwindlabs/webpack-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
47 lines (44 loc) · 1.3 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
const path = require('path')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const fs = require('fs')
// Our function that generates our html plugins
function generateHtmlPlugins (templateDir) {
// Read files in template directory
const templateFiles = fs.readdirSync(path.resolve(__dirname, templateDir))
return templateFiles.map(item => {
// Split names and extension
const parts = item.split('.')
const name = parts[0]
const extension = parts[1]
// Create new HTMLWebpackPlugin with options
return new HtmlWebpackPlugin({
filename: `${name}.html`,
template: path.resolve(__dirname, `${templateDir}/${name}.${extension}`)
})
})
}
const htmlPlugins = generateHtmlPlugins('./src/pages')
module.exports = {
entry: './src/styles.css',
mode: process.env.NODE_ENV,
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{ loader: 'css-loader', options: { importLoaders: 1 } },
'postcss-loader',
],
}),
},
],
},
plugins: [
new ExtractTextPlugin('styles.css', {
disable: process.env.NODE_ENV === 'development',
})
].concat(htmlPlugins)
}