175 lines
4.1 KiB
JavaScript
175 lines
4.1 KiB
JavaScript
const path = require('path');
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
const TerserJSPlugin = require('terser-webpack-plugin');
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
|
|
const Sharp = require('responsive-loader/sharp');
|
|
const Sass = require('sass');
|
|
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
const isDevelopment = !isProduction;
|
|
|
|
module.exports = {
|
|
watchOptions: {
|
|
ignored: /node_modules/,
|
|
},
|
|
//devtool: 'inline-source-map',
|
|
devServer: {
|
|
host: '0.0.0.0',
|
|
disableHostCheck: true,
|
|
},
|
|
optimization: {
|
|
minimizer: [
|
|
new TerserJSPlugin({
|
|
sourceMap: isDevelopment,
|
|
}),
|
|
new OptimizeCSSAssetsPlugin({}),
|
|
],
|
|
},
|
|
plugins: [
|
|
new CleanWebpackPlugin(),
|
|
new HtmlWebpackPlugin({
|
|
xhtml: true,
|
|
template: './src/index.html',
|
|
minify: {
|
|
collapseWhitespace: true,
|
|
removeComments: true,
|
|
removeRedundantAttributes: true,
|
|
removeScriptTypeAttributes: true,
|
|
removeStyleLinkTypeAttributes: true,
|
|
useShortDoctype: true,
|
|
},
|
|
inlineSource: '.(js|css)$',
|
|
}),
|
|
new HtmlWebpackInlineSourcePlugin(),
|
|
new MiniCssExtractPlugin({
|
|
filename: '[name].[contenthash].css',
|
|
chunkFilename: '[id].[contenthash].css',
|
|
}),
|
|
],
|
|
entry: {
|
|
index: './src/index.ts',
|
|
},
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.(jpe?g|png)$/i,
|
|
loader: 'responsive-loader',
|
|
options: {
|
|
adapter: Sharp,
|
|
outputPath: 'static/',
|
|
sizes: [200, 400, 800, 1200, 2000],
|
|
placeholder: false,
|
|
},
|
|
},
|
|
{
|
|
test: /\.(webm|mp4|gif)$/i,
|
|
use: [
|
|
{
|
|
loader: 'file-loader',
|
|
query: {
|
|
outputPath: 'static/',
|
|
},
|
|
},
|
|
{
|
|
loader: 'image-webpack-loader',
|
|
options: {
|
|
disable: !isProduction,
|
|
mozjpeg: {
|
|
progressive: true,
|
|
quality: 65,
|
|
},
|
|
optipng: {
|
|
enabled: true,
|
|
},
|
|
pngquant: {
|
|
quality: [0.65, 0.9],
|
|
speed: 4,
|
|
},
|
|
gifsicle: {
|
|
interlaced: false,
|
|
},
|
|
webp: {
|
|
quality: 65,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
test: /\.svg$/,
|
|
loader: 'svg-url-loader',
|
|
options: {
|
|
limit: 10 * 1024,
|
|
noquotes: true,
|
|
},
|
|
},
|
|
{
|
|
test: /\.(pdf)$/i,
|
|
use: {
|
|
loader: 'file-loader',
|
|
query: {
|
|
outputPath: 'static/',
|
|
name: '[name].[ext]',
|
|
},
|
|
},
|
|
},
|
|
{
|
|
test: /no-change.*(ico|html|txt)$/i,
|
|
use: {
|
|
loader: 'file-loader',
|
|
query: {
|
|
outputPath: '/',
|
|
name: '[name].[ext]',
|
|
},
|
|
},
|
|
},
|
|
{
|
|
test: /\.scss$/i,
|
|
use: [
|
|
MiniCssExtractPlugin.loader,
|
|
'css-loader',
|
|
'postcss-loader',
|
|
{
|
|
loader: 'resolve-url-loader',
|
|
options: {
|
|
keepQuery: true,
|
|
},
|
|
},
|
|
{
|
|
loader: 'sass-loader',
|
|
options: {
|
|
sourceMap: true,
|
|
implementation: Sass,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
test: /\.(woff2?|ttf|eot|svg)(?:[?#].+)?$/,
|
|
use: {
|
|
loader: 'file-loader',
|
|
options: {
|
|
name: '[name].[ext]',
|
|
outputPath: 'static/fonts/',
|
|
},
|
|
},
|
|
include: /fonts/,
|
|
},
|
|
{
|
|
test: /\.ts$/,
|
|
use: 'ts-loader',
|
|
exclude: /node_modules/,
|
|
},
|
|
],
|
|
},
|
|
resolve: {
|
|
extensions: ['.ts', '.js'],
|
|
},
|
|
output: {
|
|
filename: '[name].[contenthash].js',
|
|
path: path.resolve(__dirname, 'dist'),
|
|
},
|
|
};
|