Skip to content

add new feature: make we can extract css #94

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 3 commits into from

Conversation

NE-SmallTown
Copy link

@NE-SmallTown NE-SmallTown commented May 31, 2017

Similar with this pr and this feature

Sorry about that I am not familiar with this repo's test framework.But believe I have did some tests.

And sorry about that I am using windows,so I have to import some extra dependencies like cross-env,mkdirp to make the command work.

If you want to test,first you should npm run build in the root directory and then you should copy the generated dist directory to this demo's node_modules/babel-plugin-react-css-modules/dist to make we can test.And second go to the demo's root directory,then execute npm run build,it will call this plugin to generate result.And you can see whether the result is what I want.

BTW,I create a new css file named table2.css to test whether we can extract more than one css files to just one file.There are 2 test which I have done:

1.Test extract compiled all css to one file(note that in this mode you need to add "removeImport": true in the option because we have extracted our css to somewhere,so if you don't do this,we will can't find the corresponding css module.And in this mode you should not use --copy-files because if you do,the css you copy is still origin css. i.e. it doesn't be processed):

babel config:

{
  "extractCss": {
    "to": "lib/cssDist/myApp.css"
  },
  "removeImport": true,
  "generateScopedName": "[name]___[local]___[hash:base64:2]"
}

result:

Imgur

And you can notice that although we import table.css twice(in AnonymouseStyleResolution.js and RuntimeStyleResolution.js),but the result css file doesn't has duplicate content.That's what we need.

2.Test extract compiled css to their own component path of the src(note that in this mode you need to add the param --copy-files in your script config):

babel config:

{
  "extractCss": {
    "stayInOwnComponent": true
  },
  "generateScopedName": "[name]___[local]___[hash:base64:2]"
}

result:

Imgur

@gajus
Copy link
Owner

gajus commented May 31, 2017

@NE-SmallTown
Copy link
Author

see this comment

@gajus
Copy link
Owner

gajus commented May 31, 2017

Closing for reasons discussed in #51 (comment).

tl;dr; For 3rd party component development, use webpack to build CSS as a separate build step and add a babel plugin to remove the CSS imports.

@gajus gajus closed this May 31, 2017
@NE-SmallTown
Copy link
Author

Ok.I will give it a try though I have tried before.

@NE-SmallTown
Copy link
Author

Sorry,I still think webpack can't do this.If you don't mind,I will fork this repo and publish it to make the module of package.json can work.

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.

2 participants