diff2html/webpack.website.ts

147 lines
3.8 KiB
TypeScript
Raw Normal View History

2019-12-29 22:31:32 +00:00
import path from 'path';
2019-12-29 22:31:32 +00:00
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
2019-12-29 22:31:32 +00:00
const pages = ['index', 'demo'];
const config: webpack.Configuration[] = pages.map(page => {
return {
devServer: {
port: 3000,
open: true,
2019-12-29 22:31:32 +00:00
contentBase: path.join(__dirname, './website'),
},
entry: {
2019-12-29 22:31:32 +00:00
[page]: `./website/templates/pages/${page}/${page}.ts`,
},
output: {
2019-12-29 22:31:32 +00:00
path: path.resolve(__dirname, './docs'),
},
resolve: {
2019-12-29 22:31:32 +00:00
extensions: ['.tsx', '.ts', '.jsx', '.js'],
},
module: {
rules: [
{
test: /\.tsx?$/,
2019-12-29 22:31:32 +00:00
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.handlebars$/,
2019-12-29 22:31:32 +00:00
loader: 'handlebars-loader',
options: {
precompileOptions: {
2019-12-29 22:31:32 +00:00
knownHelpersOnly: false,
},
2019-12-29 22:31:32 +00:00
helperDirs: [path.join(__dirname, 'website/templates/helpers')],
partialDirs: [path.join(__dirname, 'website/templates')],
},
},
{
test: /\.(css)$/,
2019-12-29 22:31:32 +00:00
use: [MiniCssExtractPlugin.loader, { loader: 'css-loader', options: { importLoaders: 1 } }, 'postcss-loader'],
},
{
test: /\.(html)$/,
use: {
2019-12-29 22:31:32 +00:00
loader: 'html-loader',
options: {
2019-12-29 22:31:32 +00:00
attrs: ['img:src'],
},
},
},
{
2019-12-29 22:31:32 +00:00
test: /\.woff(2)?(\?v=\d\.\d\.\d)?$/,
use: [
{
2019-12-29 22:31:32 +00:00
loader: 'url-loader',
options: {
limit: 1000,
2019-12-29 22:31:32 +00:00
mimetype: 'application/font-woff',
},
},
],
},
{
2019-12-29 22:31:32 +00:00
test: /\.(ttf|eot|svg)(\?v=\d\.\d\.\d)?$/,
loader: 'file-loader',
},
{
test: /\.(jpeg|jpg|png|gif)$/,
use: [
{
2019-12-29 22:31:32 +00:00
loader: 'file-loader',
options: {
2019-12-29 22:31:32 +00:00
name: '[name].[ext]',
outputPath: 'images/',
useRelativePath: true,
},
},
{
2019-12-29 22:31:32 +00:00
loader: 'image-webpack-loader',
options: {
mozjpeg: {
progressive: true,
2019-12-29 22:31:32 +00:00
quality: 65,
},
optipng: {
2019-12-29 22:31:32 +00:00
enabled: true,
},
pngquant: {
quality: [0.65, 0.9],
2019-12-29 22:31:32 +00:00
speed: 4,
},
gifsicle: {
2019-12-29 22:31:32 +00:00
interlaced: false,
},
webp: {
2019-12-29 22:31:32 +00:00
quality: 75,
},
},
},
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
2019-12-29 22:31:32 +00:00
filename: '[name].css',
chunkFilename: '[id].css',
}),
new HtmlWebpackPlugin({
hash: true,
inject: true,
title: `${page} page`,
filename: `${page}.html`,
template: `./website/templates/pages/${page}/${page}.handlebars`,
2019-12-29 22:31:32 +00:00
minify: {
html5: true,
collapseWhitespace: true,
caseSensitive: true,
removeEmptyElements: false,
removeComments: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
2019-12-29 22:31:32 +00:00
minifyURLs: true,
},
}),
new CopyWebpackPlugin([
2019-12-29 22:31:32 +00:00
{ from: 'website/favicon.ico', to: 'favicon.ico' },
{ from: 'website/robots.txt', to: 'robots.txt' },
{ from: 'website/sitemap.xml', to: 'sitemap.xml' },
]),
],
};
});
export default config;