webpack打包的时候报错,错在哪了

发布于 2022-09-06 01:24:17 字数 4759 浏览 23 评论 0

我在打包的时候报了这个错

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:
   object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string] | function
   The entry point(s) of the compilation.
   Details:
    * configuration.entry['main'] should be a string.
    * configuration.entry['main'] should NOT have duplicate items (items ## 0 and 1 are identical) ({
        "keyword": "uniqueItems",
        "dataPath": ".entry['main']",
        "schemaPath": "#/definitions/common.nonEmptyArrayOfUniqueStringValues/uniqueItems",
        "params": {
          "i": 1,
          "j": 0
        },
        "message": "should NOT have duplicate items (items ## 0 and 1 are identical)",
        "schema": true,
        "parentSchema": {
          "items": {
            "minLength": 1,
            "type": "string"
          },
          "minItems": 1,
          "type": "array",
          "uniqueItems": true
        },
        "data": [
          "display-modules",
          "display-modules"
        ]
      }).
      [non-empty string]
    * configuration.entry['main'] should be one of these:
      non-empty string | [non-empty string]
    * configuration.entry should be a string.
    * configuration.entry should be an array:
      [non-empty string]
    * configuration.entry should be an instance of function
      function returning an entry object or a promise..

我的配置文件是这样的

var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');



module.exports = {
    output: {
        path:  __dirname + '/build',
        publicPath:'/build',
        filename: '[name]_[chunkhash:8].js',
        library: '[name]',
    },
    entry: {
        "lib": ['jquery','js-cookie','icheck','store','placeholder','toastr']
    },
    plugins: [
        new webpack.ProvidePlugin({
            'jQuery': 'jquery',
            'window.jQuery':'jquery'
        }),
        new webpack.optimize.UglifyJsPlugin({
            output: {
                comments: false,
            },
            compress: {
                warnings: false
            }
        }),
        new webpack.DllPlugin({
            path: 'manifest.json',
            name: '[name]',
            context: __dirname,
        }),
        new HtmlWebpackPlugin({
            template: 'html-loader!../templates/layout.html',
            filename: '../../templates/layout.html',
            xhtml:true,
            inject: 'head'
        }),
        new HtmlWebpackPlugin({
            template: 'html-loader!../templates/order/order.html',
            filename: '../../templates/order/order.html',
            xhtml:true,
            inject: 'head'
        }),
        new HtmlWebpackPlugin({
            template: 'html-loader!../templates/order/pay.html',
            filename: '../../templates/order/pay.html',
            xhtml:true,
            inject: 'head'
        }),
        new HtmlWebpackPlugin({
            template: 'html-loader!../templates/order/wechat.html',
            filename: '../../templates/order/wechat.html',
            xhtml:true,
            inject: 'head'
        }),
        new HtmlWebpackPlugin({
            template: 'html-loader!../templates/register/organ-cellphone.html',
            filename: '../../templates/register/organ-cellphone.html',
            xhtml:true,
            inject: 'head'
        }),
        new HtmlWebpackPlugin({
            template: 'html-loader!../templates/register/organ-email.html',
            filename: '../../templates/register/organ-email.html',
            xhtml:true,
            inject: 'head'
        }),
        new HtmlWebpackPlugin({
            template: 'html-loader!../templates/register/organ-profile.html',
            filename: '../../templates/register/organ-profile.html',
            xhtml:true,
            inject: 'head'
        }),
        new HtmlWebpackPlugin({
            template: 'html-loader!../templates/register/person-profile.html',
            filename: '../../templates/register/person-profile.html',
            xhtml:true,
            inject: 'head'
        }),
        new HtmlWebpackPlugin({
            template: 'html-loader!../templates/register/person-register.html',
            filename: '../../templates/register/person-register.html',
            xhtml:true,
            inject: 'head'
        }),
        new HtmlWebpackPlugin({
            template: 'html-loader!../templates/login/logout.html',
            filename: '../../templates/login/logout.html',
            xhtml:true,
            inject: 'head'
        })
    ],
};

请问错在哪了呢

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

迷你仙 2022-09-13 01:24:17

你的这个入口文件是错误的, jquery之类的公共模块需要提取出来,参考一下这个插件

还有就是多页面入口和模板插件HtmlWebpackPlugin写成类似这样的形式更好,

const htmlPages = function() {
    const pageDir = path.resolve(__dirname, './src/templates');
    const templateFiles = glob.sync(`${pageDir}/**/*.html`);
    const configHtmlPlugins = [];
    templateFiles.forEach(item => {
        const pageName = item.substring(item.lastIndexOf('\/') + 1, item.lastIndexOf('.'));
        const htmlPlugin = new HtmlWebpackPlugin({
            title: pageName,
            template: item,
            filename: `${pageName}.html`,
            inject: 'body',
            chunks: [pageName],
            hash: true
        });
        configHtmlPlugins.push(htmlPlugin);
    });

    return configHtmlPlugins;
};

module.exports = {
    ...
    plugins: [
        ...htmlPages()
    ]
    ...
}

具体你看下这篇文章吧,写的的很详细webpack多页面的配置,不过这篇博客webpack还在1.*,现在都3.5了, 所以楼主你最好还是要自己看下文档,webpack中文官网

我之前也配了一个简单的多页面的配置文件,你可以参考下,然后在结合自己实际情况来写webpack配置

猫七 2022-09-13 01:24:17

should be a string.

For example

entry: {
    fron: './src/fron.js',
    back: './src/back.js'
}
风和你 2022-09-13 01:24:17

最后怎么解决的?

抱着落日 2022-09-13 01:24:17

我已经找到答案了

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文