worker-typescript-template icon indicating copy to clipboard operation
worker-typescript-template copied to clipboard

Webpack config does not coincide with package.json "main" or README

Open renshawdev opened this issue 5 years ago • 1 comments

The webpack config defines the build out put as follows:

output: {
    filename: `worker.${mode}.js`,
    path: path.join(__dirname, 'dist'),
  },

but the package.json defines the main entrypoint as index.js, which will never exist, and will be used by wrangler preview to serve a local demo, and obviously anything else that relies on the main property of package.json to run the code.

Resolution

  1. The main property of package.json should be updated to match the file output in webpack.config
  2. The output file of webpack.config should not be dynamic and always output to whatever the main property of package.json is

I suggest (based on typical best practices): // webpack.config.js

output: {
    filename: `index.js`,
    path: path.join(__dirname, 'dist'),
  },

// package.json

"main": "dist/index.js"

There is no need to build to different filenames for different modes, a developer or even a CI/CD runner should know whether it is running in a particular mode which may affect the structure and content of the built files, but the names should be the same so any issues for the same file in different environments can be compared without headaches or the need to look into build configurations for different modes.

Finally, the readme has the link to the index function in src labelled with .js extension, when it is a .ts file. The readme should also have content explaining the dev (I have more to say about the dev script, but beyond the scope of this issue) and build scripts, and maybe a one-liner to mention using wrangler preview.

renshawdev avatar Feb 15 '20 17:02 renshawdev

I ran into the same issue. Check out PR #11 though, it fixes this issue by adding the webpack config to your toml file.

ChrisTolmeijer avatar Mar 31 '20 23:03 ChrisTolmeijer