[develop] refactor: apply webpack-defaults#542
[develop] refactor: apply webpack-defaults#542michael-ciniawsky wants to merge 1 commit intowebpack:developfrom michael-ciniawsky:defaults
Conversation
|
|
||
| let locals; | ||
|
|
||
| if (meta && meta.locals) { |
There was a problem hiding this comment.
This would be where locals are added if postcss-loader passes them, needs to be replaced with the current implementation or ES2015 Module Export
import css, { className1, className2 } from './file.css' {String}, {Locals}
import css, * as styles from 'file.css'
// or
import './file.css' {String}
import * as styles from './file.css' {Locals}There was a problem hiding this comment.
@michael-ciniawsky I would prefer
import css, { className1, className2 } from './file.css' {String}, {Locals}
But honestly I do not even know 😄
There was a problem hiding this comment.
😅 yeah.. it's a possiblity import * as styles from 'file.css' is the clear favourite 🏅
|
|
||
| Promise.resolve() | ||
| .then(() => { | ||
| if (meta && meta.ast) return processor(ast, map, processOptions); |
There was a problem hiding this comment.
We can pass the PostCSS AST directly now to avoid a second parse of CSS
|
@michael-ciniawsky But what about the new loader? Seems this PR related to current implementation. We have problems with perf and css-modules in current implementation. If i set |
| @@ -0,0 +1,8 @@ | |||
| { | |||
| "file": "alias", | |||
There was a problem hiding this comment.
Please don't use config as json, this does not make it possible to test the js functions and other expressions.
Don't remove tests, we must adapt them, otherwise we will get millions of regressions as in postcss-loader.
There was a problem hiding this comment.
And frankly speaking, this approach to testing is not very convenient, we need to revise it.
There was a problem hiding this comment.
Yep, this needs an update as in postcss-loader
|
/cc @bebraw @d3viant0ne take part |
|
@evilebottnawi I adpated the basic tests and a few are missing as the decision to move directly to |
|
|
|
The |
|
@michael-ciniawsky seems we need good roadmap for |
|
Yep I take a look at this PR later and I think we should just start then, all outstanding things can get there own issue and PR for discussion and we have at least |
|
Given defaults already exists in We have been asked to not do anything major with css-loader while Tobias is working on the new-loader and this definitely qualifies, ping him in slack and get his opinion on defaults as it relates to the existing css-loader. |
| * | ||
| * @return {cb} cb Callback | ||
| */ | ||
| export default function loader (src, map, meta) { |
There was a problem hiding this comment.
I didn't know that loaders support the meta argument. What is it actually? :)
As far as I remember loaders supported a possibility to pass value to the next loader, which would be available as inputValue (https://webpack.github.io/docs/loaders.html#value).
Is meta a more explicit way to do that?
There was a problem hiding this comment.
Yep this should work according to sokra, needs to be tested though :), the fourth argument of the callback can take a meta {Object}
function loader (src, map, meta) {// {String} | {Object} | {Object}
....
.then(({ css, map, messages }) => cb(null, css, map, { messages })
}| let locals; | ||
|
|
||
| if (meta && meta.locals) { | ||
| locals = `exports.locals = ${meta.locals};`; |
There was a problem hiding this comment.
Should meta.locals be a string?
I actually thought that user would pass a plain object here, so it will be convenient to use it :)
There was a problem hiding this comment.
Also, in the future versions the object may contain a prototype chain (css-modules/css-modules#147), so it would be necessary to make a proper serializer here.
There was a problem hiding this comment.
No no, this is more of a placeholder yet :D :D. I was in the process of trying out how to ES2015 modulify this. That's where we need to start afresh and if CSSM tsay in css-loader there will be no meta locals, since this was originally intended to coma from postcss-loader. Any other ideas how we can do it a highly welcome 😛
let locals = []
Object.keys(meta.locals).forEach((key) => {
locals.push(`export const ${key} = ${meta.locals[key]}`)
})
locals = locals.join('\n')There was a problem hiding this comment.
JSON.stringify will be enough for the beginning :)
Actually, css-loader had an option, which camelized key names of the locals, so thats why it was a bit complicated and looks like some ppl still use it.
|
@d3viant0ne The |
|
@sullenor @evilebottnawi Should we just merge this into |
|
I think the right solution will be to make a single postcss plugin, which will contain the necessary set of plugins which implement the But there are some difficulties related to the css modules /cc @TrySound |
I guess |
|
Yeah agree it would be the best to have a standalone plugin
|
|
@michael-ciniawsky - Tobias has a design for the style loader chain which he will be disseminating to all of us soon. In the short term, the |
Refactor
webpack-defaultsFeatures
localsBreaking
options.rootoptions.minimize(CSSNano)options.modulesoptions.camelCaseoptions.importLoadersTODO
url()'s (options.url{Array|Regex})loclasprocessing (camelCaseas default, no option ?)localsas ES2015 ModuleDiscuss
:locla :local()(Global Mode) ? (Recommended)cssnanoor move topostcss-loader?cc @sullenor @TrySound