Ошибки конфигурации записей и зависимостей Webpack - PullRequest
0 голосов
/ 03 марта 2020

У меня есть несколько записей, которые все импортируют jQuery. Это дает мне сообщение об ошибке «Несколько блоков генерируют ресурсы для одного и того же имени файла», я предполагаю, что это связано с тем, что jQuery импортируется в каждый файл. Я прочитал документацию Webpack по зависимостям, но она не сработала, когда я попробовал то, что есть в документации. Вот мой текущий конфиг:

const path = require('path');

module.exports = {
    entry: {
        content: './src/content.js',
        header: './src/header.js',
        frontpage:'./src/frontpage.js',
        footer:'./src/footer.js',
        remove:'./src/remove.js',
        results:'./src/results.js'
    },
    output: {
        filename: 'content.js',
        path: path.resolve(__dirname, 'dist'),
    }
};

Из того, что я читал из документов, это должно выглядеть так, но оно продолжало выдавать ошибки, говоря:

Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.entry should be one of these:
   function | object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string]
   -> The entry point(s) of the compilation.
   Details:
    * configuration.entry['frontpage'] should be a string.
      -> The string is resolved to a module which is loaded upon startup.
    * configuration.entry['frontpage'] should be an array:
      [non-empty string]
      -> A non-empty array of non-empty strings
    * configuration.entry['frontpage'] should be one of these:
      [non-empty string]
      -> All modules are loaded upon startup. The last one is exported.
    * configuration.entry['frontpage'] should be one of these:
      non-empty string | [non-empty string]
      -> An entry point with name

Вот эта конфигурация

const path = require('path');
const jquery = require('jquery')
module.exports = {
    entry: {
        content: { import: './src/content.js', dependOn: 'shared' },
        header: { import: './src/header.js', dependOn: 'shared' },
        frontpage: { import: './src/frontpage.js', dependOn: 'shared' },
        footer: { import: './src/footer.js', dependOn: 'shared' },
        remove: { import: './src/remove.js', dependOn: 'shared' },
        results: { import: './src/results.js', dependOn: 'shared' },
        shared: 'jquery'
    },
    output: {
        filename: 'content.js',
        path: path.resolve(__dirname, 'dist'),
    }
};

что я делаю не так?

PS Я пытаюсь сохранить его в одном файле.

Это страница документа, о которой я говорю

1 Ответ

0 голосов
/ 09 марта 2020

Как описано в https://github.com/webpack/webpack/issues/10433 г-ном Смелуковым

зависимость будет доступна, поскольку webpack@5.0.0-beta.14 webpack 4 не поддерживает ее

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...