简体   繁体   中英

Custom startup command for Node.js app on Azure with Babel 6

I'm having the same issue as this question which wasn't really resolved as the original questioner abandoned this route. I'm trying to run a node app on Azure using Babel6. The package.json file I'm using has the following in it:

  "scripts": {
      "start": "node ./node_modules/babel-cli/bin/babel-node.js server.js"
   }

I've checked using the Azure console and the babel-cli node module is installed and the server.js file is in wwwroot . Despite this I get the following when I commit to Azure:

remote: Start script "./node_modules/babel-cli/bin/babel-node.js
        server.js" from package.json is not found.

The npm version running on Azure is 3.10.3, node version is 6.6.0. Can anyone advise on how to get this up and running. Any help much appreciated!

It seems that to run node.js applications in ES2015 on Web Apps. We need to compile them to ES5 version, you can leverage Custom Deployment Script to achieve this.

Here is example repos on GitHub, which leverages gulp and custom deployment script to compile the node.js from ES6 to ES5 via the Azure deployment task.

Specially, this example defines several scripts in package.json for the deployment task calling:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "gulp nodemon",
    "build": "gulp build"
  },

And manually call the npm scripts in deploy.cmd before KuduSync task move the deployment folder to production folder.

:Deployment
echo Handling node.js deployment.

:: 0. Select node version for build
call :SelectNodeVersion

:: 1. Install build dependencies
pushd "%DEPLOYMENT_SOURCE%"
call :ExecuteCmd !NPM_CMD! install --production
IF !ERRORLEVEL! NEQ 0 goto error
popd

:: 2. Run build command
pushd "%DEPLOYMENT_SOURCE%"
call :ExecuteCmd !NPM_CMD! run-script build
IF !ERRORLEVEL! NEQ 0 goto error
popd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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