Skip to content

about css assert path ,two Solution(css路径的问题解决方案) #179

Closed
@zhangbiggs

Description

@zhangbiggs

the CSS modules will be generated as Blobs, so relative paths don't work (they would be relative to > chrome:blob or chrome:devtools). In order for assets to maintain correct paths setting output.publicPath > property of webpack configuration must be set, so that absolute paths are generated.

style-loder 无法自己设置publicpath, 所以只能在ExtractTextPlugin后的css目录路径 和 webpack.base.conf做文章的,
解決的办法有两个,

  • 一个在办法是在webpack.base.conf 里设置assetsPublicPath:'/' 根目录,assetsSubDirectory: './在服务器中的相对路径/static',
    config/index.js
    assetsSubDirectory: 'AbsolutePath/projectPath/static',
    assetsPublicPath: '/',

  • 还有一个是在ExtractTextPlugin,css目录路径,把脱离出来的css路径裸在项目路径,在webpack.prod.conf中设置,
    // 不需要提到static/css 中
    //new ExtractTextPlugin(utils.assetsPath('css/[name].[contenthash].css')),  
    new ExtractTextPlugin('[name].[contenthash].css'),

config/index.js

  assetsSubDirectory: 'static',
    assetsPublicPath: './',

两种方法都可以解决css 中img问题,

在知道项目的绝对路径可以用一方法,
不知道项目的绝对路径可以用二方法,(只是css文件裸在youproject中)^-^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions