在 postcss 和汇总中创建单独的 CSS 文件
Create separate CSS files in postcss & rollup
我希望我在 JS 中导入的每个 css
文件都为我的构建创建一个新的 css 文件。例如:
import "./app.css";
import "./admin.css";
将创建 dist/app.css
和 dist/admin.css
。我正在使用汇总,这是我的配置文件:
import commonjs from "@rollup/plugin-commonjs";
import postcss from "rollup-plugin-postcss";
import resolve from "@rollup/plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import postcssImport from "postcss-import";
import postcssNested from "postcss-nested";
import autoprefixer from "autoprefixer";
const dev = process.env.WP_ENV === "development";
export default {
input: "src/main.js",
output: {
sourcemap: dev,
format: "iife",
name: "main",
file: "dist/main.bundle.js",
},
plugins: [
resolve({
browser: true,
}),
postcss({
plugins: [postcssImport(), postcssNested(), autoprefixer()],
extract: true,
sourceMap: "inline",
minimize: !dev,
}),
commonjs(),
!dev && terser(),
],
watch: {
clearScreen: false,
},
};
没有记载,但是可以根据their source code、exclude
使用include
、exclude
。
此处为两个 css 文件的示例:
import { resolve } from "path"
plugins: [
postcss({
include: "**/admin.css",
extract: resolve('dist/admin.css')
}),
postcss({
include: "**/app.css",
extract: resolve('dist/app.css')
})
]
如果您想排除一个文件:
plugins: [
postcss({
exclude: "**/bootstrap.css",
extract: resolve('dist/app.css')
}),
postcss({
include: "**/bootstrap.css",
extract: resolve('dist/bootstrap.css')
})
]
我希望我在 JS 中导入的每个 css
文件都为我的构建创建一个新的 css 文件。例如:
import "./app.css";
import "./admin.css";
将创建 dist/app.css
和 dist/admin.css
。我正在使用汇总,这是我的配置文件:
import commonjs from "@rollup/plugin-commonjs";
import postcss from "rollup-plugin-postcss";
import resolve from "@rollup/plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import postcssImport from "postcss-import";
import postcssNested from "postcss-nested";
import autoprefixer from "autoprefixer";
const dev = process.env.WP_ENV === "development";
export default {
input: "src/main.js",
output: {
sourcemap: dev,
format: "iife",
name: "main",
file: "dist/main.bundle.js",
},
plugins: [
resolve({
browser: true,
}),
postcss({
plugins: [postcssImport(), postcssNested(), autoprefixer()],
extract: true,
sourceMap: "inline",
minimize: !dev,
}),
commonjs(),
!dev && terser(),
],
watch: {
clearScreen: false,
},
};
没有记载,但是可以根据their source code、exclude
使用include
、exclude
。
此处为两个 css 文件的示例:
import { resolve } from "path"
plugins: [
postcss({
include: "**/admin.css",
extract: resolve('dist/admin.css')
}),
postcss({
include: "**/app.css",
extract: resolve('dist/app.css')
})
]
如果您想排除一个文件:
plugins: [
postcss({
exclude: "**/bootstrap.css",
extract: resolve('dist/app.css')
}),
postcss({
include: "**/bootstrap.css",
extract: resolve('dist/bootstrap.css')
})
]