|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +const Path = require('path'); |
| 21 | + |
| 22 | +const MiniCssExtractPlugin = require('mini-css-extract-plugin'); |
| 23 | +const { REPO_ROOT } = require('@kbn/dev-utils'); |
| 24 | +const webpack = require('webpack'); |
| 25 | + |
| 26 | +const SharedDeps = require('./index'); |
| 27 | + |
| 28 | +const MOMENT_SRC = require.resolve('moment/min/moment-with-locales.js'); |
| 29 | + |
| 30 | +exports.getWebpackConfig = ({ dev = false } = {}) => ({ |
| 31 | + mode: dev ? 'development' : 'production', |
| 32 | + entry: { |
| 33 | + [SharedDeps.distFilename.replace(/\.js$/, '')]: './entry.js', |
| 34 | + [SharedDeps.darkCssDistFilename.replace(/\.css$/, '')]: [ |
| 35 | + '@elastic/eui/dist/eui_theme_dark.css', |
| 36 | + '@elastic/charts/dist/theme_only_dark.css', |
| 37 | + ], |
| 38 | + [SharedDeps.lightCssDistFilename.replace(/\.css$/, '')]: [ |
| 39 | + '@elastic/eui/dist/eui_theme_light.css', |
| 40 | + '@elastic/charts/dist/theme_only_light.css', |
| 41 | + ], |
| 42 | + }, |
| 43 | + context: __dirname, |
| 44 | + devtool: dev ? '#cheap-source-map' : false, |
| 45 | + output: { |
| 46 | + path: SharedDeps.distDir, |
| 47 | + filename: '[name].js', |
| 48 | + sourceMapFilename: '[file].map', |
| 49 | + publicPath: '__REPLACE_WITH_PUBLIC_PATH__', |
| 50 | + devtoolModuleFilenameTemplate: info => |
| 51 | + `kbn-ui-shared-deps/${Path.relative(REPO_ROOT, info.absoluteResourcePath)}`, |
| 52 | + library: '__kbnSharedDeps__', |
| 53 | + }, |
| 54 | + |
| 55 | + module: { |
| 56 | + noParse: [MOMENT_SRC], |
| 57 | + rules: [ |
| 58 | + { |
| 59 | + test: /\.css$/, |
| 60 | + use: [MiniCssExtractPlugin.loader, 'css-loader'], |
| 61 | + }, |
| 62 | + ], |
| 63 | + }, |
| 64 | + |
| 65 | + resolve: { |
| 66 | + alias: { |
| 67 | + moment: MOMENT_SRC, |
| 68 | + }, |
| 69 | + }, |
| 70 | + |
| 71 | + optimization: { |
| 72 | + noEmitOnErrors: true, |
| 73 | + }, |
| 74 | + |
| 75 | + performance: { |
| 76 | + // NOTE: we are disabling this as those hints |
| 77 | + // are more tailored for the final bundles result |
| 78 | + // and not for the webpack compilations performance itself |
| 79 | + hints: false, |
| 80 | + }, |
| 81 | + |
| 82 | + plugins: [ |
| 83 | + new MiniCssExtractPlugin({ |
| 84 | + filename: '[name].css', |
| 85 | + }), |
| 86 | + new webpack.DefinePlugin({ |
| 87 | + 'process.env.NODE_ENV': dev ? '"development"' : '"production"', |
| 88 | + }), |
| 89 | + ], |
| 90 | +}); |
0 commit comments