在生产中部署react-react-rails应用程序时出错

时间:2016-10-13 09:13:24

标签: ruby-on-rails node.js reactjs webpack react-on-rails

我已经在我们的生产环境(Ubuntu 14.04.3 LTS)上安装了nam和节点,现在尝试部署使用gem react-on-rails实现Redux / ReactJS的rails应用程序。在开发环境中一切都很好,但我觉得我在这里碰壁。

执行npm run build:production时出现问题 这是"构建:生产":" NODE_ENV =生产webpack --config webpack.config.js"

以下是部署期间的日志:

   NODE_ENV=production webpack --config webpack.config.js                                                                                                      

   sh: 1: webpack: not found

   npm ERR! Linux 3.13.0-48-generic
   npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "build:production"
   npm ERR! node v4.6.0
   npm ERR! npm  v2.15.9
   npm ERR! file sh
   npm ERR! code ELIFECYCLE
   npm ERR! errno ENOENT
   npm ERR! syscall spawn
   npm ERR! react-webpack-rails-tutorial@0.0.1 build:production: `NODE_ENV=production webpack --config webpack.config.js`
   npm ERR! spawn ENOENT
   npm ERR!
   npm ERR! Failed at the react-webpack-rails-tutorial@0.0.1 build:production script 'NODE_ENV=production webpack --config webpack.config.js'

这是webpack.config.js文件:

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

const devBuild = process.env.NODE_ENV !== 'production';
const nodeEnv = devBuild ? 'development' : 'production';

const config = {
  entry: [
    'es5-shim/es5-shim',
    'es5-shim/es5-sham',
    'babel-polyfill',
    './app/bundles/Chat/startup/ChatApp'
  ],

  output: {
    filename: 'webpack-bundle.js',
    path: '../app/assets/webpack',
  },

  resolve: {
    extensions: ['', '.js', '.jsx'],
    alias: {
      react: path.resolve('./node_modules/react'),
      'react-dom': path.resolve('./node_modules/react-dom'),
    },
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify(nodeEnv),
      },
    }),
  ],
  module: {
    loaders: [
      {
        test: require.resolve('react'),
        loader: 'imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham',
      },
      {
        test: /\.jsx?$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
      },
    ],
  },
};

module.exports = config;

if (devBuild) {
  console.log('Webpack dev build for Rails'); // eslint-disable-line no-console
  module.exports.devtool = 'eval-source-map';
} else {
  config.plugins.push(
    new webpack.optimize.DedupePlugin()
  );
  console.log('Webpack production build for Rails'); // eslint-disable-line no-console
}

更新了我的package.json

{
  "name": "react-webpack-rails-tutorial",
  "version": "0.0.1",
  "engines": {
    "node": "5.10.0",
    "npm": "3.5.0"
  },
  "scripts": {
    "build:test": "webpack --config webpack.config.js",
    "build:production": "NODE_ENV=production webpack --config webpack.config.js",
    "build:development": "webpack -w --config webpack.config.js"
  },
  "cacheDirectories": ["node_modules", "client/node_modules"],
  "dependencies": {
    "babel": "^6.5.2",
    "babel-cli": "^6.6.5",
    "babel-core": "^6.7.4",
    "babel-loader": "^6.2.4",
    "babel-runtime": "^6.6.1",
    "babel-polyfill": "^6.7.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "babel-preset-stage-0": "^6.5.0",
    "es5-shim": "^4.5.7",
    "expose-loader": "^0.7.1",
    "immutable": "^3.7.6",
    "imports-loader": "^0.6.5",
    "mirror-creator": "1.1.0",
    "react": "^0.14.8 || ^15.0.0",
    "react-dom": "^0.14.8 || ^15.0.0",
    "react-on-rails": "6.1.1",
    "react-redux": "^4.4.1",
    "redux": "^3.3.1",
    "redux-promise": "^0.5.3",
    "redux-thunk": "^2.0.1",
    "webpack": "^1.12.14"
  },
  "devDependencies": {
  }
}

你们有什么想法可能有什么不对吗?我刚刚在生产环境中意识到我有节点v4.6.0,但对rails的反应至少需要节点5。 也许我的问题就在那里..

我的rails项目中的app / assets文件夹下有web pack-bundle.js文件。所以文件不缺少

0 个答案:

没有答案
相关问题