Skip to content

Commit 39f540e

Browse files
committed
test: add nextjs mangle case and snap
1 parent f363928 commit 39f540e

File tree

11 files changed

+1289
-209
lines changed

11 files changed

+1289
-209
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages/unplugin-tailwindcss-mangle/test/fixtures/**/*

apps/next-app/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
"prepare": "tw-patch"
1111
},
1212
"dependencies": {
13-
"@types/node": "18.15.11",
14-
"@types/react": "18.0.37",
15-
"@types/react-dom": "18.0.11",
13+
"@types/node": "18.16.0",
14+
"@types/react": "18.2.0",
15+
"@types/react-dom": "18.2.0",
1616
"autoprefixer": "10.4.14",
17-
"eslint": "8.38.0",
18-
"eslint-config-next": "13.3.0",
19-
"next": "13.3.0",
20-
"postcss": "8.4.22",
17+
"eslint": "8.39.0",
18+
"eslint-config-next": "13.3.1",
19+
"next": "13.3.1",
20+
"postcss": "8.4.23",
2121
"react": "18.2.0",
2222
"react-dom": "18.2.0",
2323
"tailwindcss": "3.3.1",

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
"@icebreakers/rollup": "^0.3.0",
2222
"@icebreakers/tsconfig": "^0.0.6",
2323
"@tsconfig/recommended": "^1.0.2",
24-
"@types/jest": "^29.5.0",
25-
"@types/node": "^18.15.11",
24+
"@types/jest": "^29.5.1",
25+
"@types/node": "^18.16.0",
2626
"cross-env": "^7.0.3",
27-
"eslint": "^8.38.0",
27+
"eslint": "^8.39.0",
2828
"jest": "^29.5.0",
2929
"only-allow": "^1.1.1",
30-
"prettier": "^2.8.7",
31-
"rollup": "^3.20.6",
30+
"prettier": "^2.8.8",
31+
"rollup": "^3.21.0",
3232
"ts-jest": "^29.1.0",
3333
"ts-node": "^10.9.1",
3434
"turbo": "^1.9.3",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/fixtures/**/*

packages/unplugin-tailwindcss-mangle/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { jsHandler } from './js'
1010
import { cssHandler } from './css'
1111
import type { sources } from 'webpack'
1212
import path from 'path'
13+
import fs from 'fs'
1314

1415
// const cachedHtmlSource = new Map<string, sources.Source | OutputAsset>()
1516
// const cachedJsSource = new Map<string, sources.Source | OutputChunk>()
@@ -135,6 +136,8 @@ export const unplugin = createUnplugin((options: Options | undefined = {}, meta)
135136
return
136137
}
137138

139+
// fs.writeFileSync('./tw-class-set.json', JSON.stringify(Array.from(runtimeSet)), 'utf-8')
140+
138141
if (groupedEntries.html.length) {
139142
for (let i = 0; i < groupedEntries.html.length; i++) {
140143
const [file, asset] = groupedEntries.html[i]
@@ -175,10 +178,13 @@ export const unplugin = createUnplugin((options: Options | undefined = {}, meta)
175178
outputCachedMap.forEach(({ js }, key) => {
176179
if (js.size) {
177180
js.forEach((chunk, file) => {
178-
const code = jsHandler((chunk as sources.Source).source().toString(), {
181+
const rawCode = (chunk as sources.Source).source().toString()
182+
const code = jsHandler(rawCode, {
179183
runtimeSet,
180184
classGenerator
181185
}).code
186+
// fs.writeFileSync(path.basename(file), rawCode)
187+
// fs.writeFileSync(path.basename(file) + '.out', code)
182188
const source = new ConcatSource(code)
183189
compilation.emitAsset(getEmitAssetPath(key, file), source)
184190
})

packages/unplugin-tailwindcss-mangle/test/.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/unplugin-tailwindcss-mangle/test/__snapshots__/js.test.ts.snap

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,219 @@ exports[`js handler common TemplateElement 1`] = `
77
element.innerHTML = \`<div class="tw-a tw-b">count is \${counter}</div>\`;"
88
`;
99
10+
exports[`js handler nextjs server side mangle 1`] = `
11+
""use strict";
12+
13+
(() => {
14+
var exports = {};
15+
exports.id = 405;
16+
exports.ids = [405];
17+
exports.modules = {
18+
/***/957: /***/(__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
19+
__webpack_require__.r(__webpack_exports__);
20+
/* harmony export */
21+
__webpack_require__.d(__webpack_exports__, {
22+
/* harmony export */"default": () => /* binding */Home
23+
/* harmony export */
24+
});
25+
/* harmony import */
26+
var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(997);
27+
/* harmony import */
28+
var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
29+
/* harmony import */
30+
var next_font_google_target_css_path_pages_index_tsx_import_Inter_arguments_subsets_latin_variableName_inter___WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(941);
31+
/* harmony import */
32+
var next_font_google_target_css_path_pages_index_tsx_import_Inter_arguments_subsets_latin_variableName_inter___WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(next_font_google_target_css_path_pages_index_tsx_import_Inter_arguments_subsets_latin_variableName_inter___WEBPACK_IMPORTED_MODULE_2__);
33+
/* harmony import */
34+
var next_image__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(395);
35+
/* harmony import */
36+
var next_image__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(next_image__WEBPACK_IMPORTED_MODULE_1__);
37+
function Home() {
38+
return /*#__PURE__*/(0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("main", {
39+
className: "flex tw-a tw-b tw-c tw-d tw-e",
40+
children: [/*#__PURE__*/(0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
41+
className: "tw-f tw-g tw-h tw-c tw-d tw-i tw-j tw-k",
42+
children: [/*#__PURE__*/(0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("p", {
43+
className: "fixed tw-l tw-m flex tw-g tw-n tw-o tw-p tw-q tw-r tw-s tw-t tw-u tw-v tw-w tw-x tw-y tw-z tw-aa tw-ba tw-ca tw-da tw-ea",
44+
children: ["Get started by editing\\xa0", /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("code", {
45+
className: "tw-i tw-fa",
46+
children: "pages/index.tsx"
47+
})]
48+
}), /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
49+
className: "fixed tw-ga tw-l flex tw-ha tw-g tw-ia tw-n tw-ja tw-ka tw-la tw-ma tw-na tw-y tw-oa tw-z tw-pa",
50+
children: /*#__PURE__*/(0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("a", {
51+
className: "tw-qa flex tw-ra tw-sa tw-ta tw-ua tw-va",
52+
href: "https://vercel.com?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app",
53+
target: "_blank",
54+
rel: "noopener noreferrer",
55+
children: ["By ", /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(next_image__WEBPACK_IMPORTED_MODULE_1___default(), {
56+
src: "/vercel.svg",
57+
alt: "Vercel Logo",
58+
className: "tw-wa",
59+
width: 100,
60+
height: 24,
61+
priority: true
62+
})]
63+
})
64+
})]
65+
}), /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
66+
className: "relative flex tw-ra tw-xa tw-ya tw-za tw-ab tw-bb tw-cb tw-db tw-eb tw-fb tw-gb tw-hb tw-ib tw-jb tw-kb tw-lb tw-mb tw-nb tw-ob tw-pb tw-qb tw-rb tw-sb tw-tb tw-ub tw-vb tw-wb",
67+
children: /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(next_image__WEBPACK_IMPORTED_MODULE_1___default(), {
68+
className: "relative tw-xb tw-wa",
69+
src: "/next.svg",
70+
alt: "Next.js Logo",
71+
width: 180,
72+
height: 37,
73+
priority: true
74+
})
75+
}), /*#__PURE__*/(0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
76+
className: "tw-yb grid tw-zb tw-ac tw-bc tw-cc",
77+
children: [/*#__PURE__*/(0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("a", {
78+
href: "https://nextjs.org/docs?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app",
79+
className: "group tw-dc border tw-ec tw-fc tw-gc tw-hc tw-ic tw-jc tw-kc tw-lc",
80+
target: "_blank",
81+
rel: "noopener noreferrer",
82+
children: [/*#__PURE__*/(0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("h2", {
83+
className: \`\${next_font_google_target_css_path_pages_index_tsx_import_Inter_arguments_subsets_latin_variableName_inter___WEBPACK_IMPORTED_MODULE_2___default().className} tw-mc tw-nc tw-oc\`,
84+
children: ["Docs ", /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("span", {
85+
className: "tw-pc tw-qc tw-rc tw-sc",
86+
children: "->"
87+
})]
88+
}), /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("p", {
89+
className: \`\${next_font_google_target_css_path_pages_index_tsx_import_Inter_arguments_subsets_latin_variableName_inter___WEBPACK_IMPORTED_MODULE_2___default().className} tw-tc tw-uc tw-j tw-vc\`,
90+
children: "Find in-depth information about Next.js features and API."
91+
})]
92+
}), /*#__PURE__*/(0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("a", {
93+
href: "https://nextjs.org/learn?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app",
94+
className: "group tw-dc border tw-ec tw-fc tw-gc tw-hc tw-ic tw-jc tw-kc tw-lc",
95+
target: "_blank",
96+
rel: "noopener noreferrer",
97+
children: [/*#__PURE__*/(0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("h2", {
98+
className: \`\${next_font_google_target_css_path_pages_index_tsx_import_Inter_arguments_subsets_latin_variableName_inter___WEBPACK_IMPORTED_MODULE_2___default().className} tw-mc tw-nc tw-oc\`,
99+
children: ["Learn ", /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("span", {
100+
className: "tw-pc tw-qc tw-rc tw-sc",
101+
children: "->"
102+
})]
103+
}), /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("p", {
104+
className: \`\${next_font_google_target_css_path_pages_index_tsx_import_Inter_arguments_subsets_latin_variableName_inter___WEBPACK_IMPORTED_MODULE_2___default().className} tw-tc tw-uc tw-j tw-vc\`,
105+
children: "Learn about Next.js in an interactive course with\\xa0quizzes!"
106+
})]
107+
}), /*#__PURE__*/(0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("a", {
108+
href: "https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app",
109+
className: "group tw-dc border tw-ec tw-fc tw-gc tw-hc tw-ic tw-jc tw-kc tw-lc",
110+
target: "_blank",
111+
rel: "noopener noreferrer",
112+
children: [/*#__PURE__*/(0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("h2", {
113+
className: \`\${next_font_google_target_css_path_pages_index_tsx_import_Inter_arguments_subsets_latin_variableName_inter___WEBPACK_IMPORTED_MODULE_2___default().className} tw-mc tw-nc tw-oc\`,
114+
children: ["Templates ", /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("span", {
115+
className: "tw-pc tw-qc tw-rc tw-sc",
116+
children: "->"
117+
})]
118+
}), /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("p", {
119+
className: \`\${next_font_google_target_css_path_pages_index_tsx_import_Inter_arguments_subsets_latin_variableName_inter___WEBPACK_IMPORTED_MODULE_2___default().className} tw-tc tw-uc tw-j tw-vc\`,
120+
children: "Discover and deploy boilerplate example Next.js\\xa0projects."
121+
})]
122+
}), /*#__PURE__*/(0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("a", {
123+
href: "https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app",
124+
className: "group tw-dc border tw-ec tw-fc tw-gc tw-hc tw-ic tw-jc tw-kc tw-lc",
125+
target: "_blank",
126+
rel: "noopener noreferrer",
127+
children: [/*#__PURE__*/(0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("h2", {
128+
className: \`\${next_font_google_target_css_path_pages_index_tsx_import_Inter_arguments_subsets_latin_variableName_inter___WEBPACK_IMPORTED_MODULE_2___default().className} tw-mc tw-nc tw-oc\`,
129+
children: ["Deploy ", /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("span", {
130+
className: "tw-pc tw-qc tw-rc tw-sc",
131+
children: "->"
132+
})]
133+
}), /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("p", {
134+
className: \`\${next_font_google_target_css_path_pages_index_tsx_import_Inter_arguments_subsets_latin_variableName_inter___WEBPACK_IMPORTED_MODULE_2___default().className} tw-tc tw-uc tw-j tw-vc\`,
135+
children: "Instantly deploy your Next.js site to a shareable URL with Vercel."
136+
})]
137+
})]
138+
})]
139+
});
140+
}
141+
142+
/***/
143+
},
144+
145+
/***/918: /***/module => {
146+
module.exports = require("next/dist/shared/lib/amp-context.js");
147+
148+
/***/
149+
},
150+
151+
/***/732: /***/module => {
152+
module.exports = require("next/dist/shared/lib/amp-mode.js");
153+
154+
/***/
155+
},
156+
157+
/***/796: /***/module => {
158+
module.exports = require("next/dist/shared/lib/head-manager-context.js");
159+
160+
/***/
161+
},
162+
163+
/***/486: /***/module => {
164+
module.exports = require("next/dist/shared/lib/image-blur-svg.js");
165+
166+
/***/
167+
},
168+
169+
/***/744: /***/module => {
170+
module.exports = require("next/dist/shared/lib/image-config-context.js");
171+
172+
/***/
173+
},
174+
175+
/***/843: /***/module => {
176+
module.exports = require("next/dist/shared/lib/image-config.js");
177+
178+
/***/
179+
},
180+
181+
/***/552: /***/module => {
182+
module.exports = require("next/dist/shared/lib/image-loader");
183+
184+
/***/
185+
},
186+
187+
/***/470: /***/module => {
188+
module.exports = require("next/dist/shared/lib/side-effect.js");
189+
190+
/***/
191+
},
192+
193+
/***/618: /***/module => {
194+
module.exports = require("next/dist/shared/lib/utils/warn-once.js");
195+
196+
/***/
197+
},
198+
199+
/***/689: /***/module => {
200+
module.exports = require("react");
201+
202+
/***/
203+
},
204+
205+
/***/997: /***/module => {
206+
module.exports = require("react/jsx-runtime");
207+
208+
/***/
209+
}
210+
};
211+
212+
;
213+
214+
// load runtime
215+
var __webpack_require__ = require("../webpack-runtime.js");
216+
__webpack_require__.C(exports);
217+
var __webpack_exec__ = moduleId => __webpack_require__(__webpack_require__.s = moduleId);
218+
var __webpack_exports__ = __webpack_require__.X(0, [463, 262], () => __webpack_exec__(957));
219+
module.exports = __webpack_exports__;
220+
})();"
221+
`;
222+
10223
exports[`js handler z-10 not transform 1`] = `
11224
"{
12225
className: "tw-a tw-b tw-c tw-d tw-e tw-f tw-g tw-h";

0 commit comments

Comments
 (0)