css-loader 1.0.1 → 7.1.4

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/cjs.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ const loader = require("./index");
4
+ module.exports = loader.default;
5
+ module.exports.defaultGetLocalIdent = require("./utils").defaultGetLocalIdent;
package/dist/index.js ADDED
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = loader;
7
+ var _postcss = _interopRequireDefault(require("postcss"));
8
+ var _package = _interopRequireDefault(require("postcss/package.json"));
9
+ var _semver = require("semver");
10
+ var _options = _interopRequireDefault(require("./options.json"));
11
+ var _plugins = require("./plugins");
12
+ var _utils = require("./utils");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ /*
15
+ MIT License http://www.opensource.org/licenses/mit-license.php
16
+ Author Tobias Koppers @sokra
17
+ */
18
+
19
+ async function loader(content, map, meta) {
20
+ const rawOptions = this.getOptions(_options.default);
21
+ const callback = this.async();
22
+ if (this._compiler && this._compiler.options && this._compiler.options.experiments && this._compiler.options.experiments.css && this._module && (this._module.type === "css" || this._module.type === "css/auto" || this._module.type === "css/global" || this._module.type === "css/module")) {
23
+ this.emitWarning(new Error('You can\'t use `experiments.css` (`experiments.futureDefaults` enable built-in CSS support by default) and `css-loader` together, please set `experiments.css` to `false` or set `{ type: "javascript/auto" }` for rules with `css-loader` in your webpack config (now css-loader does nothing).'));
24
+ callback(null, content, map, meta);
25
+ return;
26
+ }
27
+ let options;
28
+ try {
29
+ options = (0, _utils.normalizeOptions)(rawOptions, this);
30
+ } catch (error) {
31
+ callback(error);
32
+ return;
33
+ }
34
+ const plugins = [];
35
+ const replacements = [];
36
+ const exports = [];
37
+ if ((0, _utils.shouldUseModulesPlugins)(options)) {
38
+ plugins.push(...(0, _utils.getModulesPlugins)(options, this));
39
+ }
40
+ const importPluginImports = [];
41
+ const importPluginApi = [];
42
+ let isSupportAbsoluteURL = false;
43
+
44
+ // TODO enable by default in the next major release
45
+ if (this._compilation && this._compilation.options && this._compilation.options.experiments && this._compilation.options.experiments.buildHttp) {
46
+ isSupportAbsoluteURL = true;
47
+ }
48
+ if ((0, _utils.shouldUseImportPlugin)(options)) {
49
+ plugins.push((0, _plugins.importParser)({
50
+ // TODO need to fix on webpack side, webpack tries to resolve `./runtime/api.js paths like `http://site.com/runtime/api.js`, maybe we should try first request like absolute, the second like a relative to context
51
+ isSupportAbsoluteURL: false,
52
+ isSupportDataURL: false,
53
+ isCSSStyleSheet: options.exportType === "css-style-sheet",
54
+ loaderContext: this,
55
+ imports: importPluginImports,
56
+ api: importPluginApi,
57
+ filter: options.import.filter,
58
+ urlHandler: url => (0, _utils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
59
+ }));
60
+ }
61
+ const urlPluginImports = [];
62
+ if ((0, _utils.shouldUseURLPlugin)(options)) {
63
+ const needToResolveURL = !options.esModule;
64
+ plugins.push((0, _plugins.urlParser)({
65
+ isSupportAbsoluteURL,
66
+ isSupportDataURL: options.esModule,
67
+ imports: urlPluginImports,
68
+ replacements,
69
+ context: this.context,
70
+ rootContext: this.rootContext,
71
+ filter: (0, _utils.getFilter)(options.url.filter, this.resourcePath),
72
+ resolver: needToResolveURL ? this.getResolve({
73
+ mainFiles: [],
74
+ extensions: []
75
+ }) :
76
+ // eslint-disable-next-line no-undefined
77
+ undefined,
78
+ urlHandler: url => (0, _utils.stringifyRequest)(this, url)
79
+ // Support data urls as input in new URL added in webpack@5.38.0
80
+ }));
81
+ }
82
+ const icssPluginImports = [];
83
+ const icssPluginApi = [];
84
+ const needToUseIcssPlugin = (0, _utils.shouldUseIcssPlugin)(options);
85
+ if (needToUseIcssPlugin) {
86
+ plugins.push((0, _plugins.icssParser)({
87
+ loaderContext: this,
88
+ imports: icssPluginImports,
89
+ api: icssPluginApi,
90
+ replacements,
91
+ exports,
92
+ urlHandler: url => (0, _utils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
93
+ }));
94
+ }
95
+
96
+ // Reuse CSS AST (PostCSS AST e.g 'postcss-loader') to avoid reparsing
97
+ if (meta) {
98
+ const {
99
+ ast
100
+ } = meta;
101
+ if (ast && ast.type === "postcss" && (0, _semver.satisfies)(ast.version, `^${_package.default.version}`)) {
102
+ // eslint-disable-next-line no-param-reassign
103
+ content = ast.root;
104
+ }
105
+ }
106
+ const {
107
+ resourcePath
108
+ } = this;
109
+ let result;
110
+ try {
111
+ result = await (0, _postcss.default)(plugins).process(content, {
112
+ hideNothingWarning: true,
113
+ from: resourcePath,
114
+ to: resourcePath,
115
+ map: options.sourceMap ? {
116
+ prev: map ? (0, _utils.normalizeSourceMap)(map, resourcePath) : null,
117
+ inline: false,
118
+ annotation: false
119
+ } : false
120
+ });
121
+ } catch (error) {
122
+ if (error.file) {
123
+ this.addDependency(error.file);
124
+ }
125
+ callback(error.name === "CssSyntaxError" ? (0, _utils.syntaxErrorFactory)(error) : error);
126
+ return;
127
+ }
128
+ for (const warning of result.warnings()) {
129
+ this.emitWarning((0, _utils.warningFactory)(warning));
130
+ }
131
+ const imports = [].concat(icssPluginImports.sort(_utils.sort)).concat(importPluginImports.sort(_utils.sort)).concat(urlPluginImports.sort(_utils.sort));
132
+ const api = [].concat(importPluginApi.sort(_utils.sort)).concat(icssPluginApi.sort(_utils.sort));
133
+ if (options.modules.exportOnlyLocals !== true) {
134
+ imports.unshift({
135
+ type: "api_import",
136
+ importName: "___CSS_LOADER_API_IMPORT___",
137
+ url: (0, _utils.stringifyRequest)(this, require.resolve("./runtime/api"))
138
+ });
139
+ if (options.sourceMap) {
140
+ imports.unshift({
141
+ importName: "___CSS_LOADER_API_SOURCEMAP_IMPORT___",
142
+ url: (0, _utils.stringifyRequest)(this, require.resolve("./runtime/sourceMaps"))
143
+ });
144
+ } else {
145
+ imports.unshift({
146
+ importName: "___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___",
147
+ url: (0, _utils.stringifyRequest)(this, require.resolve("./runtime/noSourceMaps"))
148
+ });
149
+ }
150
+ }
151
+ const isTemplateLiteralSupported = (0, _utils.supportTemplateLiteral)(this);
152
+ const importCode = (0, _utils.getImportCode)(imports, options);
153
+ let moduleCode;
154
+ try {
155
+ moduleCode = (0, _utils.getModuleCode)(result, api, replacements, options, isTemplateLiteralSupported, this);
156
+ } catch (error) {
157
+ callback(error);
158
+ return;
159
+ }
160
+ const exportCode = (0, _utils.getExportCode)(exports, replacements, needToUseIcssPlugin, options, isTemplateLiteralSupported);
161
+ const {
162
+ getJSON
163
+ } = options.modules;
164
+ if (typeof getJSON === "function") {
165
+ try {
166
+ await getJSON({
167
+ resourcePath,
168
+ imports,
169
+ exports,
170
+ replacements
171
+ });
172
+ } catch (error) {
173
+ callback(error);
174
+ return;
175
+ }
176
+ }
177
+ callback(null, `${importCode}${moduleCode}${exportCode}`);
178
+ }
@@ -0,0 +1,218 @@
1
+ {
2
+ "title": "CSS Loader options",
3
+ "additionalProperties": false,
4
+ "properties": {
5
+ "url": {
6
+ "description": "Allows to enables/disables `url()`/`image-set()` functions handling.",
7
+ "link": "https://github.com/webpack/css-loader#url",
8
+ "anyOf": [
9
+ {
10
+ "type": "boolean"
11
+ },
12
+ {
13
+ "type": "object",
14
+ "properties": {
15
+ "filter": {
16
+ "instanceof": "Function"
17
+ }
18
+ },
19
+ "additionalProperties": false
20
+ }
21
+ ]
22
+ },
23
+ "import": {
24
+ "description": "Allows to enables/disables `@import` at-rules handling.",
25
+ "link": "https://github.com/webpack/css-loader#import",
26
+ "anyOf": [
27
+ {
28
+ "type": "boolean"
29
+ },
30
+ {
31
+ "type": "object",
32
+ "properties": {
33
+ "filter": {
34
+ "instanceof": "Function"
35
+ }
36
+ },
37
+ "additionalProperties": false
38
+ }
39
+ ]
40
+ },
41
+ "modules": {
42
+ "description": "Allows to enable/disable CSS Modules or ICSS and setup configuration.",
43
+ "link": "https://github.com/webpack/css-loader#modules",
44
+ "anyOf": [
45
+ {
46
+ "type": "boolean"
47
+ },
48
+ {
49
+ "enum": ["local", "global", "pure", "icss"]
50
+ },
51
+ {
52
+ "type": "object",
53
+ "additionalProperties": false,
54
+ "properties": {
55
+ "auto": {
56
+ "description": "Allows auto enable CSS modules based on filename.",
57
+ "link": "https://github.com/webpack/css-loader#auto",
58
+ "anyOf": [
59
+ {
60
+ "instanceof": "RegExp"
61
+ },
62
+ {
63
+ "instanceof": "Function"
64
+ },
65
+ {
66
+ "type": "boolean"
67
+ }
68
+ ]
69
+ },
70
+ "mode": {
71
+ "description": "Setup `mode` option.",
72
+ "link": "https://github.com/webpack/css-loader#mode",
73
+ "anyOf": [
74
+ {
75
+ "enum": ["local", "global", "pure", "icss"]
76
+ },
77
+ {
78
+ "instanceof": "Function"
79
+ }
80
+ ]
81
+ },
82
+ "localIdentName": {
83
+ "description": "Allows to configure the generated local ident name.",
84
+ "link": "https://github.com/webpack/css-loader#localidentname",
85
+ "type": "string",
86
+ "minLength": 1
87
+ },
88
+ "localIdentContext": {
89
+ "description": "Allows to redefine basic loader context for local ident name.",
90
+ "link": "https://github.com/webpack/css-loader#localidentcontext",
91
+ "type": "string",
92
+ "minLength": 1
93
+ },
94
+ "localIdentHashSalt": {
95
+ "description": "Allows to add custom hash to generate more unique classes.",
96
+ "link": "https://github.com/webpack/css-loader#localidenthashsalt",
97
+ "type": "string",
98
+ "minLength": 1
99
+ },
100
+ "localIdentHashFunction": {
101
+ "description": "Allows to specify hash function to generate classes.",
102
+ "link": "https://github.com/webpack/css-loader#localidenthashfunction",
103
+ "type": "string",
104
+ "minLength": 1
105
+ },
106
+ "localIdentHashDigest": {
107
+ "description": "Allows to specify hash digest to generate classes.",
108
+ "link": "https://github.com/webpack/css-loader#localidenthashdigest",
109
+ "type": "string",
110
+ "minLength": 1
111
+ },
112
+ "localIdentHashDigestLength": {
113
+ "description": "Allows to specify hash digest length to generate classes.",
114
+ "link": "https://github.com/webpack/css-loader#localidenthashdigestlength",
115
+ "type": "number"
116
+ },
117
+ "hashStrategy": {
118
+ "description": "Allows to specify should localName be used when computing the hash.",
119
+ "link": "https://github.com/webpack/css-loader#hashstrategy",
120
+ "enum": ["resource-path-and-local-name", "minimal-subset"]
121
+ },
122
+ "localIdentRegExp": {
123
+ "description": "Allows to specify custom RegExp for local ident name.",
124
+ "link": "https://github.com/webpack/css-loader#localidentregexp",
125
+ "anyOf": [
126
+ {
127
+ "type": "string",
128
+ "minLength": 1
129
+ },
130
+ {
131
+ "instanceof": "RegExp"
132
+ }
133
+ ]
134
+ },
135
+ "getLocalIdent": {
136
+ "description": "Allows to specify a function to generate the classname.",
137
+ "link": "https://github.com/webpack/css-loader#getlocalident",
138
+ "instanceof": "Function"
139
+ },
140
+ "namedExport": {
141
+ "description": "Enables/disables ES modules named export for locals.",
142
+ "link": "https://github.com/webpack/css-loader#namedexport",
143
+ "type": "boolean"
144
+ },
145
+ "exportGlobals": {
146
+ "description": "Allows to export names from global class or id, so you can use that as local name.",
147
+ "link": "https://github.com/webpack/css-loader#exportglobals",
148
+ "type": "boolean"
149
+ },
150
+ "exportLocalsConvention": {
151
+ "description": "Style of exported classnames.",
152
+ "link": "https://github.com/webpack/css-loader#localsconvention",
153
+ "anyOf": [
154
+ {
155
+ "enum": [
156
+ "asIs",
157
+ "as-is",
158
+ "camelCase",
159
+ "camel-case",
160
+ "camelCaseOnly",
161
+ "camel-case-only",
162
+ "dashes",
163
+ "dashesOnly",
164
+ "dashes-only"
165
+ ]
166
+ },
167
+ {
168
+ "instanceof": "Function"
169
+ }
170
+ ]
171
+ },
172
+ "exportOnlyLocals": {
173
+ "description": "Export only locals.",
174
+ "link": "https://github.com/webpack/css-loader#exportonlylocals",
175
+ "type": "boolean"
176
+ },
177
+ "getJSON": {
178
+ "description": "Allows outputting of CSS modules mapping through a callback.",
179
+ "link": "https://github.com/webpack/css-loader#getJSON",
180
+ "instanceof": "Function"
181
+ }
182
+ }
183
+ }
184
+ ]
185
+ },
186
+ "sourceMap": {
187
+ "description": "Allows to enable/disable source maps.",
188
+ "link": "https://github.com/webpack/css-loader#sourcemap",
189
+ "type": "boolean"
190
+ },
191
+ "importLoaders": {
192
+ "description": "Allows enables/disables or setups number of loaders applied before CSS loader for `@import`/CSS Modules and ICSS imports.",
193
+ "link": "https://github.com/webpack/css-loader#importloaders",
194
+ "anyOf": [
195
+ {
196
+ "type": "boolean"
197
+ },
198
+ {
199
+ "type": "string"
200
+ },
201
+ {
202
+ "type": "integer"
203
+ }
204
+ ]
205
+ },
206
+ "esModule": {
207
+ "description": "Use the ES modules syntax.",
208
+ "link": "https://github.com/webpack/css-loader#esmodule",
209
+ "type": "boolean"
210
+ },
211
+ "exportType": {
212
+ "description": "Allows exporting styles as array with modules, string or constructable stylesheet (i.e. `CSSStyleSheet`).",
213
+ "link": "https://github.com/webpack/css-loader#exporttype",
214
+ "enum": ["array", "string", "css-style-sheet"]
215
+ }
216
+ },
217
+ "type": "object"
218
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "icssParser", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _postcssIcssParser.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "importParser", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _postcssImportParser.default;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "urlParser", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _postcssUrlParser.default;
22
+ }
23
+ });
24
+ var _postcssImportParser = _interopRequireDefault(require("./postcss-import-parser"));
25
+ var _postcssIcssParser = _interopRequireDefault(require("./postcss-icss-parser"));
26
+ var _postcssUrlParser = _interopRequireDefault(require("./postcss-url-parser"));
27
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _icssUtils = require("icss-utils");
8
+ var _utils = require("../utils");
9
+ const plugin = (options = {}) => {
10
+ return {
11
+ postcssPlugin: "postcss-icss-parser",
12
+ async OnceExit(root) {
13
+ const importReplacements = Object.create(null);
14
+ const {
15
+ icssImports,
16
+ icssExports
17
+ } = (0, _icssUtils.extractICSS)(root);
18
+ const imports = new Map();
19
+ const tasks = [];
20
+ const {
21
+ loaderContext
22
+ } = options;
23
+ const resolver = loaderContext.getResolve({
24
+ dependencyType: "icss",
25
+ conditionNames: ["style"],
26
+ extensions: ["..."],
27
+ mainFields: ["css", "style", "main", "..."],
28
+ mainFiles: ["index", "..."],
29
+ preferRelative: true
30
+ });
31
+
32
+ // eslint-disable-next-line guard-for-in
33
+ for (const url in icssImports) {
34
+ const tokens = icssImports[url];
35
+ if (Object.keys(tokens).length === 0) {
36
+ // eslint-disable-next-line no-continue
37
+ continue;
38
+ }
39
+ let normalizedUrl = url;
40
+ let prefix = "";
41
+ const queryParts = normalizedUrl.split("!");
42
+ if (queryParts.length > 1) {
43
+ normalizedUrl = queryParts.pop();
44
+ prefix = queryParts.join("!");
45
+ }
46
+ const request = (0, _utils.requestify)((0, _utils.normalizeUrl)(normalizedUrl, true), loaderContext.rootContext);
47
+ const doResolve = async () => {
48
+ const resolvedUrl = await (0, _utils.resolveRequests)(resolver, loaderContext.context, [...new Set([normalizedUrl, request])]);
49
+ if (!resolvedUrl) {
50
+ return;
51
+ }
52
+
53
+ // eslint-disable-next-line consistent-return
54
+ return {
55
+ url: resolvedUrl,
56
+ prefix,
57
+ tokens
58
+ };
59
+ };
60
+ tasks.push(doResolve());
61
+ }
62
+ const results = await Promise.all(tasks);
63
+ for (let index = 0; index <= results.length - 1; index++) {
64
+ const item = results[index];
65
+ if (!item) {
66
+ // eslint-disable-next-line no-continue
67
+ continue;
68
+ }
69
+ const newUrl = item.prefix ? `${item.prefix}!${item.url}` : item.url;
70
+ const importKey = newUrl;
71
+ let importName = imports.get(importKey);
72
+ if (!importName) {
73
+ importName = `___CSS_LOADER_ICSS_IMPORT_${imports.size}___`;
74
+ imports.set(importKey, importName);
75
+ options.imports.push({
76
+ type: "icss_import",
77
+ importName,
78
+ url: options.urlHandler(newUrl),
79
+ icss: true,
80
+ index
81
+ });
82
+ options.api.push({
83
+ importName,
84
+ dedupe: true,
85
+ index
86
+ });
87
+ }
88
+ for (const [replacementIndex, token] of Object.keys(item.tokens).entries()) {
89
+ const replacementName = `___CSS_LOADER_ICSS_IMPORT_${index}_REPLACEMENT_${replacementIndex}___`;
90
+ const localName = item.tokens[token];
91
+ importReplacements[token] = replacementName;
92
+ options.replacements.push({
93
+ replacementName,
94
+ importName,
95
+ localName
96
+ });
97
+ }
98
+ }
99
+ if (Object.keys(importReplacements).length > 0) {
100
+ (0, _icssUtils.replaceSymbols)(root, importReplacements);
101
+ }
102
+ for (const name of Object.keys(icssExports)) {
103
+ const value = (0, _icssUtils.replaceValueSymbols)(icssExports[name], importReplacements);
104
+ options.exports.push({
105
+ name,
106
+ value
107
+ });
108
+ }
109
+ }
110
+ };
111
+ };
112
+ plugin.postcss = true;
113
+ var _default = exports.default = plugin;