初始化代码
This commit is contained in:
37
uniapp/uni-app/node_modules/postcss-loader/src/Error.js
generated
vendored
Normal file
37
uniapp/uni-app/node_modules/postcss-loader/src/Error.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* **PostCSS Syntax Error**
|
||||
*
|
||||
* Loader wrapper for postcss syntax errors
|
||||
*
|
||||
* @class SyntaxError
|
||||
* @extends Error
|
||||
*
|
||||
* @param {Object} err CssSyntaxError
|
||||
*/
|
||||
class SyntaxError extends Error {
|
||||
constructor (error) {
|
||||
super(error)
|
||||
|
||||
const { line, column, reason } = error
|
||||
|
||||
this.name = 'SyntaxError'
|
||||
|
||||
this.message = `${this.name}\n\n`
|
||||
|
||||
if (typeof line !== 'undefined') {
|
||||
this.message += `(${line}:${column}) `
|
||||
}
|
||||
|
||||
this.message += `${reason}`
|
||||
|
||||
const code = error.showSourceCode()
|
||||
|
||||
if (code) {
|
||||
this.message += `\n\n${code}\n`
|
||||
}
|
||||
|
||||
this.stack = false
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SyntaxError
|
||||
31
uniapp/uni-app/node_modules/postcss-loader/src/Warning.js
generated
vendored
Normal file
31
uniapp/uni-app/node_modules/postcss-loader/src/Warning.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* **PostCSS Plugin Warning**
|
||||
*
|
||||
* Loader wrapper for postcss plugin warnings (`root.messages`)
|
||||
*
|
||||
* @class Warning
|
||||
* @extends Error
|
||||
*
|
||||
* @param {Object} warning PostCSS Warning
|
||||
*/
|
||||
class Warning extends Error {
|
||||
constructor (warning) {
|
||||
super(warning)
|
||||
|
||||
const { text, line, column } = warning
|
||||
|
||||
this.name = 'Warning'
|
||||
|
||||
this.message = `${this.name}\n\n`
|
||||
|
||||
if (typeof line !== 'undefined') {
|
||||
this.message += `(${line}:${column}) `
|
||||
}
|
||||
|
||||
this.message += `${text}`
|
||||
|
||||
this.stack = false
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Warning
|
||||
232
uniapp/uni-app/node_modules/postcss-loader/src/index.js
generated
vendored
Normal file
232
uniapp/uni-app/node_modules/postcss-loader/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
const path = require('path')
|
||||
|
||||
const { getOptions } = require('loader-utils')
|
||||
const validateOptions = require('schema-utils')
|
||||
|
||||
const postcss = require('postcss')
|
||||
const postcssrc = require('postcss-load-config')
|
||||
|
||||
const Warning = require('./Warning.js')
|
||||
const SyntaxError = require('./Error.js')
|
||||
const parseOptions = require('./options.js')
|
||||
|
||||
/**
|
||||
* **PostCSS Loader**
|
||||
*
|
||||
* Loads && processes CSS with [PostCSS](https://github.com/postcss/postcss)
|
||||
*
|
||||
* @method loader
|
||||
*
|
||||
* @param {String} css Source
|
||||
* @param {Object} map Source Map
|
||||
*
|
||||
* @return {cb} cb Result
|
||||
*/
|
||||
function loader (css, map, meta) {
|
||||
const options = Object.assign({}, getOptions(this))
|
||||
|
||||
validateOptions(require('./options.json'), options, 'PostCSS Loader')
|
||||
|
||||
const cb = this.async()
|
||||
const file = this.resourcePath
|
||||
|
||||
const sourceMap = options.sourceMap
|
||||
|
||||
Promise.resolve().then(() => {
|
||||
const length = Object.keys(options)
|
||||
.filter((option) => {
|
||||
switch (option) {
|
||||
// case 'exec':
|
||||
case 'ident':
|
||||
case 'config':
|
||||
case 'sourceMap':
|
||||
return
|
||||
default:
|
||||
return option
|
||||
}
|
||||
})
|
||||
.length
|
||||
|
||||
if (length) {
|
||||
return parseOptions.call(this, options)
|
||||
}
|
||||
|
||||
const rc = {
|
||||
path: path.dirname(file),
|
||||
ctx: {
|
||||
file: {
|
||||
extname: path.extname(file),
|
||||
dirname: path.dirname(file),
|
||||
basename: path.basename(file)
|
||||
},
|
||||
options: {}
|
||||
}
|
||||
}
|
||||
|
||||
if (options.config) {
|
||||
if (options.config.path) {
|
||||
rc.path = path.resolve(options.config.path)
|
||||
}
|
||||
|
||||
if (options.config.ctx) {
|
||||
rc.ctx.options = options.config.ctx
|
||||
}
|
||||
}
|
||||
|
||||
rc.ctx.webpack = this
|
||||
|
||||
return postcssrc(rc.ctx, rc.path)
|
||||
}).then((config) => {
|
||||
if (!config) {
|
||||
config = {}
|
||||
}
|
||||
|
||||
if (config.file) {
|
||||
this.addDependency(config.file)
|
||||
}
|
||||
|
||||
// Disable override `to` option from `postcss.config.js`
|
||||
if (config.options.to) {
|
||||
delete config.options.to
|
||||
}
|
||||
// Disable override `from` option from `postcss.config.js`
|
||||
if (config.options.from) {
|
||||
delete config.options.from
|
||||
}
|
||||
|
||||
let plugins = config.plugins || []
|
||||
|
||||
let options = Object.assign({
|
||||
from: file,
|
||||
map: sourceMap
|
||||
? sourceMap === 'inline'
|
||||
? { inline: true, annotation: false }
|
||||
: { inline: false, annotation: false }
|
||||
: false
|
||||
}, config.options)
|
||||
|
||||
// Loader Exec (Deprecated)
|
||||
// https://webpack.js.org/api/loaders/#deprecated-context-properties
|
||||
if (options.parser === 'postcss-js') {
|
||||
css = this.exec(css, this.resource)
|
||||
}
|
||||
|
||||
if (typeof options.parser === 'string') {
|
||||
options.parser = require(options.parser)
|
||||
}
|
||||
|
||||
if (typeof options.syntax === 'string') {
|
||||
options.syntax = require(options.syntax)
|
||||
}
|
||||
|
||||
if (typeof options.stringifier === 'string') {
|
||||
options.stringifier = require(options.stringifier)
|
||||
}
|
||||
|
||||
// Loader API Exec (Deprecated)
|
||||
// https://webpack.js.org/api/loaders/#deprecated-context-properties
|
||||
if (config.exec) {
|
||||
css = this.exec(css, this.resource)
|
||||
}
|
||||
|
||||
if (sourceMap && typeof map === 'string') {
|
||||
map = JSON.parse(map)
|
||||
}
|
||||
|
||||
if (sourceMap && map) {
|
||||
options.map.prev = map
|
||||
}
|
||||
|
||||
return postcss(plugins)
|
||||
.process(css, options)
|
||||
.then((result) => {
|
||||
let { css, map, root, processor, messages } = result
|
||||
|
||||
result.warnings().forEach((warning) => {
|
||||
this.emitWarning(new Warning(warning))
|
||||
})
|
||||
|
||||
messages.forEach((msg) => {
|
||||
if (msg.type === 'dependency') {
|
||||
this.addDependency(msg.file)
|
||||
}
|
||||
})
|
||||
|
||||
map = map ? map.toJSON() : null
|
||||
|
||||
if (map) {
|
||||
map.file = path.resolve(map.file)
|
||||
map.sources = map.sources.map((src) => path.resolve(src))
|
||||
}
|
||||
|
||||
if (!meta) {
|
||||
meta = {}
|
||||
}
|
||||
|
||||
const ast = {
|
||||
type: 'postcss',
|
||||
version: processor.version,
|
||||
root
|
||||
}
|
||||
|
||||
meta.ast = ast
|
||||
meta.messages = messages
|
||||
|
||||
if (this.loaderIndex === 0) {
|
||||
/**
|
||||
* @memberof loader
|
||||
* @callback cb
|
||||
*
|
||||
* @param {Object} null Error
|
||||
* @param {String} css Result (JS Module)
|
||||
* @param {Object} map Source Map
|
||||
*/
|
||||
cb(null, `module.exports = ${JSON.stringify(css)}`, map)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberof loader
|
||||
* @callback cb
|
||||
*
|
||||
* @param {Object} null Error
|
||||
* @param {String} css Result (Raw Module)
|
||||
* @param {Object} map Source Map
|
||||
*/
|
||||
cb(null, css, map, meta)
|
||||
|
||||
return null
|
||||
})
|
||||
}).catch((err) => {
|
||||
if (err.file) {
|
||||
this.addDependency(err.file)
|
||||
}
|
||||
|
||||
return err.name === 'CssSyntaxError'
|
||||
? cb(new SyntaxError(err))
|
||||
: cb(err)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Andrey Sitnik (@ai) <andrey@sitnik.ru>
|
||||
*
|
||||
* @license MIT
|
||||
* @version 3.0.0
|
||||
*
|
||||
* @module postcss-loader
|
||||
*
|
||||
* @requires path
|
||||
*
|
||||
* @requires loader-utils
|
||||
* @requires schema-utils
|
||||
*
|
||||
* @requires postcss
|
||||
* @requires postcss-load-config
|
||||
*
|
||||
* @requires ./options.js
|
||||
* @requires ./Warning.js
|
||||
* @requires ./SyntaxError.js
|
||||
*/
|
||||
module.exports = loader
|
||||
36
uniapp/uni-app/node_modules/postcss-loader/src/options.js
generated
vendored
Normal file
36
uniapp/uni-app/node_modules/postcss-loader/src/options.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* **PostCSS Options Parser**
|
||||
*
|
||||
* Transforms the loader options into a valid postcss config `{Object}`
|
||||
*
|
||||
* @method parseOptions
|
||||
*
|
||||
* @param {Boolean} exec Execute CSS-in-JS
|
||||
* @param {String|Object} parser PostCSS Parser
|
||||
* @param {String|Object} syntax PostCSS Syntax
|
||||
* @param {String|Object} stringifier PostCSS Stringifier
|
||||
* @param {Array|Object|Function} plugins PostCSS Plugins
|
||||
*
|
||||
* @return {Promise} PostCSS Config
|
||||
*/
|
||||
function parseOptions ({ exec, parser, syntax, stringifier, plugins }) {
|
||||
if (typeof plugins === 'function') {
|
||||
plugins = plugins.call(this, this)
|
||||
}
|
||||
|
||||
if (typeof plugins === 'undefined') {
|
||||
plugins = []
|
||||
} else if (!Array.isArray(plugins)) {
|
||||
plugins = [ plugins ]
|
||||
}
|
||||
|
||||
const options = {}
|
||||
|
||||
options.parser = parser
|
||||
options.syntax = syntax
|
||||
options.stringifier = stringifier
|
||||
|
||||
return Promise.resolve({ options, plugins, exec })
|
||||
}
|
||||
|
||||
module.exports = parseOptions
|
||||
57
uniapp/uni-app/node_modules/postcss-loader/src/options.json
generated
vendored
Normal file
57
uniapp/uni-app/node_modules/postcss-loader/src/options.json
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"config": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string"
|
||||
},
|
||||
"ctx": {
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"properties": {
|
||||
"ctx": "should be {Object} (https://github.com/postcss/postcss-loader#context-ctx)",
|
||||
"path": "should be {String} (https://github.com/postcss/postcss-loader#path)"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"exec": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"parser": {
|
||||
"type": [ "string", "object" ]
|
||||
},
|
||||
"syntax": {
|
||||
"type": [ "string", "object" ]
|
||||
},
|
||||
"stringifier": {
|
||||
"type": [ "string", "object" ]
|
||||
},
|
||||
"plugins": {
|
||||
"anyOf": [
|
||||
{ "type": "array" },
|
||||
{ "type": "object" },
|
||||
{ "instanceof": "Function" }
|
||||
]
|
||||
},
|
||||
"sourceMap": {
|
||||
"type": [ "string", "boolean" ]
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"properties": {
|
||||
"exec": "should be {Boolean} (https://github.com/postcss/postcss-loader#exec)",
|
||||
"config": "should be {Object} (https://github.com/postcss/postcss-loader#config)",
|
||||
"parser": "should be {String|Object} (https://github.com/postcss/postcss-loader#parser)",
|
||||
"syntax": "should be {String|Object} (https://github.com/postcss/postcss-loader#syntax)",
|
||||
"stringifier": "should be {String|Object} (https://github.com/postcss/postcss-loader#stringifier)",
|
||||
"plugins": "should be {Array|Object|Function} (https://github.com/postcss/postcss-loader#plugins)",
|
||||
"sourceMap": "should be {String|Boolean} (https://github.com/postcss/postcss-loader#sourcemap)"
|
||||
}
|
||||
},
|
||||
"additionalProperties": true
|
||||
}
|
||||
Reference in New Issue
Block a user