Übergeben Sie den Export durch eine Hauptdatei in WebPackJavaScript

Javascript-Forum
Anonymous
 Übergeben Sie den Export durch eine Hauptdatei in WebPack

Post by Anonymous »

Ich versuche, eine Bibliothek mit Webpack zu erstellen. Beim Verzehr meiner Bibliothek möchte ich m anrufen können

Code: Select all

yLibrary.showAlert()
aus einem Skript -Tag oder einem anderen JS -Dokument. Mein Problem ist, dass ich mehrere Dateien habe, die alle in eine Main.js -Datei importiert werden, die der Einstiegspunkt meiner Bibliothek ist. Wenn ich jede Datei in main.js importiere und exportiere, funktioniert sie. Meine Frage ist, gibt es eine Möglichkeit, alle Dateien zu exportieren, ohne jedes einzeln einzeln aufzulisten? < /P>
Beispiel: < /p>

Code: Select all

//alerts.js
export function showAlert() {
console.log("show alert called");
}

//translations.js
export function translateText() {
console.log("translate text called");
}

//main.js
import "./components/alerts.js";
import "./components/translations.js";

//Note: I want to avoid this part
export * from "/components/alerts.js";
export * from "/components/translations.js";

//webpack.library.config.js
const path = require("path");
const libraryName = "rmsui";
var configLib = Object.assign({}, config, {
mode: "development",
name: "myLibrary",
entry: {
// JS
myLibrary: "./js/main.js",
errorPages: "./js/errorPages.js" //some other entrypoint not shown above
},
output: {
path: path.resolve(__dirname, "./wwwroot/dist"),
filename: "js/[name].js",
globalObject: "this",
library: {
name: libraryName,
type: "umd",
},
libraryTarget: "var",
//umdNamedDefine: true,
assetModuleFilename: "assets/[hash][ext][query]"
},
plugins: [
//new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: "css/[name].css"
})
]
});
module.exports = configLib;

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post