Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugin-loader] Use postcss plugins, improved resolving #382

Merged
merged 1 commit into from
Nov 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/@sanity/plugin-loader/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path')
const Module = require('module')
const interopRequire = require('interop-require')
const cssHook = require('css-modules-require-hook')
const postcss = require('@sanity/webpack-integration/v3')
const resolver = require('@sanity/resolver')
const util = require('@sanity/util')
const reduceConfig = util.reduceConfig
Expand Down Expand Up @@ -121,7 +122,20 @@ function registerLoader(options) {
return request
}

return realResolve(request, parent)
if (!options.allowLocalDependencies) {
return realResolve(request, parent)
}

try {
return realResolve(request, parent)
} catch (err) { /* intentional noop */ }

// Attempt local resolve
try {
return realResolve(request, module.parent)
} catch (deepErr) {
return undefined
}
}

// "Most significant"-imports can be directly resolved to their implementation,
Expand All @@ -138,7 +152,9 @@ function registerLoader(options) {

// Register CSS hook
cssHook({
generateScopedName: options.generateScopedName || '[name]__[local]___[hash:base64:5]'
generateScopedName: options.generateScopedName || '[name]__[local]___[hash:base64:5]',
prepend: postcss.getPostcssPlugins({basePath: basePath})
.filter(plugin => plugin.postcssPlugin !== 'postcss-import')
})
}

Expand Down
3 changes: 2 additions & 1 deletion packages/@sanity/plugin-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"dependencies": {
"@sanity/resolver": "^0.120.0",
"@sanity/util": "^0.120.0",
"css-modules-require-hook": "^4.2.2",
"@sanity/webpack-integration": "^0.120.0",
"css-modules-require-hook": "4.1.0",
"interop-require": "^1.0.0"
}
}