2017-07-30 79 views
0

我知道這是webpack的常見問題;如果它不會提供任何有關錯誤原因或位置的信息,那麼調試某些內容確實很困難。webpack - output.filename錯誤

,我發現了錯誤:

Error: 'output.filename' is required, either in config file or as --output-filename 

我知道它有什麼地方有語法錯誤的事,但我太新的WebPack弄明白。

這是我的配置文件。它在根文件夾(即我最初運行的文件夾:npm init)中稱爲「webpack.config.js」。

const webpack = require('webpack'); 
const path = require("path"); 
const ExtractTextPlugin = require("extract-text-webpack-plugin") 
const RewriteImportPlugin = require("less-plugin-rewrite-import"); 

const root_dir = path.resolve(__dirname) 
const src_dir = path.resolve(__dirname, "webpack_src") 
const build_dir = path.resolve(__dirname, "webpack_bin") 
const node_mod_dir = path.resolve(__dirname, 'node_modules'); 
const extractLESS = new ExtractTextPlugin('style.css'); 

const config = { 
    entry: { 
    index: path.resolve(src_dir, 'index.js') 
    }, 
    output: { 
    path: build_dir, 
    filename: 'bundle.js' 
    }, 
    resolve: { 
    modules: [root_dir, 'node_modules'], 
    }, 
    module: { 
    rules: [ 
     { 
     loader: 'babel-loader', 
     test: /\.(js)$/ 
     }, 
     { 
     use: extractLESS.extract({ 
      fallback: 'style-loader', 
      use: [ 
      'css-loader', 
      { 
       loader: 'less-loader', 
       options: { 
       paths: [root_dir, node_mod_dir], 
       plugins: [ 
        new RewriteImportPlugin({ 
        paths: { 
         '../../theme.config': __dirname + '/semantic_ui/theme.config', 
        } 
        }) 
       ] 
       } 
      }] 
     }), 
     test: /\.less$/ 
     }, 
     { 
     use: ['file-loader'], 
     test: /\.(png|jpg|gif|woff|svg|eot|ttf|woff2)$/ 
     }, 
    ] 
    }, 
    plugins: [ 
    extractLESS, 
    new webpack.optimize.ModuleConcatenationPlugin() 
    ] 
}; 

module.exports = { 
    config 
}; 

回答

1

要導出module.exports = { config },這意味着你有一個屬性,即config出口對象,但預計的WebPack對象是整個配置。 Webpack需要output.filename,而您只能提供config.output.filename

出口應該是你的config

module.exports = config; 
+0

這就是它!我看到另一個線程有很多類似的語法建議,但沒有一個提到了括號問題。 – twils0

+0

我(錯誤地)雖然任何方式都可以接受 - 括號或不帶。如果任何人想要一個非Frankenstein(我已經從上面的代碼片段中更正了一些其他的東西),那麼我將使用這個博客來說明如何實現語義 - 用戶反應和無語義的主題,鏈接到git的例子:[neekey](http://neekey.net/2016/12/09/integrate-react-webpack-with-semantic-ui-and-theming/) – twils0