Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added support for assets #90

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

Closed
EmilLuta wants to merge 6 commits into django-webpack:master from EmilLuta:assets_support
Closed

Added support for assets #90

EmilLuta wants to merge 6 commits into django-webpack:master from EmilLuta:assets_support

Conversation

@EmilLuta
Copy link

@EmilLuta EmilLuta commented Dec 7, 2016

Assets may be accessible on the tag get_asset,
therefore, anything that goes in webpack in
exported-assets.js may be accessible here,
by the same url linked into the js file
retrieving the public_path of the file

spinus reacted with thumbs up emoji
Emil Luta added 2 commits December 7, 2016 16:46
Assets may be accessible on the tag get_asset,
therefore, anything that goes in webpack in
exported-assets.js may be accessible here,
by the same url linked into the js file
retrieving the public_path of the file
Copy link

coveralls commented Dec 7, 2016
edited
Loading

Coverage Status

Coverage decreased (-1.7%) to 95.57% when pulling 2855596 on EmilLuta:assets_support into 9dcd192 on owais:master.

Copy link

coveralls commented Dec 7, 2016
edited
Loading

Coverage Status

Coverage decreased (-1.7%) to 95.57% when pulling 2855596 on EmilLuta:assets_support into 9dcd192 on owais:master.

Copy link

coveralls commented Dec 12, 2016
edited
Loading

Coverage Status

Coverage decreased (-1.7%) to 95.57% when pulling 32a730e on EmilLuta:assets_support into 9dcd192 on owais:master.

Updated the readme with use information based on
the webpack_static_path and furthermore, changed
static_assets -> webpack_static_path.
Copy link

coveralls commented Dec 12, 2016
edited
Loading

Coverage Status

Coverage decreased (-1.7%) to 95.57% when pulling b266a74 on EmilLuta:assets_support into 9dcd192 on owais:master.

Copy link

coveralls commented Dec 12, 2016
edited
Loading

Coverage Status

Coverage decreased (-1.7%) to 95.57% when pulling 3ed8aa6 on EmilLuta:assets_support into 9dcd192 on owais:master.

Copy link
Collaborator

owais commented Dec 24, 2016

@EmilLuta Thanks for the contributions. I really appreciate the time and work you put into this but I wish you had discussed this before investing all the time. I'm not sure about the way this PR changes the API of both django-webpack-loader and webpack-bundle-tracker.

BTW, you can already get references to webpack assets using the webpack_static template tag. For example,

{% webpack_static "test.jpg" %}

is replaced with the full link to test.jppg. This does not support assets with bundle hash in filename but I think that can be implement with very little or no changes to the existing API.

Copy link
Author

Hello @owais. I managed to email you a couple of times, so I thought to give it a shot at replying. Basically, what my PR adds is static files management without js. Indeed, it might've proven a good idea to have a chat before. As you stated, the changes are on both sides of the API.

If you have unclarities about how this works, let me know so we can have a look together. Basically, the only thing it does is to add files in a specific bundle, allowing them to be rendered straight from django at need as static assets.

Please, follow up in order to see whether there is a chance where we can get this merged into the current packages.

Cheers!

Copy link

@owais I understand that webpack_static can be used to reverse non hashed files, but having them hashed give us useful guarantees in terms of caching (i.e. stale assets will never be used when releasing new versions). So I totally understand @EmilLuta motivations when pushing this. Basically, the lack of this is what currently impedes me from preloading resources in django templates.

Copy link
Collaborator

owais commented Nov 24, 2017
edited
Loading

I've commented here on what would be the ideal API on webpack-bundle-tracker side to do this. With that change, I imagine it should be simple on django-webpack-loader side to support it.

django-webpack/webpack-bundle-tracker#17 (comment)

Copy link
Contributor

matthiask commented Mar 20, 2018
edited
Loading

I found out that it is quite easy to use the same paths in the webpack output as Django's ManifestStaticFilesStorage generates. Simply use the following snippet in webpack.config.js and ManifestStaticFilesStorage, and you're set:

 {
 test: /\.(png|woff|woff2|svg|eot|ttf|gif|jpe?g)$/,
 use: [
 {
 loader: 'url-loader',
 options: {
 limit: 1000,
 // ManifestStaticFilesStorage reuse.
 name: '[path][name].[md5:hash:hex:12].[ext]',
 // No need to emit files in production, collectstatic does it.
 emitFile: DEBUG,
 },
 },
 ],
 },

This means that you can just use require('image.png'), and {% static 'app/image.png' %} if you choose webpack's context and output vars wisely, something like this:

module.exports = {
 context: path.join(__dirname, 'app', 'static', 'app'),
 entry: {
 main: './main.js',
 },
 output: {
 path: path.resolve('./static/app/'),
 publicPath: DEBUG
 ? 'http' + (HTTPS ? 's' : '') + '://' + HOST + ':4000/'
 : '/static/app/',
 filename: DEBUG ? '[name].js' : '[name]-[chunkhash].js',
 chunkFilename: DEBUG ? '[name].js' : '[name]-[chunkhash].js',
 },
 resolve: {
 extensions: ['.js', '.jsx'],
 modules: ['app/static/app/'],
 alias: {},
 },
// .....
}
spinus reacted with thumbs up emoji

Copy link

spinus commented Dec 22, 2019

@matthiask thank you, useful tip!

@fjsj fjsj requested a review from rvlb May 6, 2021 13:08
Copy link
Member

fjsj commented May 6, 2021

@rvlb could you please check if this is necessary right now and how/if this is supported by current master?

Copy link
Contributor

rvlb commented Oct 22, 2021

Hi folks, closing this PR for now. We've added a tutorial on our readme on how to access the assets using webpack_static.

@rvlb rvlb closed this Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@rvlb rvlb Awaiting requested review from rvlb

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /