This repository has been archived by the owner on Jun 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
97 lines (88 loc) · 2.97 KB
/
webpack.config.js
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
const webpack = require('webpack');
const path = require('path');
const { merge } = require('webpack-merge');
const { appConfig: config, utils } = require('@cld/webpack-config');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const PreactRefreshPlugin = require('@prefresh/webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const dirApp = path.join(__dirname, 'src');
const getBuildVersion = () => {
return require('./package.json').version;
};
utils.modifyPluginOptions(config, 'Define', pluginConfig => {
Object.assign(pluginConfig.definitions, {
BUILD_VERSION: JSON.stringify(getBuildVersion()),
THREE_URL: JSON.stringify('https://product-gallery.cloudinary.com/cld-3d-viewer.js'),
THREE_DRACO_URL: JSON.stringify(
'https://res.cloudinary.com/demo/raw/upload/v1542808640/product-gallery-widget/draco/'
),
ANALYTICS_URL: JSON.stringify('https://analytics-api-s.cloudinary.com'),
CLD_VIDEO_PLAYER_JS: JSON.stringify(
'https://unpkg.com/cloudinary-video-player@{{version}}/dist/cld-video-player.min.js'
),
CLD_VIDEO_PLAYER_CSS: JSON.stringify(
'https://unpkg.com/cloudinary-video-player@{{version}}/dist/cld-video-player.min.css'
),
USE_ANALYTICS: JSON.stringify(process.env.NODE_ENV === 'production')
});
});
// Bypass default banner config because it doesn't use the build number.
utils.removePlugin(config, 'Banner');
// Remove react-intl plugin used in our generic @cld/webpack-config
utils.removePlugin(config, 'Intl');
// We don't want to inject the script tags to the HTML, instead we just use a predefined HTML file
utils.removePlugin(config, 'HtmlWebpackPlugin');
// We will use prefresh for hot reload
utils.removePlugin(config, 'ReactRefreshWebpackPlugin');
// Hot reload
config.plugins.push(new webpack.HotModuleReplacementPlugin(), new PreactRefreshPlugin());
config.plugins.push(
new webpack.BannerPlugin({
banner: `Cloudinary --> Product Gallery Widget \nbuild: ${getBuildVersion()}\n**/`
})
);
config.plugins.push(
new MiniCssExtractPlugin()
);
config.plugins.push(
new CopyWebpackPlugin({ patterns: [{ from: './public/index.html', to: './index.html' }] })
);
module.exports = merge(config, {
entry: {
all: path.join(dirApp, 'index.js')
},
output: {
publicPath: 'auto',
path: path.resolve(__dirname, './build')
},
resolve: {
alias: {
react: 'preact/compat',
'react-dom/test-utils': 'preact/test-utils',
'react-dom': 'preact/compat'
}
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules\/(?!(@cloudinary\/url-gen))/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.s[ac]ss$/i,
use: [
// fallback to style-loader in development
process.env.NODE_ENV !== 'production' ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
}
]
},
optimization: {
runtimeChunk: false
}
});