Unverified Commit cf163742 authored by Sukka's avatar Sukka Committed by GitHub

feat(cssnano-simple): merge into next repo (#46380)

parent e91de8e0
......@@ -211,7 +211,7 @@
"cross-spawn": "7.0.3",
"crypto-browserify": "3.12.0",
"css.escape": "1.5.1",
"cssnano-simple": "3.0.1",
"cssnano-preset-default": "5.2.14",
"data-uri-to-buffer": "3.0.1",
"debug": "4.1.1",
"devalue": "2.0.1",
......
// Originated from https://github.com/Timer/cssnano-preset-simple/blob/master/src/index.js
/**
* We will not try to override "postcss-svgo" here. Instead we will alias "postcss-svgo" to a stub
* plugin (located at "next/dist/compiled/postcss-plugin-stub-for-cssnano-simple") during pre-compilation
*/
module.exports = function (opts = {}) {
const options = Object.assign(
{},
{ cssDeclarationSorter: { exclude: true }, calc: { exclude: true } },
opts
)
// eslint-disable-next-line import/no-extraneous-dependencies
return require('cssnano-preset-default')(options)
}
// Originated from https://github.com/Timer/cssnano-simple/blob/master/src/index.js
/**
* This file is the actual "cssnano-simple" implementation, which will eventually be used
* by "next/src/build/cssnano-simple"
*/
const createSimplePreset = require('./cssnano-preset-simple')
module.exports = (opts = {}, postcss = require('postcss')) => {
const excludeAll = Boolean(opts && opts.excludeAll)
const userOpts = Object.assign({}, opts)
if (excludeAll) {
for (const userOption in userOpts) {
if (!userOpts.hasOwnProperty(userOption)) continue
const val = userOpts[userOption]
if (!Boolean(val)) {
continue
}
if (Object.prototype.toString.call(val) === '[object Object]') {
userOpts[userOption] = Object.assign({}, { exclude: false }, val)
}
}
}
const options = Object.assign(
{},
excludeAll ? { rawCache: true } : undefined,
userOpts
)
const plugins = []
createSimplePreset(options).plugins.forEach((plugin) => {
if (Array.isArray(plugin)) {
let [processor, pluginOpts] = plugin
processor = processor.default || processor
const isEnabled =
// No options:
(!excludeAll && typeof pluginOpts === 'undefined') ||
// Short-hand enabled:
(typeof pluginOpts === 'boolean' && pluginOpts) ||
// Include all plugins:
(!excludeAll &&
pluginOpts &&
typeof pluginOpts === 'object' &&
!pluginOpts.exclude) ||
// Exclude all plugins:
(excludeAll &&
pluginOpts &&
typeof pluginOpts === 'object' &&
pluginOpts.exclude === false)
if (isEnabled) {
plugins.push(processor(pluginOpts))
}
} else {
plugins.push(plugin)
}
})
return postcss(plugins)
}
module.exports.postcss = true
// Originated from https://github.com/Timer/cssnano-preset-simple/blob/master/postcss-plugin-stub/index.js
/**
* This file creates a stub postcss plugin
*
* It will be pre-compiled into "src/compiled/postcss-plugin-stub-for-cssnano-simple",
* which "postcss-svgo" will be aliased to when creating "cssnano-preset-simple"
*/
function pluginCreator() {
return {
postcssPlugin: 'postcss-plugin-stub',
prepare() {
return {}
},
}
}
pluginCreator.postcss = true
Object.defineProperty(exports, '__esModule', {
value: true,
})
module.exports = pluginCreator
module.exports.default = pluginCreator
{"name":"cssnano-simple","main":"index.js","author":"Joe Haddad <timer150@gmail.com>","license":"MIT"}
(()=>{var e={233:(e,r)=>{function pluginCreator(){return{postcssPlugin:"postcss-plugin-stub",prepare(){return{}}}}pluginCreator.postcss=true;Object.defineProperty(r,"__esModule",{value:true});e.exports=pluginCreator;e.exports["default"]=pluginCreator}};var r={};function __nccwpck_require__(t){var _=r[t];if(_!==undefined){return _.exports}var u=r[t]={exports:{}};var p=true;try{e[t](u,u.exports,__nccwpck_require__);p=false}finally{if(p)delete r[t]}return u.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(233);module.exports=t})();
\ No newline at end of file
......@@ -61,7 +61,6 @@ const externals = {
postcss: 'postcss',
// Ensure latest version is used
'postcss-safe-parser': 'next/dist/compiled/postcss-safe-parser',
'cssnano-simple': 'next/dist/build/cssnano-simple',
// sass-loader
// (also responsible for these dependencies in package.json)
......@@ -688,15 +687,6 @@ export async function ncc_napirs_triples(task, opts) {
.target('src/compiled/@napi-rs/triples')
}
// eslint-disable-next-line camelcase
externals['cssnano-simple'] = 'next/dist/compiled/cssnano-simple'
export async function ncc_cssnano_simple(task, opts) {
await task
.source(relative(__dirname, require.resolve('cssnano-simple')))
.ncc({ packageName: 'cssnano-simple', externals })
.target('src/compiled/cssnano-simple')
}
// eslint-disable-next-line camelcase
externals['p-limit'] = 'next/dist/compiled/p-limit'
export async function ncc_p_limit(task, opts) {
......@@ -1106,6 +1096,18 @@ export async function ncc_segment_ajv_human_errors(task, opts) {
.target('src/compiled/@segment/ajv-human-errors')
}
externals['postcss-plugin-stub-for-cssnano-simple'] =
'next/dist/compiled/postcss-plugin-stub-for-cssnano-simple'
// eslint-disable-next-line camelcase
export async function ncc_postcss_plugin_stub_for_cssnano_simple(task, opts) {
await task
.source('src/bundles/postcss-plugin-stub/index.js')
.ncc({
externals,
})
.target('src/compiled/postcss-plugin-stub-for-cssnano-simple')
}
const babelCorePackages = {
'code-frame': 'next/dist/compiled/babel/code-frame',
'@babel/generator': 'next/dist/compiled/babel/generator',
......@@ -1176,6 +1178,22 @@ export async function ncc_babel_bundle_packages(task, opts) {
await task.source('src/bundles/babel/packages/*').target('src/compiled/babel')
}
externals['cssnano-simple'] = 'next/dist/compiled/cssnano-simple'
// eslint-disable-next-line camelcase
export async function ncc_cssnano_simple_bundle(task, opts) {
const bundleExternals = {
...externals,
'postcss-svgo': 'next/dist/compiled/postcss-plugin-stub-for-cssnano-simple',
}
await task
.source('src/bundles/cssnano-simple/index.js')
.ncc({
externals: bundleExternals,
})
.target('src/compiled/cssnano-simple')
}
// eslint-disable-next-line camelcase
externals['bytes'] = 'next/dist/compiled/bytes'
export async function ncc_bytes(task, opts) {
......@@ -2035,7 +2053,6 @@ export async function ncc(task, opts) {
'ncc_napirs_triples',
'ncc_p_limit',
'ncc_raw_body',
'ncc_cssnano_simple',
'ncc_image_size',
'ncc_get_orientation',
'ncc_hapi_accept',
......@@ -2053,6 +2070,7 @@ export async function ncc(task, opts) {
'ncc_async_retry',
'ncc_async_sema',
'ncc_segment_ajv_human_errors',
'ncc_postcss_plugin_stub_for_cssnano_simple',
'ncc_assert',
'ncc_browser_zlib',
'ncc_buffer',
......@@ -2147,6 +2165,7 @@ export async function ncc(task, opts) {
await task.serial(
[
'ncc_browserslist',
'ncc_cssnano_simple_bundle',
'copy_regenerator_runtime',
'copy_babel_runtime',
'copy_constants_browserify',
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment