andywer / threads-plugin

📦 Makes your threads.js code build with webpack out of the box.
Apache License 2.0
28 stars 6 forks source link

Option to not inline files #41

Closed linonetwo closed 3 years ago

linonetwo commented 3 years ago

I can see all required files are inline into 0.index.worker.js

/***/ "./node_modules/@tiddlygit/tiddlywiki/boot sync recursive":
/*!******************************************************!*\
  !*** ./node_modules/@tiddlygit/tiddlywiki/boot sync ***!
  \******************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
        $tw.boot.bootPath = options.bootPath || path.dirname(module.filename);
        $tw.boot.corePath = path.resolve($tw.boot.bootPath,"../core");

But this seem to causes error on path.dirname(module.filename); it says module.filename is undefined.

I log the module, it is

{
  i: './node_modules/@tiddlygit/tiddlywiki/boot/boot.js',
  l: true,
  exports: { TiddlyWiki: [Function: _boot] },
  deprecate: [Function (anonymous)],
  paths: [],
  children: [],
  loaded: [Getter],
  id: [Getter],
  webpackPolyfill: 1
}

And I think it will break path.resolve($tw.boot.bootPath,"../core")

So I think if we keep @tiddlygit/tiddlywiki to be require('@tiddlygit/tiddlywiki') instead of inline it, it will works fine.

linonetwo commented 3 years ago

Seems setting https://webpack.js.org/configuration/externals/ is not working, the package is still being inlined. not required.


if I use

  new webpack.IgnorePlugin({ resourceRegExp: /@tiddlygit\/tiddlywiki/ }),
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
  new ThreadsPlugin({ target: 'electron-node-worker', plugins: [new webpack.IgnorePlugin({ resourceRegExp: /@tiddlygit\/tiddlywiki/ })] }),

it will be webpackMissingModule

!(function webpackMissingModule() { var e = new Error("Cannot find module '@tiddlygit/tiddlywiki'"); e.code = 'MODULE_NOT_FOUND'; throw e; }());

I tried https://github.com/andywer/threads-plugin/issues/19 and it is not working anymore in webpack4.

linonetwo commented 3 years ago

Finally use:

  new ExternalsPlugin({
    type: 'commonjs',
    include: path.join(__dirname, 'node_modules'),
  }),
  new ThreadsPlugin({
    target: 'electron-node-worker',
    plugins: ['ExternalsPlugin'],
  }),