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

Fix css relative asset urls #4695

Merged

Conversation

chadfawcett
Copy link
Member

Issue: resolves #4645

What I did

  • Added a react-scripts v2 cli test fixture
  • Removed the incorrect file paths for css minification in cra prod webpack config.

How to test

I tested both by adding a relative asset to the cra-kitchen-sink styles and built storybook for prod (yarn build-storybook).

I also cloned @Vinnl's repo and testing the stories there.

// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'static/css/[name].[contenthash:8].css',
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These settings were copied over from cra's webpack config. Since storybook does not have a dynamic publicPath like cra, these are not needed. As mentioned in the storybook config, relative urls always work.

https://github.com/storybooks/storybook/blob/48b2b51332156d690f49b334ce998ad5c50f0b12/lib/core/src/server/config/webpack.config.prod.js#L28-L33

@Vinnl
Copy link

Vinnl commented Nov 2, 2018

I just tested this by manually applying the same fix and I confirm that CSS-imported images are shown now. Thanks!

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't understand the change but seems to fix the problem!

@chadfawcett
Copy link
Member Author

chadfawcett commented Nov 2, 2018

@shilman In CRA, they have a dynamic public path and a check to see if relative paths should be used.

My original implementation copied over the CSS minification paths that didn't match up with the mini css loader. So this just gets those back in sync.

Edit: Can you also add the app/react label to this PR?

@igor-dv
Copy link
Member

igor-dv commented Nov 3, 2018

Can you please update the snapshots?

@shilman shilman added the react label Nov 3, 2018
@chadfawcett
Copy link
Member Author

@igor-dv Which test checks the snapshots? Everything either passes locally or fails on the Vue bugs in Master.

@codecov
Copy link

codecov bot commented Nov 4, 2018

Codecov Report

Merging #4695 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4695   +/-   ##
=======================================
  Coverage   35.59%   35.59%           
=======================================
  Files         557      557           
  Lines        6732     6732           
  Branches      884      884           
=======================================
  Hits         2396     2396           
  Misses       3876     3876           
  Partials      460      460
Impacted Files Coverage Δ
app/react/src/server/cra_config.js 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 870cee3...11a28a0. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug configuration babel / webpack patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch react
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants