|
| 1 | +import { css, html, js, json, test } from '../utils' |
| 2 | + |
| 3 | +test( |
| 4 | + 'Webpack + PostCSS (watch)', |
| 5 | + { |
| 6 | + fs: { |
| 7 | + 'package.json': json` |
| 8 | + { |
| 9 | + "main": "./src/index.js", |
| 10 | + "browser": "./src/index.js", |
| 11 | + "dependencies": { |
| 12 | + "css-loader": "^6", |
| 13 | + "postcss": "^8", |
| 14 | + "postcss-loader": "^7", |
| 15 | + "webpack": "^5", |
| 16 | + "webpack-cli": "^5", |
| 17 | + "mini-css-extract-plugin": "^2", |
| 18 | + "tailwindcss": "workspace:^", |
| 19 | + "@tailwindcss/postcss": "workspace:^" |
| 20 | + } |
| 21 | + } |
| 22 | + `, |
| 23 | + 'postcss.config.js': js` |
| 24 | + /** @type {import('postcss-load-config').Config} */ |
| 25 | + module.exports = { |
| 26 | + plugins: { |
| 27 | + '@tailwindcss/postcss': {}, |
| 28 | + }, |
| 29 | + } |
| 30 | + `, |
| 31 | + 'webpack.config.js': js` |
| 32 | + let MiniCssExtractPlugin = require('mini-css-extract-plugin') |
| 33 | +
|
| 34 | + module.exports = { |
| 35 | + plugins: [new MiniCssExtractPlugin()], |
| 36 | + module: { |
| 37 | + rules: [ |
| 38 | + { |
| 39 | + test: /.css$/i, |
| 40 | + use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'], |
| 41 | + }, |
| 42 | + ], |
| 43 | + }, |
| 44 | + } |
| 45 | + `, |
| 46 | + 'src/index.js': js`import './index.css'`, |
| 47 | + 'src/index.html': html` |
| 48 | + <div class="flex"></div> |
| 49 | + `, |
| 50 | + 'src/index.css': css` |
| 51 | + @import 'tailwindcss/theme'; |
| 52 | + @import 'tailwindcss/utilities'; |
| 53 | + `, |
| 54 | + 'src/unrelated.module.css': css` |
| 55 | + .module { |
| 56 | + color: var(--color-blue-500); |
| 57 | + } |
| 58 | + `, |
| 59 | + }, |
| 60 | + }, |
| 61 | + async ({ fs, spawn, exec, expect }) => { |
| 62 | + // Generate the initial build so output CSS files exist on disk |
| 63 | + await exec('webpack --mode=development') |
| 64 | + |
| 65 | + // NOTE: We are writing to an output CSS file which is not being ignored by |
| 66 | + // `.gitignore` nor marked with `@source not`. This should not result in an |
| 67 | + // infinite loop. |
| 68 | + let process = await spawn('webpack --mode=development --watch') |
| 69 | + await process.onStdout((m) => m.includes('compiled successfully in')) |
| 70 | + |
| 71 | + expect(await fs.dumpFiles('./dist/*.css')).toMatchInlineSnapshot(` |
| 72 | + " |
| 73 | + --- ./dist/main.css --- |
| 74 | + :root, :host { |
| 75 | + --color-blue-500: oklch(0.623 0.214 259.815); |
| 76 | + } |
| 77 | + .flex { |
| 78 | + display: flex; |
| 79 | + } |
| 80 | + " |
| 81 | + `) |
| 82 | + |
| 83 | + await fs.write( |
| 84 | + 'src/unrelated.module.css', |
| 85 | + css` |
| 86 | + .module { |
| 87 | + color: var(--color-blue-500); |
| 88 | + background-color: var(--color-red-500); |
| 89 | + } |
| 90 | + `, |
| 91 | + ) |
| 92 | + await process.onStdout((m) => m.includes('compiled successfully in')) |
| 93 | + |
| 94 | + expect(await fs.dumpFiles('./dist/*.css')).toMatchInlineSnapshot(` |
| 95 | + " |
| 96 | + --- ./dist/main.css --- |
| 97 | + :root, :host { |
| 98 | + --color-red-500: oklch(0.637 0.237 25.331); |
| 99 | + --color-blue-500: oklch(0.623 0.214 259.815); |
| 100 | + } |
| 101 | + .flex { |
| 102 | + display: flex; |
| 103 | + } |
| 104 | + " |
| 105 | + `) |
| 106 | + }, |
| 107 | +) |
0 commit comments