Answer the question
In order to leave comments, you need to log in
How to tell Webpack to open a file other than index.html?
Hello.
When you build the project, you get two files admin.html, index.html.
There are two entrypoints in the code itself. By default, the devserver always opens the port specified and the index.html file
Tell me how to create a new command in package.json like npm-start so that it runs admin.html ?
webpack.config
const path = require('path');
const Html = require('html-webpack-plugin');
const { CleanWebpackPlugin: Clean } = require('clean-webpack-plugin');
const Copy = require('copy-webpack-plugin');
const MomentLocales = require('moment-locales-webpack-plugin');
module.exports = {
entry: {
admin: './src/admin.entrypoint.js',
public: './src/public.entrypoint.js',
},
output: {
filename: '[name].js',
path: path.join(__dirname, 'dist'),
publicPath: '/',
},
module: {
rules: [
{
test: /\.jsx?$/i,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.s[ac]ss$/i,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.(png|jpg|jpeg|gif|woff|eot|ttf|otf)$/i,
loader: 'file-loader',
options: {
outputPath: 'assets',
},
},
{
test: /\.svg$/,
use: ['@svgr/webpack'],
},
],
},
resolve: {
extensions: ['*', '.js', '.jsx'],
},
plugins: [
new MomentLocales(),
new Clean(),
new Copy([{ from: 'public', to: '.' }]),
new Html({
chunks: ['admin'],
hash: true,
scriptLoading: 'defer',
template: 'public/admin.html',
inject: true,
filename: 'admin.html',
}),
new Html({
chunks: ['public'],
hash: true,
scriptLoading: 'defer',
template: 'public/index.html',
inject: true,
filename: 'index.html',
}),
// new BundleAnalyzer(),
],
devServer: {
disableHostCheck: true,
overlay: {
warnings: true,
errors: true,
},
port: `3000/admin`,
proxy: {
'/api': {
target: 'http://api-dev.greenbrands.ru',
secure: false,
changeOrigin: true,
},
},
},
};
"scripts": {
"preinstall": "npx only-allow npm",
"start": "webpack-dev-server --mode development --open --hot",
"build": "webpack --mode production",
"server": "nodemon server/index.js"
},
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