[英]how to use webpack to load script from node_modules
我需要使用script-loader從node_modules加載腳本。 我已嘗試在client_entry.js中執行以下要求
require('script-loader!canvas-to-blob');
但是我的瀏覽器出現以下錯誤:
VM1702:1Uncaught ReferenceError: module is not defined
at eval (eval at module.exports (http://patientwisdom-dev.com:8080/index.js:164122:9), <anonymous>:1:1)
at eval (<anonymous>)
at module.exports (http://patientwisdom-dev.com:8080/index.js:164122:9)
at Object.<anonymous> (http://patientwisdom-dev.com:8080/index.js:164108:26)
at __webpack_require__ (http://patientwisdom-dev.com:8080/index.js:20:30)
at Object.<anonymous> (http://patientwisdom-dev.com:8080/index.js:669:2)
at __webpack_require__ (http://patientwisdom-dev.com:8080/index.js:20:30)
at Object.<anonymous> (http://patientwisdom-dev.com:8080/index.js:48:19)
at __webpack_require__ (http://patientwisdom-dev.com:8080/index.js:20:30)
at http://patientwisdom-dev.com:8080/index.js:40:18
我也嘗試過:
require('script-loader!canvas-to-blob/index.js');
仍然沒有運氣
fyi,這適用於具有相對路徑的js文件:
require('script-loader!./test.js'); // works
但不是來自node_modules的東西
您只需要完整的相對路徑,包括node_modules
。
根據項目中js文件相對於node_modules
它可能看起來像這樣。
require('script-loader!../../node_modules/canvas-to-blob/index.js');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.