simple-sales-tax
Last commit date
assets
5 days ago
build
11 months ago
includes
5 days ago
languages
5 days ago
changelog.txt
5 days ago
readme.txt
5 days ago
simple-sales-tax.php
5 days ago
uninstall.php
3 years ago
webpack.config.js
5 months ago
webpack.config.js
119 lines
| 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 | 'tax-exemption-block': path.resolve( |
| 15 | process.cwd(), |
| 16 | 'assets/js/blocks/tax-exemption/index.js', |
| 17 | ), |
| 18 | 'tax-exemption-block-frontend': |
| 19 | path.resolve( |
| 20 | process.cwd(), |
| 21 | 'assets/js/blocks/tax-exemption/frontend.js', |
| 22 | ), |
| 23 | }, |
| 24 | module: { |
| 25 | ...defaultConfig.module, |
| 26 | rules: [ |
| 27 | ...defaultRules, |
| 28 | { |
| 29 | test: /\.(sc|sa)ss$/, |
| 30 | exclude: /node_modules/, |
| 31 | use: [ |
| 32 | MiniCssExtractPlugin.loader, |
| 33 | { loader: 'css-loader', options: { importLoaders: 1 } }, |
| 34 | { |
| 35 | loader: 'sass-loader', |
| 36 | options: { |
| 37 | sassOptions: { |
| 38 | includePaths: [ |
| 39 | path.resolve( __dirname, 'includes/vendor/woocommerce/woocommerce/plugins/woocommerce-blocks/assets/css/abstracts' ), |
| 40 | path.resolve( __dirname ) |
| 41 | ], |
| 42 | loadPaths: [ |
| 43 | path.resolve( __dirname, 'includes/vendor/woocommerce/woocommerce/plugins/woocommerce-blocks/assets/css/abstracts' ), |
| 44 | path.resolve( __dirname ) |
| 45 | ], |
| 46 | }, |
| 47 | additionalData: ( content, loaderContext ) => { |
| 48 | const { resourcePath, rootContext } = |
| 49 | loaderContext; |
| 50 | const relativePath = path.relative( |
| 51 | rootContext, |
| 52 | resourcePath |
| 53 | ); |
| 54 | |
| 55 | const abstractsPath = path.resolve( |
| 56 | __dirname, |
| 57 | 'includes/vendor/woocommerce/woocommerce/plugins/woocommerce-blocks/assets/css/abstracts' |
| 58 | ).replace( /\\/g, '/' ); |
| 59 | |
| 60 | if ( |
| 61 | relativePath.startsWith( |
| 62 | 'assets/css/abstracts/' |
| 63 | ) || |
| 64 | relativePath.startsWith( |
| 65 | 'assets\\css\\abstracts\\' |
| 66 | ) || |
| 67 | resourcePath.includes( 'assets/css/abstracts/' ) || |
| 68 | resourcePath.includes( 'assets\\css\\abstracts\\' ) |
| 69 | ) { |
| 70 | return content; |
| 71 | } |
| 72 | |
| 73 | return ( |
| 74 | `@use "sass:math";` + |
| 75 | `@use "sass:string";` + |
| 76 | `@use "sass:color";` + |
| 77 | `@use "sass:map";` + |
| 78 | `@import "${ abstractsPath }/_colors.scss";` + |
| 79 | `@import "${ abstractsPath }/_variables.scss";` + |
| 80 | `@import "${ abstractsPath }/_breakpoints.scss";` + |
| 81 | `@import "${ abstractsPath }/_mixins.scss";` + |
| 82 | content |
| 83 | ); |
| 84 | }, |
| 85 | }, |
| 86 | }, |
| 87 | ], |
| 88 | }, |
| 89 | ], |
| 90 | }, |
| 91 | plugins: [ |
| 92 | ...defaultConfig.plugins.filter( |
| 93 | (plugin) => |
| 94 | plugin.constructor.name !== 'DependencyExtractionWebpackPlugin' |
| 95 | ), |
| 96 | new WooCommerceDependencyExtractionWebpackPlugin(), |
| 97 | new MiniCssExtractPlugin({ |
| 98 | filename: `[name].css`, |
| 99 | }), |
| 100 | ], |
| 101 | resolve: { |
| 102 | alias: { |
| 103 | '@woocommerce/base-components': path.resolve( |
| 104 | process.cwd(), |
| 105 | 'includes/vendor/woocommerce/woocommerce/plugins/woocommerce-blocks/assets/js/base/components', |
| 106 | ), |
| 107 | '@woocommerce/types': path.resolve( |
| 108 | process.cwd(), |
| 109 | 'includes/vendor/woocommerce/woocommerce/plugins/woocommerce-blocks/assets/js/types', |
| 110 | ), |
| 111 | '@woocommerce/block-settings': path.resolve( |
| 112 | process.cwd(), |
| 113 | 'includes/vendor/woocommerce/woocommerce/plugins/woocommerce-blocks/assets/js/settings/blocks', |
| 114 | ), |
| 115 | }, |
| 116 | extensions: [ '.js', '.jsx', '.ts', '.tsx' ], |
| 117 | }, |
| 118 | }; |
| 119 |