Konstantin Petrov
Konstantin Petrov

Reputation: 59

pm ERR! missing script: build. I try to build one js file. I have npm library/

My main code. I has "require('node-rsa')" which in node_modules folder. Is it possible to create one file from this code?

a.js

var testFunct = function test(message) { 
    const NodeRSA = require('node-rsa');
    const key = new NodeRSA(); 
    var k = key.generateKeyPair(); 
    var p = k.exportKey('pkcs1'); 
    return p};
console.log(testFunct())

package.json

{
  "name": "pol",
  "version": "1.0.0",
  "description": "",
  "main": "a.js",
  "dependencies": {
    "node-rsa": "^1.1.1",
    "build": "webpack a.js b.js"
  },
  "devDependencies": {
    "webpack": "^5.58.2"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

webpack.config.js

module.exports = {
    entry: ['a.js'],
    output: {
      path: './build',
      filename: 'bundle.js'
  
    }
  }

enter image description here

Upvotes: 0

Views: 71

Answers (1)

Mario Varchmin
Mario Varchmin

Reputation: 3782

Add this entry to the scripts section of your package.json:

"build": "webpack"

This will trigger webpack, when you run the build action.

Upvotes: 1

Related Questions