61 lines
1.7 KiB
JavaScript
61 lines
1.7 KiB
JavaScript
|
const path = require('path');
|
||
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||
|
|
||
|
module.exports = {
|
||
|
entry: './src/index.js',
|
||
|
output: {
|
||
|
filename: '[name].bundle.js',
|
||
|
path: path.resolve(__dirname, 'dist'),
|
||
|
},
|
||
|
plugins: [
|
||
|
new MiniCssExtractPlugin(),
|
||
|
new CleanWebpackPlugin(),
|
||
|
new HtmlWebpackPlugin({
|
||
|
template: 'src/index.html'
|
||
|
}),
|
||
|
],
|
||
|
module: {
|
||
|
rules: [
|
||
|
{
|
||
|
test: /\.inline\.css$/i,
|
||
|
use: [
|
||
|
{
|
||
|
loader: 'style-loader',
|
||
|
options: {
|
||
|
insert: function insertAtTop(element) {
|
||
|
var parent = document.querySelector('head');
|
||
|
// eslint-disable-next-line no-underscore-dangle
|
||
|
var lastInsertedElement =
|
||
|
window._lastElementInsertedByStyleLoader;
|
||
|
|
||
|
if (!lastInsertedElement) {
|
||
|
parent.insertBefore(element, parent.firstChild);
|
||
|
} else if (lastInsertedElement.nextSibling) {
|
||
|
parent.insertBefore(element, lastInsertedElement.nextSibling);
|
||
|
} else {
|
||
|
parent.appendChild(element);
|
||
|
}
|
||
|
|
||
|
// eslint-disable-next-line no-underscore-dangle
|
||
|
window._lastElementInsertedByStyleLoader = element;
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
'css-loader',
|
||
|
'postcss-loader'],
|
||
|
},
|
||
|
{
|
||
|
test: /\.css$/i,
|
||
|
exclude: /\.inline\.css$/i,
|
||
|
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
|
||
|
},
|
||
|
{
|
||
|
test: /.(png|svg|jpg|jpeg|gif)$/i,
|
||
|
type: 'asset',
|
||
|
},
|
||
|
]
|
||
|
},
|
||
|
};
|