@compiled/webpack-loader 0.9.8 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiled-loader.js +8 -2
- package/dist/compiled-loader.js.map +1 -1
- package/dist/types.d.ts +7 -0
- package/package.json +11 -11
- package/src/__tests__/compiled-loader.test.ts +5 -1
- package/src/__tests__/extract-plugin.test.ts +11 -3
- package/src/compiled-loader.ts +7 -0
- package/src/types.ts +8 -0
package/dist/compiled-loader.js
CHANGED
|
@@ -30,7 +30,7 @@ let hasErrored = false;
|
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
32
|
function getLoaderOptions(context) {
|
|
33
|
-
const { bake = true, extract = false, importReact = undefined, nonce = undefined, resolve = {}, extensions = undefined, parserBabelPlugins = [], transformerBabelPlugins = [], [extract_plugin_1.pluginName]: isPluginEnabled = false, ssr = false, optimizeCss = true, addComponentName = false, } = typeof context.getOptions === 'undefined'
|
|
33
|
+
const { bake = true, extract = false, importReact = undefined, nonce = undefined, resolve = {}, extensions = undefined, parserBabelPlugins = [], transformerBabelPlugins = [], [extract_plugin_1.pluginName]: isPluginEnabled = false, ssr = false, optimizeCss = true, addComponentName = false, classNameCompressionMap = undefined, } = typeof context.getOptions === 'undefined'
|
|
34
34
|
? // Webpack v4 flow
|
|
35
35
|
(0, loader_utils_1.getOptions)(context)
|
|
36
36
|
: // Webpack v5 flow
|
|
@@ -73,6 +73,9 @@ function getLoaderOptions(context) {
|
|
|
73
73
|
addComponentName: {
|
|
74
74
|
type: 'boolean',
|
|
75
75
|
},
|
|
76
|
+
classNameCompressionMap: {
|
|
77
|
+
type: 'object',
|
|
78
|
+
},
|
|
76
79
|
},
|
|
77
80
|
});
|
|
78
81
|
return {
|
|
@@ -88,6 +91,7 @@ function getLoaderOptions(context) {
|
|
|
88
91
|
ssr,
|
|
89
92
|
optimizeCss,
|
|
90
93
|
addComponentName,
|
|
94
|
+
classNameCompressionMap,
|
|
91
95
|
};
|
|
92
96
|
}
|
|
93
97
|
/**
|
|
@@ -145,7 +149,9 @@ async function compiledLoader(code) {
|
|
|
145
149
|
],
|
|
146
150
|
options.bake && [
|
|
147
151
|
'@compiled/babel-plugin',
|
|
148
|
-
Object.assign(Object.assign({}, options), {
|
|
152
|
+
Object.assign(Object.assign({}, options), {
|
|
153
|
+
// Turn off compressing class names if stylesheet extraction is off
|
|
154
|
+
classNameCompressionMap: options.extract && options.classNameCompressionMap, onIncludedFiles: (files) => includedFiles.push(...files), resolver: {
|
|
149
155
|
// The resolver needs to be synchronous, as babel plugins must be synchronous
|
|
150
156
|
resolveSync: (context, request) => {
|
|
151
157
|
return resolver.resolveSync({}, (0, path_1.dirname)(context), request);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiled-loader.js","sourceRoot":"","sources":["../src/compiled-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,+BAA0C;AAE1C,sCAAgE;AAChE,2CAAyD;AACzD,uDAA0E;AAC1E,+CAA0C;AAG1C,qDAA8D;AAG9D,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAA6C;IACrE,MAAM,EACJ,IAAI,GAAG,IAAI,EACX,OAAO,GAAG,KAAK,EACf,WAAW,GAAG,SAAS,EACvB,KAAK,GAAG,SAAS,EACjB,OAAO,GAAG,EAAE,EACZ,UAAU,GAAG,SAAS,EACtB,kBAAkB,GAAG,EAAE,EACvB,uBAAuB,GAAG,EAAE,EAC5B,CAAC,2BAAU,CAAC,EAAE,eAAe,GAAG,KAAK,EACrC,GAAG,GAAG,KAAK,EACX,WAAW,GAAG,IAAI,EAClB,gBAAgB,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"compiled-loader.js","sourceRoot":"","sources":["../src/compiled-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,+BAA0C;AAE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,CAAC,EAAE,OAAO,CAAC,CAAC;4BAC7D,CAAC;yBACF;iBAEJ;aACF,CAAC,MAAM,CAAC,iBAAS,CAAC;SACpB,CAAC,CAAC;QAEH,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC7B,IAAI,CAAC,aAAa,CAAC,IAAA,gBAAS,EAAC,IAAI,CAAC,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,IAAI,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,EAAE,EAAE,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,mCAAI,SAAS,CAAC,CAAC;KAC9D;IAAC,OAAO,CAAU,EAAE;QACnB,+CAA+C;QAC/C,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC7E,QAAQ,CAAC,KAAK,CAAC,CAAC;KACjB;AACH,CAAC;AAvFD,iCAuFC;AAED,SAAgB,KAAK;IACnB,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,CAAC,UAAU,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,2BAAU,CAAC,EAAE;QAC1D,IAAI,CAAC,SAAS,CACZ,IAAA,mBAAW,EAAC,gBAAgB,CAAC,CAC3B,gLAAgL,CACjL,CACF,CAAC;QAEF,4FAA4F;QAC5F,UAAU,GAAG,IAAI,CAAC;KACnB;AACH,CAAC;AAZD,sBAYC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -64,6 +64,13 @@ export interface CompiledLoaderOptions {
|
|
|
64
64
|
* Default to `false`
|
|
65
65
|
*/
|
|
66
66
|
addComponentName?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* A map holds the key-value pairs between full Atomic class names and the compressed ones
|
|
69
|
+
* i.e. { '_aaaabbbb': 'a' }
|
|
70
|
+
*
|
|
71
|
+
* Default to `undefined`
|
|
72
|
+
*/
|
|
73
|
+
classNameCompressionMap?: object;
|
|
67
74
|
}
|
|
68
75
|
export interface CompiledExtractPluginOptions {
|
|
69
76
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compiled/webpack-loader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "A familiar and performant compile time CSS-in-JS library for React.",
|
|
5
5
|
"homepage": "https://compiledcssinjs.com/docs/pkg-webpack-loader",
|
|
6
6
|
"bugs": "https://github.com/atlassian-labs/compiled/issues/new?assignees=&labels=bug&template=bug_report.md",
|
|
@@ -20,26 +20,26 @@
|
|
|
20
20
|
"src"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@babel/core": "^7.
|
|
24
|
-
"@babel/parser": "^7.
|
|
25
|
-
"@compiled/babel-plugin": "^0.
|
|
26
|
-
"@compiled/babel-plugin-strip-runtime": "^0.
|
|
27
|
-
"@compiled/css": "^0.
|
|
28
|
-
"@compiled/utils": "^0.
|
|
23
|
+
"@babel/core": "^7.21.0",
|
|
24
|
+
"@babel/parser": "^7.21.2",
|
|
25
|
+
"@compiled/babel-plugin": "^0.18.1",
|
|
26
|
+
"@compiled/babel-plugin-strip-runtime": "^0.18.0",
|
|
27
|
+
"@compiled/css": "^0.10.0",
|
|
28
|
+
"@compiled/utils": "^0.7.0",
|
|
29
29
|
"enhanced-resolve": "^5.12.0",
|
|
30
30
|
"loader-utils": "^2.0.4",
|
|
31
31
|
"webpack-sources": "^3.2.3"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@compiled/react": "^0.
|
|
35
|
-
"babel-loader": "^
|
|
36
|
-
"css-loader": "^6.7.
|
|
34
|
+
"@compiled/react": "^0.12.0",
|
|
35
|
+
"babel-loader": "^9.1.2",
|
|
36
|
+
"css-loader": "^6.7.3",
|
|
37
37
|
"memfs": "^3.4.13",
|
|
38
38
|
"mini-css-extract-plugin": "^1.6.2",
|
|
39
39
|
"react": "^17.0.2",
|
|
40
40
|
"ts-node": "^10.9.1",
|
|
41
41
|
"tsconfig-paths": "^4.1.2",
|
|
42
|
-
"webpack": "^5.
|
|
42
|
+
"webpack": "^5.76.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"webpack": ">= 4.46.0"
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import { join } from 'path';
|
|
2
6
|
|
|
3
7
|
import { bundle as bundleEntry } from './test-utils';
|
|
@@ -22,7 +26,7 @@ describe.each<'development' | 'production'>(['development', 'production'])(
|
|
|
22
26
|
if (mode === 'development') {
|
|
23
27
|
expect(assets['main.js']).toInclude("console.log('Hello world!');");
|
|
24
28
|
} else {
|
|
25
|
-
expect(assets['main.js']).toMatchInlineSnapshot(`"console.log(
|
|
29
|
+
expect(assets['main.js']).toMatchInlineSnapshot(`"console.log("Hello world!");"`);
|
|
26
30
|
}
|
|
27
31
|
});
|
|
28
32
|
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import { join } from 'path';
|
|
2
6
|
|
|
3
7
|
import { bundle as bundleEntry } from './test-utils';
|
|
@@ -20,6 +24,10 @@ describe('CompiledExtractPlugin', () => {
|
|
|
20
24
|
return undefined;
|
|
21
25
|
});
|
|
22
26
|
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
process.env.AUTOPREFIXER = 'off';
|
|
29
|
+
});
|
|
30
|
+
|
|
23
31
|
it('throws when the plugin is not configured', async () => {
|
|
24
32
|
const errors = await bundle(join(fixturesPath, 'local-styles.tsx'), {
|
|
25
33
|
disableExtractPlugin: true,
|
|
@@ -148,9 +156,9 @@ describe('CompiledExtractPlugin', () => {
|
|
|
148
156
|
|
|
149
157
|
expect(actual).toMatchInlineSnapshot(`
|
|
150
158
|
"._syaz1r31{color:currentColor}
|
|
151
|
-
._ajmmnqa1{
|
|
152
|
-
._1hmsglyw{
|
|
153
|
-
._4bfu1r31{
|
|
159
|
+
._ajmmnqa1{text-decoration-style:solid}
|
|
160
|
+
._1hmsglyw{text-decoration-line:none}
|
|
161
|
+
._4bfu1r31{text-decoration-color:currentColor}
|
|
154
162
|
._n7zl17qw{border-bottom:1px solid transparent}
|
|
155
163
|
._n7zl1l01{border-bottom:1px solid rgba(135,119,217,0.2)}
|
|
156
164
|
._syaz1cj8{color:var(--_xexnhp)}
|
package/src/compiled-loader.ts
CHANGED
|
@@ -32,6 +32,7 @@ function getLoaderOptions(context: LoaderContext<CompiledLoaderOptions>) {
|
|
|
32
32
|
ssr = false,
|
|
33
33
|
optimizeCss = true,
|
|
34
34
|
addComponentName = false,
|
|
35
|
+
classNameCompressionMap = undefined,
|
|
35
36
|
}: CompiledLoaderOptions = typeof context.getOptions === 'undefined'
|
|
36
37
|
? // Webpack v4 flow
|
|
37
38
|
getOptions(context)
|
|
@@ -75,6 +76,9 @@ function getLoaderOptions(context: LoaderContext<CompiledLoaderOptions>) {
|
|
|
75
76
|
addComponentName: {
|
|
76
77
|
type: 'boolean',
|
|
77
78
|
},
|
|
79
|
+
classNameCompressionMap: {
|
|
80
|
+
type: 'object',
|
|
81
|
+
},
|
|
78
82
|
},
|
|
79
83
|
});
|
|
80
84
|
|
|
@@ -91,6 +95,7 @@ function getLoaderOptions(context: LoaderContext<CompiledLoaderOptions>) {
|
|
|
91
95
|
ssr,
|
|
92
96
|
optimizeCss,
|
|
93
97
|
addComponentName,
|
|
98
|
+
classNameCompressionMap,
|
|
94
99
|
};
|
|
95
100
|
}
|
|
96
101
|
|
|
@@ -163,6 +168,8 @@ export default async function compiledLoader(
|
|
|
163
168
|
'@compiled/babel-plugin',
|
|
164
169
|
{
|
|
165
170
|
...options,
|
|
171
|
+
// Turn off compressing class names if stylesheet extraction is off
|
|
172
|
+
classNameCompressionMap: options.extract && options.classNameCompressionMap,
|
|
166
173
|
onIncludedFiles: (files: string[]) => includedFiles.push(...files),
|
|
167
174
|
resolver: {
|
|
168
175
|
// The resolver needs to be synchronous, as babel plugins must be synchronous
|
package/src/types.ts
CHANGED
|
@@ -78,6 +78,14 @@ export interface CompiledLoaderOptions {
|
|
|
78
78
|
* Default to `false`
|
|
79
79
|
*/
|
|
80
80
|
addComponentName?: boolean;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A map holds the key-value pairs between full Atomic class names and the compressed ones
|
|
84
|
+
* i.e. { '_aaaabbbb': 'a' }
|
|
85
|
+
*
|
|
86
|
+
* Default to `undefined`
|
|
87
|
+
*/
|
|
88
|
+
classNameCompressionMap?: object;
|
|
81
89
|
}
|
|
82
90
|
|
|
83
91
|
export interface CompiledExtractPluginOptions {
|