Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parcel-namer-rewrite: no "parcel-namer-rewrite" section in package.json. Use no-rules config #12

Open
Southclaws opened this issue May 20, 2022 · 6 comments

Comments

@Southclaws
Copy link

Getting this error even though there is a section, copied straight from readme.

  "parcel-namer-rewrite": {
    "chain": "@parcel/namer-default",
    "rules": {
      "index.ts": "index.js"
    }
  },

Did the key change?

@ol-loginov
Copy link
Owner

ol-loginov commented May 24, 2022

Nothing has changed. It should inside root element, like this:

{
  // ...
  "parcel-namer-rewrite": {
    "chain": "@parcel/namer-default",
    "rules": {
      "(.*).css": "assets-rewrite/css/$1{.hash}.css",
      "(.*).js": "assets-rewrite/js/$1{.hash}.js",
      "(.*).(jpg|png|gif|svg|webp|avif)": "assets/img1/$1.$2"
    }
  },
  // ....
}

@Southclaws
Copy link
Author

Yeah that's how it was, I couldn't get it to work at all unfortunately.

@viktorkasap
Copy link

I checked from your repo, not work
Added myscript.js to 404.html, and after build myrewrite/js/myscript.js does not exist

Screen
https://share.cleanshot.com/VxNmt0

@ol-loginov
Copy link
Owner

ol-loginov commented Jun 2, 2022

Ok, there is the branch for this issue
https://github.com/ol-loginov/parcel-namer-rewrite-issues/tree/12

There are 2 issues:

  1. Plugin uses file name returned by default namer. And as long as your "myscript.js" is not entry point - it's named by entry bundle. That's why it get name "404.js" (because bundle is constructed from 404.html) and ignored by rewrite rules.
  2. And if you add this file as entry (see package.json/targets/default/source) - you won't get the desired result, because the first rule match will be used: "(.*).js". To match "myscript.js", one should move this rule to first position in packages.json

After both of this points has been taken into account - you'll got what you need. You may find the example in that branch.

@viktorkasap
Copy link

viktorkasap commented Jun 2, 2022

02-06-2022-15-12-04-PhpStorm

It seems to work as it should, but the file is empty inside =/

Работает как надо вроде бы, но файл пустой внутри =/

@ol-loginov
Copy link
Owner

This is because of optimization. Unused function test has been thrown away.

You should "exports" stuff that you need outside the file. For example, call a function, use exports or assign attribute to global (like in "standalone.js" in repo)

I've changed the branch to simplify example.

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

No branches or pull requests

3 participants