bertramdev / asset-pipeline

The core implementation of the asset pipeline for the jvm
193 stars 91 forks source link

Add node_modules resolution #272

Closed jjelliott closed 3 years ago

jjelliott commented 3 years ago

This makes it so applications using the pipeline can use a node-modules directory thereby enabling the usage of npm for package resolution.

With this approach, the package.json for your project needs to be at the asset root (src/assets or grails-app/assets) and you need to run npm from there.

This means you can do this:

/path/to/project/grails-app/assets $  npm i react 

Then you can import the module as if it were an actual Node project.

import React from 'react';

Using the modules in this way makes Intellij able to understand large libraries like React better as well.

This does not use Node or NPM in any way for the build process, only for package management, so things that require an actual Node environment will still need to be built outside of the project.

The groovy-json dependency was not added lightly, but if it needs removed I can try to work around it.

Please let me know if anything needs reworked or improved.

davydotcom commented 3 years ago

Very awesome!