https://github.com/sergebat/test-webpack-lazymode
'use strict';
module.exports = {
entry: './app.js',
mode: "development",
output: {
filename: "bundle.js"
},
devServer: {
lazy: true,
inline: false,
filename: "bundle.js"
}
};
http://localhost:8080/bundle.js should return bundle in Lazy mode when loaded in browser.
Browser displays: "Cannot GET /bundle.js".
If lazy: true is removed, bundle.js returns fine.
I tried http://localhost:8080/dist/bundle.js, tried removing optional filename in devServer, tried removing inline: false. Neither of these options worked for me.
Sync repo at https://github.com/sergebat/test-webpack-lazymode, then:
npx webpack-dev-server
and open bundle in browser.
I'm not running in lazy mode, but I have found that if I set inline: false that I appear to get a jQuery deferred error. If I remove inline: false and go with the default everything works fine. This is unfortunate however, because I'm requesting an asset from webpack-dev-server for another app, if I don't set inline: false it reloads the whole page for my non-webpack app.
Here is the error:
jQuery.Deferred exception: n(...) is not a function TypeError: n(...) is not a function
at HTMLDocument.<anonymous> (https://localhost:8080/__webpack_dev_server__/live.bundle.js:1:163209)
at c (https://localhost:8080/__webpack_dev_server__/live.bundle.js:1:105849)
at l (https://localhost:8080/__webpack_dev_server__/live.bundle.js:1:106151) undefined
T.Deferred.exceptionHook @ live.bundle.js:1
@scottsword this will be fixed in next release (fixed in #1329)
@sergebat, webpack-dev-server only passes the lazy option to webpack-dev-middleware; so I think the issue is in that package.
@SpaceK33z thanks. I'll try to reproduce with raw 'webpack-dev-middleware' over weekend, and if it occurs there, will create and link issue there.
@SpaceK33z thanks man, I saw that someone added a fix for it yesterday, just hasn't made its way out. For posterity, the issue I encountered was different than OP's and was fixed with this commit - https://github.com/webpack/webpack-dev-server/commit/f2db057ac105ec945f0e62dba64441c4ccfde59c
@SpaceK33z interestingly enough, things seem work fine on webpack-dev-middleware:
https://github.com/sergebat/test-webpack-lazymode/blob/master/testmw.js
File above works fine on Ubuntu node testmw.js for me (not on Windows, as things seem to be broken there the hard way, but that's another issue I guess https://github.com/webpack/webpack-dev-middleware/issues/270)
At the same time, node_modules/.bin/webpack-dev-server displays "Cannot GET /bundle.js" for me on Ubuntu.
In case it helps someone diagnose the issue, it starts to work if path is explicitly and incorrectly specified like this:
'use strict';
module.exports = {
entry: './app.js',
mode: "development",
output: {
filename: "bundle.js",
path: "/" // <- :)
},
devServer: {
lazy: true
}
};
Thanks for figuring this out.
Setting the filename option fixed the problem in my case :
devServer: {
lazy: true,
filename: 'index.html',
}
This issue is still there, I tried all the above-mentioned solutions and no one works. I'm just following the guides and I just tried to play with the different options when I reached the Development section.
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackManifestPlugin = require('webpack-manifest-plugin');
const distFolder = path.resolve(__dirname, 'dist');
const filename = 'bundle.js';
module.exports = {
mode: 'development',
entry: {
app: './src/index.js',
print: './src/print.js'
},
plugins: [
new CleanWebpackPlugin(distFolder),
new HtmlWebpackPlugin({
title: 'Hello from Output Management'
})
],
devtool: 'inline-source-map',
devServer: {
open: true,
contentBase: distFolder,
port: 8008,
compress: true
},
output: {
filename: filename,
path: distFolder
}
}
Oooooooookey. i found it
<script src="/bundle.js"></script>
console.log('works');
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'index.html',
// production
// path: path.resolve('./dist'),
// dev
path: '/',
},
devServer: {
contentBase: path.resolve(__dirname, 'public'),
lazy: true,
},
};
{
"dependencies": {
"webpack": "^4.32.2",
"webpack-dev-server": "^3.4.1",
"webpack-cli": "^3.3.2"
},
"scripts": {
"start": "webpack-dev-server --config webpack.config.js",
"build": "webpack --config webpack.config.js"
}
}
So problem already solved? If not please create actual minimum reproducible test repo, thanks
it doesnt work with HtmlWebpackPlugin, but should
@notiv-nt Speciously? __If not please create actual minimum reproducible test repo, thanks__
@evilebottnawi https://github.com/notiv-nt/webpack-lazy
Thanks
output: {
// Production
// path: path.resolve('./dist'),
// Dev, yarn build throws an error
path: '/',
},
dev-server should run plugins on start
What you mean? Please clarify
output.path — absolute path
https://webpack.js.org/configuration/output#outputpath
htmlwebpackplugin does not work in webpack-dev-server
👀
Lazy was removed from webpack-dev-middleware due incompatibility with webpack and will be removed in next release