mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
fix(postcss): default to preset-env and cssnano last (#5215)
This commit is contained in:
parent
37006f6267
commit
adf423a57f
@ -9,12 +9,22 @@ import createResolver from 'postcss-import-resolver'
|
|||||||
import { isPureObject } from '@nuxt/utils'
|
import { isPureObject } from '@nuxt/utils'
|
||||||
|
|
||||||
export const orderPresets = {
|
export const orderPresets = {
|
||||||
cssnanoLast: (names) => {
|
cssnanoLast(names) {
|
||||||
const nanoIndex = names.indexOf('cssnano')
|
const nanoIndex = names.indexOf('cssnano')
|
||||||
if (nanoIndex !== names.length - 1) {
|
if (nanoIndex !== names.length - 1) {
|
||||||
names.push(names.splice(nanoIndex, 1)[0])
|
names.push(names.splice(nanoIndex, 1)[0])
|
||||||
}
|
}
|
||||||
return names
|
return names
|
||||||
|
},
|
||||||
|
presetEnvLast(names) {
|
||||||
|
const nanoIndex = names.indexOf('postcss-preset-env')
|
||||||
|
if (nanoIndex !== names.length - 1) {
|
||||||
|
names.push(names.splice(nanoIndex, 1)[0])
|
||||||
|
}
|
||||||
|
return names
|
||||||
|
},
|
||||||
|
presetEnvAndCssnanoLast(names) {
|
||||||
|
return orderPresets.cssnanoLast(orderPresets.presetEnvLast(names))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +63,7 @@ export default class PostcssConfig {
|
|||||||
'cssnano': dev ? false : { preset: 'default' }
|
'cssnano': dev ? false : { preset: 'default' }
|
||||||
},
|
},
|
||||||
// Array, String or Function
|
// Array, String or Function
|
||||||
order: 'cssnanoLast'
|
order: 'presetEnvAndCssnanoLast'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,15 +90,15 @@ describe('basic dev', () => {
|
|||||||
expect(vueLoader.options).toEqual(vue)
|
expect(vueLoader.options).toEqual(vue)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Config: cssnano is at then end of postcss plugins', () => {
|
test('Config: preset-env and cssnano are at then end of postcss plugins', () => {
|
||||||
const plugins = postcssLoader.options.plugins.map((plugin) => {
|
const plugins = postcssLoader.options.plugins.map((plugin) => {
|
||||||
return plugin.postcssPlugin
|
return plugin.postcssPlugin
|
||||||
})
|
})
|
||||||
expect(plugins).toEqual([
|
expect(plugins).toEqual([
|
||||||
'postcss-import',
|
'postcss-import',
|
||||||
'postcss-url',
|
'postcss-url',
|
||||||
'postcss-preset-env',
|
|
||||||
'nuxt-test',
|
'nuxt-test',
|
||||||
|
'postcss-preset-env',
|
||||||
'cssnano'
|
'cssnano'
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user