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

Extending wp scripts to handle scss #14847

Closed
Show file tree
Hide file tree
Changes from 4 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
44 changes: 38 additions & 6 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const { BundleAnalyzerPlugin } = require( 'webpack-bundle-analyzer' );
const LiveReloadPlugin = require( 'webpack-livereload-plugin' );
const path = require( 'path' );
const postcssPresetEnv = require( 'postcss-preset-env' );

/**
* Internal dependencies
Expand Down Expand Up @@ -66,11 +67,14 @@ const externals = [
const isProduction = process.env.NODE_ENV === 'production';
const mode = isProduction ? 'production' : 'development';

const getBabelLoaderOptions = () => hasBabelConfig() ? {} : {
babelrc: false,
configFile: false,
presets: [ require.resolve( '@wordpress/babel-preset-default' ) ],
};
const getBabelLoaderOptions = () =>
hasBabelConfig() ?
{} :
{
babelrc: false,
configFile: false,
presets: [ require.resolve( '@wordpress/babel-preset-default' ) ],
};

const config = {
mode,
Expand Down Expand Up @@ -102,6 +106,33 @@ const config = {
options: getBabelLoaderOptions(),
},
},
{
test: /\.(sc|sa|c)ss$/,
gziolo marked this conversation as resolved.
Show resolved Hide resolved
use: [
{
loader: require.resolve( 'file-loader' ),
options: {
name: '[name].css',
},
},
{
loader: require.resolve( 'extract-loader' ),
},
{
loader: require.resolve( 'css-loader' ),
},
{
loader: require.resolve( 'sass-loader' ),
},
{
loader: require.resolve( 'postcss-loader' ),
options: {
ident: 'postcss',
plugins: () => [ postcssPresetEnv( /* pluginOptions */ ) ],
},
},
],
},
],
},
plugins: [
Expand All @@ -110,7 +141,8 @@ const config = {
process.env.WP_BUNDLE_ANALYZER && new BundleAnalyzerPlugin(),
// WP_LIVE_RELOAD_PORT global variable changes port on which live reload works
// when running watch mode.
! isProduction && new LiveReloadPlugin( { port: process.env.WP_LIVE_RELOAD_PORT || 35729 } ),
! isProduction &&
new LiveReloadPlugin( { port: process.env.WP_LIVE_RELOAD_PORT || 35729 } ),
].filter( Boolean ),
stats: {
children: false,
Expand Down
7 changes: 7 additions & 0 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@
"chalk": "^2.4.1",
"check-node-version": "^3.1.1",
"cross-spawn": "^5.1.0",
"css-loader": "^2.1.1",
gziolo marked this conversation as resolved.
Show resolved Hide resolved
"eslint": "^5.12.1",
"extract-loader": "^3.1.0",
"file-loader": "^3.0.1",
"jest": "^24.1.0",
"jest-puppeteer": "^4.0.0",
"node-sass": "^4.11.0",
"npm-package-json-lint": "^3.6.0",
"postcss-loader": "^3.0.0",
"postcss-preset-env": "^6.6.0",
"puppeteer": "1.6.1",
"read-pkg-up": "^1.0.1",
"resolve-bin": "^0.4.0",
"sass-loader": "^7.1.0",
"source-map-loader": "^0.2.4",
"stylelint": "^9.10.1",
"stylelint-config-wordpress": "^13.1.0",
Expand Down