2018-08-30 15:25:33 +01:00
|
|
|
const path = require('path');
|
|
|
|
const autoprefixer = require('autoprefixer');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const flexBugsFixes = require('postcss-flexbugs-fixes');
|
2018-10-12 13:20:59 +01:00
|
|
|
const CleanWebpackPlugin = require('clean-webpack-plugin');
|
2018-08-30 15:25:33 +01:00
|
|
|
|
|
|
|
const RESOURCES_PATH = path.resolve(__dirname);
|
|
|
|
const ENTRY_REACT = path.resolve(RESOURCES_PATH, 'src/index.js');
|
|
|
|
const HTML_PATH = path.resolve(RESOURCES_PATH, 'public/index.html');
|
|
|
|
|
|
|
|
const PUBLIC_PATH = path.resolve(__dirname, '../build/static');
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
target: 'web',
|
|
|
|
context: RESOURCES_PATH,
|
|
|
|
entry: {
|
|
|
|
bundle: ENTRY_REACT,
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: PUBLIC_PATH,
|
2018-10-09 08:25:21 +01:00
|
|
|
filename: '[name].[chunkhash].js',
|
2018-08-30 15:25:33 +01:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
modules: ['node_modules'],
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
|
fallback: 'style-loader',
|
|
|
|
use: [{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
ident: 'postcss',
|
|
|
|
plugins: () => [
|
|
|
|
flexBugsFixes,
|
|
|
|
autoprefixer({
|
|
|
|
browsers: [
|
|
|
|
'>1%',
|
|
|
|
'last 4 versions',
|
|
|
|
'Firefox ESR',
|
|
|
|
'not ie < 9',
|
|
|
|
],
|
|
|
|
flexbox: 'no-2009',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
cacheDirectory: true,
|
|
|
|
presets: [
|
|
|
|
['env', {
|
|
|
|
modules: false,
|
|
|
|
}],
|
|
|
|
'react',
|
|
|
|
'stage-2',
|
|
|
|
],
|
|
|
|
plugins: ['transform-runtime', 'transform-object-rest-spread'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
exclude: [/\.js$/, /\.html$/, /\.json$/, /\.css$/],
|
|
|
|
use: {
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
fallback: 'file-loader',
|
|
|
|
name: 'media/[name].[hash:8].[ext]',
|
|
|
|
limit: 10 * 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
|
|
}),
|
2018-10-12 13:20:59 +01:00
|
|
|
new CleanWebpackPlugin(['*.*'], {
|
|
|
|
root: PUBLIC_PATH,
|
|
|
|
verbose: false,
|
|
|
|
dry: false,
|
|
|
|
}),
|
2018-08-30 15:25:33 +01:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
inject: true,
|
2018-10-09 08:25:21 +01:00
|
|
|
cache: false,
|
2018-08-30 15:25:33 +01:00
|
|
|
template: HTML_PATH,
|
|
|
|
}),
|
|
|
|
new ExtractTextPlugin({
|
2018-10-09 08:25:21 +01:00
|
|
|
filename: '[name].[contenthash].css',
|
2018-08-30 15:25:33 +01:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = config;
|