gpt4 book ai didi

webpack - 为什么 Tailwind 中的清除选项不适用于 Webpack

转载 作者:行者123 更新时间:2023-12-05 08:48:01 25 4
gpt4 key购买 nike

我使用 Tailwind 设置了 Webpack,除了清除之外,一切似乎都运行良好。该文件有 4mb,我可以在其中看到所有的顺风工具类。在过去的 30 分钟里,我试图找到解决方案,但没有任何效果。

这是我的 package.json 脚本“构建”和所有依赖项:

{
"name": "MemeGenerator",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --config webpack.prod.js",
"watch": "webpack --watch --config webpack.dev.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/MB9900/MemeGenerator.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/MB9900/MemeGenerator/issues"
},
"homepage": "https://github.com/MB9900/MemeGenerator#readme",
"devDependencies": {
"autoprefixer": "^10.2.5",
"css-loader": "^5.1.3",
"html-webpack-plugin": "^5.3.1",
"postcss": "^8.2.8",
"postcss-cli": "^8.3.1",
"postcss-loader": "^5.2.0",
"style-loader": "^2.0.0",
"tailwindcss": "^2.0.3",
"webpack": "^5.26.0",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2",
"webpack-merge": "^5.7.3"
}
}

这里是 webpack.common

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: './src/js/app.js',
output: {
path: path.resolve(__dirname, 'dist'),
clean: true
},
module: {
rules: [
{
test: /\.css$/i,
include: path.resolve(__dirname, 'src/css'),
use: ['style-loader', 'css-loader', 'postcss-loader']
}
]
}
};

这里是 webpack.prod.js

const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');

module.exports = merge(common, {
mode: 'production',
output: {
filename: '[name].[contenthash].js',
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.[contenthash].html',
template: 'src/html/index.html'
})
],
});

这是postcss.config.js


module.exports = {
plugins: [
require('tailwindcss'),
require('autoprefixer')
],
};

最后:tailwind.config.js

module.exports = {
purge: {
enable: true,
content: [
'./src/**/*.html',
'./src/**/*.js'
]
},
darkMode: false,
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
};

最佳答案

似乎“NODE_ENV”没有设置为“production”。我试图在 tailwind.config.js 中使用“enable: true”修复此问题,但它是 enabled: true。现在它工作正常。

关于webpack - 为什么 Tailwind 中的清除选项不适用于 Webpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66656364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com