Reputation: 531
After building my application in my index.html, the file reference looks like below,
<script type="text/javascript" src="inline.c15b1b72bcd63b7c92ca.bundle.js"></script>
(for example I have shown only for this file).
Since, I have to run my application in server "xyzwebsite.com/app".
I need to copy bundled files to the "app" folder, but when I try to do that I get 404 not found error.
I am new for Angular cli and bundling the app and all these stunts! How can I fix this?
Thanks in advance!
Upvotes: 2
Views: 5387
Reputation: 2052
Using webpack.config.js
If you want much more control to change bundle path using webpack.config.js
file rather than .angular-cli.json
file then do this.
1. Run `ng eject`
This command will expose webpack.config.js
file in your root directory. You can configure that file.
2. Run `npm install`
As npm eject will add new dependencies related to loaders, those needs to be installed which can be done using above command.
3. "output": {
"path": path.join(process.cwd(), "dist"),
"filename": "scripts/[name].[chunkhash:20].bundle.js",
"chunkFilename": "scripts/[id].[chunkhash:20].chunk.js"
}
In webpack.config.js
file edit output entry and add your desired directory name for JS files as shown above. Using this, you can get control over bundling path.
I hope this will be helpful!
Upvotes: 4
Reputation: 676
ng build --base-href /app/
At first I expected that changing the base tag in index.html would do the trick: But after build it seems to be set to default (/) unless you add the above mentioned option.
Upvotes: 5
Reputation: 5039
According to the official documentation, you can just specify the root
and the outdir
parameter which will define the location for your file. Just set them to your /app directory and you'll be fine.
Having to move your generated file somewhere else does not seems to be a good idea in my opinion, better way is to directly generate them in the right location.
Upvotes: 2