0

我正在测试windowspack系统上的webpack和node.js。 我有此脚本“webpack.config.js”未找到Webpack优化构造函数

var debug = process.env.NODE_ENV !== "production"; 
var webpack = require('webpack'); 

module.exports = { 
    context: __dirname, 
    devtool: debug ? "inline-sourcemap" : null, 
    entry: "./js/scripts.js", 
    output: { 
    path: __dirname + "/js", 
    filename: "scripts.min.js" 
    }, 
    plugins: debug ? [] : [ 
    new webpack.optimize.DedupePlugin(), 
    new webpack.optimize.OccurenceOrderPlugin(), 
    new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }), 
    ], 
}; 

当我打电话的WebPack与生产标签我收到以下错误:

C:\Users\srussell\Desktop\GitHub\nodejsTest\webpack.config.js:14 
    new webpack.optimize.OccurenceOrderPlugin(), 
    ^

TypeError: webpack.optimize.OccurenceOrderPlugin is not a constructor 
    at Object.<anonymous> (C:\Users\srussell\Desktop\GitHub\nodejsTest\webpack.config.js:14:5) 
    at Module._compile (module.js:570:32) 
    at Object.Module._extensions..js (module.js:579:10) 
    at Module.load (module.js:487:32) 
    at tryModuleLoad (module.js:446:12) 
    at Function.Module._load (module.js:438:3) 
    at Module.require (module.js:497:17) 
    at require (internal/module.js:20:19) 
    at requireConfig (C:\Users\srussell\AppData\Roaming\npm\node_modules\webpack\bin\convert-argv.js:96:18) 
    at C:\Users\srussell\AppData\Roaming\npm\node_modules\webpack\bin\convert-argv.js:109:17 

然而,当我从节点控制台运行console.log(require('webpack')); cmd它显示我已安装webpack并且优化功能和方法可用。

C:\Users\srussell\Desktop\GitHub\nodejsTest>node 
> console.log(require('webpack')); 
{ [Function: webpack] 
    WebpackOptionsDefaulter: [Function: WebpackOptionsDefaulter], 
    WebpackOptionsApply: [Function: WebpackOptionsApply], 
    Compiler: { [Function: Compiler] Watching: [Function: Watching] }, 
    MultiCompiler: [Function: MultiCompiler], 
    NodeEnvironmentPlugin: [Function: NodeEnvironmentPlugin], 
    validate: [Function: bound validateSchema], 
    validateSchema: [Function: validateSchema], 
    WebpackOptionsValidationError: [Function: WebpackOptionsValidationError], 
    DefinePlugin: [Getter], 
    NormalModuleReplacementPlugin: [Getter], 
    ContextReplacementPlugin: [Getter], 
    IgnorePlugin: [Getter], 
    WatchIgnorePlugin: [Getter], 
    BannerPlugin: [Getter], 
    PrefetchPlugin: [Getter], 
    AutomaticPrefetchPlugin: [Getter], 
    ProvidePlugin: [Getter], 
    HotModuleReplacementPlugin: [Getter], 
    SourceMapDevToolPlugin: [Getter], 
    EvalSourceMapDevToolPlugin: [Getter], 
    EvalDevToolModulePlugin: [Getter], 
    CachePlugin: [Getter], 
    ExtendedAPIPlugin: [Getter], 
    ExternalsPlugin: [Getter], 
    JsonpTemplatePlugin: [Getter], 
    LibraryTemplatePlugin: [Getter], 
    LoaderTargetPlugin: [Getter], 
    MemoryOutputFileSystem: [Getter], 
    ProgressPlugin: [Getter], 
    SetVarMainTemplatePlugin: [Getter], 
    UmdMainTemplatePlugin: [Getter], 
    NoErrorsPlugin: [Getter], 
    NoEmitOnErrorsPlugin: [Getter], 
    NewWatchingPlugin: [Getter], 
    EnvironmentPlugin: [Getter], 
    DllPlugin: [Getter], 
    DllReferencePlugin: [Getter], 
    LoaderOptionsPlugin: [Getter], 
    NamedModulesPlugin: [Getter], 
    HashedModuleIdsPlugin: [Getter], 
    ModuleFilenameHelpers: [Getter], 
    optimize: 
    { AggressiveMergingPlugin: [Getter], 
    AggressiveSplittingPlugin: [Getter], 
    CommonsChunkPlugin: [Getter], 
    ChunkModuleIdRangePlugin: [Getter], 
    DedupePlugin: [Getter], 
    LimitChunkCountPlugin: [Getter], 
    MinChunkSizePlugin: [Getter], 
    OccurrenceOrderPlugin: [Getter], 
    UglifyJsPlugin: [Getter] }, 
    dependencies: {} } 
undefined 

任何帮助表示赞赏!如果有帮助,这里是项目的链接。 https://github.com/russellsean/nodejsTest

回答

2

傻我...发生有两个'r'字母,我最初有一个。