无效的配置Webpack v3.10.0

时间:2018-02-01 11:15:02

标签: node.js webpack

当我尝试运行以下命令时;

node node_modules/webpack/bin/webpack.js --config ./project1/webpack.config.vendor.js --env.prod

我收到以下错误?

  

node:配置对象无效。 Webpack已初始化   使用与API架构不匹配的配置对象。在   line:1 char:1   + node node_modules / webpack / bin / webpack.js --config ./project1 ...   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:NotSpecified :(无效的配置...... API架构。:String)[],RemoteException       + FullyQualifiedErrorId:NativeCommandError

     
      
  • configuration [0] .entry应该是以下之一:object {:非空字符串| [非空字符串]} |非空字符串|   [非空字符串] |功能 - >的入口点   汇编。细节:      
        
    • configuration [0] .entry ['vendor']应该是一个字符串。    - >该字符串被解析为在启动时加载的模块。
    •   
    • 配置[0] .entry ['vendor'] [5]应该是一个字符串。    - >非空字符串
    •   
    • 配置[0] .entry应该是一个字符串。    - >没有名字的入口点。该字符串被解析为在启动时加载的模块。
    •   
    • 配置[0] .entry应该是一个数组:   [非空字符串]
    •   
    • configuration [0] .entry应该是一个函数实例    - >函数返回条目对象,条目字符串,条目数组或对这些东西的承诺。
    •   
  •   
  • 配置[1] .entry应该是以下之一:object {:非空字符串| [非空字符串]} |非空字符串|   [非空字符串] |功能 - >的入口点   汇编。细节:      
        
    • 配置[1] .entry ['vendor']应该是一个字符串。    - >该字符串被解析为在启动时加载的模块。
    •   
    • 配置[1] .entry ['vendor'] [15]应该是一个字符串。    - >非空字符串
    •   
    • 配置[1] .entry应该是一个字符串。    - >没有名字的入口点。该字符串被解析为在启动时加载的模块。
    •   
    • 配置[1] .entry应该是一个数组:   [非空字符串]
    •   
    • 配置[1] .entry应该是一个函数实例    - >函数返回条目对象,条目字符串,条目数组或对这些东西的承诺。
    •   
  •   

我的webpack.config.vendor.js是;

const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const merge = require('webpack-merge');
const treeShakableModules = [
    '@angular/animations',
    '@angular/common',
    '@angular/compiler',
    '@angular/core',
    '@angular/forms',
    '@angular/http',
    '@angular/platform-browser',
    '@angular/platform-browser-dynamic',
    '@angular/router',
    'zone.js',
];
const nonTreeShakableModules = [
    'bootstrap',
    'bootstrap/dist/css/bootstrap.css',
    'es6-promise',
    'es6-shim',
    'event-source-polyfill', ,
    'font-awesome/css/font-awesome.css',
    'ngx-bootstrap',
    'angular2-useful-swiper',
    'jquery'
];
const allModules = treeShakableModules.concat(nonTreeShakableModules);

module.exports = (env) => {
    const extractCSS = new ExtractTextPlugin('vendor.css');
    const isDevBuild = !(env && env.prod);
    const sharedConfig = {
        stats: { modules: false },
        resolve: { extensions: [ '.js' ] },
        module: {
            rules: [
                { test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, use: 'url-loader?limit=100000' }
            ]
        },
        output: {
            publicPath: 'dist/',
            filename: '[name].js',
            library: '[name]_[hash]'
        },
        plugins: [
            new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable)
            new webpack.ContextReplacementPlugin(/\@angular\b.*\b(bundles|linker)/, path.join(__dirname, './ClientApp')), // Workaround for https://github.com/angular/angular/issues/11580
            new webpack.ContextReplacementPlugin(/angular(\\|\/)core(\\|\/)@angular/, path.join(__dirname, './ClientApp')), // Workaround for https://github.com/angular/angular/issues/14898
            new webpack.IgnorePlugin(/^vertx$/) // Workaround for https://github.com/stefanpenner/es6-promise/issues/100
        ]
    };

    const clientBundleConfig = merge(sharedConfig, {
        entry: {
            // To keep development builds fast, include all vendor dependencies in the vendor bundle.
            // But for production builds, leave the tree-shakable ones out so the AOT compiler can produce a smaller bundle.
            vendor: isDevBuild ? allModules : nonTreeShakableModules
        },
        output: { path: path.join(__dirname, 'wwwroot', 'dist') },
        module: {
            rules: [
                { test: /\.css(\?|$)/, use: extractCSS.extract({ use: isDevBuild ? 'css-loader' : 'css-loader?minimize' }) }
            ]
        },
        plugins: [
            extractCSS,
            new webpack.DllPlugin({
                path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'),
                name: '[name]_[hash]'
            })
        ].concat(isDevBuild ? [] : [
            new webpack.optimize.UglifyJsPlugin()
        ])
    });

    const serverBundleConfig = merge(sharedConfig, {
        target: 'node',
        resolve: { mainFields: ['main'] },
        entry: { vendor: allModules.concat(['aspnet-prerendering']) },
        output: {
            path: path.join(__dirname, 'ClientApp', 'dist'),
            libraryTarget: 'commonjs2',
        },
        module: {
            rules: [ { test: /\.css(\?|$)/, use: ['to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize' ] } ]
        },
        plugins: [
            new webpack.DllPlugin({
                path: path.join(__dirname, 'ClientApp', 'dist', '[name]-manifest.json'),
                name: '[name]_[hash]'
            })
        ]
    });

    return [clientBundleConfig, serverBundleConfig];
}

对于completness我的package.json是;

{
  "name": "project1",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "test": "karma start ClientApp/test/karma.conf.js"
  },
  "devDependencies": {
    "@angular/animations": "6.0.0-beta.2",
    "@angular/common": "6.0.0-beta.2",
    "@angular/compiler": "6.0.0-beta.2",
    "@angular/compiler-cli": "6.0.0-beta.2",
    "@angular/core": "6.0.0-beta.2",
    "@angular/forms": "6.0.0-beta.2",
    "@angular/http": "6.0.0-beta.2",
    "@angular/platform-browser": "6.0.0-beta.2",
    "@angular/platform-browser-dynamic": "6.0.0-beta.2",
    "@angular/platform-server": "6.0.0-beta.2",
    "@angular/router": "6.0.0-beta.2",
    "@ngtools/webpack": "1.10.0-beta.3",
    "@types/chai": "4.1.2",
    "@types/jasmine": "2.8.6",
    "@types/webpack-env": "1.13.5",
    "angular2-router-loader": "0.3.5",
    "angular2-template-loader": "0.6.2",
    "angular2-useful-swiper": "5.0.1",
    "aspnet-prerendering": "^3.0.1",
    "aspnet-webpack": "^2.0.1",
    "awesome-typescript-loader": "3.4.1",
    "bootstrap": "4.0.0",
    "chai": "4.1.2",
    "css": "2.2.1",
    "css-loader": "0.28.9",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.12",
    "expose-loader": "0.7.4",
    "extract-text-webpack-plugin": "3.0.2",
    "file-loader": "1.1.6",
    "font-awesome": "4.7.0",
    "html-loader": "0.5.5",
    "isomorphic-fetch": "2.2.1",
    "jasmine-core": "2.9.1",
    "jquery": "3.3.1",
    "json-loader": "0.5.7",
    "karma": "2.0.0",
    "karma-chai": "0.1.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-jasmine": "1.1.1",
    "karma-webpack": "2.0.9",
    "ngx-bootstrap": "2.0.2",
    "preboot": "6.0.0-beta.1",
    "raw-loader": "0.5.1",
    "reflect-metadata": "0.1.12",
    "rxjs": "5.5.6",
    "style-loader": "0.20.1",
    "to-string-loader": "1.1.5",
    "typescript": "2.7.1",
    "url-loader": "0.6.2",
    "webpack": "^3.10.0",
    "webpack-hot-middleware": "2.21.0",
    "webpack-merge": "4.1.1",
    "zone.js": "0.8.20"
  }
}

任何人都可以告诉我发生了什么

0 个答案:

没有答案