Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Add docs about asset management #1808

Open
SephReed opened this issue Feb 20, 2020 · 9 comments
Open

Add docs about asset management #1808

SephReed opened this issue Feb 20, 2020 · 9 comments
Assignees
Labels
4.0.0 education Make things as easy to learn as possible

Comments

@SephReed
Copy link
Contributor

The auto importing topic is covered in one part of the docs, but it would be nice to have a dedicated section. A bit of stuff:

// fuse config

dependencies.include = "path/to/resource/folder/"

Using a literal import

import ref from "./image.png"

document.body.innerHTML += `<img src="${ref}">`;
@SephReed SephReed added the education Make things as easy to learn as possible label Feb 20, 2020
@SephReed SephReed self-assigned this Feb 20, 2020
@nchanged
Copy link
Contributor

nchanged commented Feb 20, 2020

Should consider resources field too.

@SephReed
Copy link
Contributor Author

Hey. I'm trying to use an image in fuse-box 4.0 and can't figure it out.

If I do:

import ref from "./image.png"

It gives "./abc123.png" when it should give "./resources/abc123.png". Also, it renames it which I don't want it to do.

I've tried adding this to my cofig:

dependencies: {
    include: ['tslib', "./assets"],
  },

But it's not copying my assets folder over.

I can't figure out how to display an image right now. :/

@SephReed
Copy link
Contributor Author

For now I'm just manually copy pasting into dist.

@nchanged
Copy link
Contributor

Add link configuration, There is a bug where it prioritizes it's local config over the global one

@SephReed
Copy link
Contributor Author

I still haven't figured out how to work around this problem in fuse-box.

It seems there should be some very, very simple way to copy files from one folder to another inside dist.

Right now I'm trying to use chokidar to achieve this because I can not figure out how to make it happen in fuse-box.

@SephReed
Copy link
Contributor Author

For this config:

export interface IDependencies {
ignore?: Array<string | RegExp>;
importRefs?: Array<IImportRef>;
include?: Array<string>;
serverIgnoreExternals?: boolean;
}

What would it take to make the following config option possible:

interface IDependecyIncludeConfig {
  target: string;             // path or glob to files that should be included in dist
  distPath: string;         // path from dist root for where files should be copied
}

The result being something like so:

cosnt bundler = fusebox({
  // ... omitted
  dependencies: {
    include: [
      {   
        target: "../assets/img/**/*", 
        distPath: "./img" 
      }
    ]
  }
});

I remember this type of stuff was really easy with sparky, but I don't think Sparky is around anymore (Is it?). So maybe this kind of behavior could become part of standard fuse-box.

@SephReed
Copy link
Contributor Author

The following code does not work:

class Context {
  isProduction;
  runServer;
}
const { task, src } = sparky<Context>(Context);

// src("./assets/**/*")
//   .dest("./dist", "")
//   .exec();

task("default", async () => {
  await src("./assets/**/**.**")
    .dest("./dist/", ".")
    .exec();
});

@SephReed
Copy link
Contributor Author

I can't find a single usage of sparky().src() anywhere in the entire codebase: https://github.com/fuse-box/fuse-box/search?p=5&q=sparky+src%28

@SephReed
Copy link
Contributor Author

Found the issue:

const s = path.normalize(ensureFuseBoxPath(file)).split(newLocationBase);
if (!s[1]) {
log.error(`Can't find base of ${newLocationBase} of ${file}`);
return;
} else {
const newFileLocation = path.join(root, s[1]);
ensureDir(path.dirname(newFileLocation));
await writeFile(newFileLocation, readFiles[file]);

For some reason all files that have a newLocation and newBase (which is true whenever sparky().dest()) are put into folders of their filetype.

It seems like maybe some logic that belongs in the resources use case got put into sparky proper.

In any case, it no longer appears to be possible to use sparky to simply copy files from one place to another.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4.0.0 education Make things as easy to learn as possible
Projects
None yet
Development

No branches or pull requests

3 participants