Skip to content

You can now set custom config path. #143

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

Closed
wants to merge 1 commit into from
Closed

You can now set custom config path. #143

wants to merge 1 commit into from

Conversation

sainthkh
Copy link
Contributor

@sainthkh sainthkh commented Dec 2, 2016

I personally organize all of my build settings to "build" folder. However, postcss-loader only accepts configuration files in its ancestor folders.

So, I changed the code to accept the custom configuration path by
'postcss?config=./the/path/to/your/config/file/from/the/root',

I hope you like it.

@ai
Copy link
Contributor

ai commented Dec 2, 2016

Thanks for PR. Let’s discuss one thing.

Main idea behind common PostCSS config is to share same config between different tools: webpack-loader, IDE, etc. With config path other tools will not find config and will work in different way.

Does babel CLI has option for config? Where you put .babelrc?

@sainthkh
Copy link
Contributor Author

sainthkh commented Dec 3, 2016

As for your question, it seems that you cannot change your .babelrc path.

Actually, I don't use .babelrc file and I included the babel options in my webpack.config.js. In there, there are css-loader for CSS Modules and postcss-loader for those CSS files. The loader setting is like below.

loaders: [{  
	test: path.join(__dirname, '..', 'app'),  
	loader: ['babel-loader'],  
	query: {
		cacheDirectory: './temp/babel_cache',
		presets: ['react', 'es2015']
	}
}, {
	test: /\.css$/,
	loaders: [
		'style?sourceMap',
		'css?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]',
		'postcss?config=./build/postcss.config.js',
	]
}]

And below is my project folder.

+app
- Various Components and code
+build
-webpack.config.js
-pocstcss.config.js
+static
-various static assets
index.js
package.json

There are some people like me who love organizing config files in one place. I think it's not a harmful option.

As for webpack-dev-server, it has --config option, too. So, it works perfect for the people like me.

p.s.
I checked the travis CI and it seems that I ignored the coding convention. If you decide to accept this PR, I will change that code to meet the convention.

@ai
Copy link
Contributor

ai commented Dec 3, 2016

I like clean project tree too. But I think right now root is a common place for config 😆.

Because I love global config idea. What do you think about this solution. We will add this option, but still not as part of public API?

It will not be in docs to not blocking global config promotion. OK?

@sainthkh
Copy link
Contributor Author

sainthkh commented Dec 3, 2016

Good.

I agree that my personal preference(separate folder for config) is a bit minor. So, I think that your solution is the best for everyone.

Then, I will send you another PR that meets code convention.

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Dec 3, 2016

@sainthkh The behaviour you want to achieve is having all config files in a separate e.g ./config folder? Because postcss.config.js should be loaded relative to the current file processed by postcss-loader e.g

|–src
|   |–styles
|       |–index.css
|       |–postcss.config.js
|   |–scripts
|       |–index.js
|       |–.babelrc
|   |–components
|       |–index.html
|       |–posthtml.config.js
|–webpack.config.js / gulpfile.js / gruntfile.js / postcss -i ... -o result.css (CLI)
|–package.json

If you want to have it all in one place and don't need a function as config => package.json

package.json

{
  "name": "",
   "version": "",
   "scripts": "",
   "dependencies": {}
   "postcss": { parser: "",  plugins: {}}
   "babel":  { env: {}, presets: [] }
    ...
}

@sainthkh
Copy link
Contributor Author

sainthkh commented Dec 3, 2016

@michael-ciniawsky Yes, that's possible. However, PostCSS has a lot of configuration. In json file, you cannot handle them.

So, if you want to move postcss.config.js to ./config and handle the configuration, the code change is necessary.

@michael-ciniawsky
Copy link
Member

So, if you want to move postcss.config.js to ./config and handle the configuration, the code change is necessary.

@sainthkh Yep, I understand, was not meant to be against it, asked to clearify usecase :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants