css-loader 3.0.0 → 3.3.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,55 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [3.3.0](https://github.com/webpack-contrib/css-loader/compare/v3.2.1...v3.3.0) (2019-12-09)
6
+
7
+
8
+ ### Features
9
+
10
+ * support `pure` css modules ([#1008](https://github.com/webpack-contrib/css-loader/issues/1008)) ([6177af5](https://github.com/webpack-contrib/css-loader/commit/6177af5596566fead13a8f66d5abcb4dc2b744db))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * do not crash when an assert return `null` or `undefined` ([#1006](https://github.com/webpack-contrib/css-loader/issues/1006)) ([6769783](https://github.com/webpack-contrib/css-loader/commit/67697833725e1cff12a14663390bbe4c65ea36d2))
16
+ * reduce count of `require` ([#1004](https://github.com/webpack-contrib/css-loader/issues/1004)) ([80e9662](https://github.com/webpack-contrib/css-loader/commit/80e966280f2477c5c0e4553d3be3a04511fea381))
17
+
18
+ ### [3.2.1](https://github.com/webpack-contrib/css-loader/compare/v3.2.0...v3.2.1) (2019-12-02)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * add an additional space after the escape sequence ([#998](https://github.com/webpack-contrib/css-loader/issues/998)) ([0961304](https://github.com/webpack-contrib/css-loader/commit/0961304020832fc9ca70cc708f4366e1f868e765))
24
+ * compatibility with ES modules syntax and hash in `url` function ([#1001](https://github.com/webpack-contrib/css-loader/issues/1001)) ([8f4d6f5](https://github.com/webpack-contrib/css-loader/commit/8f4d6f508187513347106a436eda993f874065f1))
25
+
26
+ ## [3.2.0](https://github.com/webpack-contrib/css-loader/compare/v3.1.0...v3.2.0) (2019-08-06)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * replace `.` characters in localIndent to `-` character (regression) ([#982](https://github.com/webpack-contrib/css-loader/issues/982)) ([967fb66](https://github.com/webpack-contrib/css-loader/commit/967fb66))
32
+
33
+
34
+ ### Features
35
+
36
+ * support es modules for assets loader ([#984](https://github.com/webpack-contrib/css-loader/issues/984)) ([9c5126c](https://github.com/webpack-contrib/css-loader/commit/9c5126c))
37
+
38
+ ## [3.1.0](https://github.com/webpack-contrib/css-loader/compare/v3.0.0...v3.1.0) (2019-07-18)
39
+
40
+
41
+ ### Bug Fixes
42
+
43
+ * converting all (including reserved and control) filesystem characters to `-` (it was regression in `3.0.0` version) ([#972](https://github.com/webpack-contrib/css-loader/issues/972)) ([f51859b](https://github.com/webpack-contrib/css-loader/commit/f51859b))
44
+ * default context should be undefined instead of null ([#965](https://github.com/webpack-contrib/css-loader/issues/965)) ([9c32885](https://github.com/webpack-contrib/css-loader/commit/9c32885))
45
+
46
+
47
+ ### Features
48
+
49
+ * allow `modules.getLocalIdent` to return a falsy value ([#963](https://github.com/webpack-contrib/css-loader/issues/963)) ([9c3571c](https://github.com/webpack-contrib/css-loader/commit/9c3571c))
50
+ * improved validation error messages ([65e4fc0](https://github.com/webpack-contrib/css-loader/commit/65e4fc0))
51
+
52
+
53
+
5
54
  ## [3.0.0](https://github.com/webpack-contrib/css-loader/compare/v2.1.1...v3.0.0) (2019-06-11)
6
55
 
7
56
 
@@ -24,7 +73,7 @@ All notable changes to this project will be documented in this file. See [standa
24
73
  * minimum required nodejs version is 8.9.0
25
74
  * `@value` at rules now support in `selector`, recommends checking all `@values` at-rule usage (hint: you can add prefix to all `@value` at-rules, for example `@value v-foo: black;` or `@value m-foo: screen and (max-width: 12450px)`, and then do upgrade)
26
75
  * invert `{Function}` behavior for `url` and `import` options (need return `true` when you want handle `url`/`@import` and return `false` if not)
27
- * `exportLocalsStyle` option was remove in favor `localsConvention` option, also it is accept only `{String}` value (use `camelCase` value if you previously value was `true` and `asIs` if you previously value was `false`)
76
+ * `camelCase` option was remove in favor `localsConvention` option, also it is accept only `{String}` value (use `camelCase` value if you previously value was `true` and `asIs` if you previously value was `false`)
28
77
  * `exportOnlyLocals` option was remove in favor `onlyLocals` option
29
78
  * `modules` option now can be `{Object}` and allow to setup `CSS Modules` options:
30
79
  * `localIdentName` option was removed in favor `modules.localIdentName` option
package/README.md CHANGED
@@ -109,21 +109,22 @@ module.exports = {
109
109
 
110
110
  ## Options
111
111
 
112
- | Name | Type | Default | Description |
113
- | :-----------------------------------------: | :-------------------------: | :-----: | :------------------------------------------------- |
114
- | **[`url`](#url)** | `{Boolean\|Function}` | `true` | Enable/Disable `url()` handling |
115
- | **[`import`](#import)** | `{Boolean\|Function}` | `true` | Enable/Disable @import handling |
116
- | **[`modules`](#modules)** | `{Boolean\|String\|Object}` | `false` | Enable/Disable CSS Modules and setup their options |
117
- | **[`sourceMap`](#sourcemap)** | `{Boolean}` | `false` | Enable/Disable Sourcemaps |
118
- | **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Number of loaders applied before CSS loader |
119
- | **[`localsConvention`](#localsconvention)** | `{String}` | `asIs` | Setup style of exported classnames |
120
- | **[`onlyLocals`](#onlylocals)** | `{Boolean}` | `false` | Export only locals |
112
+ | Name | Type | Default | Description |
113
+ | :-----------------------------------------: | :-------------------------: | :------: | :--------------------------------------------------------------------- |
114
+ | **[`url`](#url)** | `{Boolean\|Function}` | `true` | Enables/Disables `url`/`image-set` functions handling |
115
+ | **[`import`](#import)** | `{Boolean\|Function}` | `true` | Enables/Disables `@import` at-rules handling |
116
+ | **[`modules`](#modules)** | `{Boolean\|String\|Object}` | `false` | Enables/Disables CSS Modules and their configuration |
117
+ | **[`sourceMap`](#sourcemap)** | `{Boolean}` | `false` | Enables/Disables generation of source maps |
118
+ | **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Enables/Disables or setups number of loaders applied before CSS loader |
119
+ | **[`localsConvention`](#localsconvention)** | `{String}` | `'asIs'` | Style of exported classnames |
120
+ | **[`onlyLocals`](#onlylocals)** | `{Boolean}` | `false` | Export only locals |
121
121
 
122
122
  ### `url`
123
123
 
124
124
  Type: `Boolean|Function`
125
125
  Default: `true`
126
126
 
127
+ Enables/Disables `url`/`image-set` functions handling.
127
128
  Control `url()` resolving. Absolute URLs and root-relative URLs are not resolving.
128
129
 
129
130
  Examples resolutions:
@@ -200,9 +201,10 @@ module.exports = {
200
201
 
201
202
  ### `import`
202
203
 
203
- Type: `Boolean`
204
+ Type: `Boolean|Function`
204
205
  Default: `true`
205
206
 
207
+ Enables/Disables `@import` at-rules handling.
206
208
  Control `@import` resolving. Absolute urls in `@import` will be moved in runtime code.
207
209
 
208
210
  Examples resolutions:
@@ -285,6 +287,8 @@ module.exports = {
285
287
  Type: `Boolean|String|Object`
286
288
  Default: `false`
287
289
 
290
+ Enables/Disables CSS Modules and their configuration.
291
+
288
292
  The `modules` option enables/disables the **[CSS Modules](https://github.com/css-modules/css-modules)** specification and setup basic behaviour.
289
293
 
290
294
  Using `false` value increase performance because we avoid parsing **CSS Modules** features, it will be useful for developers who use vanilla css or use other technologies.
@@ -313,6 +317,7 @@ module.exports = {
313
317
 
314
318
  Using `local` value requires you to specify `:global` classes.
315
319
  Using `global` value requires you to specify `:local` classes.
320
+ Using `pure` value requires selectors must contain at least one local class or id.
316
321
 
317
322
  You can find more information [here](https://github.com/css-modules/css-modules).
318
323
 
@@ -536,7 +541,7 @@ module.exports = {
536
541
  ##### `mode`
537
542
 
538
543
  Type: `String`
539
- Default: `local`
544
+ Default: `'local'`
540
545
 
541
546
  Setup `mode` option. You can omit the value when you want `local` mode.
542
547
 
@@ -563,11 +568,20 @@ module.exports = {
563
568
  ##### `localIdentName`
564
569
 
565
570
  Type: `String`
566
- Default: `[hash:base64]`
571
+ Default: `'[hash:base64]'`
567
572
 
568
573
  You can configure the generated ident with the `localIdentName` query parameter.
569
574
  See [loader-utils's documentation](https://github.com/webpack/loader-utils#interpolatename) for more information on options.
570
575
 
576
+ Recommendations:
577
+
578
+ - use `'[path][name]__[local]'` for development
579
+ - use `'[hash:base64]'` for production
580
+
581
+ The `[local]` placeholder contains original class.
582
+
583
+ **Note:** all reserved (`<>:"/\|?*`) and control filesystem characters (excluding characters in the `[local]` placeholder) will be converted to `-`.
584
+
571
585
  **webpack.config.js**
572
586
 
573
587
  ```js
@@ -703,14 +717,12 @@ module.exports = {
703
717
  Type: `Boolean`
704
718
  Default: `false`
705
719
 
706
- To include source maps set the `sourceMap` option.
720
+ Enables/Disables generation of source maps.
707
721
 
708
- I.e. the `mini-css-extract-plugin` can handle them.
722
+ To include source maps set the `sourceMap` option.
709
723
 
710
724
  They are not enabled by default because they expose a runtime overhead and increase in bundle size (JS source maps do not).
711
725
 
712
- In addition to that relative paths are buggy and you need to use an absolute public path which includes the server URL.
713
-
714
726
  **webpack.config.js**
715
727
 
716
728
  ```js
@@ -734,6 +746,8 @@ module.exports = {
734
746
  Type: `Number`
735
747
  Default: `0`
736
748
 
749
+ Enables/Disables or setups number of loaders applied before CSS loader.
750
+
737
751
  The option `importLoaders` allows you to configure how many loaders before `css-loader` should be applied to `@import`ed resources.
738
752
 
739
753
  **webpack.config.js**
@@ -749,7 +763,10 @@ module.exports = {
749
763
  {
750
764
  loader: 'css-loader',
751
765
  options: {
752
- importLoaders: 2, // 0 => no loaders (default); 1 => postcss-loader; 2 => postcss-loader, sass-loader
766
+ importLoaders: 2,
767
+ // 0 => no loaders (default);
768
+ // 1 => postcss-loader;
769
+ // 2 => postcss-loader, sass-loader
753
770
  },
754
771
  },
755
772
  'postcss-loader',
@@ -766,7 +783,9 @@ This may change in the future when the module system (i. e. webpack) supports lo
766
783
  ### `localsConvention`
767
784
 
768
785
  Type: `String`
769
- Default: `undefined`
786
+ Default: `'asIs'`
787
+
788
+ Style of exported classnames.
770
789
 
771
790
  By default, the exported JSON keys mirror the class names (i.e `asIs` value).
772
791
 
@@ -814,7 +833,9 @@ module.exports = {
814
833
  Type: `Boolean`
815
834
  Default: `false`
816
835
 
817
- Export only locals (**useful** when you use **css modules**).
836
+ Export only locals.
837
+
838
+ **Useful** when you use **css modules** for pre-rendering (for example SSR).
818
839
  For pre-rendering with `mini-css-extract-plugin` you should use this option instead of `style-loader!css-loader` **in the pre-rendering bundle**.
819
840
  It doesn't embed CSS but only exports the identifier mappings.
820
841
 
@@ -853,7 +874,7 @@ module.exports = {
853
874
  use: ['style-loader', 'css-loader'],
854
875
  },
855
876
  {
856
- test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/,
877
+ test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
857
878
  loader: 'url-loader',
858
879
  options: {
859
880
  limit: 8192,
@@ -872,6 +893,47 @@ For production builds it's recommended to extract the CSS from your bundle being
872
893
 
873
894
  - As an alternative, if seeking better development performance and css outputs that mimic production. [extract-css-chunks-webpack-plugin](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin) offers a hot module reload friendly, extended version of mini-css-extract-plugin. HMR real CSS files in dev, works like mini-css in non-dev
874
895
 
896
+ ### CSS modules and pure CSS
897
+
898
+ When you have pure CSS (without CSS modules) and CSS modules in project you can use this setup:
899
+
900
+ **webpack.config.js**
901
+
902
+ ```js
903
+ module.exports = {
904
+ module: {
905
+ rules: [
906
+ {
907
+ // For pure CSS (without CSS modules)
908
+ test: /\.css$/i,
909
+ exclude: /\.module\.css$/i,
910
+ use: ['style-loader', 'css-loader'],
911
+ },
912
+ {
913
+ // For CSS modules
914
+ test: /\.module\.css$/i,
915
+ use: [
916
+ 'style-loader',
917
+ {
918
+ loader: 'css-loader',
919
+ options: {
920
+ modules: true,
921
+ },
922
+ },
923
+ ],
924
+ },
925
+ {
926
+ test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
927
+ loader: 'url-loader',
928
+ options: {
929
+ limit: 8192,
930
+ },
931
+ },
932
+ ],
933
+ },
934
+ };
935
+ ```
936
+
875
937
  ## Contributing
876
938
 
877
939
  Please take a moment to read our contributing guidelines if you haven't yet done so.
package/dist/index.js CHANGED
@@ -31,7 +31,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
31
31
  */
32
32
  function loader(content, map, meta) {
33
33
  const options = (0, _loaderUtils.getOptions)(this) || {};
34
- (0, _schemaUtils.default)(_options.default, options, 'CSS Loader');
34
+ (0, _schemaUtils.default)(_options.default, options, {
35
+ name: 'CSS Loader',
36
+ baseDataPath: 'options'
37
+ });
35
38
  const callback = this.async();
36
39
  const sourceMap = options.sourceMap || false; // Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it
37
40
  // eslint-disable-next-line no-param-reassign
@@ -53,68 +56,66 @@ function loader(content, map, meta) {
53
56
 
54
57
  if (options.modules) {
55
58
  plugins.push(...(0, _utils.getModulesPlugins)(options, this));
56
- } // Run other loader (`postcss-loader`, `sass-loader` and etc) for importing CSS
57
-
59
+ }
58
60
 
59
- const importPrefix = (0, _utils.getImportPrefix)(this, options.importLoaders);
60
- plugins.push((0, _plugins.icssParser)({
61
- loaderContext: this,
62
- importPrefix,
63
- localsConvention: options.localsConvention
64
- }));
61
+ const exportType = options.onlyLocals ? 'locals' : 'full';
62
+ plugins.push((0, _plugins.icssParser)());
65
63
 
66
- if (options.import !== false) {
64
+ if (options.import !== false && exportType === 'full') {
67
65
  plugins.push((0, _plugins.importParser)({
68
- loaderContext: this,
69
- importPrefix,
70
66
  filter: (0, _utils.getFilter)(options.import, this.resourcePath)
71
67
  }));
72
68
  }
73
69
 
74
- if (options.url !== false) {
70
+ if (options.url !== false && exportType === 'full') {
75
71
  plugins.push((0, _plugins.urlParser)({
76
- loaderContext: this,
77
72
  filter: (0, _utils.getFilter)(options.url, this.resourcePath, value => (0, _loaderUtils.isUrlRequest)(value))
78
73
  }));
79
74
  }
80
75
 
81
76
  (0, _postcss.default)(plugins).process(content, {
82
- from: (0, _loaderUtils.getRemainingRequest)(this).split('!').pop(),
83
- to: (0, _loaderUtils.getCurrentRequest)(this).split('!').pop(),
77
+ from: this.remainingRequest.split('!').pop(),
78
+ to: this.currentRequest.split('!').pop(),
84
79
  map: options.sourceMap ? {
85
80
  prev: map,
86
81
  inline: false,
87
82
  annotation: false
88
- } : null
83
+ } : false
89
84
  }).then(result => {
90
85
  result.warnings().forEach(warning => this.emitWarning(new _Warning.default(warning)));
91
-
92
- if (!result.messages) {
93
- // eslint-disable-next-line no-param-reassign
94
- result.messages = [];
95
- }
96
-
97
- const {
98
- onlyLocals
99
- } = options;
100
- const importItems = result.messages.filter(message => message.type === 'import' ? message : false).reduce((accumulator, currentValue) => {
101
- accumulator.push(currentValue.import);
102
- return accumulator;
103
- }, []);
104
- const exportItems = result.messages.filter(message => message.type === 'export' ? message : false).reduce((accumulator, currentValue) => {
105
- accumulator.push(currentValue.export);
106
- return accumulator;
107
- }, []);
108
- const importCode = (0, _utils.getImportCode)(importItems, onlyLocals);
109
- const moduleCode = (0, _utils.getModuleCode)(result, sourceMap, onlyLocals);
110
- const exportCode = (0, _utils.getExportCode)(exportItems, onlyLocals);
111
- const apiCode = (0, _utils.getApiCode)(this, sourceMap, onlyLocals);
112
- return callback(null, (0, _utils.prepareCode)({
113
- apiCode,
114
- importCode,
115
- moduleCode,
116
- exportCode
117
- }, result.messages, this, importPrefix, onlyLocals));
86
+ const imports = [];
87
+ const exports = [];
88
+ const replacers = [];
89
+
90
+ for (const message of result.messages) {
91
+ // eslint-disable-next-line default-case
92
+ switch (message.type) {
93
+ case 'import':
94
+ imports.push(message.value);
95
+ break;
96
+
97
+ case 'export':
98
+ exports.push(message.value);
99
+ break;
100
+
101
+ case 'replacer':
102
+ replacers.push(message.value);
103
+ break;
104
+ }
105
+ } // Run other loader (`postcss-loader`, `sass-loader` and etc) for importing CSS
106
+
107
+
108
+ const apiCode = exportType === 'full' ? (0, _utils.getApiCode)(this, sourceMap) : '';
109
+ const importCode = imports.length > 0 ? (0, _utils.getImportCode)(this, imports, {
110
+ importLoaders: options.importLoaders,
111
+ exportType
112
+ }) : '';
113
+ const moduleCode = exportType === 'full' ? (0, _utils.getModuleCode)(this, result, replacers, sourceMap) : '';
114
+ const exportCode = exports.length > 0 ? (0, _utils.getExportCode)(this, exports, replacers, {
115
+ localsConvention: options.localsConvention,
116
+ exportType
117
+ }) : '';
118
+ return callback(null, [apiCode, importCode, moduleCode, exportCode].join(''));
118
119
  }).catch(error => {
119
120
  callback(error.name === 'CssSyntaxError' ? new _CssSyntaxError.default(error) : error);
120
121
  });
package/dist/options.json CHANGED
@@ -2,6 +2,7 @@
2
2
  "additionalProperties": false,
3
3
  "properties": {
4
4
  "url": {
5
+ "description": "Enables/Disables 'url'/'image-set' functions handling (https://github.com/webpack-contrib/css-loader#url).",
5
6
  "anyOf": [
6
7
  {
7
8
  "type": "boolean"
@@ -12,6 +13,7 @@
12
13
  ]
13
14
  },
14
15
  "import": {
16
+ "description": "Enables/Disables '@import' at-rules handling (https://github.com/webpack-contrib/css-loader#import).",
15
17
  "anyOf": [
16
18
  {
17
19
  "type": "boolean"
@@ -22,21 +24,20 @@
22
24
  ]
23
25
  },
24
26
  "modules": {
27
+ "description": "Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).",
25
28
  "anyOf": [
26
29
  {
27
30
  "type": "boolean"
28
31
  },
29
32
  {
30
- "type": "string",
31
- "enum": ["local", "global"]
33
+ "enum": ["local", "global", "pure"]
32
34
  },
33
35
  {
34
36
  "type": "object",
35
37
  "additionalProperties": false,
36
38
  "properties": {
37
39
  "mode": {
38
- "type": "string",
39
- "enum": ["local", "global"]
40
+ "enum": ["local", "global", "pure"]
40
41
  },
41
42
  "localIdentName": {
42
43
  "type": "string"
@@ -72,9 +73,11 @@
72
73
  ]
73
74
  },
74
75
  "sourceMap": {
76
+ "description": "Enables/Disables generation of source maps (https://github.com/webpack-contrib/css-loader#sourcemap).",
75
77
  "type": "boolean"
76
78
  },
77
79
  "importLoaders": {
80
+ "description": "Enables/Disables or setups number of loaders applied before CSS loader (https://github.com/webpack-contrib/css-loader#importloaders).",
78
81
  "anyOf": [
79
82
  {
80
83
  "type": "boolean"
@@ -85,14 +88,11 @@
85
88
  ]
86
89
  },
87
90
  "localsConvention": {
88
- "anyOf": [
89
- {
90
- "type": "string",
91
- "enum": ["asIs", "camelCase", "camelCaseOnly", "dashes", "dashesOnly"]
92
- }
93
- ]
91
+ "description": "Style of exported classnames (https://github.com/webpack-contrib/css-loader#localsconvention).",
92
+ "enum": ["asIs", "camelCase", "camelCaseOnly", "dashes", "dashesOnly"]
94
93
  },
95
94
  "onlyLocals": {
95
+ "description": "Export only locals (https://github.com/webpack-contrib/css-loader#onlylocals).",
96
96
  "type": "boolean"
97
97
  }
98
98
  },
@@ -9,79 +9,65 @@ var _postcss = _interopRequireDefault(require("postcss"));
9
9
 
10
10
  var _icssUtils = require("icss-utils");
11
11
 
12
- var _loaderUtils = _interopRequireDefault(require("loader-utils"));
13
-
14
- var _utils = require("../utils");
15
-
16
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
13
 
18
14
  const pluginName = 'postcss-icss-parser';
19
15
 
20
- function hasImportMessage(messages, url) {
21
- return messages.find(message => message.pluginName === pluginName && message.type === 'import' && message.item.url === url && message.item.media === '');
22
- }
23
-
24
- var _default = _postcss.default.plugin(pluginName, (options = {}) => function process(css, result) {
16
+ var _default = _postcss.default.plugin(pluginName, () => function process(css, result) {
25
17
  const importReplacements = Object.create(null);
26
18
  const {
27
19
  icssImports,
28
20
  icssExports
29
21
  } = (0, _icssUtils.extractICSS)(css);
30
- let index = 0;
22
+ Object.keys(icssImports).forEach((url, importIndex) => {
23
+ const tokens = Object.keys(icssImports[url]);
31
24
 
32
- for (const importUrl of Object.keys(icssImports)) {
33
- const url = _loaderUtils.default.parseString(importUrl);
25
+ if (tokens.length === 0) {
26
+ return;
27
+ }
34
28
 
35
- for (const token of Object.keys(icssImports[importUrl])) {
36
- index += 1;
37
- importReplacements[token] = `___CSS_LOADER_IMPORT___${index}___`;
29
+ const importName = `___CSS_LOADER_ICSS_IMPORT_${importIndex}___`;
30
+ result.messages.push({
31
+ pluginName,
32
+ type: 'import',
33
+ value: {
34
+ type: 'icss-import',
35
+ name: importName,
36
+ url
37
+ }
38
+ });
39
+ tokens.forEach((token, replacementIndex) => {
40
+ const name = `___CSS_LOADER_ICSS_IMPORT_${importIndex}_REPLACEMENT_${replacementIndex}___`;
41
+ const localName = icssImports[url][token];
42
+ importReplacements[token] = name;
38
43
  result.messages.push({
39
44
  pluginName,
40
- type: 'icss-import',
41
- item: {
42
- url,
43
- export: icssImports[importUrl][token],
44
- index
45
+ type: 'replacer',
46
+ value: {
47
+ type: 'icss-import',
48
+ name,
49
+ importName,
50
+ localName
45
51
  }
46
52
  });
53
+ });
54
+ });
47
55
 
48
- if (!hasImportMessage(result.messages, url)) {
49
- const media = '';
50
- const {
51
- loaderContext,
52
- importPrefix
53
- } = options;
54
- result.messages.push({
55
- pluginName,
56
- type: 'import',
57
- import: (0, _utils.getImportItemCode)({
58
- url,
59
- media
60
- }, loaderContext, importPrefix),
61
- item: {
62
- url,
63
- media
64
- }
65
- });
66
- }
67
- }
56
+ if (Object.keys(importReplacements).length > 0) {
57
+ (0, _icssUtils.replaceSymbols)(css, importReplacements);
68
58
  }
69
59
 
70
- (0, _icssUtils.replaceSymbols)(css, importReplacements);
71
-
72
- for (const exportName of Object.keys(icssExports)) {
73
- const name = exportName;
60
+ Object.keys(icssExports).forEach(name => {
74
61
  const value = (0, _icssUtils.replaceValueSymbols)(icssExports[name], importReplacements);
75
62
  result.messages.push({
76
63
  pluginName,
77
- export: (0, _utils.getExportItemCode)(name, value, options.localsConvention),
78
64
  type: 'export',
79
- item: {
65
+ value: {
80
66
  name,
81
67
  value
82
68
  }
83
69
  });
84
- }
70
+ });
85
71
  });
86
72
 
87
73
  exports.default = _default;
@@ -9,8 +9,6 @@ var _postcss = _interopRequireDefault(require("postcss"));
9
9
 
10
10
  var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
11
11
 
12
- var _utils = require("../utils");
13
-
14
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
13
 
16
14
  const pluginName = 'postcss-import-parser';
@@ -53,7 +51,7 @@ function parseImport(params) {
53
51
  }
54
52
 
55
53
  function walkAtRules(css, result, filter) {
56
- const items = [];
54
+ const items = new Map();
57
55
  css.walkAtRules(/^import$/i, atRule => {
58
56
  // Convert only top-level @import
59
57
  if (atRule.parent.type !== 'root') {
@@ -85,22 +83,43 @@ function walkAtRules(css, result, filter) {
85
83
  url,
86
84
  media
87
85
  } = parsed;
88
- items.push({
89
- url,
90
- media
91
- });
86
+ const value = items.get(url);
87
+
88
+ if (!value) {
89
+ items.set(url, new Set([media]));
90
+ } else {
91
+ value.add(media);
92
+ }
92
93
  });
93
94
  return items;
94
95
  }
95
96
 
96
- var _default = _postcss.default.plugin(pluginName, (options = {}) => function process(css, result) {
97
- const traversed = walkAtRules(css, result, options.filter);
98
- const paths = (0, _utils.uniqWith)(traversed, (value, other) => value.url === other.url && value.media === other.media);
99
- paths.forEach(item => {
97
+ var _default = _postcss.default.plugin(pluginName, options => function process(css, result) {
98
+ const items = walkAtRules(css, result, options.filter);
99
+ [...items].reduce((accumulator, currentValue) => {
100
+ const [url, medias] = currentValue;
101
+ medias.forEach(media => {
102
+ accumulator.push({
103
+ url,
104
+ media
105
+ });
106
+ });
107
+ return accumulator;
108
+ }, []).forEach((item, index) => {
109
+ const {
110
+ url,
111
+ media
112
+ } = item;
113
+ const name = `___CSS_LOADER_AT_RULE_IMPORT_${index}___`;
100
114
  result.messages.push({
101
115
  pluginName,
102
116
  type: 'import',
103
- import: (0, _utils.getImportItemCode)(item, options.loaderContext, options.importPrefix)
117
+ value: {
118
+ type: '@import',
119
+ name,
120
+ url,
121
+ media
122
+ }
104
123
  });
105
124
  });
106
125
  });