簡體   English   中英

根據文件擴展名覆蓋webpack中捆綁的內容

[英]Override what's bundled in webpack based on file extension

我試圖弄清楚webpack是否可以做這樣的事情。 我有一些代碼想綁定到特定設備上。 所以我創建了一個ViewFactories.ios.tsx,我也有ViewFactories.tsx。 我遇到的問題是,如果我在加載程序測試中忽略.ios.tsx,它仍然會被捆綁。 我正在使用ignore-bundler插件來忽略.ios.tsx文件,但是引用只是空的。 即:

/** still getting loaded here: **/
const ViewFactories_ios_1 = __importDefault(__webpack_require__(/*! ./ViewFactories.ios */ "./build/app/src/modules/layouts/factories/ViewFactories.ios.tsx"));

/*** the referenced section, but blank now ***/
/***/ "./build/app/src/modules/layouts/factories/ViewFactories.ios.tsx":
/*!***********************************************************************!*\
  !*** ./build/app/src/modules/layouts/factories/ViewFactories.ios.tsx ***!
  \***********************************************************************/
/*! dynamic exports provided */
/*! all exports used */
/***/ (function(module, exports) {
/***/ }),

我真正想要的是對ViewFactories.tsx的引用,而不是對ViewFactories.ios.tsx的引用。 Webpack中是否可以訪問某種依賴關系圖,以告知加載程序使用默認值而不是.ios.tsx?

我的webpack配置:

   {
      test: (modulePath) => {
          if (/\.ios\./.test(modulePath)) {
              console.log(modulePath);
              return false;
          }
          return /\.tsx?$/.test(modulePath);
      },
      loader: "awesome-typescript-loader",
      options: {
          configFileName: 'tsconfig.web.json',
          transpileOnly: true,
          errorsAsWarnings: true,
      }
    },
    {
        test: (modulePath) => {
            if (/\.ios\./.test(modulePath)) {
                console.log('Ignored:  ', modulePath);
                return true;
            }
            return false;
        },
        loader: 'ignore-loader'
    },

只需構建兩個捆綁包,使用相同的共享配置選項?

// webpack.config.js for two different bundles

let sharedModuleDef = {
  rules: ...
}

let sharedPlugins = ...

let iosBundle = {
  entry: "src/ios.entry.js",
  output: {
    path: ...
    filename: "ios.bundle.js"
  },
  module: sharedModuleDef,
  ...
};

let everythingElse = {
  entry: "src/main.entry.js",
  output: {
    path: ...
    filename: "standard.bundle.js"
  },
  module: sharedModuleDef,
  ...
};

module.exports = [iosBundle, everythingElse];

暫無
暫無

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

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