Skip to content

Instantly share code, notes, and snippets.

@sergioska
Last active March 31, 2018 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergioska/951155ebd3727d41e03420ad0d41b91c to your computer and use it in GitHub Desktop.
Save sergioska/951155ebd3727d41e03420ad0d41b91c to your computer and use it in GitHub Desktop.
webpack configuration to use dev server without add localhost switch on source
<IfModule mod_rewrite.c>
RewriteEngine On
# redirect every requested real file (.js, .css, ecc ...) to webpack dev server
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^public/assets/(.*)$ http://localhost:3000/assets/$1 [L]
</IfModule>
var webpack = require('webpack');
module.exports = function(env) {
var config = {
entry: {
"main": [
// ... source js path
]
},
output: {
path: path.resolve(__dirname, 'web/public'),
filename: "assets/js/[name].bundle.js"
},
devServer: {
contentBase: __dirname + '/web/public',
hot: true,
inline: true,
host: "localhost",
port: 3000,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
}
},
};
config.plugins = [
new webpack.HotModuleReplacementPlugin(),
// ...
]
return config;
};
@sergioska
Copy link
Author

sergioska commented Mar 31, 2018

Follow below steps to use WDS (webpack dev server) with apache to serve assets path directly from dev server without add any bad switch code to your sources

  1. add devServer section to webpack.config.js
  2. add RewriteCond/RewriteRule snippet to your .htaccess con public path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment