Skip to content

(publicPath) Problem with CSS url path when I add publicPath(deployUrl) in angular-cli.json #4035

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

Closed
changLiuUNSW opened this issue Jan 16, 2017 · 3 comments · Fixed by #4036

Comments

@changLiuUNSW
Copy link
Contributor

changLiuUNSW commented Jan 16, 2017

Hi,

this is my directory:

|-src
  |-app
  |- assets
      |-svg
         |-more.svg
  |-environments
  |-index.html
  |-styles.scss
....

I add "deployUrl": "client/dist/", to my angular-cli.json.

I have following CSS in the styles.scss:

.more {
  background: url("./assets/svg/more.svg");
  float: right;
  height: 24px;
  margin-top: 12px;
  width: 24px;
}

After I run ng build , it will translate to:

.more {
  background: url("client/dist/more.svg");
  float: right;
  height: 24px;
  margin-top: 12px;
  width: 24px;
}

When I load my application, the background SVG will be loaded from wrong path:
http://www.xxxx.com/MyApplication/client/dist/client/dist/more.svg

The correct Path should be:
http://www.xxxx.com/MyApplication/client/dist/more.svg

I can do a quick fix by overriding the publicPath setting of ExtractTextPlugin

if (stylePaths.length > 0) {
    // load global css as css files
    cssLoaders.push(...baseRules.map(({test, loaders}) => ({
      include: stylePaths, test, loaders: ExtractTextPlugin.extract({
        remove: false,
        loader: ['css-loader', ...commonLoaders, ...loaders],
        fallbackLoader: 'style-loader',
        publicPath: ''
      })
    })));
  }

Does anyone have the same issue or have a better fix for this?

@changLiuUNSW changLiuUNSW changed the title problem with CSS url path when I add deployUrl in angular-cli.json (publicPath) (publicPath) problem with CSS url path when I add deployUrl in angular-cli.json Jan 16, 2017
@changLiuUNSW changLiuUNSW changed the title (publicPath) problem with CSS url path when I add deployUrl in angular-cli.json (publicPath) Problem with CSS url path when I add deployUrl in angular-cli.json Jan 16, 2017
@changLiuUNSW changLiuUNSW changed the title (publicPath) Problem with CSS url path when I add deployUrl in angular-cli.json (publicPath) Problem with CSS url path when I add publicPath(deployUrl) in angular-cli.json Jan 16, 2017
@changLiuUNSW
Copy link
Contributor Author

changLiuUNSW commented Jan 16, 2017

It will also break url path for font-awesome when added like:

"styles": [
    "styles.css",
    "../node_modules/font-awesome/css/font-awesome.css"
]

@changLiuUNSW
Copy link
Contributor Author

Same issue webpack-contrib/css-loader#234

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants