schovi / webpack-chrome-extension

Moved and redesigned into https://github.com/schovi/create-chrome-extension
MIT License
167 stars 27 forks source link

Fix incorrect URL in production mode #10

Closed MattSPalmer closed 9 years ago

MattSPalmer commented 9 years ago

Currently, webpackScriptURL is a direct copy of the index.html URL. This causes an error when building for production, as shown below:

  1. popup/index.html yields a webpackScriptURL of popup/index.js
  2. We inject <script src="popup/index.js" async defer></script>
  3. We get an error because the relative script path from popup/index.html is index.js, not popup/index.js (we don't have two nested popup directories)

This change addresses the issue by calling Remove.path on webpackScriptURL when NODE_ENV is 'production', giving us the correct relative URL to index.js.

schovi commented 9 years ago

Really thanks for this. I noticed, that problem is not path itself, but fact that path is relative. When we are in popup url like chrome-extension:98S7AD98AS7D98AS/popup and load script something/main.js it looks for /popup/something/main.js

I fixed it by changing script path to absolute in https://github.com/schovi/webpack-chrome-extension/commit/9ffe78cf13028b5d88e8442e3e8e1995856c6f62