Juniorrrrr
@Juniorrrrr

Как указать Webpack открыть иной файл помимо index.html?

Здравствуйте.
При билде проекта получается два файла admin.html, index.html.
В самом коде есть два entrypoint. ПО дефолту девсервер всегда открывает порт указанный и файл index.html

Подскажите как создать новую команду в package.json на подобии npm-start так чтобы она запускала 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,
      },
    },
  },
};


Отрывок из package.json

"scripts": {
    "preinstall": "npx only-allow npm",
    "start": "webpack-dev-server --mode development --open --hot",
    "build": "webpack --mode production",
    "server": "nodemon server/index.js"
  },
  • Вопрос задан
  • 486 просмотров
Пригласить эксперта
Ответы на вопрос 1
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы