-
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
Leverage loaders for use with CSS / images / etc #37
Comments
Hi, @tquetano-r7! That's a great idea! never thought about inheriting the loaders from the config before.
Yeah, only plugins were added. I believe in adding a feature only when I know for sure there's a use case for it. Plugins, for example, were added because people wanted to use the DLL in production and needed a way to pass it thru the uglify plugin. |
Hi, @tquetano-r7, I'm playing around with this idea in the loaders branch. I would like to share my thoughts with you if you don't mind. First, I can allow the user to pass the new AutoDllPlugin({
filename: '[name].dll.js',
entry: { vendor: [ ... ] },
module: {
strictExportPresence: true,
rules: [
{
oneOf: [
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: require.resolve('url-loader'),
options: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]'
}
},
{
exclude: [/\.js$/, /\.html$/, /\.json$/],
loader: require.resolve('file-loader'),
options: {
name: 'static/media/[name].[hash:8].[ext]'
}
}
]
}
]
}
}); But because it makes a lot of sense to reuse the loaders from your own config, I thought about adding an module.exports = {
entry: {
app: './src/index.js'
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
module: {
strictExportPresence: true,
rules: [
{
oneOf: [
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: require.resolve('url-loader'),
options: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]'
}
},
{
exclude: [/\.js$/, /\.html$/, /\.json$/],
loader: require.resolve('file-loader'),
options: {
name: 'static/media/[name].[hash:8].[ext]'
}
}
]
}
]
}
plugins: [
new AutoDllPlugin({
filename: '[name].dll.js',
entry: { vendor: [ ... ] },
module: 'inherit'
});
]
}; I thought about doing the same with plugins, but it can get a bit awkward (Adding an AutoDLL plugin to the DLL itself.. hmm.. 🙃) I still need to test it, a lot. What do you think? I would love to hear your feedback. Also, If you can help me get a few good test cases I would appreciate it a lot (like what loaders font-awesome needs, and what other libs you know that require a special loader) Asaf |
It would also help to supply config options which get merged with the default config. In the main webpack config I just do this to avoid webpack throwing {
node: {
fs: 'empty',
module: 'empty',
net: 'empty',
},
} But when I now try to use this plugin, I cannot set this config, which results in the exception mentioned above. So maybe it would be possible instead of just allowing modules to be specified that every config can be specified. Even better would be if the complete webpack config is taken as is and then modify Maybe something like this could work: new AutoDllPlugin({
filename: '[name].dll.js',
entry: { vendor: [ ... ] },
webpack: {
// my custom webpack config
}
}); |
Hi @danez,
You are right, It will be much better to find a generic solution instead. To better understand the challenges, here's what happens behind the scenes. If this is your config: new AutoDllPlugin({
entry: {
vendor:['react', 'react-dom']
},
filename: '[name].dll.js',
plugins: [
new SomePlugin({
foo: 'bar'
})
]
}); The generated DLL config will look like that: {
entry: {
vendor: [
'react',
'react-dom',
],
},
output: {
filename: '[name].dll.js',
library: '[name]_[hash]',
path: '/abs-path-to-your-project/.cache/node_modules/autodll-webpack-plugin/environment-name__unique-hash',
},
plugins: [
DllPlugin {
options: {
name: '[name]_[hash]',
path: '/abs-path-to-your-project/node_modules/.cache/autodll-webpack-plugin/environment-name__unique-hash/[name].manifest.json',
},
},
SomePlugin {
options: {
foo: 'bar'
},
}
],
resolve: {
extensions: [
'.js',
'.jsx',
'.json'
],
},
} This is how the user's option will be merged into:
So if we'll take your suggestion for example: new AutoDllPlugin({
entry: {
vendor:['react', 'react-dom']
},
filename: '[name].dll.js',
webpack: {
entry: {
vendor: [ ... ],
other: [ ... ]
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle-dll.js",
publicPath: "/assets/",
library: "MyLibrary",
libraryTarget: "umd",
}
module: { ... },
plugins: [ ... ],
node: { ... }
}
}); Now we got a few dilemmas to think about:
Yes, this is something I really want the plugin to have, the ability to inherit from the user's config. I don't know how much intuitive it will be as the default behavior (although it seems like it does, judging from the latest issues) module.exports = {
entry: {
app: './src/index.js'
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
module: {
rules: [ ... ]
}
node: node: {
fs: 'empty',
module: 'empty',
net: 'empty',
},
performance: {
hints: false,
},
devtool: 'cheap-module-source-map',
plugins: [
new AutoDllPlugin({
filename: '[name].dll.js',
entry: { vendor: [ ... ] },
inherit: true // <---
config: {
plugins: [
new UglifyJsPlugin()
]
}
}),
new HtmlPlugin({
template: "index.ejs"
}),
new webpack.DefinePlugin({
PRODUCTION: JSON.stringify(true),
VERSION: JSON.stringify("5fa3b9")
})
]
}; By setting
Then, he can override it using the Plugins are the most problematic. Of course, the user can override that by settings The best option I can think of is to not inherit plugins in the first place. I would love to hear your opinion, Asaf |
I assumed that this ( Technically, loaders can also apply to vendor dependencies. For example, it was previously necessary (in webpack 1.x) to add In my case, I have a home-grown library (that we modify very infrequently) that I need to bundle using specific loaders. Is there a solution for this apart from reverting to a manual DllPlugin configuration? |
@fortinmike I have the same needs, and was quite disapointed too. I guess everyone thinks their use case is a common one ;) @asfktz IMHO Please let me know if I can help. Ultimately, thanks for this hard work, simplyfing is really hard 👍 |
@fortinmike @thomasbertet, It's important to me to be aware of more advanced use cases so I can keep them in mind while I add new features. I apologize that it takes so long, My life got a bit too busy lately and I hope to get more free time soon. I almost finished working on that one. hope to publish it on the weekend. Asaf |
I would like to confirm that |
Hi @niieani, Yeah, I agree. inherit makes a lot of sense for me too. I implemented both of the features ( module.exports = {
context: __dirname,
entry: {
main: './src/index.js',
},
module: {
rules: [ ... ]
},
plugins: [
new UglifyJsPlugin()
new AutoDllPlugin({
filename: '[name].[hash].js',
entry: {
dllBundle: [ ... ],
},
inherit: true, // inherit from the parent config
config: {} // extend the config
})
]
}; It works! but there are issues that prevent me from shipping it:Inhering plugins Loaders are not working properly Steps to reproduce the bug:
I believe this has something to do with the why I assign the assets created by the DLL to the compilation.assets. autodll-webpack-plugin/src/plugin.js Lines 78 to 96 in 2044537
Have any idea what can cause this? |
Has there been any movement on this? I have a huge react codebase of >25 apps that I want to split into DLLs to improve build times. If I understand correctly I wont be able to do that currently with |
Stepping through a debugger during compilation shows that
path:'' because in that case the file-loader publicPath doesn't need anything prepended.
file-loader is ultimately calling autodll-webpack-plugin/src/plugin.js Lines 90 to 92 in a8b44f7
like you would expect. It might be a bug in using a combination of DLLs + css-loader + file-loader. I will look into this further when I have some time |
Hi, @tryggvigy It seems like you have much more direction than I had. That will be so amazing if you manage to solve it. Here are some tips for better debugging: open 2 terminal windows,
That's the debugging workflow I use (btw, @niieani, It might be useful for you too). Also Let me know if you need further clarifications. Thanks! |
Curious if there was any more movement on this. We would also like to leverage autodll for separate yarn workspaces we have in our app. @asfktz would you mind updating the |
Hi @switz, Currently, there's no progress on this. You're more than welcome to send a PR. Thanks! |
@asfktz Thanks for this great plugin, very much in need of |
I think this is the missing piece that will bring auto dll plugin complete, because external css and assets can rather be big and the build can speed up much by bundling them to dlls. |
It works new AutoDllPlugin({
filename: '[name].[hash].js',
entry: {
},
inherit: true, // inherit from the parent config
config: {} // extend the config
})
inherit: true // <--- Thanks! |
Perhaps I'm being optimistic but ... it would be pretty fantastic if we could leverage the webpack loaders we were already using to allow bringing CSS / images into the DLL bundle. Not even sure if its possible, but with packages that are mixed mediums and unchanging (think
font-awesome
) the inclusion would be pretty sweet.Not an issue, more a polite request / fervent hope.
EDIT: I noticed that you could add
plugins
as you do in the webpack config, so I tried addingrules
in the same way and it appears to not impact anything. :(The text was updated successfully, but these errors were encountered: