Skip to content

Commit bee7ccd

Browse files
committed
Set up Tailwind
1 parent c5d7342 commit bee7ccd

File tree

7 files changed

+417
-34
lines changed

7 files changed

+417
-34
lines changed

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@
3434
"vue": "^3.2.25"
3535
},
3636
"devDependencies": {
37+
"@tailwindcss/forms": "^0.5.3",
3738
"@vitejs/plugin-vue": "^2.2.0",
3839
"@vue/test-utils": "^2.0.0-rc.17",
40+
"autoprefixer": "^10.4.13",
3941
"bootstrap": "^4",
4042
"eslint": "^8.8.0",
4143
"eslint-config-prettier": "^8.3.0",
4244
"eslint-plugin-prettier": "^4.0.0",
4345
"eslint-plugin-vue": "^8.4.1",
4446
"jest": "^27.5.1",
4547
"jest-environment-jsdom": "^27.5.1",
48+
"postcss": "^8.4.18",
49+
"tailwindcss": "^3.2.1",
4650
"vite": "^2.8.0",
4751
"vite-jest": "^0.1.4"
4852
}

postcss.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
}

src/demo/App.vue

+1-8
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
</template>
9292

9393
<script>
94-
import '../../node_modules/bootstrap/dist/css/bootstrap.css';
94+
import './tailwind.css';
9595
import { Bootstrap4Pagination, Bootstrap5Pagination, TailwindPagination } from '../lib';
9696
import RenderToIFrame from './components/RenderToIFrame';
9797
@@ -149,13 +149,6 @@ export default {
149149
150150
return 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css';
151151
},
152-
scriptUrl() {
153-
if (this.style === 'tailwind') {
154-
return 'https://cdn.tailwindcss.com';
155-
}
156-
157-
return '';
158-
},
159152
},
160153
161154
mounted () {

src/demo/components/RenderToIframe.js

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h, ref, createApp, onMounted, onBeforeUpdate } from 'vue';
1+
import {h, ref, createApp, onMounted, onBeforeUpdate} from 'vue';
22

33
export default {
44
name: 'RenderToIFrame',
@@ -7,21 +7,18 @@ export default {
77
type: String,
88
default: '',
99
},
10-
scriptUrl: {
11-
type: String,
12-
default: '',
13-
},
1410
},
1511
setup(props, { slots }) {
1612
const iframeRef = ref(null);
1713
const iframeBody = ref(null);
1814
const iframeHead = ref(null);
1915
const iframeCSS = ref(null);
20-
const iframeScript = ref(null);
2116
const iframeStyle = ref(null);
2217
let iframeApp = null;
2318

24-
onMounted(() => {
19+
onMounted(async () => {
20+
const tailwindCss = await import('../tailwind.css');
21+
2522
iframeBody.value = iframeRef.value.contentDocument.body;
2623
iframeHead.value = iframeRef.value.contentDocument.head;
2724
const el = document.createElement('div');
@@ -32,7 +29,7 @@ export default {
3229
iframeHead.value.appendChild(iframeCSS.value);
3330
iframeStyle.value = document.createElement('style');
3431
iframeStyle.value.innerHTML =
35-
'body { margin: 0; padding: 10px; background: #f8f9fa; }';
32+
'body { margin: 0; padding: 10px; background: #f8f9fa; }' + tailwindCss.default;
3633
iframeHead.value.appendChild(iframeStyle.value);
3734

3835
iframeApp = createApp({
@@ -42,21 +39,14 @@ export default {
4239
},
4340
}).mount(el);
4441
});
42+
4543
onBeforeUpdate(() => {
4644
if (!iframeApp || !iframeRef.value) {
4745
return;
4846
}
4947
iframeCSS.value.href = props.cssUrl;
50-
if (props.scriptUrl) {
51-
iframeScript.value = document.createElement('script');
52-
iframeScript.value.id = 'custom-script';
53-
iframeScript.value.src = props.scriptUrl;
54-
iframeHead.value.appendChild(iframeScript.value);
55-
} else {
56-
document.getElementById('custom-script')?.remove();
57-
iframeScript.value = null;
58-
}
5948
});
49+
6050
return () => h('iframe', { ref: iframeRef });
6151
},
6252
};

src/demo/tailwind.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;

tailwind.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/** @type {import('tailwindcss').Config} */
2+
module.exports = {
3+
content: [
4+
'./src/**/*.vue',
5+
],
6+
theme: {
7+
extend: {},
8+
},
9+
plugins: [
10+
require('@tailwindcss/forms'),
11+
],
12+
}

0 commit comments

Comments
 (0)