简体   繁体   English

在Webpack生产配置中找不到Bundle.js

[英]Bundle.js not found on webpack production config

I am using two configuration for webpack, dev and prod for my react app. 我正在为webpack使用两个配置,即我的react应用程序的dev和prod。 The dev works fine but when i use the prod to start an express server, it gives me an error that bundle.js is not found, even though when running the build command it builds the bundle.js in the dist folder. 开发人员工作正常,但是当我使用产品启动快速服务器时,即使运行build命令时,它会在dist文件夹中构建bundle.js,但它却给我一个错误,即没有找到bundle.js。

Here's my webpack.prod.js 这是我的webpack.prod.js

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  devtool: 'source-map',
  entry: './app/app.js',
  output: {
    path: path.join(__dirname, '..', 'dist'),
  filename: 'bundle.js',
},
plugins: [
  new HtmlWebpackPlugin({
  template: 'app/index.html',
  inject: true,
  minify: {
    removeComments: true,
    collapseWhitespace: true,
    removeRedundantAttributes: true,
    useShortDoctype: true,
    removeEmptyAttributes: true,
    removeStyleLinkTypeAttributes: true,
    keepClosingSlash: true,
    minifyJS: true,
    minifyCSS: true,
    minifyURLs: true,
  },
}),
new webpack.DefinePlugin({
  'process.env': {
    NODE_ENV: JSON.stringify('production'),
  },
}),
new webpack.optimize.UglifyJsPlugin({
  minimize: true,
  compress: {
    warnings: false,
   },
 }),
],
module: {
  loaders: [
    {
      test: /.jsx?$/,
      loader: 'babel-loader',
      include: path.join(__dirname, '..', 'app'),
      exclude: /node_modules/,
      query: {
        presets: ['es2015', 'react'],
     },
    },
   {
     test: /\.html$/,
     loader: 'html-loader',
    },
    {
      test: /\.scss$/,
      loaders: ['style-loader', 'css-loader', 'sass-loader'],
    },
  ],
 },
};

my package.json file 我的package.json文件

"scripts": {
    "start": "cross-env NODE_ENV=production node server",
    "dev": "cross-env NODE_ENV=development webpack-dev-server  --config ./webpack/webpack.dev.js --hot --inline",
    "build": "rm -rf dist && webpack --config ./webpack/webpack.prod.js --progress --colors",
    "test": "jest"
},
"dependencies": {
    "boostrap": "^1.0.0",
    "cross-env": "^4.0.0",
    "enzyme-to-json": "^1.5.1",
    "express": "^4.15.2",
    "react": "15.4.1",
    "react-dom": "15.4.1",
    "react-router": "3.0.0",
    "whatwg-fetch": "^2.0.3"
},
"devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-core": "^6.24.1",
    "babel-jest": "^19.0.0",
    "babel-loader": "^6.4.1",
    "babel-polyfill": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "chai": "^3.5.0",
    "css-loader": "^0.28.0",
    "enzyme": "^2.8.2",
    "eslint": "^3.19.0",
    "eslint-config-airbnb": "^14.1.0",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^4.0.0",
    "eslint-plugin-react": "^6.10.3",
    "file-loader": "^0.11.1",
    "html-loader": "^0.4.5",
    "html-webpack-plugin": "^2.28.0",
    "jest": "^19.0.2",
    "node-sass": "^4.5.2",
    "react-addons-test-utils": "^15.5.1",
    "react-hot-loader": "^1.3.1",
    "sass-loader": "^6.0.3",
    "sinon": "^2.1.0",
    "style-loader": "^0.16.1",
    "webpack": "^2.4.1",
    "webpack-dev-middleware": "^1.10.1",
    "webpack-dev-server": "^2.4.2",
    "webpack-hot-middleware": "^2.18.0"
}

As you can see in the directory structure below, dist/bundle.js is clearly present but webpack/express doesn't seem to get it 如您在下面的目录结构中看到的,dist / bundle.js很明显,但是webpack / express似乎没有得到它

project directory : 项目目录:

在此处输入图片说明

Rei Dien提供的解决方案解决了这个问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM