133 lines
3 KiB
JavaScript
133 lines
3 KiB
JavaScript
const path = require('path');
|
|
const HtmlWebpackPlugin = require('html-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 Sass = require('sass');
|
|
|
|
const PATHS = {
|
|
entryPoint: path.resolve(__dirname, 'src/index.ts'),
|
|
bundles: path.resolve(__dirname, 'dist'),
|
|
};
|
|
|
|
module.exports = {
|
|
entry: {
|
|
index: PATHS.entryPoint,
|
|
},
|
|
target: 'web',
|
|
output: {
|
|
filename: '[name].[contenthash].js',
|
|
path: PATHS.bundles,
|
|
},
|
|
devtool: 'source-map',
|
|
watchOptions: {
|
|
aggregateTimeout: 600,
|
|
ignored: /node_modules/,
|
|
},
|
|
devServer: {
|
|
host: '0.0.0.0',
|
|
disableHostCheck: true,
|
|
},
|
|
optimization: {
|
|
minimize: true,
|
|
usedExports: true,
|
|
minimizer: [
|
|
new TerserJSPlugin({
|
|
sourceMap: true,
|
|
test: /\.js$/,
|
|
}),
|
|
new OptimizeCSSAssetsPlugin({}),
|
|
],
|
|
},
|
|
plugins: [
|
|
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',
|
|
}),
|
|
],
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.scss$/,
|
|
use: [
|
|
MiniCssExtractPlugin.loader,
|
|
'css-loader',
|
|
'postcss-loader',
|
|
{
|
|
loader: 'resolve-url-loader',
|
|
options: {
|
|
keepQuery: true,
|
|
},
|
|
},
|
|
{
|
|
loader: 'sass-loader',
|
|
options: {
|
|
sourceMap: true,
|
|
implementation: Sass,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
test: /\.ts$/,
|
|
use: {
|
|
loader: 'ts-loader',
|
|
},
|
|
exclude: /node_modules/,
|
|
},
|
|
{
|
|
test: /\.(ico|png|jpg)$/,
|
|
use: {
|
|
loader: 'file-loader',
|
|
query: {
|
|
outputPath: '/',
|
|
name: '[name].[ext]',
|
|
},
|
|
},
|
|
},
|
|
{
|
|
test: /no-change.*(html|txt)$/i,
|
|
use: {
|
|
loader: 'file-loader',
|
|
query: {
|
|
outputPath: '/',
|
|
name: '[name].[ext]',
|
|
},
|
|
},
|
|
},
|
|
{
|
|
test: /\.(svg)$/,
|
|
use: {
|
|
loader: 'file-loader',
|
|
query: {
|
|
outputPath: '/static',
|
|
name: '[name].[ext]',
|
|
},
|
|
},
|
|
},
|
|
{
|
|
test: /\.js$/,
|
|
enforce: 'pre',
|
|
use: ['source-map-loader'],
|
|
},
|
|
],
|
|
},
|
|
resolve: {
|
|
extensions: ['.ts', '.js'],
|
|
},
|
|
};
|