2018-12-22 03:10:49 +03:00
|
|
|
var path = require('path');
|
|
|
|
var webpack = require('webpack');
|
|
|
|
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
var CleanWebpackPlugin = require('clean-webpack-plugin');
|
|
|
|
var ExportFilesWebpackPlugin = require('export-files-webpack-plugin');
|
|
|
|
|
|
|
|
var pkg = require('./package.json');
|
|
|
|
|
|
|
|
var isProduction = process.env.NODE_ENV === 'production';
|
|
|
|
|
|
|
|
module.exports = {
|
2019-01-09 03:06:21 +03:00
|
|
|
mode: process.env.NODE_ENV || 'development',
|
2018-12-22 03:10:49 +03:00
|
|
|
devtool: 'eval',
|
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',
|
|
|
|
'./demo/src/js/index'
|
|
|
|
],
|
2018-12-22 03:10:49 +03:00
|
|
|
output: {
|
|
|
|
path: path.join(__dirname, 'demo/dist'),
|
2019-01-09 03:06:21 +03:00
|
|
|
filename: 'js/bundle.js'
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new CleanWebpackPlugin(isProduction ? ['demo/dist'] : []),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
inject: true,
|
|
|
|
template: 'demo/src/index.html',
|
|
|
|
filename: 'index.html',
|
|
|
|
package: pkg
|
|
|
|
}),
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': {
|
|
|
|
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
|
2019-01-10 21:51:14 +03:00
|
|
|
}
|
2020-08-01 02:40:46 +03:00
|
|
|
})
|
2019-01-10 21:51:14 +03:00
|
|
|
].concat(
|
|
|
|
isProduction
|
|
|
|
? [
|
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
|
|
|
compress: { warnings: false },
|
|
|
|
output: { comments: false }
|
|
|
|
})
|
|
|
|
]
|
|
|
|
: [
|
|
|
|
new ExportFilesWebpackPlugin('demo/dist/index.html'),
|
|
|
|
new webpack.HotModuleReplacementPlugin()
|
|
|
|
]
|
|
|
|
),
|
2018-12-22 03:10:49 +03:00
|
|
|
resolve: {
|
2019-01-09 03:06:21 +03:00
|
|
|
extensions: ['*', '.js', '.jsx']
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
module: {
|
2019-01-10 21:51:14 +03:00
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
include: [
|
|
|
|
path.join(__dirname, 'src'),
|
|
|
|
path.join(__dirname, 'demo/src/js')
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
2019-01-10 21:51:14 +03:00
|
|
|
devServer: isProduction
|
|
|
|
? null
|
|
|
|
: {
|
|
|
|
quiet: false,
|
|
|
|
port: 3000,
|
|
|
|
hot: true,
|
|
|
|
stats: {
|
|
|
|
chunkModules: false,
|
|
|
|
colors: true
|
|
|
|
},
|
|
|
|
historyApiFallback: true
|
|
|
|
}
|
2018-12-22 03:10:49 +03:00
|
|
|
};
|