2017-08-03 35 views
1

我有一個文件夾結構的反應項目作爲的WebPack多次入境和多次生成文件

  • parentDir
    - >方向1
    - >方向2
    - > DIR3
    - > Dir4

我想我的生成文件目錄特點是parentDir下的結構與

  • 功能
    - > Dir1Bundle
    - > Dir2Bundle
    - > Dir3Bundle
    - > Dir4Bundle

我webpack.config.js文件

var path = require('path'); 

module.exports = [{ 
    output: { 
    path: __dirname + './features/bulletinBoard', 
    publicPath: '/', 
    filename: 'bundle.js' 
    }, 
    entry: './Bulletin_Board/index.js', 
}, { 
    output: { 
    path: __dirname + './features/communityDirectory', 
    publicPath: '/', 
    filename: 'bundle.js' 
    }, 
    entry: './Community_Directory/index.js', 
}]; 

module.exports = { 
    module: { 
    rules: [ 
     {test: /\.js$/, include: path.join(__dirname, 'Bulletin_Board'), loaders: ['babel']}, 
     {test: /(\.css)$/, loaders: ['style', 'css']}, 
     {test: /\.ico$/, loader: 'file?name=[name].[ext]'}, 
     { test: /\.(png|jpg)$/, loader: 'url-loader?limit=500000' }, 
     { test: /\.svg(\?v=\d+.\d+.\d+)?$/, loader: 'url-loader?limit=500000&mimetype=image/svg+xml' }, 
     { test: /\.eot/, loader: 'url-loader?limit=300000&mimetype=application/vnd.ms-fontobject' }, 
     { test: /\.woff2/, loader: 'url-loader?limit=300000&mimetype=application/font-woff2' }, 
     { test: /\.woff/, loader: 'url-loader?limit=300000&mimetype=application/font-woff' }, 
     { test: /\.[ot]tf(\?v=\d+.\d+.\d+)?$/, loader: 'url-loader?limit=300000&mimetype=application/font-ttf' } 
    ] 
    } 
}; 

據我說,一切都很好,但我得到的錯誤爲

webpack 1.15.0 
Usage: https://webpack.github.io/docs/cli.html 

Options: 
    --help, -h, -? 
    --config 
    --context 
    --entry 
    --module-bind 
    --module-bind-post 
    --module-bind-pre 
    --output-path 
    --output-file 
    --output-chunk-file 
    --output-named-chunk-file 
    --output-source-map-file 
    --output-public-path 
    --output-jsonp-function 
    --output-pathinfo 
    --output-library 
    --output-library-target 
    --records-input-path 
    --records-output-path 
    --records-path 
    --define 
    --target 
    --cache                       [default: 
    --watch, -w 
    --watch which closes when stdin ends 
    --watch-aggregate-timeout 
    --watch-poll 
    --hot 
    --debug 
    --devtool 
    --progress 
    --resolve-alias 
    --resolve-loader-alias 
    --optimize-max-chunks 
    --optimize-min-chunk-size 
    --optimize-minimize 
    --optimize-occurence-order 
    --optimize-dedupe 
    --prefetch 
    --provide 
    --labeled-modules 
    --plugin 
    --bail 
    --profile 
    -d         shortcut for --debug --devtool sourcemap --output-pathinfo 
    -p         shortcut for --optimize-minimize 
    --json, -j 
    --colors, -c 
    --sort-modules-by 
    --sort-chunks-by 
    --sort-assets-by 
    --hide-modules 
    --display-exclude 
    --display-modules 
    --display-chunks 
    --display-error-details 
    --display-origins 
    --display-cached 
    --display-cached-assets 
    --display-reasons, --verbose, -v 

Output filename not configured. 

我不知道我在這裏錯過了什麼,我的文件名也是正確的。我的webpack.config.js位於parentDir下。

請幫助我。

回答

0

有很多錯誤的配置文件

您需要導出配置對象不是一個數組

module.exports = [{ 
    // wrong 
    ... 
}] 

module.exports = { 
    //right 
    ... 
} 

,並要覆蓋的module.exports前值,當你裝載機 加入rules

module.exports = { 
    module: { 
    rules: [ 
    ... 
    ] 
    } 
} 

insted的做

module.exports.module = rules: [ 
... 
] 

這將增加一個新的屬性,而不是覆蓋現有

,並使用正確的配置模式是這樣定義多個入口點 和使用複製的WebPack-插件侑文件複製在不同的地方

var path = require('path'); 

module.exports = { 
    entry: [ 
    './Bulletin_Board/index.js', 
    './second_entry_file.js' 
    ], 

    output: { 
    path: __dirname + './features/communityDirectory', 
    publicPath: '/', 
    filename: 'bundle.[name].js' 
    }, 

    module: { 
    rules: [ 
     {test: /\.js$/, include: path.join(__dirname, 'Bulletin_Board'), loaders: ['babel']}, 
     {test: /(\.css)$/, loaders: ['style', 'css']}, 
     {test: /\.ico$/, loader: 'file?name=[name].[ext]'}, 
     { test: /\.(png|jpg)$/, loader: 'url-loader?limit=500000' }, 
     { test: /\.svg(\?v=\d+.\d+.\d+)?$/, loader: 'url-loader?limit=500000&mimetype=image/svg+xml' }, 
     { test: /\.eot/, loader: 'url-loader?limit=300000&mimetype=application/vnd.ms-fontobject' }, 
     { test: /\.woff2/, loader: 'url-loader?limit=300000&mimetype=application/font-woff2' }, 
     { test: /\.woff/, loader: 'url-loader?limit=300000&mimetype=application/font-woff' }, 
     { test: /\.[ot]tf(\?v=\d+.\d+.\d+)?$/, loader: 'url-loader?limit=300000&mimetype=application/font-ttf' } 
    ] 
    } 
}; 
+0

我想輸出也在不同的文件夾「路徑:__dirname +'./features/ [name]'」。是否會在不同文件夾中輸出 –

+0

否這不會給出不同文件夾中的輸出,但有webpack插件女巫會在編譯後將您的文件複製到不同的文件夾中 –

+0

看看這個插件https://github.com/kevlened/複製的WebPack-插件 –