django icon indicating copy to clipboard operation
django copied to clipboard

Javascript modules support for ManifestStaticFilesStorage

Open mangelozzi opened this issue 2 years ago • 1 comments

Modern web developement includes CSS custom properties, Javascript modules, and web components.

Unfortunately the manifest storage doesnt support changing the URL of Javascript modules (it only supports JS source maps). Javascript modules solve many of the problems Javascript suffers from as it grew from its infant stags to where it is now. They are important for writing robust Javascript code.

I recommend adding support for them. Unfortunately it is quite a complex regex as there are variations when importing. Ideally one would run it on .js and .mjs files, but I but it does not seems like an easy modification, so I went with .mjs as its more likely to only affect the people who would benefit from it.

It works on the following import styles (taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules):

import { name, draw, reportArea, reportPerimeter } from './modules/square.js';                         
import randomSquare from './modules/square.js';                                                        
import {default as randomSquare} from './modules/square.js';                                           
import { newFunctionName, anotherNewFunctionName } from './modules/module.js';                         
import { function1 as newFunctionName,                                                                 
        function2 as anotherNewFunctionName } from './modules/module.js';                              
import { name, draw, reportArea, reportPerimeter } from './modules/square.js';                         
import { name, draw, reportArea, reportPerimeter } from './modules/circle.js';                         
import { name, draw, reportArea, reportPerimeter } from './modules/triangle.js';                       
import { name as squareName,                                                                           
        draw as drawSquare,                                                                            
        reportArea as reportSquareArea,                                                                
        reportPerimeter as reportSquarePerimeter } from './modules/square.js';                         
                                                                                                       
import { squareName, drawSquare, reportSquareArea, reportSquarePerimeter } from './modules/square.js'; 
import * as Canvas from './modules/canvas.js';                                                         
import { Square } from './modules/square.js';                                                          
import { Square, Circle, Triangle } from './modules/shapes.js';                                        
import colors from './modules/getColors.js';                                                           

mangelozzi avatar Dec 10 '21 12:12 mangelozzi

@mangelozzi Thanks :+1: Have you seen the previous attempt 91e21836f667c784a8a63ab1f18d81f553e679cb? which was reverted ba9ced3e9a643a05bc521f0a2e6d02e3569de374. See also ticket-32319 and ticket-33253.

felixxm avatar Dec 10 '21 12:12 felixxm

Fixed by e44d348c99f0a449180399045ac54b3909121a03.

felixxm avatar Dec 07 '22 09:12 felixxm