简体   繁体   中英

Push JS from npm module to browser in ApostropheCMS

Is it possible to push JS from an npm module to the browser in ApostropheCMS?

The file lib/modules/my-module/public/js/custom.js has been pushed to the browser with pushAsset successfully.

Three.js has been installed with npm i three .

Now THREE needs to get to the browser somehow for import, as described here .

I need to do this browserside:

var THREE = require('three');

require is a feature that comes with build tools like webpack or browserify. Those tools are not standard parts of apostrophe, nor are they built into browsers. You need to use a tool like webpack to compile code that contains require statements. So what you do instead is push the output files of your webpack pipeline as assets in apostrophe.

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