Skip to content

Commit

Permalink
[plugin-loader] Use postcss plugins, improved resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Nov 26, 2017
1 parent 137bcbc commit 494e6bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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"
}
}

0 comments on commit 494e6bf

Please sign in to comment.