-
Notifications
You must be signed in to change notification settings - Fork 22
Porting webpacker config files to plain webpack #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @dbalatero, thank you for the feedback! Extracting a config from Webpacker: The gem does not have such function. It would better for Webpacker to have it. FYI someone tried The next, about Hot Module Replacement: I proposed in my blog post using rack-proxy to enable HMR. I think that installing such rack middleware can be supported in my gem. So, how about starting/stopping webpack-dev-server along with rails? My thought is that webpack-dev-server should start manually separated from rails s. The last is about the test mode. I run |
I am going to think about hot reload in development mode and pre-compile in test mode. |
FYI: I'm trying pre-compile in test by using rspec's |
@nikushi cool! I'd be down to work on a PR to add rack-proxy to enable webpack-dev-server/HMR passthrough. I agree that webpack-dev-server should be started alongside Rails manually. |
The webpack plugin for browsersync is pretty handy in this regard. You get a reload whenever a js, rb or erb file is changed. Not for everyone, but this flow is nice to work with once you have it set up. Basicly, webpack-dev-server is proxys requests based on url. Requests to const jsonPlaceholderProxy = proxy('/javascripts/webpack/', { //change to match your output folder
target: 'https://localhost:8081',
changeOrigin: true, // for vhosted sites, changes host header to match to target's host
logLevel: 'debug',
secure: false,
ssl: {
key: fs.readFileSync('./ssllocal/server.key', 'utf8'),
cert: fs.readFileSync('./ssllocal/server.crt', 'utf8')
},
pathRewrite: {
'^/javascripts/webpack/(.*)': '/$1' // rewrite path
}
});
}
// later in plugins (there are better ways to detect WDS, but we just set explicit flags)
process.env.WPD_HMR !== 'false' ? new BrowserSyncPlugin(
// BrowserSync options
{
host: `${subdomain}.domain.me`, // or localhost
port: 3002,
watchOptions: {
ignoreInitial: true,
ignored: '*.txt'
},
files: ['./app/**/{*.erb,*.rb}'],
open: false,
proxy: {
target: `https://${subdomain}.domain.me:3000/`, // or localhost
middleware: [jsonPlaceholderProxy]
},
https: { key: './ssllocal/server.key', cert: './ssllocal/server.crt' }
},
{ reload: false } // prevent BrowserSync from reloading the page and let Webpack Dev Server take care of this
) : noop() This is a departure from other solutions, but at least it works with HMR and style injection. Plus its nice to have erb files reload the browser when saved. Hope this is useful. |
Now you are able to use this function with v0.3.0 🚀. |
Hi @nikushi! Funnily enough I started on a gem just like yours at https://github.com/dbalatero/webpack-lite a while back. I saw your article https://medium.com/@nikushi/replacing-rails-webpacker-with-vanilla-webpack-54b7ea90d913 and got curious about your project. I like where it's at so far!
I'm curious about a few things before diving into trying this gem:
How do you propose porting a Webpacker config from a production app to plain Webpack? My thought was to actually dump out the final Webpacker config to a file and then make surgical edits to it to bring it back to parity with what Webpacker provides behind the scenes.
Is there any interest in replicating the compile-on-first-request functionality that Webpacker has? Or does that become irrelevant as long as you:
webpack-dev-server
in development modewebpack-dev-server
in test modeThe text was updated successfully, but these errors were encountered: