Пакет Webpack с более чем одной записью не работает - PullRequest
0 голосов
/ 06 апреля 2020

Я создал проект с CRA и извлек из него. Я добавил более одной записи в конфигурацию веб-пакета. Если я создаю и использую вывод, он работает нормально. Но когда я использую команду "npm start", работает только одна запись, и для отдыха в браузере не выполняются никакие сценарии.

Пример исходного кода из конфигурации webpack:

// This is the sample entry in webpack config file. Out of these 3 entry only one works fine. Other two doesn't load any modules at runtime. No errors in console as well.
entry: {
      index: getEntryPoint(paths.appIndexJs, isEnvDevelopment, 3000),
      menu: getEntryPoint(paths.menuJs, isEnvDevelopment, 3000),
      background: getEntryPoint(paths.backgroundJs, isEnvDevelopment, 3000),
    },
plugins: [
      // Generates an `index.html` file with the <script> injected.
      getHtmlWebpackPlugin(paths.appHtml, ["index"], "index.html", isEnvProduction),
      getHtmlWebpackPlugin(paths.menuHtml, ["menu"], "menu.html", isEnvProduction),
      getHtmlWebpackPlugin(paths.backgroundHtml, ["background"], "background.html", isEnvProduction),

function getEntryPoint(entryPath, isEnvDevelopment, port) {
  return [
      // Include an alternative client for WebpackDevServer. A client's job is to
      // connect to WebpackDevServer by a socket and get notified about changes.
      // When you save a file, the client will either apply hot updates (in case
      // of CSS changes), or refresh the page (in case of JS changes). When you
      // make a syntax error, this client will display a syntax error overlay.
      // Note: instead of the default WebpackDevServer client, we use a custom one
      // to bring better experience for Create React App users. You can replace
      // the line below with these two lines if you prefer the stock client:
      // require.resolve('webpack-dev-server/client') + '?/',
      // require.resolve('webpack/hot/dev-server'),
      isEnvDevelopment &&
        require.resolve('react-dev-utils/webpackHotDevClient'),
        //require.resolve('webpack-dev-server/client') + '?/',
        //require.resolve('webpack/hot/dev-server'),
      // Finally, this is your app's code:
      entryPath,
      // We include the app code last so that if there is a runtime error during
      // initialization, it doesn't blow up the WebpackDevServer client, and
      // changing JS code would still trigger a refresh.
  ].filter(Boolean);

function getHtmlWebpackPlugin(template, chunks, filename, isEnvProduction) {
  return new HtmlWebpackPlugin(
    Object.assign(
      {},
      {
        inject: true,
        template,
        chunks,
        filename
      },
      isEnvProduction
        ? {
          minify: {
            removeComments: true,
            collapseWhitespace: true,
            removeRedundantAttributes: true,
            useShortDoctype: true,
            removeEmptyAttributes: true,
            removeStyleLinkTypeAttributes: true,
            keepClosingSlash: true,
            minifyJS: true,
            minifyCSS: true,
            minifyURLs: true,
          },
        }
        : undefined
    )
  );
}

Я пытаюсь получить доступ к следующему URL из браузера на основе записи, определенной в приведенном выше коде.

    - http://localhost:3000/index.html
    - http://localhost:3000/menu.html
    - http://localhost:3000/background.html

Вы можете загрузить полный пример кода со следующего URL, если вы хотел бы воспроизвести проблему и попробовать. Включен файл README во вложении с инструкциями по воспроизведению проблемы: https://drive.google.com/file/d/1Bg8o0ydE8RujMu3dj80kWrUVc3XVKOoZ/view?usp=sharing

Любая помощь очень ценится.

...