最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Add path when webpack creates static asset files react, create react app - Stack Overflow

programmeradmin1浏览0评论

I have a react application, which I built with create react app, when I run build it generates the static assets I need and then the index.html file. I am running this on a Ratpack server with gradle. I then use gradle to move these files to my Ratpack directory so I can run it with the Ratpack server. When I move the files I need to add /assets/ onto the url for the JS and CSS file.

For example at the moment it creates the path like this

<script type="text/javascript" src="/static/js/main.dab68f70.js">

where as I need

<script type="text/javascript" src="assets/static/js/main.dab68f70.js">

Is it possible to somehow automate this as each time I run my application the files in my ratpack assets are overwritten by the new files.

I have a react application, which I built with create react app, when I run build it generates the static assets I need and then the index.html file. I am running this on a Ratpack server with gradle. I then use gradle to move these files to my Ratpack directory so I can run it with the Ratpack server. When I move the files I need to add /assets/ onto the url for the JS and CSS file.

For example at the moment it creates the path like this

<script type="text/javascript" src="/static/js/main.dab68f70.js">

where as I need

<script type="text/javascript" src="assets/static/js/main.dab68f70.js">

Is it possible to somehow automate this as each time I run my application the files in my ratpack assets are overwritten by the new files.

Share Improve this question edited Feb 10, 2017 at 18:13 N P asked Feb 10, 2017 at 13:04 N PN P 2,6297 gold badges37 silver badges59 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

What about configuring Webpack output publicPath like this?

output: {
    ...    
    publicPath: "assets",
}

I am using this with Webpack 1.x

The docs can be found here: http://webpack.github.io/docs/configuration.html#output-publicpath

3 Years later......

I had this issue today. And found all the same answers I'm sure you did.

Here is how I fixed it, I went into the index.html file that loads those few files and changed the path manually.

Took about 3 minutes.

In the end I used npm eject, this then exposes all the config files for webpack. From here I edited my webpack config to get my desired paths for my assets.

You can add "homepage": ".", in your package.json file. It will make the build files with relative path. Bit weird though, but it worked for me.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论