search

Home  >  Q&A  >  body text

node.js - npm run build之后页面样式丢失

开发环境中,react项目界面是这样

使用npm run build打包之后,把dist下的文件放到node服务器上就变成了这样:

为什么用npm run build打包之后样式会丢失呢?

天蓬老师天蓬老师2863 days ago916

reply all(6)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 16:27:50

    Path problem, try to use node to proxy the dist directory to the root directory.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 16:27:50

    First of all, you have to list what libraries you use for packaging and how to configure them.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 16:27:50

    Then take a look at your packaged path,
    and the path to import css in the packaged page, is it correct?
    Whether publicPath is set

    reply
    0
  • 迷茫

    迷茫2017-04-17 16:27:50

    Go to the index.js file in the config folder to find the build object, and change the "/" in assetsPublicPath to "./"

    reply
    0
  • PHPz

    PHPz2017-04-17 16:27:50

    Open the chrome debugging interface, what’s wrong

    reply
    0
  • 迷茫

    迷茫2017-04-17 16:27:50

    If nothing else, it should be a path problem. The best way is to look at the console error report, find your root path, and then match your style path based on the root path.

    reply
    0
  • Cancelreply