gpt4 book ai didi

webpack - 如何使用webpack-dev-server多个条目点

转载 作者:行者123 更新时间:2023-12-03 15:01:48 25 4
gpt4 key购买 nike

我想使用webpack-dev-server在一个端口上托管多个入口点。我当前的配置如下:

entry: {
//Application specific code.
main: [
`webpack-dev-server/client?http://${config.HOST}:${config.PORT}`,
'webpack/hot/only-dev-server',
'./app/base.js',
'./app/main.js'
],

login: [
`webpack-dev-server/client?http://${config.HOST}:${config.PORT}`,
'webpack/hot/only-dev-server',
'./app/base.js',
'./app/login.js'
],
},
output: {
path: assetsPath,
publicPath: `http://${config.HOST}:${config.PORT}/public/dist/`,
chunkFilename: "[name].js",
filename: '[name].js',
},


但是似乎现在对我不起作用。有什么帮助吗?

最佳答案

这是工作多个入口点Webpack配置的示例。让我知道是否有帮助。
我使用webpack.optimize.CommonsChunkPlugin('common.js'),自动生成具有常见js部分的common.js文件。

var path = require('path');
var webpack = require('webpack');
var WebpackErrorNotificationPlugin = require('webpack-error-notification')


var buildEntryPoint = function(entryPoint){
return [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
entryPoint
]
}

module.exports = {
devtool: 'eval',
entry: {
search: buildEntryPoint('./src/index'),
generic: buildEntryPoint('./src/index-generic')
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
publicPath: '/static/'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin('common.js'),
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
__CLIENT__: true,
__SERVER__: false,
__DEV__: true,
__DEVTOOLS__: true // <-- Toggle redux-devtools
})
],
resolve: {
alias: {
'redbox-react': path.join(__dirname, '..', '..', 'src')
},
extensions: ['', '.js']
},
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
include: path.join(__dirname, 'src')
}]
}
};

关于webpack - 如何使用webpack-dev-server多个条目点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31844343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com