100 lines
2.1 KiB
JavaScript
100 lines
2.1 KiB
JavaScript
const path = require('path');
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
|
|
module.exports = (env, argv) => {
|
|
const isProduction = argv.mode === 'production';
|
|
|
|
return {
|
|
entry: './src/index.js',
|
|
|
|
output: {
|
|
path: path.resolve(__dirname, '../growheads_de/dist/3d/'),
|
|
filename: isProduction ? '[name].[contenthash].js' : '[name].js',
|
|
clean: true,
|
|
publicPath: '/3d/'
|
|
},
|
|
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.css$/i,
|
|
use: ['style-loader', 'css-loader']
|
|
},
|
|
{
|
|
test: /\.(png|jpg|jpeg|gif|svg)$/i,
|
|
type: 'asset/resource',
|
|
generator: {
|
|
filename: 'assets/images/[name].[hash][ext]'
|
|
}
|
|
},
|
|
{
|
|
test: /\.(obj|mtl)$/i,
|
|
type: 'asset/resource',
|
|
generator: {
|
|
filename: 'assets/models/[name].[hash][ext]'
|
|
}
|
|
}
|
|
]
|
|
},
|
|
|
|
plugins: [
|
|
new HtmlWebpackPlugin({
|
|
template: './src/index.html',
|
|
filename: 'index.html',
|
|
minify: isProduction
|
|
}),
|
|
new CopyWebpackPlugin({
|
|
patterns: [
|
|
{
|
|
from: 'cube.obj',
|
|
to: 'cube.obj'
|
|
},
|
|
{
|
|
from: 'cube.mtl',
|
|
to: 'cube.mtl'
|
|
},
|
|
{
|
|
from: 'cube/',
|
|
to: 'cube/'
|
|
},
|
|
{
|
|
from: 'camera-config.json',
|
|
to: 'camera-config.json'
|
|
}
|
|
]
|
|
})
|
|
],
|
|
|
|
devServer: {
|
|
static: {
|
|
directory: path.join(__dirname, 'dist')
|
|
},
|
|
compress: true,
|
|
port: 8080,
|
|
open: true,
|
|
hot: true,
|
|
historyApiFallback: true
|
|
},
|
|
|
|
optimization: {
|
|
splitChunks: {
|
|
chunks: 'all',
|
|
cacheGroups: {
|
|
vendor: {
|
|
test: /[\\/]node_modules[\\/]/,
|
|
name: 'vendors',
|
|
chunks: 'all'
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
devtool: isProduction ? 'source-map' : 'eval-source-map',
|
|
|
|
resolve: {
|
|
extensions: ['.js', '.json']
|
|
}
|
|
};
|
|
};
|