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

Updating build steps (CSS) #67

Merged
merged 9 commits into from Feb 26, 2018

Conversation

jandre3000
Copy link
Contributor

@jandre3000 jandre3000 commented Feb 20, 2018

Removing 'css/vendor' folder in favor of adding npm modules and
having them import automatically via postcss-import plugin.

Adding newer version of WikimediaUI Base & normalize.css via npm.

Fixing grunt watch task to ignore files in the 'css/build' folder

Adding npm tasks to call Grunt, for those who don't install Grunt globally.

Removing css/vendor folder in favor of adding NPM modules and
having them import automatically via postcss-import plugin.

Adding newer version of Wikimedia UI Base & normalize.css via NPM.

Fixing grunt watch task to ignore files in the css/build folder

Adding npm tasks to call grunt, for those who don't install grunt globally.
@jandre3000 jandre3000 requested review from prtksxna and Volker-E and removed request for prtksxna February 20, 2018 14:21
@@ -1,7 +1,12 @@
@import 'vendor/wikimedia-ui-base.css';
/* ::: Vendor Imports ::: */
/* loaded from node_modules folders by postCSS-import plugin.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“Load”

package.json Outdated
@@ -32,9 +32,12 @@
"stylelint-config-wikimedia": "0.4.2"
},
"dependencies": {
"fontfaceobserver": "^2.0.9"
"fontfaceobserver": "^2.0.9",
"normalize.css": "^8.0.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're supporting old IE, we should pinpoint to an older version of normalize, which 7.0.0 on a quick look should be fine here. (And also adding a note about it)

package.json Outdated
"fontfaceobserver": "^2.0.9"
"fontfaceobserver": "^2.0.9",
"normalize.css": "^8.0.0",
"wikimedia-ui-base": "^0.10.0"
},
"scripts": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we've got those scripts for CI and npm stated above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shoot I forgot about CI. I will have to add an "npm test" script back in (that runs the default CI on GitHub).

In regards to adding npm run dev and npm run build, this might seem verbose but in my mind it actually makes things easier. I think npm install -> npm run dev -> npm run build -> npm run test is becoming more common across newer projects[1] (although now I think npm run start might be better than npm run dev ).

More importantly though, running grunt through npm means that you don't have to install grunt globally on your system. The grunt commands won't work unless you run npm install -g grunt after you run npm install. Running the gulp commands inside npm ensures that npm install actually installs all the dependencies you need[2]. Also, if you're working on many projects, you can run into issues with having different versions of grunt installed globally. This approach makes sure everyone who works on the project uses the same version of grunt.

1.https://github.com/facebook/create-react-app/blob/next/package.json
2.https://www.joezimjs.com/javascript/no-more-global-npm-packages/

Some asset paths were left unchanged after moving the css file to
`css/build`.

Removing the need for `grunt-contrib-cssmin` since PostCSS can
integrate a minifier.

This means we don't have to output an uncompressed css file in the
`build` folder. Instead we can generate the minified file in one pass,
which also gets rid of the cssmin grunt tasks.

Also outputting a source map for the minified CSS file.
@Volker-E
Copy link
Collaborator

I think the outlined way makes sense here, would love to hear @Ladsgroup's and @prtksxna's opinions as well.

@Ladsgroup
Copy link
Member

I think it's good idea to move towards using npm modules and making things more streamlined.

@Volker-E
Copy link
Collaborator

As stated in personal conversations with both, @j4n-co and @prtksxna the reason for the extra file step of committed wmui-style-guide.css has been an extra debugging insurance against something in PostCSS build step going wrong. PostCSS is mighty, but also sometimes easily misconfigured.
Therefore I'd prefer to stay with a middle step.

@@ -1,16 +1,16 @@
@font-face {
font-family: 'Charter';
src: url( '../fonts/Charter_regular.woff2' ) format( 'woff2' ),
url( '../fonts/Charter_regular.woff' ) format( 'woff' );
src: url( '../../fonts/Charter_regular.woff2' ) format( 'woff2' ),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I just noticed that this was broken on the master branch. Thanks for fixing it...

Minified CSS gets compiles with source maps, unminified does not.
@jandre3000
Copy link
Contributor Author

@Volker-E 8b6f0c7 adds the compiled, unminified CSS file back in. Unfortunately, this does add some complexity to the grunt file. There are now two postcss 'subtasks' postcss:dev and postcss:min. Both take the source files and output dev/minified versions.

This is different than the previous cssmin task, which took the compiled file and minified it.

The reason for this difference is that it's valuable to have source maps with the minified version, and in order to properly create the source map, the source file has to be... the source. If we just minified the compiled version, we would have a source map pointing the compiled 'dev' css instead of the postcss.

I'm not too concerned that this will add a few milliseconds to the build.

Gruntfile.js Outdated
map: {
inline: false, // save all sourcemaps as separate files...
annotation: 'css/build/' // ...to the specified directory
// outputs unminified compiled CSS file into `build` dir
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments preferred to start with uppercase letter

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an eslint rule for that ( https://eslint.org/docs/rules/capitalized-comments ) if you wanted to enforce this.

Gruntfile.js Outdated
@@ -9,6 +9,31 @@ module.exports = function ( grunt ) {
grunt.loadNpmTasks( 'grunt-stylelint' );
grunt.loadNpmTasks( 'grunt-svgmin' );

// Postcss processors without minifier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

”PostCSS“

Gruntfile.js Outdated
@@ -9,6 +9,31 @@ module.exports = function ( grunt ) {
grunt.loadNpmTasks( 'grunt-stylelint' );
grunt.loadNpmTasks( 'grunt-svgmin' );

// Postcss processors without minifier
var postcssProcessorsDev = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

postCssProcessorsDev is the MW way of writing it. Compare for example onResourceLoaderGetLessVars in mobile frontend.

Gruntfile.js Outdated
require( 'postcss-import' )( {
from: "css/wmui-style-guide.dev.css"
} ),
// require( 'postcss-cssnext' )(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why leave this in?

Gruntfile.js Outdated
files: {
'css/build/wmui-style-guide.min.css': 'css/wmui-style-guide.dev.css'
}
// outputs minified compiled CSS file + src maps into `build` dir
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above, instead of “outputs” “Output”, see also https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Documentation_comments
Also, extra whitespace after '+'

Copy link
Collaborator

@Volker-E Volker-E left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments inline

Copy link
Collaborator

@Volker-E Volker-E left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Volker-E Volker-E merged commit 7a8ff8c into wikimedia:master Feb 26, 2018
Ladsgroup pushed a commit that referenced this pull request Oct 9, 2019
- Removing 'css/vendor folder in favor of adding npm modules and
having them import automatically via postcss-import plugin.
- Adding newer version of WikimediaUI Base & normalize.css via npm.
- Fixing 'grunt watch' task to ignore files in the 'css/build' folder
- Adding npm tasks to call Grunt, for those who don't install Grunt globally.
- Downgrading normalize.css to v7 & fixing typo
- Fixing relative paths in CSS URLs & switching minifier to cssnano
- Removing the need for `grunt-contrib-cssmin` since PostCSS can
integrate a minifier.
This means we don't have to output an uncompressed css file in the
`build` folder. Instead we can generate the minified file in one pass,
which also gets rid of the cssmin grunt tasks.
- Also outputting a source map for the minified CSS file.
- Adding seperate grunt tasks for compiling minified and unminifed CSS
  Minified CSS gets compiles with source maps, unminified does not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants