I am having a problem with my webpack configuration.
I am having several entries in my configuration file, webpack.production.js
my problem is that when generating the file, they build
all come with the extension .js
.
In one of my entries I have added the package.json
so that the output serves me in npm
.
entry: {
index: path.resolve(__dirname, './src/index.js'),
package: './package.json',
}
...
output: {
path: path.resolve(__dirname, './build'),
}
Departure:
How can I make my output files keep the extension?
webpack: 5.61.0
webpack-cli: 4.9.1
What you want to do can be done in many ways, the easiest would be to use npm for the extra processing ( example option 1 ). Now, if you can't do this, then you can make use of an additional plugin in webpack
CopyWebpackPlugin
( example option 2 )Option 1
You could do it in 2 steps:
webpack
package.json
into thedist
withnpm
It would be something like this in your package.json, the section
scripts
:Option 2
There is a Webpack plugin called CopyWebpackPlugin. In order to use it you must configure it and add it to your
module.exports
Install it:
Then in your
webpack.config.js
And ready. Now when you do the build it will be copied.
A 'hack' to achieve this could be to add a file
package.js
with the plain text:and change your
webpack.config.js
with:This way you trick webpack into transferring the file to the destination folder thinking that part of the bundled code needs it.