diff --git a/packages/cli/generators/project/templates/package.json.ejs b/packages/cli/generators/project/templates/package.json.ejs index c08f134813be..acc1a5760570 100644 --- a/packages/cli/generators/project/templates/package.json.ejs +++ b/packages/cli/generators/project/templates/package.json.ejs @@ -61,9 +61,9 @@ <% } -%> <% } -%> <% if (packageManager === 'yarn') { -%> - "pretest": "yarn run clean && yarn run build", + "pretest": "yarn run rebuild", <% } else { -%> - "pretest": "npm run clean && npm run build", + "pretest": "npm run rebuild", <% } -%> <% if (project.mocha) { -%> "test": "lb-mocha --allow-console-logs \"dist/__tests__\"", @@ -94,9 +94,11 @@ "preopenapi-spec": "npm run build", "openapi-spec": "node ./dist/openapi-spec", <% if (packageManager === 'yarn') { -%> - "prestart": "yarn run build", + "rebuild": "yarn run clean && yarn run build", + "prestart": "yarn run rebuild", <% } else { -%> - "prestart": "npm run build", + "rebuild": "npm run clean && npm run build", + "prestart": "npm run rebuild", <% } -%> "start": "node -r source-map-support/register .", <% } -%> diff --git a/packages/cli/generators/project/templates/package.plain.json.ejs b/packages/cli/generators/project/templates/package.plain.json.ejs index 53ce2b72aff3..445acf2ed33f 100644 --- a/packages/cli/generators/project/templates/package.plain.json.ejs +++ b/packages/cli/generators/project/templates/package.plain.json.ejs @@ -62,9 +62,9 @@ <% } -%> <% } -%> <% if (packageManager === 'yarn') { -%> - "pretest": "yarn run clean && yarn run build", + "pretest": "yarn run rebuild", <% } else { -%> - "pretest": "npm run clean && npm run build", + "pretest": "npm run rebuild", <% } -%> <% if (project.mocha) { -%> "test": "mocha dist/__tests__", @@ -93,9 +93,11 @@ "migrate": "node ./dist/migrate", "openapi-spec": "node ./dist/openapi-spec", <% if (packageManager === 'yarn') { -%> - "prestart": "yarn run build", + "rebuild": "yarn run clean && yarn run build", + "prestart": "yarn run rebuild", <% } else { -%> - "prestart": "npm run build", + "rebuild": "npm run clean && npm run build", + "prestart": "npm run rebuild", <% } -%> "start": "node -r source-map-support/register .", <% } -%> diff --git a/packages/cli/test/integration/lib/project-generator.js b/packages/cli/test/integration/lib/project-generator.js index d8a8146ca5a4..666661a32297 100644 --- a/packages/cli/test/integration/lib/project-generator.js +++ b/packages/cli/test/integration/lib/project-generator.js @@ -283,7 +283,8 @@ module.exports = function (projGenerator, props, projectType) { ); assert.jsonFileContent('package.json', { scripts: { - prestart: 'npm run build', + rebuild: 'npm run clean && npm run build', + prestart: 'npm run rebuild', start: 'node -r source-map-support/register .', }, }); @@ -296,7 +297,8 @@ module.exports = function (projGenerator, props, projectType) { assert.noFileContent('package.json', '"@loopback/rest"'); assert.noFileContent('package.json', '"@loopback/openapi-v3"'); assert.noJsonFileContent('package.json', { - prestart: 'npm run build', + rebuild: 'npm run clean && npm run build', + prestart: 'npm run rebuild', start: 'node .', }); }