zoukankan      html  css  js  c++  java
  • [Webpack 2] Import a non-ES6 module with Webpack

    When you have a dependency that does not export itself properly, you can use the exports-loader to force it to export the pieces of the file that you need.

    Install:

    npm i -D exports-loader

    Add exports-loader to the module you want:

     module: {
          loaders: [
           ...
            {
              test: require.resolve('./src/js/non_node_modules/left-pad'),
              loaders: [
                'exports?leftPad',
              ],
            }
          ],

    There is no problem, the module still exists on 'window' object, we want it be es6 module which not exists on 'window' object.

    Install:

    npm i -D imports-loader

    Add imports-loader the the module:

        module: {
          loaders: [
            ...
            {
              test: require.resolve('./src/js/non_node_modules/left-pad'),
              loaders: [
                'imports?window=>{}',
                'exports?leftPad',
              ],
            }
          ],
        },

    Here it sets 'windows' object to empty object to clean the left-pad module.

  • 相关阅读:
    浅谈线段树
    浅谈KMP
    20200729线上模拟题解
    20200727线上模拟题解
    声明
    tarjan--割点,缩点
    20201029模拟
    高精模板
    二分图--二分图的几种模型
    树的直径与树的重心
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5615671.html
Copyright © 2011-2022 走看看