| 1 |
const path = require( 'path' ); |
| 2 |
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); |
| 3 |
const WooCommerceDependencyExtractionWebpackPlugin = require( '@woocommerce/dependency-extraction-webpack-plugin' ); |
| 4 |
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' ); |
| 5 |
|
| 6 |
// Remove SASS rule from the default config so we can define our own. |
| 7 |
const defaultRules = defaultConfig.module.rules.filter( ( rule ) => { |
| 8 |
return String( rule.test ) !== String( /\.(sc|sa)ss$/ ); |
| 9 |
} ); |
| 10 |
|
| 11 |
module.exports = { |
| 12 |
...defaultConfig, |
| 13 |
entry: { |
| 14 |
index: path.resolve( |
| 15 |
process.cwd(), |
| 16 |
'inc', |
| 17 |
'modules', |
| 18 |
'checkout', |
| 19 |
'blocks', |
| 20 |
'order-date', |
| 21 |
'src', |
| 22 |
'js', |
| 23 |
'index.js' |
| 24 |
), |
| 25 |
'checkout-order-date-block': path.resolve( |
| 26 |
process.cwd(), |
| 27 |
'inc', |
| 28 |
'modules', |
| 29 |
'checkout', |
| 30 |
'blocks', |
| 31 |
'order-date', |
| 32 |
'src', |
| 33 |
'js', |
| 34 |
'block.js' |
| 35 |
), |
| 36 |
'checkout-order-date-block-frontend': path.resolve( |
| 37 |
process.cwd(), |
| 38 |
'inc', |
| 39 |
'modules', |
| 40 |
'checkout', |
| 41 |
'blocks', |
| 42 |
'order-date', |
| 43 |
'src', |
| 44 |
'js', |
| 45 |
'frontend.js' |
| 46 |
), |
| 47 |
}, |
| 48 |
output: { |
| 49 |
...defaultConfig.output, |
| 50 |
path: path.resolve( |
| 51 |
process.cwd(), |
| 52 |
'inc', |
| 53 |
'modules', |
| 54 |
'checkout', |
| 55 |
'blocks', |
| 56 |
'order-date', |
| 57 |
'build' |
| 58 |
), |
| 59 |
}, |
| 60 |
module: { |
| 61 |
...defaultConfig.module, |
| 62 |
rules: [ |
| 63 |
...defaultRules, |
| 64 |
{ |
| 65 |
test: /\.(sc|sa)ss$/, |
| 66 |
exclude: /node_modules/, |
| 67 |
use: [ |
| 68 |
MiniCssExtractPlugin.loader, |
| 69 |
{ loader: 'css-loader', options: { importLoaders: 1 } }, |
| 70 |
{ |
| 71 |
loader: 'sass-loader', |
| 72 |
options: { |
| 73 |
sassOptions: { |
| 74 |
includePaths: [ 'src/css' ], |
| 75 |
}, |
| 76 |
}, |
| 77 |
}, |
| 78 |
], |
| 79 |
}, |
| 80 |
], |
| 81 |
}, |
| 82 |
plugins: [ |
| 83 |
...defaultConfig.plugins.filter( |
| 84 |
( plugin ) => |
| 85 |
plugin.constructor.name !== 'DependencyExtractionWebpackPlugin' |
| 86 |
), |
| 87 |
new WooCommerceDependencyExtractionWebpackPlugin(), |
| 88 |
new MiniCssExtractPlugin( { |
| 89 |
filename: `[name].css`, |
| 90 |
} ), |
| 91 |
], |
| 92 |
}; |
| 93 |
|