最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin8PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far