R
R
RomkaChev2015-11-30 20:39:59
Yii
RomkaChev, 2015-11-30 20:39:59

How to include nodejs package in yii2 project?

In a Yii2 project, you need to include a dependency on the nodejs package - https://github.com/tmpvar/2d-polygon-boolean
In composer.json I write:

{
    //...
    "require": {
        "npm-asset/2d-polygon-boolean" : ">=1.0.1"
    }
    //...
}

After execution , a bunch of packages appear composer updatein the folder ./vendor/npmalong with the specified (2d-polygon-boolean)
Create the following resource bundle and connect it to the view:
class PolygonBooleanAsset extends yii\web\AssetBundle {
  public $sourcePath = '@npm/2d-polygon-boolean';
  public $js         = [
    '2d-polygon-boolean.js'
  ];
}

When launched at a specific Url in the console, of course, errors are pouring in. Uncaught ReferenceError: require is not defined
And now, in fact, the question is:
What needs to be done to run this script in the browser?
Dig towards Browserify and others like them?
And if so, how to make a project on Yii2 friends with all this here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander N++, 2015-11-30
@RomkaChev

npm-asset assets are not suitable as normal JS for the browser this is all for server-side nodejs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question