@compiled/webpack-loader 0.9.1 → 0.9.3
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
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, } = 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, } = typeof context.getOptions === 'undefined'
|
|
34
34
|
? // Webpack v4 flow
|
|
35
35
|
(0, loader_utils_1.getOptions)(context)
|
|
36
36
|
: // Webpack v5 flow
|
|
@@ -67,6 +67,9 @@ function getLoaderOptions(context) {
|
|
|
67
67
|
ssr: {
|
|
68
68
|
type: 'boolean',
|
|
69
69
|
},
|
|
70
|
+
optimizeCss: {
|
|
71
|
+
type: 'boolean',
|
|
72
|
+
},
|
|
70
73
|
},
|
|
71
74
|
});
|
|
72
75
|
return {
|
|
@@ -80,6 +83,7 @@ function getLoaderOptions(context) {
|
|
|
80
83
|
transformerBabelPlugins,
|
|
81
84
|
[extract_plugin_1.pluginName]: isPluginEnabled,
|
|
82
85
|
ssr,
|
|
86
|
+
optimizeCss,
|
|
83
87
|
};
|
|
84
88
|
}
|
|
85
89
|
/**
|
|
@@ -89,7 +93,7 @@ function getLoaderOptions(context) {
|
|
|
89
93
|
* @param code
|
|
90
94
|
*/
|
|
91
95
|
async function compiledLoader(code) {
|
|
92
|
-
var _a, _b, _c, _d, _e;
|
|
96
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
93
97
|
const callback = this.async();
|
|
94
98
|
// Bail early if Compiled isn't in the module or we're looking at compiled runtime code
|
|
95
99
|
if (code.indexOf('@compiled/react') === -1 ||
|
|
@@ -98,20 +102,23 @@ async function compiledLoader(code) {
|
|
|
98
102
|
}
|
|
99
103
|
try {
|
|
100
104
|
const includedFiles = [];
|
|
101
|
-
const
|
|
105
|
+
const _h = getLoaderOptions(this), { resolve } = _h, options = __rest(_h, ["resolve"]);
|
|
102
106
|
// Transform to an AST using the local babel config.
|
|
103
107
|
const ast = await (0, core_1.parseAsync)(code, {
|
|
104
108
|
filename: this.resourcePath,
|
|
105
109
|
caller: { name: 'compiled' },
|
|
106
110
|
rootMode: 'upward-optional',
|
|
107
|
-
|
|
111
|
+
parserOpts: {
|
|
112
|
+
plugins: (_a = options.parserBabelPlugins) !== null && _a !== void 0 ? _a : undefined,
|
|
113
|
+
},
|
|
114
|
+
plugins: (_b = options.transformerBabelPlugins) !== null && _b !== void 0 ? _b : undefined,
|
|
108
115
|
});
|
|
109
116
|
// Setup the default resolver, where webpack will merge any passed in options with the default
|
|
110
117
|
// resolve configuration. Ideally, we use this.getResolve({ ...resolve, useSyncFileSystemCalls: true, })
|
|
111
118
|
// However, it does not work correctly when in development mode :/
|
|
112
119
|
const resolver = enhanced_resolve_1.ResolverFactory.createResolver(Object.assign(Object.assign(Object.assign({
|
|
113
120
|
// @ts-expect-error
|
|
114
|
-
fileSystem: new enhanced_resolve_1.CachedInputFileSystem(fs_1.default, 4000) }, ((
|
|
121
|
+
fileSystem: new enhanced_resolve_1.CachedInputFileSystem(fs_1.default, 4000) }, ((_d = (_c = this._compilation) === null || _c === void 0 ? void 0 : _c.options.resolve) !== null && _d !== void 0 ? _d : {})), resolve), {
|
|
115
122
|
// This makes the resolver invoke the callback synchronously
|
|
116
123
|
useSyncFileSystemCalls: true }));
|
|
117
124
|
// Transform using the Compiled Babel Plugin - we deliberately turn off using the local config.
|
|
@@ -120,8 +127,11 @@ async function compiledLoader(code) {
|
|
|
120
127
|
configFile: false,
|
|
121
128
|
sourceMaps: true,
|
|
122
129
|
filename: this.resourcePath,
|
|
130
|
+
parserOpts: {
|
|
131
|
+
plugins: (_e = options.parserBabelPlugins) !== null && _e !== void 0 ? _e : undefined,
|
|
132
|
+
},
|
|
123
133
|
plugins: [
|
|
124
|
-
...((
|
|
134
|
+
...((_f = options.transformerBabelPlugins) !== null && _f !== void 0 ? _f : []),
|
|
125
135
|
options.extract && [
|
|
126
136
|
'@compiled/babel-plugin-strip-runtime',
|
|
127
137
|
{
|
|
@@ -143,7 +153,7 @@ async function compiledLoader(code) {
|
|
|
143
153
|
includedFiles.forEach((file) => {
|
|
144
154
|
this.addDependency((0, path_1.normalize)(file));
|
|
145
155
|
});
|
|
146
|
-
callback(null, (result === null || result === void 0 ? void 0 : result.code) || '', (
|
|
156
|
+
callback(null, (result === null || result === void 0 ? void 0 : result.code) || '', (_g = result === null || result === void 0 ? void 0 : result.map) !== null && _g !== void 0 ? _g : undefined);
|
|
147
157
|
}
|
|
148
158
|
catch (e) {
|
|
149
159
|
// @ts-expect-error Not checking for error type
|
|
@@ -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,
|
|
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,GACnB,GAA0B,OAAO,OAAO,CAAC,UAAU,KAAK,WAAW;QAClE,CAAC,CAAC,kBAAkB;YAClB,IAAA,yBAAU,EAAC,OAAO,CAAC;QACrB,CAAC,CAAC,kBAAkB;YAClB,OAAO,CAAC,UAAU,CAAC;gBACjB,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,IAAI,EAAE;wBACJ,IAAI,EAAE,SAAS;qBAChB;oBACD,OAAO,EAAE;wBACP,IAAI,EAAE,SAAS;qBAChB;oBACD,WAAW,EAAE;wBACX,IAAI,EAAE,SAAS;qBAChB;oBACD,KAAK,EAAE;wBACL,IAAI,EAAE,QAAQ;qBACf;oBACD,OAAO,EAAE;wBACP,IAAI,EAAE,QAAQ;qBACf;oBACD,UAAU,EAAE;wBACV,IAAI,EAAE,OAAO;qBACd;oBACD,kBAAkB,EAAE;wBAClB,IAAI,EAAE,OAAO;qBACd;oBACD,uBAAuB,EAAE;wBACvB,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AAC;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;AArFD,iCAqFC;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
|
@@ -19,6 +19,11 @@ export interface CompiledLoaderOptions {
|
|
|
19
19
|
* When using @babel/preset-react with the automatic runtime this is not needed and can be set to false.
|
|
20
20
|
*/
|
|
21
21
|
importReact?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Will run additional cssnano plugin to normalize CSS during build.
|
|
24
|
+
* Default to `true`.
|
|
25
|
+
*/
|
|
26
|
+
optimizeCss?: boolean;
|
|
22
27
|
/**
|
|
23
28
|
* Enables CSP support,
|
|
24
29
|
* read [Security](https://compiledcssinjs.com/docs/security) for more information.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compiled/webpack-loader",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
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",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@babel/core": "^7.17.10",
|
|
24
|
-
"@compiled/babel-plugin": "^0.16.
|
|
24
|
+
"@compiled/babel-plugin": "^0.16.5",
|
|
25
25
|
"@compiled/babel-plugin-strip-runtime": "^0.16.0",
|
|
26
|
-
"@compiled/css": "^0.8.
|
|
27
|
-
"@compiled/react": "0.11.
|
|
26
|
+
"@compiled/css": "^0.8.4",
|
|
27
|
+
"@compiled/react": "0.11.1",
|
|
28
28
|
"@compiled/utils": "^0.6.16",
|
|
29
29
|
"enhanced-resolve": "^5.10.0",
|
|
30
30
|
"loader-utils": "^2.0.2",
|
|
@@ -145,7 +145,7 @@ describe('CompiledExtractPlugin', () => {
|
|
|
145
145
|
._4bfu1r31{-webkit-text-decoration-color:currentColor;text-decoration-color:currentColor}
|
|
146
146
|
._n7zl17qw{border-bottom:1px solid transparent}
|
|
147
147
|
._n7zl1l01{border-bottom:1px solid rgba(135,119,217,0.2)}
|
|
148
|
-
.
|
|
148
|
+
._syaz1cj8{color:var(--_xexnhp)}
|
|
149
149
|
._p12f1us4{max-width:140rem}
|
|
150
150
|
._18u01wug{margin-left:auto}
|
|
151
151
|
._otyridpf{margin-bottom:0}
|
package/src/compiled-loader.ts
CHANGED
|
@@ -30,6 +30,7 @@ function getLoaderOptions(context: LoaderContext<CompiledLoaderOptions>) {
|
|
|
30
30
|
transformerBabelPlugins = [],
|
|
31
31
|
[pluginName]: isPluginEnabled = false,
|
|
32
32
|
ssr = false,
|
|
33
|
+
optimizeCss = true,
|
|
33
34
|
}: CompiledLoaderOptions = typeof context.getOptions === 'undefined'
|
|
34
35
|
? // Webpack v4 flow
|
|
35
36
|
getOptions(context)
|
|
@@ -67,6 +68,9 @@ function getLoaderOptions(context: LoaderContext<CompiledLoaderOptions>) {
|
|
|
67
68
|
ssr: {
|
|
68
69
|
type: 'boolean',
|
|
69
70
|
},
|
|
71
|
+
optimizeCss: {
|
|
72
|
+
type: 'boolean',
|
|
73
|
+
},
|
|
70
74
|
},
|
|
71
75
|
});
|
|
72
76
|
|
|
@@ -81,6 +85,7 @@ function getLoaderOptions(context: LoaderContext<CompiledLoaderOptions>) {
|
|
|
81
85
|
transformerBabelPlugins,
|
|
82
86
|
[pluginName]: isPluginEnabled,
|
|
83
87
|
ssr,
|
|
88
|
+
optimizeCss,
|
|
84
89
|
};
|
|
85
90
|
}
|
|
86
91
|
|
|
@@ -113,6 +118,9 @@ export default async function compiledLoader(
|
|
|
113
118
|
filename: this.resourcePath,
|
|
114
119
|
caller: { name: 'compiled' },
|
|
115
120
|
rootMode: 'upward-optional',
|
|
121
|
+
parserOpts: {
|
|
122
|
+
plugins: options.parserBabelPlugins ?? undefined,
|
|
123
|
+
},
|
|
116
124
|
plugins: options.transformerBabelPlugins ?? undefined,
|
|
117
125
|
});
|
|
118
126
|
|
|
@@ -134,6 +142,9 @@ export default async function compiledLoader(
|
|
|
134
142
|
configFile: false,
|
|
135
143
|
sourceMaps: true,
|
|
136
144
|
filename: this.resourcePath,
|
|
145
|
+
parserOpts: {
|
|
146
|
+
plugins: options.parserBabelPlugins ?? undefined,
|
|
147
|
+
},
|
|
137
148
|
plugins: [
|
|
138
149
|
...(options.transformerBabelPlugins ?? []),
|
|
139
150
|
options.extract && [
|
package/src/types.ts
CHANGED
|
@@ -25,6 +25,12 @@ export interface CompiledLoaderOptions {
|
|
|
25
25
|
*/
|
|
26
26
|
importReact?: boolean;
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Will run additional cssnano plugin to normalize CSS during build.
|
|
30
|
+
* Default to `true`.
|
|
31
|
+
*/
|
|
32
|
+
optimizeCss?: boolean;
|
|
33
|
+
|
|
28
34
|
/**
|
|
29
35
|
* Enables CSP support,
|
|
30
36
|
* read [Security](https://compiledcssinjs.com/docs/security) for more information.
|