mirror of
git://develop.git.wordpress.org/
synced 2025-02-06 23:50:43 +01:00
99702c84eb
Props aristath, adamsilverstein, SergeyBiryukov, gziolo. Fixes #56388. git-svn-id: https://develop.svn.wordpress.org/trunk@55193 602fd350-edb4-49c9-b593-d223f7449a82
86 lines
1.7 KiB
JavaScript
86 lines
1.7 KiB
JavaScript
/**
|
|
* External dependencies
|
|
*/
|
|
const TerserPlugin = require( 'terser-webpack-plugin' );
|
|
const postcss = require( 'postcss' );
|
|
const { join } = require( 'path' );
|
|
|
|
const baseDir = join( __dirname, '../../' );
|
|
|
|
const baseConfig = ( env ) => {
|
|
const mode = env.environment;
|
|
|
|
const config = {
|
|
target: 'browserslist',
|
|
mode,
|
|
optimization: {
|
|
moduleIds: mode === 'production' ? 'deterministic' : 'named',
|
|
minimizer: [
|
|
new TerserPlugin( {
|
|
extractComments: false,
|
|
} ),
|
|
]
|
|
},
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.js$/,
|
|
use: [ 'source-map-loader' ],
|
|
enforce: 'pre',
|
|
},
|
|
],
|
|
},
|
|
resolve: {
|
|
modules: [
|
|
baseDir,
|
|
'node_modules',
|
|
],
|
|
alias: {
|
|
'lodash-es': 'lodash',
|
|
},
|
|
},
|
|
stats: 'errors-only',
|
|
watch: env.watch,
|
|
};
|
|
|
|
if ( mode === 'development' && env.buildTarget === 'build/' ) {
|
|
config.mode = 'production';
|
|
config.optimization = {
|
|
minimize: false,
|
|
moduleIds: 'deterministic',
|
|
};
|
|
} else if ( mode !== 'production' ) {
|
|
config.devtool = process.env.SOURCEMAP || 'source-map';
|
|
}
|
|
|
|
return config;
|
|
};
|
|
|
|
const stylesTransform = ( mode ) => ( content ) => {
|
|
return postcss( [
|
|
require( 'cssnano' )( {
|
|
preset: mode === 'production' ? 'default' : [
|
|
'default',
|
|
{
|
|
discardComments: {
|
|
removeAll: ! content.includes( 'Copyright' ) && ! content.includes( 'License' ),
|
|
},
|
|
normalizeWhitespace: false,
|
|
},
|
|
],
|
|
} ),
|
|
] )
|
|
.process( content, { from: 'src/app.css', to: 'dest/app.css' } )
|
|
.then( ( result ) => result.css );
|
|
};
|
|
|
|
const normalizeJoin = ( ...paths ) => join( ...paths ).replace( /\\/g, '/' );
|
|
|
|
|
|
module.exports = {
|
|
baseDir,
|
|
baseConfig,
|
|
normalizeJoin,
|
|
stylesTransform,
|
|
};
|