0

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

执行 npm run build:production 时出现问题,即 "build:production": "NODE_ENV=production 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 文件。所以文件没有丢失

4

0 回答 0