cebg-site/webpack.desktop.dev.js
2022-09-28 19:11:14 +08:00

110 lines
2.8 KiB
JavaScript

const path = require('path')
const glob = require('glob')
var webpack = require('webpack')
const htmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const entryFiles = glob.sync(path.join(__dirname, './src/desktop/*.html'))
const htmlWebpackPlugins = []
// entryFiles.map((entryFile) => {
// const matchRes = entryFile.match(/src\/desktop\/(.*)\.html$/)
// const pageName = matchRes && matchRes[1]
// console.log(pageName)
// htmlWebpackPlugins.push(
// new htmlWebpackPlugin({
// template: path.join(__dirname, `./src/desktop/${pageName}.html`),
// filename: `${pageName}.html`,
// inject: 'body',
// }),
// )
// })
module.exports = {
mode: 'development',
entry: './src/desktop/js/app.js',
output: {
path: path.resolve(__dirname, 'dist/desktop'),
filename: 'js/[name]-[hash].js',
publicPath: './',
assetModuleFilename: 'img/[hash][ext][query]',
},
module: {
rules: [
{
test: /\.(png|jpg|gif|jpeg|svg)$/,
// type: 'asset/resource',
dependency: { not: ['url'] },
loader: 'url-loader',
options: {
name: '[hash].[ext][query]',
limit: 1024 * 10,
outputPath: 'img',
},
},
{
test: /\.(woff|ttf|svg|eot|ico)$/,
use: ['url-loader'],
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, { loader: 'css-loader' }],
},
{
test: /.html$/,
use: [
{
loader: 'html-loader',
options: {
esModule: false,
sources: {
list: [
'...',
{
tag: 'a',
attribute: 'data-bigimg',
type: 'src',
},
{
tag: 'a',
attribute: 'data-imgdetail',
type: 'src',
},
],
},
},
},
'template-ejs-loader',
],
},
// {
// exclude: /\.(css|js|html|json|less|png|jpg|gif|woff|ttf|svg|eot)$/,
// loader: 'file-loader',
// },
],
},
plugins: [
new htmlWebpackPlugin({
template: path.join(__dirname, `./src/desktop/index1.html`),
filename: `index.html`,
inject: 'body',
}),
new MiniCssExtractPlugin(),
].concat(htmlWebpackPlugins),
optimization: {
splitChunks: {
chunks: 'all',
},
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
new OptimizeCssAssetsPlugin(),
],
},
}