Former-commit-id: a29546c3c7db3bd054f5152ee83090ac867c3ef6 [formerly a29546c3c7db3bd054f5152ee83090ac867c3ef6 [formerly a29546c3c7db3bd054f5152ee83090ac867c3ef6 [formerly a29546c3c7db3bd054f5152ee83090ac867c3ef6 [formerly 188d1c6292e0d7f7f03006204bf273ac9a2f9977 [formerly fed4de2ac75aaaef6f53e956eeefa9ffb1f9488e]]]]] Former-commit-id: c92e5a290e02f7bd42c900fe876b5c39a3c65b96 Former-commit-id: 03cc8603d0c0ea41061c93d148ccd27392a734b7 Former-commit-id: 386bcbbd1cda7d937586276d44c6700bd5f2179c [formerly 97afb45274677dd9fd150820ac013841c5c57ffd] Former-commit-id: 690a6d79c1150a087f44f9e04fcfd6ddd0533104 Former-commit-id: 9733ed87d2468567430f9ab12974456ed41d1ba8 Former-commit-id: 565f61c0bde06f9f595cb1ee17474d09f1e64345 Former-commit-id: 316ed7256b3a814848af2651a057b7ae910f3421 Former-commit-id: 6d583d013f77297bf905b8b84bd5808b08db14c7
31 lines
754 B
JavaScript
Executable File
31 lines
754 B
JavaScript
Executable File
const path = require('path')
|
|
const loaderUtils = require('loader-utils')
|
|
|
|
const { blockName, defaultPropName } = require('./config.js')
|
|
|
|
module.exports = function (content /*, map, meta */) {
|
|
const loaderContext = this
|
|
|
|
const {
|
|
rootContext,
|
|
resourcePath
|
|
} = loaderContext
|
|
|
|
const context = rootContext || process.cwd()
|
|
const options = loaderUtils.getOptions(loaderContext) || {}
|
|
const rawShortFilePath = path
|
|
.relative(context, resourcePath)
|
|
.replace(/^(\.\.[\/\\])+/, '')
|
|
|
|
const propName = options.propName || defaultPropName
|
|
|
|
content += `
|
|
<${blockName}>
|
|
export default function (Component) {
|
|
Component.options.${propName} = ${JSON.stringify(rawShortFilePath.replace(/\\/g, '/'))}
|
|
}
|
|
</${blockName}>
|
|
`
|
|
return content
|
|
}
|