webpack / tapable

Just a little module for plugins.
MIT License
3.71k stars 393 forks source link

refactor: remove nodejs module `util` #166

Closed hustcc closed 2 years ago

hustcc commented 2 years ago

to avoid error below in webpack 5:

image

linux-foundation-easycla[bot] commented 2 years ago

CLA Signed

The committers are authorized under a signed CLA.

alexander-akait commented 2 years ago

We already supports browser https://github.com/webpack/tapable/blob/master/package.json#L31

hustcc commented 2 years ago

We already supports browser https://github.com/webpack/tapable/blob/master/package.json#L31

not valid config for webpack 5.

image


There is only 1 api which is from nodejs util. There is absolutely no need to use built-in modules, and then modify the building config for browsers.

The right way is remove the built-in module and directly use the polyfill code.

hustcc commented 2 years ago

Now, we solve it by below code, very dirty.

module.exports = {
  mode: 'production',
  entry: './src/index.ts',
  output: {
    library: 'Spreadsheet',
    libraryTarget: 'umd',
    filename: 'spreadsheet.min.js',
  },
  resolve: {
    extensions: ['.ts', '.tsx', '.js'],
    fallback: {
      // use polyfill util code from `tapable`
      util: require.resolve('tapable/lib/util-browser.js'),
    },
  },
  plugins: [
  ],
  module: {
    rules: [
      { test: /\.tsx?$/, loader: 'ts-loader' }
    ]
  },
  externals: {
  },
};
alexander-akait commented 2 years ago

The right way is remove the built-in module and directly use the polyfill code.

No, I can't reproduce your problem... Maybe you can provide full example?

hustcc commented 2 years ago

The right way is remove the built-in module and directly use the polyfill code.

No, I can't reproduce your problem... Maybe you can provide full example?

I have no time to provide full example. In terms of code rationality, the best way to support the browser is to delete util, to avoid the dependence of build configure.

I can support browsers directly. Why do I need to rely on building?

hustcc commented 2 years ago

way to reproduce:

"ts-jest": "^24.3.0",
"ts-loader": "^9.2.6",
"typescript": "^4.4.2",
"webpack": "^5.64.4",
"webpack-cli": "^4.9.1"
alexander-akait commented 2 years ago

Why do your bundle tapable? Do you use it in your application?

hustcc commented 2 years ago

Why do your bundle tapable? Do you use it in your application?

antv/g depends on tapable, I am using antv/g to dev an module which should be used in browser by script.

alexander-akait commented 2 years ago

There is only one problem - tracking depredations on Node.js using CLI, but I think it is not real problem...