Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Named worker generates hashed file anyway? also output path not working #117

Closed
jwmann opened this issue Jan 8, 2018 · 1 comment
Closed

Comments

@jwmann
Copy link

jwmann commented Jan 8, 2018

This is how I'm importing my worker.

import pdfExportWorker from 'worker-loader?name=dist.pdf.export.worker.js!../workers/pdf.export.worker';

This is the output of npm run build:

Child worker:
                                 Asset     Size  Chunks                    Chunk Names
        4aab728959a0654ef2f9.worker.js   492 kB          [emitted]  [big]
    4aab728959a0654ef2f9.worker.js.map  1.02 MB          [emitted]
             dist.pdf.export.worker.js  2.63 kB       0  [emitted]         main
         dist.pdf.export.worker.js.map  2.84 kB       0  [emitted]         main
       [3] ./node_modules/worker-loader/dist/cjs.js?{"publicPath":"/workers/"}!./workers/pdf.export.worker.js 101 bytes {0} [not cacheable] [built]
    Child worker:
                                     Asset     Size  Chunks                    Chunk Names
            4aab728959a0654ef2f9.worker.js   492 kB       0  [emitted]  [big]  main
        4aab728959a0654ef2f9.worker.js.map  1.02 MB       0  [emitted]         main
           [0] ./workers/pdf.export.worker.js 16.9 kB {0} [built]
           [3] ../jsPDF/jspdf.js 79.8 kB {0} [built]
           [4] ../jsPDF-AutoTable/dist/jspdf.plugin.autotable.src.js 390 kB {0} [built]
            + 2 hidden modules

Running on Webpack ^3.10.0

I'm also trying to output all these generated files (I have like 5 workers) inside their own dist folder or something but I can't for the life of me get it working. I've looked at #36 and saw this but it doesn't do anything for me.

Am I missing something?

@jwmann
Copy link
Author

jwmann commented Jan 10, 2018

So I solved this by removing my rule in webpack to look for my workers.

Remove this

      {
        test: /\.worker\.js$/,
        loader: 'worker-loader',
        options: {
          publicPath: '/workers/',
        }
      }

I realized that the import call it calling the worker-loader module itself and bypassing the webpack config, and then the webpack config will then look for those files as normal, regardless of the import.

I also was able to put them all in their own folder by adding a path before the name.
These are my imports in case anyone is looking to fix this in the future. May also fix #118

import rowsExportWorker from 'worker-loader?name=/dist/rows.export.worker.js&inline=true!../workers/rows.export.worker';
import columnsExportWorker from 'worker-loader?name=/dist/columns.export.worker.js&inline=true!../workers/columns.export.worker';
import pdfExportWorker from 'worker-loader?name=/dist/pdf.export.worker.js&inline=true!../workers/pdf.export.worker';
import csvExportWorker from 'worker-loader?name=/dist/csv.export.worker.js&inline=true!../workers/csv.export.worker';
import excelExportWorker from 'worker-loader?name=/dist/excel.export.worker.js&inline=true!../workers/excel.export.worker';

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant