116 lines
2.8 KiB
JavaScript
116 lines
2.8 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 Sass = require('sass');
|
|
|
|
const isProduction = process.env.NODE_ENV == 'production';
|
|
const isDevelopment = !isProduction;
|
|
|
|
module.exports = {
|
|
watchOptions: {
|
|
ignored: /node_modules/,
|
|
},
|
|
devtool: 'source-map',
|
|
devServer: {
|
|
host: '0.0.0.0',
|
|
disableHostCheck: true,
|
|
},
|
|
optimization: {
|
|
minimize: true,
|
|
minimizer: [
|
|
new TerserJSPlugin({
|
|
sourceMap: isDevelopment,
|
|
cache: true,
|
|
test: /\.ts$/i,
|
|
terserOptions: {
|
|
ecma: 5,
|
|
warnings: true,
|
|
parse: {},
|
|
compress: { defaults: true },
|
|
mangle: true,
|
|
module: false,
|
|
output: null,
|
|
toplevel: true,
|
|
nameCache: null,
|
|
ie8: false,
|
|
keep_classnames: false,
|
|
keep_fnames: false,
|
|
safari10: false,
|
|
},
|
|
}),
|
|
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: /\.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: /\.js$/,
|
|
enforce: 'pre',
|
|
use: ['source-map-loader'],
|
|
},
|
|
{
|
|
test: /\.ts$/,
|
|
use: {
|
|
loader: 'ts-loader',
|
|
},
|
|
exclude: /node_modules/,
|
|
},
|
|
],
|
|
},
|
|
resolve: {
|
|
extensions: ['.ts', '.js'],
|
|
},
|
|
output: {
|
|
filename: '[name].[contenthash].js',
|
|
path: path.resolve(__dirname, 'dist'),
|
|
},
|
|
};
|