This is in my webpack.config.js
:
var path = require('path');
module.exports = {
entry: './src/index.jsx',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js'
},
devServer: {
inline: true,
port: 8080
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015', 'react']
}
}
]
}
}
And this is how I run it:
$ webpack-dev-server --watch-poll --progress --colors
$ webpack --progress --colors
The problem I'm having is that webpack-dev-server
is serving the bundle file at the root of my folder (not on the build
) folder how I would expect. But webpack
outputs the bundle file to build/
(how I expect) to.
So I have to change the script scr when I do a build.
Is there a way to solve that? Maybe is just bad configuration on my webpack.config.js
.
I'm running ubuntu BTW.
The webpack-dev-server will serve the files in the current directory, unless you configure a specific content base. Using this config webpack-dev-server will serve the static files in your public folder. It'll watch your source files for changes and when changes are made the bundle will be recompiled.
Either method will start a server instance and begin listening for connections from localhost on port 8080 . webpack-dev-server is configured by default to support live-reload of files as you edit your assets while the server is running. See the documentation for more use cases and options.
publicPath tells webpack-dev-server or express server to serve this bundled file ie examples/dist/app.js from specified virtual location in server ie /public/assets/js. So in your html file, you have to reference this file as <script src="public/assets/js/app.js"></script>
Webpack v4+ will minify your code by default in production mode . Note that while the TerserPlugin is a great place to start for minification and being used by default, there are other options out there: ClosureWebpackPlugin.
publicPath tells webpack-dev-server where to serve your bundle in memory
output: {
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js',
publicPath: '/build/'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With