Code Monkey home page Code Monkey logo

Comments (5)

dhh avatar dhh commented on July 30, 2024

Yes, I like this. cc @brenogazzola

from propshaft.

brenogazzola avatar brenogazzola commented on July 30, 2024

Sure! @rainerborene Could you also post some sample code of this in action?

From what I'm seeing, the resolve_digested_from will allow us to pass logo.png and have propshaft find logo-DIGEST-digested.png. I'm a bit confused about the digested though. If the builder already generated the file in that format, shouldn't it have already compiled the JS files to replace a reference to logo.png with logo-DIGEST.digested.png? This is what happens when we configure webpack/esbuild to generate entryfiles and chunkfiles with the .digested pattern.

This seems to me something that you’d pass “logo.png”, which is the file the builder wanted, and propshaft would gind “logo-DIGEST.png”, which is what propshaft generated.

from propshaft.

rainerborene avatar rainerborene commented on July 30, 2024

@brenogazzola Not sure if I follow. By digested you mean the digested_path helper method, right? If you want we can have a quick call on Zoom.

from propshaft.

brenogazzola avatar brenogazzola commented on July 30, 2024

Sorry, let me be more specific (we can try zoom if it’s still confusing)

By digested I meant this line:

pattern = /\A#{filename}-([0-9a-zA-Z]{7,128})\.digested\.#{extname}\z/

I expected it to be:

pattern = /\A#{filename}-([0-9a-zA-Z]{7,128})\.#{extname}\z/

From what I understood of your PR and use case, you have an image file referenced in your JS files as something like logo.png. When you run rails assets:precompile, propshaft will rename the file to logo-DIGEST.png, which means the JS file will not be able to load it. You want to solve that by using a regex to compare file_name with the assets logical paths in the loadpath. Therefore the extra \.digested in the regex seems unnecessary to me. File will only have .digested in their name if the bundler was specifically configured to generate that name. If you are using this new feature in this PR, you are probably not configuring the bunlder to add .digested (I think?)

from propshaft.

rainerborene avatar rainerborene commented on July 30, 2024

Sorry, let me be more specific (we can try zoom if it’s still confusing)

Same time zone as yours. Plz ping me at rainerborene at gmail dot com.

If you are using this new feature in this PR, you are probably not configuring the bunlder to add .digested (I think?)

Exact the opposite! Take a look at the output option of the following webpack configuration. As you can see webpack will generate chunks and assets with the .digested. suffix on the filename so that propshaft could understand it and skip the hashing process. The downside is that I cannot link a chunk or asset path using the preload_link_tag (or any other helper) anymore because it weren't digested by propshaft in the first place. That's the issue we're trying to solve here.

module.exports = {
  output: {
    filename: "[name].js",
    sourceMapFilename: "[file].map",
    chunkFilename: "[name]-[contenthash].digested.js",
    assetModuleFilename: "asset-[contenthash].digested[ext]",
    path: path.resolve(__dirname, "app/assets/builds"),
  }
}

from propshaft.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.