-
Notifications
You must be signed in to change notification settings - Fork 80
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
Fixed: Usage with CommonsChunks module #2
Comments
Hi, @arunoda, I believe it's related to the This is one of the things that brought me a lot of headaches when I tried to figure out how the DLLPlugin works. You should set the context to the root of the project. For example:
You should set the context like so: module.exports = {
entry: './src/index.js',
...
plugins: [
new AutoDllPlugin({
context: path.join(__dirname, '..'),
entry: {
vendor: [
'react',
'react-dom'
]
}
})
]
}; I see that your context in your config is set to I plan to make it more clear in the readme and also warn the user when a module exists in both the DLL and the main bundles. I see that the also, I see that you use the inject option, but you reference the DLL bundle yourself in getScripts () {
const { dev } = this.context._documentProps
if (dev) {
return [
this.getChunkScript('manifest.js'),
this.getChunkScript('commons.js'),
this.getChunkScript('vendor.js'),
this.getChunkScript('main.js')
]
}
...
} The This is why the recommended way also includes the HtmlPlugin Please let me know if you need any further help (: Asaf |
I'll try to run your fork locally, to see if I can help you set it up. |
@asfktz that'd be amazing. |
Turns out It was the context after all, but in a different way than I expected. Your bundles look like that: {
'main.js': [ '/Users/asafkatz/dev/next.js/dist/client/next.js' ],
'bundles/pages/index.js': [ './pages/index.js?entry' ],
'bundles/pages/other.js': [ './pages/other.js?entry' ],
'bundles/pages/_error.js': [ '/Users/asafkatz/dev/next.js/dist/pages/_error.js?entry' ],
'bundles/pages/_document.js': [ '/Users/asafkatz/dev/next.js/dist/pages/_document.js?entry' ]
} (note that next.js is a symlink, but it should work as a regular dependency too) We got two different contexts here. For the pages bundles, it was the user's project root as expected ( I was surprised to discover that in the case of I never saw an absolute path as an entry module before, It's good to be aware that such use case exists. The solution is to set the context like so: new AutoDllPlugin({
context: join(__dirname, '../../..'), // '/Users/asafkatz/dev/next.js'
filename: '[name].js',
path: './',
entry: {
vendor: [
'react',
'react-dom'
]
}
}), Theatrically, you should be able to use 2 instances of AutoDllPlugin at once, one for each context. [
new AutoDllPlugin({
context: join(__dirname, '../../..'), // '/Users/asafkatz/dev/next.js'
filename: '[name].js',
path: './',
entry: {
vendor: [
'react',
'react-dom'
]
}
}),
new AutoDllPlugin({
context: dir, // The user's root project
filename: '[name].js',
path: './',
entry: {
'user-vendors': [
'cowsay-browser'
]
}
})
] But it will not work in the current version because of the way the cache is handled. Also, I believe #6 may affect you. Really enjoyed to dive into the internals of next.js, it's beautiful! Please let me know if you need any further help. |
Thanks for @asfktz for digging into this. |
Hi, @arunoda! I wanted to let you know that the cache problem has fixed I forked your fork to test it with the new version of the plugin: You'll see that there are now 2 AutoDll instances, one for next.js and one for the user. If you'll inspect the source of I am curious to know how you intend to use it. It's important for me to learn from the use cases so the plugin could evolve in the right direction. Please let me know if you need any further help. Asaf. |
@asfktz Nice. I'll play along with this. |
Hey, this looks like pretty great.
I just started trying to integrate this with Next.js. (We've a pretty complex webpack config)
Specially we use the "common chunks plugin".
When I use this as mentioned in the recommend way, I got react and react-dom in the
vendor.js
. But it's also in thecommons.js
as well.This is my code: vercel/next.js#2433
Is there anything else I've to do here.
The text was updated successfully, but these errors were encountered: