mirror of https://github.com/webpack/webpack.git
				
				
				
			feat(css): allow to use default and named export
This commit is contained in:
		
							parent
							
								
									e00439e7fa
								
							
						
					
					
						commit
						f3dbf6bc39
					
				|  | @ -1030,6 +1030,11 @@ class CssParser extends Parser { | |||
| 
 | ||||
| 		module.buildInfo.strict = true; | ||||
| 		module.buildMeta.exportsType = this.namedExports ? "namespace" : "default"; | ||||
| 
 | ||||
| 		if (!this.namedExports) { | ||||
| 			module.buildMeta.defaultObject = "redirect"; | ||||
| 		} | ||||
| 
 | ||||
| 		module.addDependency(new StaticExportsDependency([], true)); | ||||
| 		return state; | ||||
| 	} | ||||
|  |  | |||
|  | @ -0,0 +1,19 @@ | |||
| import * as style1 from "./style.module.css?namespace"; | ||||
| import style2 from "./style.module.css?default"; | ||||
| import { foo } from "./style.module.css?named"; | ||||
| 
 | ||||
| it("should able to import with default and named exports", () => { | ||||
| 	expect(style1.default).toEqual(nsObj({ foo: '-_style_module_css_namespace-foo' })); | ||||
| 	expect(style1.foo).toEqual("-_style_module_css_namespace-foo"); | ||||
| 	expect(style2).toEqual(nsObj({ foo: '-_style_module_css_default-foo' })); | ||||
| 	expect(foo).toEqual("-_style_module_css_named-foo"); | ||||
| }); | ||||
| 
 | ||||
| it("should able to import with different default and namex dynamic export", (done) => { | ||||
| 	import("./style.module.css?namespace").then((style1) => { | ||||
| 		expect(style1.default).toEqual(nsObj({ foo: '-_style_module_css_namespace-foo' })); | ||||
| 		expect(style1.foo).toEqual('-_style_module_css_namespace-foo'); | ||||
| 
 | ||||
| 		done(); | ||||
| 	}, done) | ||||
| }); | ||||
|  | @ -0,0 +1,3 @@ | |||
| .foo { | ||||
| 	color: red; | ||||
| } | ||||
|  | @ -0,0 +1,20 @@ | |||
| /** @type {import("../../../../").Configuration} */ | ||||
| module.exports = { | ||||
| 	target: "node", | ||||
| 	mode: "development", | ||||
| 	devtool: false, | ||||
| 	module: { | ||||
| 		rules: [ | ||||
| 			{ | ||||
| 				test: /\.css/, | ||||
| 				parser: { | ||||
| 					namedExports: false | ||||
| 				}, | ||||
| 				type: "css/module" | ||||
| 			} | ||||
| 		] | ||||
| 	}, | ||||
| 	experiments: { | ||||
| 		css: true | ||||
| 	} | ||||
| }; | ||||
		Loading…
	
		Reference in New Issue