2016-11-10 14:26:24 +01:00
|
|
|
// docs: http://webpack.github.io/docs/configuration.html
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
2018-08-14 09:49:40 +02:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2018-08-22 18:06:28 +02:00
|
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
|
|
|
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
2019-10-08 12:08:23 +02:00
|
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
2018-08-14 09:49:40 +02:00
|
|
|
const devMode = process.env.NODE_ENV !== 'production';
|
|
|
|
const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';
|
2016-11-16 22:19:38 +01:00
|
|
|
const entry = ['whatwg-fetch', './src/index'];
|
2017-01-06 11:52:44 +01:00
|
|
|
const plugins = [
|
2018-08-14 09:49:40 +02:00
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
// Options similar to the same options in webpackOptions.output
|
|
|
|
// both options are optional
|
|
|
|
filename: 'bundle.css',
|
|
|
|
}),
|
2017-01-06 11:52:44 +01:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': {
|
|
|
|
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
|
|
|
|
},
|
|
|
|
}),
|
2017-07-10 23:30:38 +02:00
|
|
|
new webpack.optimize.ModuleConcatenationPlugin(),
|
2019-10-08 12:08:23 +02:00
|
|
|
new CleanWebpackPlugin(),
|
2017-01-06 11:52:44 +01:00
|
|
|
];
|
2016-11-10 22:49:28 +01:00
|
|
|
|
2018-08-14 09:49:40 +02:00
|
|
|
if (devMode) {
|
2016-11-10 22:49:28 +01:00
|
|
|
entry.push('webpack-dev-server/client?http://localhost:3000');
|
|
|
|
entry.push('webpack/hot/only-dev-server');
|
|
|
|
plugins.push(new webpack.HotModuleReplacementPlugin());
|
|
|
|
}
|
|
|
|
|
2016-11-10 14:26:24 +01:00
|
|
|
module.exports = {
|
2018-08-14 09:49:40 +02:00
|
|
|
mode,
|
2016-11-10 22:49:28 +01:00
|
|
|
entry,
|
2016-11-10 14:26:24 +01:00
|
|
|
|
|
|
|
resolve: {
|
2017-07-10 23:30:38 +02:00
|
|
|
extensions: ['.scss', '.css', '.js', '.jsx', '.json'],
|
2016-11-10 14:26:24 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
output: {
|
2017-03-07 18:30:45 +01:00
|
|
|
path: path.join(__dirname, 'dist/public'),
|
2016-11-10 14:26:24 +01:00
|
|
|
filename: 'bundle.js',
|
|
|
|
publicPath: '/static/',
|
|
|
|
},
|
|
|
|
|
2018-08-22 18:06:28 +02:00
|
|
|
optimization: {
|
|
|
|
minimizer: [
|
|
|
|
new UglifyJsPlugin({
|
|
|
|
uglifyOptions: {
|
|
|
|
output: {
|
2018-08-22 18:10:27 +02:00
|
|
|
comments: false,
|
2018-08-22 18:06:28 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
new OptimizeCssAssetsPlugin({
|
|
|
|
cssProcessor: require('cssnano'),
|
|
|
|
cssProcessorOptions: { discardComments: { removeAll: true } },
|
|
|
|
canPrint: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
2016-11-10 14:26:24 +01:00
|
|
|
module: {
|
2017-07-10 23:30:38 +02:00
|
|
|
rules: [
|
2016-11-10 14:26:24 +01:00
|
|
|
{
|
2017-01-06 11:52:44 +01:00
|
|
|
test: /\.jsx?$/,
|
2016-11-10 14:26:24 +01:00
|
|
|
exclude: /node_modules/,
|
2017-07-10 23:30:38 +02:00
|
|
|
loader: 'babel-loader',
|
2016-11-10 14:26:24 +01:00
|
|
|
include: path.join(__dirname, 'src'),
|
|
|
|
},
|
|
|
|
{
|
2016-12-20 19:15:12 +01:00
|
|
|
test: /(\.scss)$/,
|
2018-08-14 09:49:40 +02:00
|
|
|
use: [
|
|
|
|
{ loader: devMode ? 'style-loader' : MiniCssExtractPlugin.loader },
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
modules: true,
|
|
|
|
importLoaders: 1,
|
|
|
|
localIdentName: '[name]__[local]___[hash:base64:5]',
|
2017-07-10 23:30:38 +02:00
|
|
|
},
|
2018-08-14 09:49:40 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
// data: '@import "theme/_config.scss";',
|
|
|
|
includePaths: [path.resolve(__dirname, './src')],
|
2017-07-10 23:30:38 +02:00
|
|
|
},
|
2018-08-14 09:49:40 +02:00
|
|
|
},
|
|
|
|
],
|
2016-11-10 14:26:24 +01:00
|
|
|
},
|
2016-12-20 19:15:12 +01:00
|
|
|
{
|
2018-08-14 09:49:40 +02:00
|
|
|
test: /(\.css)$/,
|
|
|
|
use: [{ loader: devMode ? 'style-loader' : MiniCssExtractPlugin.loader }, { loader: 'css-loader' }],
|
2016-12-20 19:15:12 +01:00
|
|
|
},
|
2016-11-10 14:26:24 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
|
2016-11-10 22:49:28 +01:00
|
|
|
plugins,
|
2016-11-10 14:26:24 +01:00
|
|
|
|
|
|
|
devtool: 'source-map',
|
|
|
|
|
|
|
|
devServer: {
|
|
|
|
proxy: {
|
2016-11-10 22:49:28 +01:00
|
|
|
'/api': {
|
2017-01-02 22:07:50 +01:00
|
|
|
target: process.env.UNLEASH_API || 'http://localhost:4242',
|
|
|
|
changeOrigin: true,
|
2016-11-10 14:26:24 +01:00
|
|
|
secure: false,
|
|
|
|
},
|
|
|
|
},
|
2017-01-02 22:23:13 +01:00
|
|
|
port: process.env.PORT || 3000,
|
2016-11-10 14:26:24 +01:00
|
|
|
},
|
|
|
|
};
|