| 67 | |
| 68 | // common function to get style loaders |
| 69 | const getStyleLoaders = (cssOptions, preProcessor) => { |
| 70 | const loaders = [ |
| 71 | isEnvDevelopment && require.resolve('style-loader'), |
| 72 | isEnvProduction && { |
| 73 | loader: MiniCssExtractPlugin.loader, |
| 74 | options: Object.assign( |
| 75 | {}, |
| 76 | shouldUseRelativeAssetPaths ? { publicPath: '../../' } : undefined |
| 77 | ), |
| 78 | }, |
| 79 | { |
| 80 | loader: require.resolve('css-loader'), |
| 81 | options: cssOptions, |
| 82 | }, |
| 83 | { |
| 84 | // Options for PostCSS as we reference these options twice |
| 85 | // Adds vendor prefixing based on your specified browser support in |
| 86 | // package.json |
| 87 | loader: require.resolve('postcss-loader'), |
| 88 | options: { |
| 89 | // Necessary for external CSS imports to work |
| 90 | // https://github.com/facebook/create-react-app/issues/2677 |
| 91 | ident: 'postcss', |
| 92 | plugins: () => [ |
| 93 | require('postcss-flexbugs-fixes'), |
| 94 | require('postcss-preset-env')({ |
| 95 | autoprefixer: { |
| 96 | flexbox: 'no-2009', |
| 97 | }, |
| 98 | stage: 3, |
| 99 | }), |
| 100 | ], |
| 101 | sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment, |
| 102 | }, |
| 103 | }, |
| 104 | ].filter(Boolean); |
| 105 | if (preProcessor) { |
| 106 | loaders.push({ |
| 107 | loader: require.resolve(preProcessor), |
| 108 | options: { |
| 109 | sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment, |
| 110 | }, |
| 111 | }); |
| 112 | } |
| 113 | return loaders; |
| 114 | }; |
| 115 | |
| 116 | return { |
| 117 | mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development', |