File size: 2,461 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
const path = require('path');
const glob = require('glob');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const outputPath = __dirname;
const examples = glob.sync(
path.join('examples', '@(default-theme|e-commerce|media|tourism)'),
{
cwd: path.join(__dirname, '..'),
}
);
module.exports = {
mode: 'production',
entry: examples.reduce(
(acc, example) => ({
...acc,
[example]: path.join(__dirname, '..', example, 'index.js'),
}),
{}
),
output: {
filename: '[name]/index.[chunkhash].js',
publicPath: '/',
path: outputPath,
},
resolve: {
alias: {
'react-instantsearch-dom': path.resolve(
__dirname,
'../packages/react-instantsearch-dom'
),
'react-instantsearch-dom-maps': path.resolve(
__dirname,
'../packages/react-instantsearch-dom-maps'
),
},
},
module: {
rules: [
{
test: /\.(js|ts|tsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
rootMode: 'upward',
},
},
],
},
{
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
publicPath: (filename, absolutePath, context) =>
`/${path.relative(context, absolutePath)}`,
context: path.join(__dirname, '..'),
outputPath(_url, resourcePath, context) {
return path.relative(context, resourcePath);
},
name: '[name].[ext]',
},
},
],
},
],
},
performance: {
hints: false,
},
plugins: [
...examples.map(
(example) =>
new HTMLWebpackPlugin({
template: path.join(__dirname, '..', example, 'index.html'),
filename: path.join(outputPath, example, 'index.html'),
chunks: [example],
})
),
new CopyWebpackPlugin([
...examples.map((example) => ({
from: path.join(__dirname, '..', example, 'assets'),
to: path.join(outputPath, example, 'assets'),
})),
{
from: path.join(__dirname, '..', 'assets'),
to: 'assets/',
},
]),
],
};
|