2018-12-23 03:13:56 +03:00
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
2020-08-08 22:46:01 +03:00
|
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
2018-12-23 03:13:56 +03:00
|
|
|
const ExportFilesWebpackPlugin = require('export-files-webpack-plugin');
|
|
|
|
|
|
|
|
const pkg = require('./package.json');
|
|
|
|
|
|
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
|
|
|
|
|
|
module.exports = {
|
2020-08-01 22:30:39 +03:00
|
|
|
devtool: 'eval-source-map',
|
2019-01-10 21:51:14 +03:00
|
|
|
entry: isProduction
|
|
|
|
? ['./demo/src/js/index']
|
|
|
|
: [
|
|
|
|
'webpack-dev-server/client?http://localhost:3000',
|
|
|
|
'webpack/hot/only-dev-server',
|
2020-08-08 23:26:39 +03:00
|
|
|
'./demo/src/js/index',
|
2019-01-10 21:51:14 +03:00
|
|
|
],
|
2018-12-23 03:13:56 +03:00
|
|
|
output: {
|
|
|
|
path: path.join(__dirname, 'demo/dist'),
|
2020-08-08 23:26:39 +03:00
|
|
|
filename: 'js/bundle.js',
|
2018-12-23 03:13:56 +03:00
|
|
|
},
|
|
|
|
plugins: [
|
2020-08-08 22:46:01 +03:00
|
|
|
new CleanWebpackPlugin(),
|
2018-12-23 03:13:56 +03:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
inject: true,
|
|
|
|
template: 'demo/src/index.html',
|
2020-08-08 23:26:39 +03:00
|
|
|
package: pkg,
|
2018-12-23 03:13:56 +03:00
|
|
|
}),
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': {
|
2020-08-08 23:26:39 +03:00
|
|
|
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
|
|
|
|
},
|
|
|
|
}),
|
2019-01-10 21:51:14 +03:00
|
|
|
].concat(
|
|
|
|
isProduction
|
|
|
|
? [
|
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
|
|
|
compress: { warnings: false },
|
2020-08-08 23:26:39 +03:00
|
|
|
output: { comments: false },
|
|
|
|
}),
|
2019-01-10 21:51:14 +03:00
|
|
|
]
|
|
|
|
: [
|
|
|
|
new ExportFilesWebpackPlugin('demo/dist/index.html'),
|
2020-08-08 23:26:39 +03:00
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
2019-01-10 21:51:14 +03:00
|
|
|
]
|
|
|
|
),
|
2018-12-23 03:13:56 +03:00
|
|
|
resolve: {
|
2020-08-08 23:26:39 +03:00
|
|
|
extensions: ['.js', '.jsx'],
|
2018-12-23 03:13:56 +03:00
|
|
|
},
|
|
|
|
module: {
|
2019-01-10 21:51:14 +03:00
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
include: [
|
|
|
|
path.join(__dirname, 'src'),
|
2020-08-08 23:26:39 +03:00
|
|
|
path.join(__dirname, 'demo/src/js'),
|
|
|
|
],
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
2020-08-08 23:26:39 +03:00
|
|
|
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(ttf|eot|svg|woff|woff2)$/,
|
|
|
|
loader: 'file-loader',
|
2020-08-08 23:26:39 +03:00
|
|
|
options: { outputPath: 'fonts/', publicPath: 'fonts/' },
|
|
|
|
},
|
|
|
|
],
|
2018-12-23 03:13:56 +03:00
|
|
|
},
|
2019-01-10 21:51:14 +03:00
|
|
|
devServer: isProduction
|
|
|
|
? null
|
|
|
|
: {
|
|
|
|
quiet: false,
|
|
|
|
port: 3001,
|
|
|
|
hot: true,
|
|
|
|
stats: {
|
|
|
|
chunkModules: false,
|
2020-08-08 23:26:39 +03:00
|
|
|
colors: true,
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
2020-08-08 23:26:39 +03:00
|
|
|
historyApiFallback: true,
|
|
|
|
},
|
2018-12-23 03:13:56 +03:00
|
|
|
};
|