Разделение кода с зависимостью входа, но появляется ошибка, и моя версия веб-пакета 4.41.6 (самая последняя на данный момент) - PullRequest
0 голосов
/ 28 февраля 2020

проект

../code_splitting_with_entry/
├── package-lock.json
├── package.json
├── src
│   ├── another-module.js
│   └── index.js
└── webpack.config.js

. / Src / index. js

import _ from 'loadsh';

function component() {
    var element = document.createElement('div');

    // Loadsh 现在通过import导入
    element.innerHTML = _.join(['Hello', 'webpack'], ' ');

    return element;
}

document.body.appendChild(component());

другой модуль. js

import _ from 'lodash';

console.log(
  _.join(['Another', 'module', 'loaded!'], ' ')
);

webpack.config. js

const path = require('path');
const webpack = require('webpack')
const {CleanWebpackPlugin} = require('clean-webpack-plugin');

module.exports = {
    mode: 'development',
    entry: {
        index: { import: './src/index.js',dependOn: 'shared'},
        another: { import: './src/another-module.js',dependOn: 'shared' },
        shared: 'loadsh'
    },
    output: {
        filename: '[name].bundle.js',
        path: path.resolve(__dirname, 'dist')
    },
    plugins: [
        new CleanWebpackPlugin()
    ]
}

, но это приведет к следующему результату сборки:


Invalid configuration object. Webpack has been initialised 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['index'] should be a string.
      -> The string is resolved to a module which is loaded upon startup.
    * configuration.entry['index'] should be an array:
      [non-empty string]
      -> A non-empty array of non-empty strings
    * configuration.entry['index'] should be one of these:
      [non-empty string]
      -> All modules are loaded upon startup. The last one is exported.
    * configuration.entry['index'] should be one of these:
      non-empty string | [non-empty string]
      -> An entry point with name

Иногда говорят, что точки входа поддерживают только 1024 * | [string]? Но ссылка говорит мне, что объект (object = { import string | [string], dependOn string | [string], filename string }) тоже в порядке.

Любое тело может мне помочь?

Ответы [ 2 ]

1 голос
/ 02 марта 2020

Я думаю, что вы придерживаетесь этой проблемы при следовании руководству по веб-пакету. Внимательно проверьте версию руководства. Основные документы Webpack (в URL нет версии) предназначены для V5, но дают сбивающий с толку тег «v4.41.6». В нижней части столбца навигации должна быть заметка:

Вы читаете документацию webpack 5. Измените здесь на:

, и там будет ссылка на документы v4.

Веб-рэп pack 的 被困 了 吧。 注意 的 的 的 的 eb eb URL 档 档 档 档 URL URL URL URL URL 版 版 4 4 4 4 4 4 4 4 4 4 版 版 版 4 的 链接.

0 голосов
/ 29 февраля 2020

Я обнаружил, что я использовал 'load sh' в индексе. js, но 'loda sh' в другом модуле. js.

...