汇总插件的顺序重要吗?
Do the order of rollup plugins matter?
尝试使用 rollup 和 Svelte,似乎更改 rollup.config.js
中插件的顺序没有任何区别。
plugins: [
svelte({
preprocess: sveltePreprocess(),
compilerOptions: {
// enable run-time checks when not in production
dev: !production
}
}),
// we'll extract any component CSS out into
// a separate file - better for performance
css({ output: 'bundle.css' }),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ['svelte']
}),
commonjs(),
typescript({
sourceMap: !production,
inlineSources: !production
}),
// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve(),
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload('public'),
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser()
],
总是顺序无关紧要吗?这些插件实际上 运行 是否按顺序排列?
是的,顺序很重要。
插件可以使用多个钩子,如 Rollup 的文档中所述。有些钩子是 运行 并行的,但其他钩子,特别是转换钩子,是 运行 顺序的,并且钩子传递前一个钩子的结果。
例如,如果你把一个转换 JS 的插件放在 Svelte 插件之前,它就不会工作。
尝试使用 rollup 和 Svelte,似乎更改 rollup.config.js
中插件的顺序没有任何区别。
plugins: [
svelte({
preprocess: sveltePreprocess(),
compilerOptions: {
// enable run-time checks when not in production
dev: !production
}
}),
// we'll extract any component CSS out into
// a separate file - better for performance
css({ output: 'bundle.css' }),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ['svelte']
}),
commonjs(),
typescript({
sourceMap: !production,
inlineSources: !production
}),
// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve(),
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload('public'),
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser()
],
总是顺序无关紧要吗?这些插件实际上 运行 是否按顺序排列?
是的,顺序很重要。
插件可以使用多个钩子,如 Rollup 的文档中所述。有些钩子是 运行 并行的,但其他钩子,特别是转换钩子,是 运行 顺序的,并且钩子传递前一个钩子的结果。
例如,如果你把一个转换 JS 的插件放在 Svelte 插件之前,它就不会工作。