Skip to content

Commit 25b0ecd

Browse files
authored
test: add some es-modules concatenation cases (#566)
1 parent e6e07bb commit 25b0ecd

File tree

11 files changed

+254
-0
lines changed

11 files changed

+254
-0
lines changed

Diff for: .editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ trim_trailing_whitespace = true
1111
[*.md]
1212
insert_final_newline = true
1313
trim_trailing_whitespace = false
14+
15+
[test/cases/**]
16+
insert_final_newline = false

Diff for: test/cases/es-module-concatenation/a.css

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

Diff for: test/cases/es-module-concatenation/b.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.b {
2+
background: green;
3+
}

Diff for: test/cases/es-module-concatenation/c.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.c {
2+
background: blue;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.a {
2+
background: red;
3+
}
4+
5+
.b {
6+
background: green;
7+
}
8+
9+
.c {
10+
background: blue;
11+
}
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/******/ (function(modules) { // webpackBootstrap
2+
/******/ // The module cache
3+
/******/ var installedModules = {};
4+
/******/
5+
/******/ // The require function
6+
/******/ function __webpack_require__(moduleId) {
7+
/******/
8+
/******/ // Check if module is in cache
9+
/******/ if(installedModules[moduleId]) {
10+
/******/ return installedModules[moduleId].exports;
11+
/******/ }
12+
/******/ // Create a new module (and put it into the cache)
13+
/******/ var module = installedModules[moduleId] = {
14+
/******/ i: moduleId,
15+
/******/ l: false,
16+
/******/ exports: {}
17+
/******/ };
18+
/******/
19+
/******/ // Execute the module function
20+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21+
/******/
22+
/******/ // Flag the module as loaded
23+
/******/ module.l = true;
24+
/******/
25+
/******/ // Return the exports of the module
26+
/******/ return module.exports;
27+
/******/ }
28+
/******/
29+
/******/
30+
/******/ // expose the modules object (__webpack_modules__)
31+
/******/ __webpack_require__.m = modules;
32+
/******/
33+
/******/ // expose the module cache
34+
/******/ __webpack_require__.c = installedModules;
35+
/******/
36+
/******/ // define getter function for harmony exports
37+
/******/ __webpack_require__.d = function(exports, name, getter) {
38+
/******/ if(!__webpack_require__.o(exports, name)) {
39+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
40+
/******/ }
41+
/******/ };
42+
/******/
43+
/******/ // define __esModule on exports
44+
/******/ __webpack_require__.r = function(exports) {
45+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
46+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
47+
/******/ }
48+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
49+
/******/ };
50+
/******/
51+
/******/ // create a fake namespace object
52+
/******/ // mode & 1: value is a module id, require it
53+
/******/ // mode & 2: merge all properties of value into the ns
54+
/******/ // mode & 4: return value when already ns object
55+
/******/ // mode & 8|1: behave like require
56+
/******/ __webpack_require__.t = function(value, mode) {
57+
/******/ if(mode & 1) value = __webpack_require__(value);
58+
/******/ if(mode & 8) return value;
59+
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
60+
/******/ var ns = Object.create(null);
61+
/******/ __webpack_require__.r(ns);
62+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
63+
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
64+
/******/ return ns;
65+
/******/ };
66+
/******/
67+
/******/ // getDefaultExport function for compatibility with non-harmony modules
68+
/******/ __webpack_require__.n = function(module) {
69+
/******/ var getter = module && module.__esModule ?
70+
/******/ function getDefault() { return module['default']; } :
71+
/******/ function getModuleExports() { return module; };
72+
/******/ __webpack_require__.d(getter, 'a', getter);
73+
/******/ return getter;
74+
/******/ };
75+
/******/
76+
/******/ // Object.prototype.hasOwnProperty.call
77+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
78+
/******/
79+
/******/ // __webpack_public_path__
80+
/******/ __webpack_require__.p = "";
81+
/******/
82+
/******/
83+
/******/ // Load entry module and return exports
84+
/******/ return __webpack_require__(__webpack_require__.s = 0);
85+
/******/ })
86+
/************************************************************************/
87+
/******/ ([
88+
/* 0 */
89+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
90+
91+
"use strict";
92+
// ESM COMPAT FLAG
93+
__webpack_require__.r(__webpack_exports__);
94+
95+
// CONCATENATED MODULE: ./a.css
96+
// extracted by mini-css-extract-plugin
97+
98+
// CONCATENATED MODULE: ./b.css
99+
// extracted by mini-css-extract-plugin
100+
101+
// CONCATENATED MODULE: ./c.css
102+
// extracted by mini-css-extract-plugin
103+
104+
// CONCATENATED MODULE: ./index.js
105+
106+
107+
108+
109+
110+
/***/ })
111+
/******/ ]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.a {
2+
background: red;
3+
}
4+
5+
.b {
6+
background: green;
7+
}
8+
9+
.c {
10+
background: blue;
11+
}
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/******/ (() => { // webpackBootstrap
2+
/******/ "use strict";
3+
/******/ var __webpack_modules__ = ([
4+
/* 0 */
5+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
6+
7+
// ESM COMPAT FLAG
8+
__webpack_require__.r(__webpack_exports__);
9+
10+
// CONCATENATED MODULE: ./a.css
11+
// extracted by mini-css-extract-plugin
12+
13+
// CONCATENATED MODULE: ./b.css
14+
// extracted by mini-css-extract-plugin
15+
16+
// CONCATENATED MODULE: ./c.css
17+
// extracted by mini-css-extract-plugin
18+
19+
// CONCATENATED MODULE: ./index.js
20+
21+
22+
23+
24+
25+
/***/ })
26+
/******/ ]);
27+
/************************************************************************/
28+
/******/ // The module cache
29+
/******/ var __webpack_module_cache__ = {};
30+
/******/
31+
/******/ // The require function
32+
/******/ function __webpack_require__(moduleId) {
33+
/******/ // Check if module is in cache
34+
/******/ if(__webpack_module_cache__[moduleId]) {
35+
/******/ return __webpack_module_cache__[moduleId].exports;
36+
/******/ }
37+
/******/ // Create a new module (and put it into the cache)
38+
/******/ var module = __webpack_module_cache__[moduleId] = {
39+
/******/ // no module.id needed
40+
/******/ // no module.loaded needed
41+
/******/ exports: {}
42+
/******/ };
43+
/******/
44+
/******/ // Execute the module function
45+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
46+
/******/
47+
/******/ // Return the exports of the module
48+
/******/ return module.exports;
49+
/******/ }
50+
/******/
51+
/************************************************************************/
52+
/******/ /* webpack/runtime/make namespace object */
53+
/******/ (() => {
54+
/******/ // define __esModule on exports
55+
/******/ __webpack_require__.r = (exports) => {
56+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
57+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
58+
/******/ }
59+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
60+
/******/ };
61+
/******/ })();
62+
/******/
63+
/************************************************************************/
64+
/******/ // startup
65+
/******/ // Load entry module
66+
/******/ __webpack_require__(0);
67+
/******/ // This entry module used 'exports' so it can't be inlined
68+
/******/ })()
69+
;

Diff for: test/cases/es-module-concatenation/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import './a.css';
2+
import './b.css';
3+
import './c.css';

Diff for: test/cases/es-module-concatenation/webpack.config.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Self from '../../../src';
2+
3+
module.exports = {
4+
entry: './index.js',
5+
optimization: {
6+
concatenateModules: true,
7+
},
8+
module: {
9+
rules: [
10+
{
11+
test: /\.css$/,
12+
use: [
13+
{
14+
loader: Self.loader,
15+
options: {
16+
esModule: true,
17+
},
18+
},
19+
'css-loader',
20+
],
21+
},
22+
],
23+
},
24+
plugins: [
25+
new Self({
26+
filename: '[name].css',
27+
}),
28+
],
29+
};

Diff for: test/enforce-esm.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import webpack from 'webpack';
2+
13
import { getCompiler, source, compile } from './helpers';
24

5+
const isWebpack5 = webpack.version[0] === '5';
6+
37
it('should enforce esm for empty module with options.esModule', async (done) => {
48
const compiler = getCompiler(
59
'./esm.js',
@@ -11,6 +15,7 @@ it('should enforce esm for empty module with options.esModule', async (done) =>
1115
);
1216
const stats = await compile(compiler);
1317
expect(stats.hasErrors()).toBe(false);
18+
expect(stats.compilation.modules.length).toBe(isWebpack5 ? 4 : 2);
1419
expect(source('./simple.css', stats)).toMatchInlineSnapshot(`
1520
"// extracted by mini-css-extract-plugin
1621
export {};"
@@ -29,6 +34,7 @@ it('should keep empty module without options.esModule', async (done) => {
2934
);
3035
const stats = await compile(compiler);
3136
expect(stats.hasErrors()).toBe(false);
37+
expect(stats.compilation.modules.length).toBe(isWebpack5 ? 7 : 3);
3238
expect(source('./simple.css', stats)).toMatchInlineSnapshot(
3339
`"// extracted by mini-css-extract-plugin"`
3440
);

0 commit comments

Comments
 (0)