簡體   English   中英

Haxe + Webpack 導出空對象

[英]Haxe + Webpack exporting empty object

我正在嘗試在 Haxe 編譯器導出的 JS 上運行 webpack-dev-server。 我正在使用 hxgenjs 庫將 haxe 輸出拆分為單獨的模塊,並且我正在嘗試通過 webpack 合並它們(以使用熱模塊替換功能)。 一切似乎都沒問題,但輸出是空對象。 這是我的webpack.config.js

module.exports = {
  entry: './build/Game-hxgenjs.js',
  mode: 'development',
  devtool: "inline-source-map",
  output: {
    filename: 'Game-webpack.js',
    path: path.resolve(__dirname, 'bin/js'),
    publicPath: '/bin/js/',
    libraryTarget: "umd",
    library: "MyLib"
  },
  devServer: {
    publicPath: '/bin/js/',
    compress: false,
    port: 8080,
    hot: true,
    inline: true,
    headers: {
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Headers': '*'
    },
    proxy: {
       // some proxy settings
    }
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin()
  ]
};

並且入口js文件有這樣的內容:

if (module.hot) module.hot.accept();
require("./Std")
var $import = require("./import_stub").default;
function base_navigation_elements_NavigationDotsContainer() {return require("./base/navigation/elements/NavigationDotsContainer");}
function base_navigation_elements_NavigationScore() {return require("./base/navigation/elements/NavigationScore");}
function custom_game_Manager() {return require("./custom/game/Manager");}
function base_navigation_elements_NavigationDot() {return require("./base/navigation/elements/NavigationDot");}
function library_Library() {return require("./library/Library");}
function platform_topbar_TopbarProxy() {return require("./platform/topbar/TopbarProxy");}
function base_navigation_Navigation() {return require("./base/navigation/Navigation");}
function base_navigation_elements_NavigationAnimation() {return require("./base/navigation/elements/NavigationAnimation");}
function base_navigation_elements_NavigationButton() {return require("./base/navigation/elements/NavigationButton");}
function base_navigation_elements_NavigationPreloader() {return require("./base/navigation/elements/NavigationPreloader");}
function base_navigation_elements_NavigationButtonSpaceBar() {return require("./base/navigation/elements/NavigationButtonSpaceBar");}
(custom_game_Manager().default).main();
exports["base"] = exports["base"] || {}
exports["base"]["navigation"] = exports["base"]["navigation"] || {}
exports["base"]["navigation"]["elements"] = exports["base"]["navigation"]["elements"] || {}
exports["base"]["navigation"]["elements"]["NavigationDotsContainer"] = (base_navigation_elements_NavigationDotsContainer().default)
exports["base"] = exports["base"] || {}
exports["base"]["navigation"] = exports["base"]["navigation"] || {}
exports["base"]["navigation"]["elements"] = exports["base"]["navigation"]["elements"] || {}
exports["base"]["navigation"]["elements"]["NavigationScore"] = (base_navigation_elements_NavigationScore().default)
exports["base"] = exports["base"] || {}
exports["base"]["navigation"] = exports["base"]["navigation"] || {}
exports["base"]["navigation"]["elements"] = exports["base"]["navigation"]["elements"] || {}
exports["base"]["navigation"]["elements"]["NavigationDot"] = (base_navigation_elements_NavigationDot().default)
exports["library"] = exports["library"] || {}
exports["library"]["Library"] = (library_Library().default)
exports["platform"] = exports["platform"] || {}
exports["platform"]["topbar"] = exports["platform"]["topbar"] || {}
exports["platform"]["topbar"]["TopbarProxy"] = (platform_topbar_TopbarProxy().default)
exports["base"] = exports["base"] || {}
exports["base"]["navigation"] = exports["base"]["navigation"] || {}
exports["base"]["navigation"]["Navigation"] = (base_navigation_Navigation().default)
exports["base"] = exports["base"] || {}
exports["base"]["navigation"] = exports["base"]["navigation"] || {}
exports["base"]["navigation"]["elements"] = exports["base"]["navigation"]["elements"] || {}
exports["base"]["navigation"]["elements"]["NavigationAnimation"] = (base_navigation_elements_NavigationAnimation().default)
exports["base"] = exports["base"] || {}
exports["base"]["navigation"] = exports["base"]["navigation"] || {}
exports["base"]["navigation"]["elements"] = exports["base"]["navigation"]["elements"] || {}
exports["base"]["navigation"]["elements"]["NavigationButton"] = (base_navigation_elements_NavigationButton().default)
exports["base"] = exports["base"] || {}
exports["base"]["navigation"] = exports["base"]["navigation"] || {}
exports["base"]["navigation"]["elements"] = exports["base"]["navigation"]["elements"] || {}
exports["base"]["navigation"]["elements"]["NavigationPreloader"] = (base_navigation_elements_NavigationPreloader().default)
exports["base"] = exports["base"] || {}
exports["base"]["navigation"] = exports["base"]["navigation"] || {}
exports["base"]["navigation"]["elements"] = exports["base"]["navigation"]["elements"] || {}
exports["base"]["navigation"]["elements"]["NavigationButtonSpaceBar"] = (base_navigation_elements_NavigationButtonSpaceBar().default)

這是自動生成的文件。 問題是,當我運行 webpack-dev-server 時,它會生成它的東西……最后有這塊代碼:

/***/ 0:
/*!********************************************************************************************************************!*\
  !*** multi (webpack)-dev-server/client?http://localhost:8080 (webpack)/hot/dev-server.js ./build/Game-hxgenjs.js  ***!
  \********************************************************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(/*! C:\path\to\project\node_modules\webpack-dev-server\client\index.js?http://localhost:8080 */"./node_modules/webpack-dev-server/client/index.js?http://localhost:8080");
__webpack_require__(/*! C:\path\to\project\node_modules\webpack\hot\dev-server.js */"./node_modules/webpack/hot/dev-server.js");
__webpack_require__(/*! ./build/Game-hxgenjs.js */"./build/Game-hxgenjs.js");
module.exports = __webpack_require__(0);


/***/ })

/******/ });
});

在哪里

__webpack_require__(0) 

返回一個空對象,所以 window.MyLib 是一個空對象。 當我在這個地方放置斷點時,我可以看到上一行:

__webpack_require__(/*! ./build/Game-hxgenjs.js */"./build/Game-hxgenjs.js"); 

實際上返回了我需要的東西(所有從入口 js 文件中導出的東西)。 有人可以幫我弄清楚發生了什么以及模塊“0”究竟是什么?

很可能您正在使用 webpack5,它有一個已知錯誤: webpack5.xx + webpack-dev-server 3.xx在 devserver 模式下將模塊導出為空對象,當純 webpack 構建和監視工作正常時。

修復安裝"webpack-dev-server": "^4.0.0-beta.0"

npm i webpack-dev-server@next -D

請不要在 webpack-dev-server 4.xx devServer.publicPath選項更改為static

  devServer: {
        static: path.join(__dirname, 'build'),
        hot: true,
    },

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM