Skip to content

Commit 60cc79e

Browse files
test: es modules
1 parent 9b6b8b3 commit 60cc79e

File tree

21 files changed

+288
-0
lines changed

21 files changed

+288
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.foo__style__a-class {
2+
background: red;
3+
}
4+
5+
.foo__style__b__class {
6+
color: green;
7+
}
8+
9+
.foo__style__cClass {
10+
color: blue;
11+
}
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/******/ "use strict";
2+
/******/ var __webpack_modules__ = ([
3+
/* 0 */,
4+
/* 1 */
5+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
6+
7+
__webpack_require__.r(__webpack_exports__);
8+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
9+
/* harmony export */ "aClass": () => (/* binding */ aClass),
10+
/* harmony export */ "bClass": () => (/* binding */ bClass),
11+
/* harmony export */ "cClass": () => (/* binding */ cClass)
12+
/* harmony export */ });
13+
// extracted by mini-css-extract-plugin
14+
const aClass = "foo__style__a-class";
15+
const bClass = "foo__style__b__class";
16+
const cClass = "foo__style__cClass";
17+
18+
/***/ })
19+
/******/ ]);
20+
/************************************************************************/
21+
/******/ // The module cache
22+
/******/ var __webpack_module_cache__ = {};
23+
/******/
24+
/******/ // The require function
25+
/******/ function __webpack_require__(moduleId) {
26+
/******/ // Check if module is in cache
27+
/******/ if(__webpack_module_cache__[moduleId]) {
28+
/******/ return __webpack_module_cache__[moduleId].exports;
29+
/******/ }
30+
/******/ // Create a new module (and put it into the cache)
31+
/******/ var module = __webpack_module_cache__[moduleId] = {
32+
/******/ // no module.id needed
33+
/******/ // no module.loaded needed
34+
/******/ exports: {}
35+
/******/ };
36+
/******/
37+
/******/ // Execute the module function
38+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
39+
/******/
40+
/******/ // Return the exports of the module
41+
/******/ return module.exports;
42+
/******/ }
43+
/******/
44+
/************************************************************************/
45+
/******/ /* webpack/runtime/define property getters */
46+
/******/ (() => {
47+
/******/ // define getter functions for harmony exports
48+
/******/ __webpack_require__.d = (exports, definition) => {
49+
/******/ for(var key in definition) {
50+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
51+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
52+
/******/ }
53+
/******/ }
54+
/******/ };
55+
/******/ })();
56+
/******/
57+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
58+
/******/ (() => {
59+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
60+
/******/ })();
61+
/******/
62+
/******/ /* webpack/runtime/make namespace object */
63+
/******/ (() => {
64+
/******/ // define __esModule on exports
65+
/******/ __webpack_require__.r = (exports) => {
66+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
67+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
68+
/******/ }
69+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
70+
/******/ };
71+
/******/ })();
72+
/******/
73+
/************************************************************************/
74+
var __webpack_exports__ = {};
75+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
76+
(() => {
77+
__webpack_require__.r(__webpack_exports__);
78+
/* harmony import */ var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
79+
80+
81+
// eslint-disable-next-line no-console
82+
console.log({ css: _style_css__WEBPACK_IMPORTED_MODULE_0__.default, aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass });
83+
84+
})();
85+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import css, { aClass, bClass, cClass } from './style.css';
2+
3+
// eslint-disable-next-line no-console
4+
console.log({ css, aClass, bClass, cClass });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.a-class {
2+
background: red;
3+
}
4+
5+
.b__class {
6+
color: green;
7+
}
8+
9+
.cClass {
10+
color: blue;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const webpack = require('webpack');
2+
3+
module.exports = () => webpack.version[0] !== '4';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import Self from '../../../src';
2+
3+
module.exports = {
4+
entry: './index.js',
5+
module: {
6+
rules: [
7+
{
8+
test: /\.css$/,
9+
use: [
10+
{
11+
loader: Self.loader,
12+
options: {
13+
esModule: true,
14+
modules: {
15+
namedExport: true,
16+
},
17+
},
18+
},
19+
{
20+
loader: 'css-loader',
21+
options: {
22+
esModule: true,
23+
modules: {
24+
namedExport: true,
25+
localIdentName: 'foo__[name]__[local]',
26+
},
27+
},
28+
},
29+
],
30+
},
31+
],
32+
},
33+
output: {
34+
module: true,
35+
},
36+
experiments: {
37+
outputModule: true,
38+
},
39+
plugins: [
40+
new Self({
41+
filename: '[name].css',
42+
}),
43+
],
44+
};
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background: red;
3+
}
4+

test/cases/output-iife/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './style.css';

test/cases/output-iife/style.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background: red;
3+
}

test/cases/output-iife/test.filter.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const webpack = require('webpack');
2+
3+
module.exports = () => webpack.version[0] !== '4';
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Self from '../../../src';
2+
3+
module.exports = {
4+
entry: './index.js',
5+
module: {
6+
rules: [
7+
{
8+
test: /\.css$/,
9+
use: [Self.loader, 'css-loader'],
10+
},
11+
],
12+
},
13+
output: {
14+
iife: false,
15+
},
16+
plugins: [
17+
new Self({
18+
filename: '[name].css',
19+
}),
20+
],
21+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background: red;
3+
}
4+

test/cases/output-module/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './style.css';

test/cases/output-module/style.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background: red;
3+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const webpack = require('webpack');
2+
3+
module.exports = () => webpack.version[0] !== '4';
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Self from '../../../src';
2+
3+
module.exports = {
4+
entry: './index.js',
5+
module: {
6+
rules: [
7+
{
8+
test: /\.css$/,
9+
use: [Self.loader, 'css-loader'],
10+
},
11+
],
12+
},
13+
output: {
14+
module: true,
15+
},
16+
experiments: {
17+
outputModule: true,
18+
},
19+
plugins: [
20+
new Self({
21+
filename: '[name].css',
22+
}),
23+
],
24+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.foo__style__a {
2+
background: red;
3+
}
4+
5+
.foo__style__b {
6+
color: green;
7+
}
8+
9+
.c {
10+
color: blue;
11+
}
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './style.css';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.a {
2+
background: red;
3+
}
4+
5+
:local(.b) {
6+
color: green;
7+
}
8+
9+
:global(.c) {
10+
color: blue;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const webpack = require('webpack');
2+
3+
module.exports = () => webpack.version[0] !== '4';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Self from '../../../src';
2+
3+
module.exports = {
4+
entry: './index.js',
5+
module: {
6+
rules: [
7+
{
8+
test: /\.css$/,
9+
use: [
10+
Self.loader,
11+
{
12+
loader: 'css-loader',
13+
options: {
14+
modules: {
15+
mode: 'local',
16+
localIdentName: 'foo__[name]__[local]',
17+
},
18+
},
19+
},
20+
],
21+
},
22+
],
23+
},
24+
output: {
25+
module: true,
26+
},
27+
experiments: {
28+
outputModule: true,
29+
},
30+
plugins: [
31+
new Self({
32+
filename: '[name].css',
33+
}),
34+
],
35+
};

0 commit comments

Comments
 (0)