您需要按照以下步骤操作:
- 导入:
rollup-plugin-postcss
_rollup.config.js
import postcss from 'rollup-plugin-postcss';
- 将相关部分(您的第 41-56 行
rollup.config.js
)替换为:
svelte({
preprocess: sveltePreprocess({ postcss: true }),
compilerOptions: {
dev: !production,
css: css => { css.write('bundle.css') },
},
...(production && { emitCss: false }),
}),
production
? postcss({ extract: true, minimize: true })
: css({ output: 'bundle.css' }),
- 配置 purgecss
postcss.config.js
:
const purgecss = require('@fullhuman/postcss-purgecss')({
content: ['./**/**/*.html', './**/**/*.svelte'],
whitelistPatterns: [/svelte-/],
defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || []
});
const isProduction = !process.env.ROLLUP_WATCH && !process.env.LIVERELOAD
module.exports = {
plugins: [
...(isProduction ? [purgecss] : [])
]
};