Answer the question
In order to leave comments, you need to log in
Is it possible in WebPack to output 2 files per page?
I want to minify files, connect modules, etc. through webpack for a WordPress theme.
How to make them see each other, for example, a minified script for the footer and for the header?
My webpack.config.js:
const path = require('path')
const webpack = require('webpack')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const {CleanWebpackPlugin} = require('clean-webpack-plugin')
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
const TerserWebpackPlugin = require('terser-webpack-plugin')
module.exports = {
mode: 'production',
//Входной файл
entry: {
topScripts: './webpackTopScripts.js',
bottomScripts: './webpackBottomScripts.js',
},
//Где лежат исходники
context: path.resolve(__dirname, "assets"),
//Куда складываем
output: {
filename: '[name].min.js',
path: path.resolve(__dirname, "assets/min/js")
},
plugins:[
new MiniCssExtractPlugin({
filename: '../css/style.min.css',
}),
new CleanWebpackPlugin(),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
})
],
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader'
],
},
{
test: /\.(png|jpg|jpeg|svg|gif)$/,
use: ['url-loader']
},
{
test: /\.(ttf|woff|woff2|eot)/,
use: ['url-loader'],
},
{ test: /\.(js)$/, use: 'babel-loader' }
]
},
optimization: {
minimize: true,
minimizer: [
new CssMinimizerPlugin(),
new TerserWebpackPlugin()
],
},
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question