проект
../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 }
) тоже в порядке.
Любое тело может мне помочь?