gpt4 book ai didi

javascript - 使用 webpack-dev-server 时 webpack 构建中缺少 bundle.js

转载 作者:数据小太阳 更新时间:2023-10-29 04:36:19 25 4
gpt4 key购买 nike

我看了类似的,但找不到解决我问题的具体答案。我找不到 bundle.js 文件,即使我指定了它应该输出的位置并且一切都在浏览器中工作。我知道 webpack-dev 服务器正在从内存中加载文件并且没有任何内容被写入磁盘,我如何才能构建文件并将其添加到配置文件中输出属性中指定的目录?

这是我的 package.json:

    {
"name": "redux-simple-starter",
"version": "1.0.0",
"description": "Simple starter package for Redux with React and Babel support",
"main": "index.js",
"repository": "git@github.com:StephenGrider/ReduxSimpleStarter.git",
"scripts": {
"start": "./node_modules/webpack-dev-server/bin/webpack-dev-server.js -- content-base build"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"react-hot-loader": "^1.3.0",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0"
},
"dependencies": {
"babel-preset-stage-1": "^6.1.18",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-redux": "^4.0.0",
"redux": "^3.0.4"
}
}

网络包配置:

    var path = require('path');
var webpack = require('webpack');

module.exports = {
entry: [
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
'./src/index.js'
],
output: {
path: path.join(__dirname, 'assets'),
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [{
exclude: /node_modules/,
loader: 'babel'
}]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
contentBase: './'
},

plugins: [
new webpack.HotModuleReplacementPlugin()
]
};

最佳答案

使用开发服务器时,输出放在上面。所以你实际上不会在你的文件中看到它。从您的 index.html 文件中,您需要从服务器加载它。

例如,对于我的应用程序,我加载了开发服务器、我的 vendor 文件,然后是我自己的代码。

<script src="http://localhost:8080/webpack-dev-server.js"></script>
<script src="http://localhost:8080/build/vendor.js"></script>
<script src="http://localhost:8080/build/app.js"></script>

这是我的 webpack 配置的相关部分。当我还从静态构建包中加载它时,有一些不必要的遗留位。

  app: [
'webpack/hot/dev-server',
'webpack-dev-server/client?http://localhost:8080',
'./client/index.js'
]

},
output: {
path: __dirname + '/client/build',
publicPath: '/build/',
filename: '[name].js',
pathinfo: true
},

关于javascript - 使用 webpack-dev-server 时 webpack 构建中缺少 bundle.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35870100/

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