安裝
在 Ember.js 專案中設定 Tailwind CSS。
如果尚未設定,請先建立一個新的 Ember.js 專案。最常見的方法是使用 Ember CLI.
npx ember-cli new my-project --embroider --no-welcomecd my-project
使用 npm 安裝 @tailwindcss/postcss
及其同級相依性,以及 postcss-loader
.
npm install tailwindcss @tailwindcss/postcss postcss postcss-loader
在您的 ember-cli-build.js
檔案中,設定 PostCSS 來處理您的 CSS 檔案。
'use strict';const EmberApp = require('ember-cli/lib/broccoli/ember-app');module.exports = function (defaults) { const app = new EmberApp(defaults, { // Add options here }); const { Webpack } = require('@embroider/webpack'); return require('@embroider/compat').compatBuild(app, Webpack, { skipBabel: [ { package: 'qunit', }, ], packagerOptions: { webpackConfig: { module: { rules: [ { test: /\.css$/i, use: ['postcss-loader'], }, ], }, }, }, });};
在您的專案根目錄中建立一個 postcss.config.mjs
檔案,並將 @tailwindcss/postcss
外掛程式新增到您的 PostCSS 設定。
export default { plugins: { "@tailwindcss/postcss": {}, },}
建立一個 ./app/app.css
檔案,並為 Tailwind CSS 新增一個 @import
。
@import "tailwindcss";
在您的 ./app/app.js
檔案中匯入新建立的 ./app/app.css
檔案。
import Application from '@ember/application';import Resolver from 'ember-resolver';import loadInitializers from 'ember-load-initializers';import config from 'my-project/config/environment';import 'my-project/app.css';export default class App extends Application { modulePrefix = config.modulePrefix; podModulePrefix = config.podModulePrefix; Resolver = Resolver;}loadInitializers(App, config.modulePrefix);
使用 npm run start
執行您的建置流程。
npm run start
開始使用 Tailwind 的實用類別來設定內容樣式。
{{page-title "MyProject"}}<h1 class="text-3xl font-bold underline"> Hello world!</h1>{{outlet}}