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.

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

4 Comments

Where abouts does the config,js file go? I don't have one, I used the create react app
There is a webpack.config.js file in the root of your project.
I used create react app, the only thing in the root of my project is build.gradle, package.json and yarn.lock
You are right, there is no webpack.config.js when you generate the app uding create react app. More info here github.com/facebookincubator/create-react-app/issues/99
2

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.

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.