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

Rename does not let me alter the folder to which the file is written. #70

Closed
mikebronner opened this issue Aug 23, 2023 · 1 comment
Closed

Comments

@mikebronner
Copy link

mikebronner commented Aug 23, 2023

I have tried various rename suggestions in order to remove the top level folder from being copied over, but rename only seems to affect the filename itself, and not the destination folders.

For example:

        copy({
            flatten: false,
            targets: [
                {
                    src: "resources/assets/**/*",
                    dest: "public",
                    rename: (name, extension, fullPath) => {
                        return "../" + fullPath.split(path.sep).slice(2).join(path.sep);
                    },
                },
            ],
            verbose: true,
        }),

My goal is to copy the content into public, not public/assets (which is the default behavior). Various issues in the repo recommend using rename to achieve this. Unfortunately this only works at the first level, not in multi-level globs with nested directories. You can see by the output that nested folders are repeated, instead of traversing up a folder:

  resources/assets/android-chrome-192x192.png → public/android-chrome-192x192.png [R]
  resources/assets/android-chrome-512x512.png → public/android-chrome-512x512.png [R]
  resources/assets/apple-touch-icon.png → public/apple-touch-icon.png [R]
  resources/assets/favicon-16x16.png → public/favicon-16x16.png [R]
  resources/assets/favicon-32x32.png → public/favicon-32x32.png [R]
  resources/assets/favicon.ico → public/favicon.ico [R]
  resources/assets/fonts → public/fonts [R]
  resources/assets/images → public/images [R]
  resources/assets/js → public/js [R]
  resources/assets/logo-mark.png → public/logo-mark.png [R]
  resources/assets/site.webmanifest → public/site.webmanifest [R]
  resources/assets/images/cash-for-whatever → public/assets/images/cash-for-whatever [R]
  resources/assets/images/email → public/assets/images/email [R]
  resources/assets/images/pages → public/assets/images/pages [R]
  resources/assets/images/transparent.png → public/assets/images/transparent.png [R]
  resources/assets/fonts/Raleway-Italic.ttf → public/assets/fonts/Raleway-Italic.ttf [R]
  resources/assets/fonts/Raleway.ttf → public/assets/fonts/Raleway.ttf [R]
  resources/assets/js/ckeditor5 → public/assets/js/ckeditor5 [R]
  resources/assets/images/cash-for-whatever/logo.png → public/assets/images/images/cash-for-whatever/logo.png [R]
  resources/assets/images/email/envelope-solid.png → public/assets/images/images/email/envelope-solid.png [R]
  resources/assets/images/email/full_logo-original.png → public/assets/images/images/email/full_logo-original.png [R]
  resources/assets/images/email/full_logo.png → public/assets/images/images/email/full_logo.png [R]
  resources/assets/images/email/phone-rotary-solid.png → public/assets/images/images/email/phone-rotary-solid.png [R]
  resources/assets/images/email/signature.html → public/assets/images/images/email/signature.html [R]
  resources/assets/images/pages/404.png → public/assets/images/images/pages/404.png [R]
  resources/assets/images/pages/500.png → public/assets/images/images/pages/500.png [R]
  resources/assets/images/pages/forgot-password.png → public/assets/images/images/pages/forgot-password.png [R]
  resources/assets/images/pages/login.png → public/assets/images/images/pages/login.png [R]
  resources/assets/images/pages/register.jpg → public/assets/images/images/pages/register.jpg [R]
  resources/assets/images/pages/reset-password.png → public/assets/images/images/pages/reset-password.png [R]
  resources/assets/images/pages/vuexy-login-bg.jpg → public/assets/images/images/pages/vuexy-login-bg.jpg [R]
  resources/assets/js/ckeditor5/ckeditor.js.map → public/assets/js/js/ckeditor5/ckeditor.js.map [R]
  resources/assets/js/ckeditor5/ckeditor.jsx → public/assets/js/js/ckeditor5/ckeditor.jsx [R]

Up until resources/assets/site.webmanifest → public/site.webmanifest [R] everything is correct, after that everything is incorrect, because it once again includes the assets subfolder.

(I tried without "../" and that didn't work at all.)

Any suggestions on how to address this?

Possibly related issues:
#32
#56

@mikebronner
Copy link
Author

Update: I believe I was able to get this to work using the following configuration. The notable change was to set flatten back to true:

import { defineConfig } from "vite";
import laravel from "laravel-vite-plugin";
import copy from "rollup-plugin-copy";
import path from "path";

// ! TECH DEBT: TTLT-1839
export default defineConfig({
    plugins: [
        laravel({
            input: [
                "resources/js/app.js",
            ],
            refresh: true,
        }),
        copy({
            flatten: true,
            targets: [
                {
                    src: "resources/assets/**/*",
                    dest: "public",
                    rename (name, extension, fullPath) {
                        return fullPath.split(path.sep).slice(2).join(path.sep);
                    },
                },
                {
                    src: "resources/docs/**/*",
                    dest: "public",
                    rename (name, extension, fullPath) {
                        return fullPath.split(path.sep).slice(2).join(path.sep);
                    },
                },
            ],
            verbose: false,
        }),
    ],
});

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

1 participant