生产中的Javascript包已损坏,但在开发模式下运行良好

问题描述 投票:0回答:1

我有一个带有节点服务器的React应用,几天前我的生产包非常好,但是最近我的生产包已损坏。但是我的开发包工作正常。有人可以查看我的配置并检查我在做什么错。提前致谢。

我的package.json文件是:

{
  "name": "advocacy-app",
  "version": "0.0.1",
  "description": "Advocacy is a platform that helps you amplify the impact of your top advocates. Using this, you can create customizable websites and applications.",
  "author": "Ankita Mehta <[email protected]>",
  "license": "Commercial",
  "scripts": {
    "build": "better-npm-run build",
    "build:dev": "better-npm-run build:dev",
    "build:prod": "better-npm-run build:prod",
    "build:site": "better-npm-run build:site",
    "build:site:dev": "better-npm-run build:site:dev",
    "build:site:prod": "better-npm-run build:site:prod",
    "clean": "rimraf dist-site && rimraf dist-site-server",
    "compile": "better-npm-run compile",
    "compile:server": "better-npm-run compile:server",
    "coverage": "nyc npm test",
    "fakeServer": "nodemon ./node_modules/.bin/babel-node bin/fakeServer.js",
    "lint": "eslint src server config build",
    "lint:css": "stylelint 'src/site/**/*.scss'",
    "lint:fix": "npm run lint -- --fix",
    "mobile": "npm run select-mobile && npm run react-native",
    "mocha": "find ./src -name '*.spec.js' | NODE_ENV=test xargs mocha --compilers js:babel-register,scss:tests/compilers.js --require tests/support.js --reporter spec",
    "react-native": "watchman watch-del-all && react-native start --reset-cache",
    "select-mobile": "rm -f .babelrc && cp .native.babelrc .babelrc",
    "select-web": "rm -f .babelrc && cp .web.babelrc .babelrc",
    "start": "npm run select-web && better-npm-run start",
    "start:prod": "npm run select-web && better-npm-run start:prod"
  },
  "betterScripts": {
    "build": {
      "command": "npm run select-web && npm run clean && npm run compile:server",
      "env": {
        "DEBUG": "app:*"
      }
    },
    "build:dev": {
      "command": "npm run build",
      "env": {
        "DEBUG": "app:*",
        "NODE_ENV": "development"
      }
    },
    "build:prod": {
      "command": "npm run build",
      "env": {
        "DEBUG": "app:*",
        "NODE_ENV": "production"
      }
    },
    "build:site": {
      "command": "npm run select-web && npm run clean && npm run compile",
      "env": {
        "DEBUG": "app:*"
      }
    },
    "build:site:dev": {
      "command": "npm run build:site",
      "env": {
        "DEBUG": "app:*",
        "NODE_ENV": "development"
      }
    },
    "build:site:prod": {
      "command": "npm run build:site",
      "env": {
        "DEBUG": "app:*",
        "NODE_ENV": "production"
      }
    },
    "compile:server": {
      "command": "babel-node bin/compile-server",
      "env": {
        "DEBUG": "app:*",
        "NODE_ENV": "production"
      }
    },
    "compile": {
      "command": "babel-node bin/compile",
      "env": {
        "DEBUG": "app:*"
      }
    },
    "start": {
      "command": "babel-node bin/server",
      "env": {
        "DEBUG": "app:*",
        "NODE_ENV": "development"
      }
    },
    "start:prod": {
      "command": "babel-node bin/server",
      "env": {
        "DEBUG": "app:*",
        "NODE_ENV": "production"
      }
    }
  },
  "dependencies": {
    "@expo/react-native-read-more-text": "^1.0.0",
    "@exponent/react-native-action-sheet": "^0.2.3",
    "autolinker": "^1.2.1",
    "autosize": "^3.0.17",
    "aws-config": "^1.1.3",
    "aws-sdk": "^2.34.0",
    "axios": "^0.14.0",
    "babel-cli": "6.24.0",
    "babel-core": "6.24.0",
    "babel-eslint": "^7.1.1",
    "babel-loader": "^6.2.4",
    "babel-plugin-add-module-exports": "^0.2.1",
    "babel-plugin-transform-class-properties": "6.23.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-export-extensions": "^6.22.0",
    "babel-plugin-transform-runtime": "^6.12.0",
    "babel-polyfill": "^6.9.1",
    "babel-preset-env": "^1.4.0",
    "babel-preset-es2015": "6.24.0",
    "babel-preset-node5": "11.1.0",
    "babel-preset-react": "6.23.0",
    "babel-preset-react-native": "^1.9.1",
    "babel-preset-react-optimize": "^1.0.1",
    "babel-preset-stage-0": "6.22.0",
    "babel-preset-stage-2": "6.22.0",
    "babel-register": "6.24.0",
    "babel-runtime": "^6.9.2",
    "balloon-css": "^0.3.0",
    "base64-stream": "^0.1.3",
    "bem-classnames": "^1.0.7",
    "better-npm-run": "0.0.10",
    "bluebird": "^3.4.6",
    "body-parser": "^1.15.2",
    "bootstrap": "4.0.0-alpha.2",
    "busboy-body-parser": "0.0.10",
    "chai": "^3.5.0",
    "chai-as-promised": "^5.3.0",
    "chai-enzyme": "^0.5.0",
    "chai-string": "^1.2.0",
    "classnames": "^2.2.5",
    "connect-redis": "^3.1.0",
    "crypto-js": "^3.1.9-1",
    "css-loader": "^0.23.1",
    "cssnano": "^3.3.2",
    "csv-parse": "^1.1.7",
    "dataloader": "^1.2.0",
    "debug": "^2.2.0",
    "dotenv": "8.1.0",
    "emoji-mart": "2.1.1",
    "enzyme": "^2.4.1",
    "eslint": "^3.8.1",
    "eslint-config-airbnb": "^9.0.1",
    "eslint-config-standard": "^5.3.5",
    "eslint-config-standard-jsx": "^2.0.0",
    "eslint-config-standard-react": "^3.0.0",
    "eslint-plugin-babel": "^3.3.0",
    "eslint-plugin-flowtype": "^2.20.0",
    "eslint-plugin-import": "^1.11.0",
    "eslint-plugin-jsx-a11y": "^2.0.1",
    "eslint-plugin-promise": "^2.0.0",
    "eslint-plugin-react": "^5.2.2",
    "eslint-plugin-standard": "^2.0.0",
    "eventemitter3": "1.0.2",
    "express": "^4.14.0",
    "express-request-proxy": "^2.0.0",
    "express-session": "^1.14.1",
    "express-winston": "^1.4.2",
    "extract-text-webpack-plugin": "^0.8.2",
    "faker": "^3.1.0",
    "fbjs": "0.8.12",
    "file-loader": "^0.9.0",
    "font-awesome": "^4.6.3",
    "font-awesome-webpack": "0.0.4",
    "form-data": "^1.0.1",
    "fs": "0.0.1-security",
    "git-pre-hooks": "^1.2.0",
    "html-to-react": "^1.2.2",
    "html-webpack-plugin": "^2.7.1",
    "http": "0.0.0",
    "https": "^1.0.0",
    "i18n-webpack-plugin": "^0.3.0",
    "immutability-helper": "^2.0.0",
    "imports-loader": "^0.6.5",
    "isomorphic-style-loader": "^1.0.0",
    "istanbul": "^0.4.4",
    "jscodeshift": "^0.3.32",
    "jsdom": "^9.4.1",
    "json-loader": "^0.5.4",
    "less": "^2.7.1",
    "less-loader": "^2.2.3",
    "lodash": "^4.14.1",
    "material-ui": "^0.15.3",
    "mime": "^1.3.4",
    "mocha": "^3.0.1",
    "moment": "^2.15.1",
    "moment-timezone": "^0.5.5",
    "newrelic": "^1.36.0",
    "node-sass": "^3.8.0",
    "nodemon": "^1.10.2",
    "numeral": "^1.5.3",
    "nyc": "^7.1.0",
    "path": "^0.12.7",
    "postcss-css-variables": "^0.5.1",
    "postcss-loader": "^0.9.0",
    "postcss-nested": "^1.0.0",
    "postcss-scss": "^0.1.9",
    "prop-type": "0.0.1",
    "pusher-js": "^4.0.0",
    "raw-loader": "^0.5.1",
    "react": "15.4.1",
    "react-addons-pure-render-mixin": "15.4.1",
    "react-addons-update": "15.4.1",
    "react-bootstrap": "^0.28.5",
    "react-dnd": "^2.1.4",
    "react-dnd-html5-backend": "^2.1.2",
    "react-dom": "15.4.1",
    "react-emojione": "^5.0.0",
    "react-hot-loader": "^1.3.0",
    "react-html-parser": "2.0.1",
    "react-masonry-component": "6.0.1",
    "react-mentions": "^1.1.0",
    "react-native": "0.42.3",
    "react-native-animatable": "^1.2.2",
    "react-native-calendar": "git+https://[email protected]/Pradeet/react-native-calendar.git",
    "react-native-code-push": "^1.17.3-beta",
    "react-native-cookies": "github:joeferraro/react-native-cookies#3c7b196f2631a13690bed81c9cf31ec1e5d170f8",
    "react-native-device-info": "0.9.9",
    "react-native-drawer": "2.3.0",
    "react-native-dropdown": "git+https://github.com/g6ling/react-native-dropdown.git",
    "react-native-fs": "^2.3.3",
    "react-native-htmlview": "^0.5.0",
    "react-native-image-picker": "0.26.3",
    "react-native-image-resizer": "0.1.1",
    "react-native-keyboard-aware-scroll-view": "0.2.9",
    "react-native-level-fs": "3.0.0",
    "react-native-lightbox": "0.6.0",
    "react-native-linear-gradient": "2.0.0",
    "react-native-media-kit": "github:gauravmnit07/react-native-media-kit#61453aff5f1c3c240359985f60ee4f02019db79e",
    "react-native-modal-datetime-picker": "^4.6.0",
    "react-native-push-notification": "^3.0.0",
    "react-native-root-toast": "^1.0.3",
    "react-native-router-flux": "3.38.0",
    "react-native-scrollable-tab-view": "0.6.3",
    "react-native-search-bar": "3.0.0",
    "react-native-spinkit": "1.0.2",
    "react-native-swipeout": "git+https://github.com/dancormier/react-native-swipeout.git",
    "react-native-vector-icons": "4.2.0",
    "react-native-view-transformer": "0.0.28",
    "react-overlays": "^0.6.2",
    "react-popup": "0.8.0",
    "react-quill": "^1.3.2",
    "react-range": "0.0.7",
    "react-redux": "^5.0.0",
    "react-router": "^2.0.0",
    "react-router-redux": "^4.0.5",
    "react-select": "^1.0.0-beta14",
    "react-wysiwyg": "^2.2.1",
    "redux": "^3.2.1",
    "redux-immutable-state-invariant": "^1.2.3",
    "redux-logger": "^2.6.1",
    "redux-promise-middleware": "^3.3.2",
    "redux-thunk": "^2.1.0",
    "rimraf": "^2.5.4",
    "rn-ios-user-agent": "^1.0.0",
    "rn-nodeify": "github:mvayngrib/rn-nodeify",
    "rn-viewpager": "^1.1.4",
    "rosie": "^1.6.0",
    "sass-loader": "^4.0.0",
    "sinon": "^1.17.5",
    "spr-base-ui": "0.0.1",
    "spr-space-ui": "0.7.4",
    "spr-svg-loader": "0.2.8",
    "spr-web-components": "git+ssh://[email protected]/sprinklr/spr-web-components.git#22e6daeb98c1a3ecfa89f6ed73e2fc3bca8098bb",
    "style-loader": "^0.13.1",
    "stylelint": "^7.1.0",
    "stylelint-loader": "^6.1.0",
    "superagent": "^2.3.0",
    "superagent-no-cache": "^0.1.0",
    "svg-inline-loader": "^0.6.1",
    "twitter-text": "^1.14.0",
    "url-join": "^1.1.0",
    "url-loader": "^0.5.7",
    "url-search-params-polyfill": "4.0.0",
    "uuid-js": "^0.7.5",
    "webpack": "^1.13.1",
    "webpack-dev-middleware": "^1.6.1",
    "webpack-dev-server": "^1.15.0",
    "webpack-hot-middleware": "^2.12.2",
    "winston": "^2.2.0",
    "yargs": "^4.8.1"
  },
  "devDependencies": {
    "reactotron-react-native": "^1.11.1",
    "why-did-you-update": "0.0.8"
  },
  "git-pre-hooks": {
    "pre-commit": [
      "npm run lint",
      "npm run lint:css"
    ],
    "post-commit": "git status",
    "post-checkout": "npm install",
    "post-merge": [
      "npm install"
    ]
  },
  "nyc": {
    "branches": 80,
    "check-coverage": true,
    "functions": 80,
    "lines": 80,
    "statements": 80,
    "reporter": [
      "lcov",
      "text",
      "text-summary"
    ],
    "exclude": [
      "**/*.spec.js",
      "dist",
      "tests"
    ]
  },
  "repository": {
    "type": "git",
    "url": "[email protected]:sprinklr/advocacy-app.git"
  },
  "keywords": [
    "react",
    "redux",
    "advocacy"
  ],
  "engines": {
    "node": "6.3.1",
    "npm": "3.10.6"
  },
  "react-native": {
    "path": "path-browserify",
    "fs": "react-native-level-fs",
    "dgram": "react-native-udp"
  },
  "browser": {
    "path": "path-browserify",
    "fs": "react-native-level-fs",
    "dgram": "react-native-udp"
  }
}

如您所见,我正在使用babel-node编译我的包并提供该包。我对使用bable-node表示怀疑,但是即使我删除了它,我也面临着同样的问题。

我的编译脚本如下:

    import fs from 'fs-extra';
import _debug from 'debug';
import webpackCompiler from '../build/webpack-compiler';
import webpackConfig from '../build/webpack.config';
import config from '../config';

const debug = _debug('app:bin:compile');
const paths = config.utilsPaths;

  ;(async function () {
  try {
    debug('Run compiler');
    const stats = await webpackCompiler(webpackConfig);
    if (stats.warnings.length && config.compiler_fail_on_warning) {
      debug('Config set to fail on warning, exiting with status code "1".');
      process.exit(1)
    }
  } catch (e) {
    debug('Compiler encountered an error.', e);
    process.exit(1)
  }
})();

而且我的webpack配置是:

import webpack from 'webpack';
import path from 'path';
import cssnano from 'cssnano';
import _debug from 'debug';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import I18nPlugin from 'i18n-webpack-plugin';
import {
  get as _get,
} from 'lodash';

import cssvariables from 'postcss-css-variables';

import config from '../config';
import project from '../config/project';

const debug = _debug('app:webpack:config');
const paths = config.utilsPaths;

const {
  __DEV__,
  __PROD__,
  } = config.globals;

const APP_ENTRY_PATHS = [
  'babel-polyfill',
  paths.site('index.js')
];

const LANGUAGES = ['en_US'];

if (__DEV__) {
  APP_ENTRY_PATHS.push('webpack-hot-middleware/client');
}

// CSS loaders
const STYLE_LOADER = 'style-loader';
const CSS_LOADER_WITH_MODULES = `css-loader?${JSON.stringify({
  sourceMap: __DEV__,

  // CSS Modules https://github.com/css-modules/css-modules
  modules: true,
  localIdentName: __DEV__ ? '[name]_[local]' : '[hash:base64:4]', // _[hash:base64:3]

  // CSS Nano http://cssnano.co/options/
  minimize: !__DEV__,
})}`;
const CSS_LOADER = 'css-loader';
const POSTCSS_LOADER = 'postcss';
const SASS_LOADER = 'sass-loader';
const LESS_LOADER = 'less-loader';

debug('Create configuration.');

const bundles = LANGUAGES.map((language) => {
  const languageContent = require(`${paths.site()}/language/${language}.json`);
  const webpackConfig = {
    name: 'client',
    target: 'web',
    devtool: config.compilerDevtool,
    resolve: {
      root: paths.site(),
      extensions: ['', '.js', '.jsx', '.json']
    },
    module: {
      loaders: [{
        test: /\.(js|jsx)$/,
        loader: 'babel',
        include: [
          path.resolve(__dirname, '../src'),
          path.resolve(__dirname, '../config'),
          path.resolve(__dirname, '../server'),
          path.resolve(__dirname, '../node_modules/spr-base-ui'),
          path.resolve(__dirname, '../node_modules/spr-web-components')
        ],
        query: {
          cacheDirectory: true,
          plugins: ['transform-runtime', 'transform-class-properties', 'transform-decorators-legacy', 'add-module-exports', 'transform-export-extensions'],
          presets: ['es2015', 'react', 'stage-2'],
          env: {
            production: {
              presets: ['react-optimize']
            }
          }
        }
      }, {
        test: /\.json$/,
        loader: 'json-loader'
      }, {
        test: /\.scss$/,
        include: [
          path.resolve(__dirname, '../node_modules/spr-space-ui'),
          path.resolve(__dirname, '../node_modules/spr-base-ui'),
          path.resolve(__dirname, '../node_modules/spr-web-components')
        ],
        loaders: [
          STYLE_LOADER,
          CSS_LOADER_WITH_MODULES,
          POSTCSS_LOADER,
          SASS_LOADER
        ]
      }, {
        test: /\.scss$/,
        include: [
          path.resolve(__dirname, '../src')
        ],
        loaders: [
          STYLE_LOADER,
          CSS_LOADER,
          POSTCSS_LOADER,
          SASS_LOADER
        ]
      }, {
        test: /\.less$/,
        loader: [
          STYLE_LOADER,
          CSS_LOADER,
          POSTCSS_LOADER,
          LESS_LOADER
        ]
      }, {
        test: /\.css$/,
        loaders: [
          STYLE_LOADER,
          CSS_LOADER,
          POSTCSS_LOADER
        ]
      }, {
        test: /.asvg$/,
        loader: 'svg-inline'
      }, {
        test: /\.svg$/,
        include: [
          path.resolve(__dirname, '../node_modules/spr-space-ui'),
          path.resolve(__dirname, '../node_modules/spr-base-ui'),
          path.resolve(__dirname, '../src'),
          path.resolve(__dirname, '../node_modules/spr-web-components/'),
        ],
        loader: 'spr-svg-loader!raw-loader'
      }, {
        test: /\.(png|jpg|jpeg|gif|woff|woff2|otf)$/,
        loader: 'url-loader',
        query: {
          name: '[path][name].[ext]?[hash]',
          limit: 10000
        }
      }, {
        test: /\.(eot|ttf|wav|mp3)$/,
        loader: 'file-loader',
        query: {
          name: '[path][name].[ext]?[hash]'
        }
      }, {
        test: /\.(woff2|woff)(\?v=\d+\.\d+\.\d+)?$/,
        loader: 'url',
        query: {
          limit: 10000,
          mimetype: 'application/font-woff'
        }
      }, {
        test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
        loader: 'url',
        query: {
          limit: 10000,
          mimetype: 'application/octet-stream'
        }
      }, {
        test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
        loader: 'file'
      }, {
        test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
        exclude: [
          path.resolve(__dirname, '../node_modules/spr-space-ui'),
          path.resolve(__dirname, '../node_modules/spr-base-ui'),
          path.resolve(__dirname, '../node_modules/spr-web-components/'),
          path.resolve(__dirname, '../src'),
        ],
        loader: 'url',
        query: {
          limit: 10000,
          mimetype: 'image/svg+xml'
        }
      }]
    },
    entry: {
      app: APP_ENTRY_PATHS,
      vendor: config.compilerVendor
    },
    output: {
      filename: `${language}.[name].[${config.compilerHashType}].js`,
      path: paths.dist(),
      publicPath: config.compilerPublicPath
    },
    plugins: [
      // css files from the extract-text-plugin loader
      new ExtractTextPlugin('[name]-[chunkhash].css', { allChunks: true }),
      new webpack.DefinePlugin({ ...config.globals, 'process.env.BROWSER': true }),
      new HtmlWebpackPlugin({
        title: _get(project, 'overview.siteName', 'Untitled'),
        googleAnalytics: {
          trackingId: _get(project, 'overview.googleAnalyticsId', null),
          pageViewOnLoad: true
        },
        template: paths.site('index.html'),
        hash: false,
        filename: 'index.html',
        inject: 'body',
        links: [
          {
            href: _get(project, 'design.favIconUrl', null),
            rel: 'icon',
            type: 'image/png'
          },
          ((_get(project, 'design.variables.fontUrl', '')).indexOf('.css') > -1) ? _get(project, 'design.variables.fontUrl') : null
        ],
        scripts: [],
        meta: _get(project, 'overview.meta', []),
        minify: {
          collapseWhitespace: true
        },
        mobile: true,
        sprChatSettings: _get(project, 'overview.sprChatSettings')
      }),
      new webpack.optimize.OccurenceOrderPlugin()
    ],
    postcss: [
      cssnano({
        autoprefixer: {
          add: true,
          remove: true,
          browsers: ['last 2 versions']
        },
        discardComments: {
          removeAll: true
        },
        discardDuplicates: true,
        discardUnused: false,
        mergeIdents: false,
        reduceIdents: false,
        safe: true,
        sourcemap: true
      }),
      cssvariables({
        variables: _get(project, 'design.variables', {})
      }
      ),
    ],
    sassLoader: {
      includePaths: [
        path.resolve(__dirname, '../node_modules/spr-web-components/'),
      ],
    },
  };
  if (__DEV__) {
    debug('Enable plugins for development.');
    webpackConfig.plugins.push(
      new I18nPlugin(languageContent),
      new webpack.optimize.OccurrenceOrderPlugin(),
      new webpack.HotModuleReplacementPlugin(),
      new webpack.NoErrorsPlugin()
    );
  } else if (__PROD__) {
    debug('Enable plugins for production.');
    webpackConfig.plugins.push(
      new I18nPlugin(languageContent),
      new webpack.optimize.OccurrenceOrderPlugin(),
      new webpack.optimize.DedupePlugin(),
      new webpack.optimize.UglifyJsPlugin({
        compress: {
          unused: true,
          dead_code: true,
          warnings: false
        }
      }),
      new webpack.optimize.AggressiveMergingPlugin()
    );
  }
  return webpackConfig;
});

module.exports = bundles;

enter image description here

node.js reactjs webpack
1个回答
0
投票

我认为该问题可能与生产模式中的缩小有关。您可以尝试在生产模式下禁用缩小功能并检查是否可行吗?

© www.soinside.com 2019 - 2024. All rights reserved.