我有一個非常簡單的設定來理解 webpack 基礎知識。下面是我的專案結構

在運行專案并單擊index.html頁面中的按鈕時,處理程式不會被執行,而是在控制臺中記錄錯誤。
請在這里找到專案
這可能是一個非常愚蠢的問題,但我無法理解這種行為。希望有人可以幫助我。謝謝!
uj5u.com熱心網友回復:
除非在使用 webpack 時將其匯出,否則無法使用這些函式。
index.js
export function click_blue() { ... }
export function click_red() { ... }
webpack.config.js
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
library: 'lib', // add this!
},
mode: 'development'
};
index.html
...
<button onclick="lib.click_red()">Red</button>
...
檢查webpack output.library以獲取更多資訊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/407940.html
標籤:
