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

Improve npm run watch with flags #478

Merged
merged 2 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions .dev/config/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module.exports = merge( common, {
reload: false,
}
),
new RtlCssPlugin( { filename: 'css/[name]-rtl.css' } ),
new OptimizeCssAssetsPlugin( {
assetNameRegExp: /\.*\.css$/g,
cssProcessor: require( 'cssnano' ),
Expand All @@ -37,16 +36,39 @@ module.exports = merge( common, {
],
} );

// Minify both the standard .css file and the -rtl.css files when running `npm run watch`
if ( 'development' === process.env.NODE_ENV ) {
module.exports.plugins.push(
new MiniCssExtractPlugin( {
filename: 'css/[name].min.css',
chunkFilename: '[id].css',
} ),
new MiniCssExtractPlugin( {
filename: 'css/[name]-rtl.min.css',
chunkFilename: '[id].css',
} ),
);

let flags = [];

if ( undefined !== process.argv[5] ) {

flags = process.argv[5].replace( '--', '' ).split( ',' );

}

// Generate the RTL files when running `npm run start` and a --rtl flag is set
if ( flags.includes( 'rtl' ) ) {
module.exports.plugins.push(
new RtlCssPlugin( { filename: 'css/[name]-rtl.css' } ),
);

if ( flags.includes( 'min' ) ) {
module.exports.plugins.push(
new MiniCssExtractPlugin( {
filename: 'css/[name]-rtl.min.css',
chunkFilename: '[id].css',
} ),
);
}
}

// Minify both the standard .css file and the -rtl.css files when running `npm run start` and a --min flag is set
if ( flags.includes( 'min' ) ) {
module.exports.plugins.push(
new MiniCssExtractPlugin( {
filename: 'css/[name].min.css',
chunkFilename: '[id].css',
} ),
);
}
}
155 changes: 146 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
"[![WordPress <%= pkg.engines.wordpress %>](https://img.shields.io/badge/wordpress-<% print(encodeURI(pkg.engines.wordpress)) %>-blue.svg)](https://wordpress.org/download/release-archive/)"
],
"scripts": {
"start": "composer install && npm install && npm run build",
"setup": "composer install && npm install && npm run build",
"start": "NODE_ENV=development webpack --watch --config .dev/config/webpack.dev.js",
"build": "NODE_ENV=production webpack --config .dev/config/webpack.prod.js",
"postbuild": "mkdir temp && cp -a dist/* temp && NODE_ENV=development webpack --config .dev/config/webpack.dev.js && cp -a temp/* dist && rm -rf temp && .dev/deploy-scripts/tweak-css-files.sh && npm run makepot",
"dev": "NODE_ENV=development webpack --config .dev/config/webpack.dev.js",
"postbuild": "rm -rf temp && mkdir temp && cp -a dist/* temp && NODE_ENV=development webpack --config .dev/config/webpack.dev.js && cp -a temp/* dist && rm -rf temp && .dev/deploy-scripts/tweak-css-files.sh && npm run makepot",
"postdev": "mkdir temp && cp -a dist/* temp && NODE_ENV=production webpack --config .dev/config/webpack.prod.js && cp -a temp/* dist && rm -rf temp && .dev/deploy-scripts/tweak-css-files.sh",
"watch": "NODE_ENV=development webpack --watch --config .dev/config/webpack.dev.js",
"package": "rm -rf build && mkdir -p build/go && npm run build && rsync -av --exclude-from .distignore --delete . build/go && cd build && zip -r go.zip ./go",
"version": "grunt version && git add -A .",
"postversion": "git push && git push --tags",
Expand Down