-
Notifications
You must be signed in to change notification settings - Fork 72
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
Update VirtualModulesPlugin from upstream #136
Conversation
This updates the internal VirtualModulesPlugin, which is copied from https://github.com/sysgears/webpack-virtual-modules. I went through all commits since this virtual.js was added, and applied them manually to the svelte-loader version where applicable. These upstream changes allow for using Webpack 5 with svelte-loader. This also adds a LICENSE file to comply with the requirements of the MIT license for the plugin files. The LICENSE file also adds in the text of MIT license that svelte-loader is licensed under (with a different copyright line, since svelte-loader wasn't written by SysGears)
@benmccann I've changed all uses of double quotes to single quotes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@Smittyvb You might probably need to check whether you affected by this Issue: |
Integrates the changes from: sysgears/webpack-virtual-modules#69
I've implemented sysgears/webpack-virtual-modules@4894019 from upstream, which implements watch mode support in a way that is compatible with Webpack 5. So to recap:
|
Replaces all usage of var with let/const
@Smittyvb Guys, if you are up to it, I would be open to PR to expose some interface inside |
@larixer I'm working on that: https://github.com/Smittyvb/svelte-loader/tree/wvm-as-dep |
That would be great and I think would help get this PR checked in. I talked to some of the other maintainers about getting this PR checked in since I don't have much webpack background and haven't worked on this repo much, and I think there was some feeling that they'd like to see webpack 5 support be a bit cleaner/simpler. I'm not sure exactly how you would do that, but if there's a nice interface for |
@larixer would also love to see something like that. I've forked the plugin a few times in order to allow bootstrapping in a loader. if you are looking for ideas on an interface i've found this effective: https://github.com/4Catalyzer/astroturf/blob/v1/src/VirtualModulePlugin.ts#L99-L108 |
lib/virtual.js
Outdated
function getData(storage, key) { | ||
const data = storage._data /* webpack 5 */ || storage.data /* webpack 4 */; | ||
if (data instanceof Map) { | ||
return storage.data.get(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be data.get(key)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code advices
lib/virtual.js
Outdated
return data.data[key]; | ||
} | ||
|
||
function setData(backendOrStorage, key, valueFactory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation is not nice. Better looks like getData, a webpack switch and a generic code
fix: optimize the implementation
Oh sorry - I will fix the bug - if I can, |
fix: 'backendOrStorage' is not defined no-undef
Hello everyone, it looks like there is something wrong with style handling on this branch when
The directory structure for the
And the style is connected to the component like this: Here is my Webpack configuration: {
entry, // custom generated list of entry points
mode: 'production',
output: {
path: path.join(projectRoot, 'dist'),
filename: '[name].js',
},
resolve: {
alias: {
svelte: path.resolve(projectRoot, 'node_modules', 'svelte'),
},
extensions: ['.mjs', '.js', '.svelte', '.css'],
mainFields: ['svelte', 'browser', 'module', 'main'],
},
module: {
rules: [
{ test: /.m?js$/, type: 'javascript/auto' },
{
test: /\.svelte$/,
use: {
loader: 'svelte-loader',
options: {
hotReload: false,
hydratable: true,
preprocess: sveltePreprocess(), // imported from 'svelte-preprocess'
dev: false,
emitCss: true,
},
},
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
}),
],
optimization: {
splitChunks: {
chunks: 'all',
},
},
} What fixes the error:
What doesn't fix the error:
|
I think the changed files have nothing to do with CSS. The misconduct with regard to webpack 5 and preprocess is a separate topic. It would be cool if the PR comes so that Webpack5 can work in less complex situations. |
That is solved for us leanupjs/leanup#37. |
Superseded by #146, which fixes the problem in a much better and more maintainable manner. |
Before this licence was in the package.json but it wasn't actually in the repo. sveltejs#136 would have added a license but now sveltejs#146 is the future, and that PR clears up the license issue by not including webpack-virtual-modules in-repo, so it doesn't have to affect the LICENSE file.
tl;dr: Webpack 5 support, fixes
TypeError: Cannot read property 'data' of undefined
This updates the internal VirtualModulesPlugin, which is copied from
webpack-virtual-modules
, which was originally added by @kaisermann. These changes allow for using Webpack 5 withsvelte-loader
. The changes of #125, which have also been fixed upstream, have been preserved. See #59 (comment) for the background on why the source code is just copied over instead of added as a dependency. Due to thesvelte-loader
specific changes already invirtual.js
, I have manually gone through the commit history ofwebpack-virtual-modules
and applied relevant changes instead of just copy-pasting the new source code. There is also a small change toindex.js
to prevent the error handling code from itself throwing errors, since that was causing some (now fixed) troubles when debugging my changes.This also adds in the literal text of the license of
webpack-virtual-modules
, to a newly createdLICENSE
file, since "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software".Tests and lints pass, and I have verified this works with both Webpack 4 and Webpack 5
[continuation from #132, since GH won't let me re-open it]
Closes #133