Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
398 views
in Technique[技术] by (71.8m points)

javascript - 包括使用webpack编译的捆绑软件,以在另一个js文件中使用(include bundle compiled with webpack to use in another js file)

I have the following structure of my app:

(我的应用程序具有以下结构:)

index.js

(index.js)

const app = require("./app")
exports.api = app(...)

app.js

(app.js)

//all the imports goes here
//and exporting the main function
module.exports = app => {...}

Now I need to bundle app.js with webpack but index.js must stay intact

(现在我需要将app.js与webpack捆绑在一起,但index.js必须保持完整)

The question is, after bundling the app.js , how can I require it's main function app from index.js ?

(问题是,将app.js捆绑后,如何从index.js require它是主要功能app ?)

After webpacking app.js I'm getting error in index.js that says "app is not a function" which makes sense since app.js content is now wrapped in webpack staff.

(对app.js进行网络打包后,在index.js中出现错误,提示“ app不是函数”,这是有道理的,因为app.js内容现已包装在webpack员工中。)

Any suggestions are much appreciated.

(任何建议,不胜感激。)

  ask by vir us translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your "app" bundle needs to be exported as a library .

(您的“应用”捆绑包需要导出为 。)

module.exports = {
  //...
  output: {
    library: 'MyLibrary'
  }
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...