react-static-webpack-plugin
Version:
Build full static sites using React, React Router and Webpack
109 lines (102 loc) • 2.48 kB
JavaScript
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const rupture = require('rupture');
const autoprefixer = require('autoprefixer');
const ReactStaticPlugin = require('../../dist');
module.exports = {
devtool: 'source-map',
context: __dirname,
entry: {
app: [
'normalize.css',
'./client/index.js',
],
},
output: {
path: path.join(__dirname, 'build'),
filename: '[name].js',
publicPath: '/',
},
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: true,
options: {
postcss: [autoprefixer({ browsers: ['last 2 versions'] })],
stylus: {
use: [rupture()],
},
},
}),
new ExtractTextPlugin({
filename: '[name].css',
allChunks: true,
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
new webpack.optimize.UglifyJsPlugin({
screw_ie8: true,
sourceMap: true,
compressor: { warnings: false },
}),
new ReactStaticPlugin({
routes: './client/routes.js',
template: './template.js',
}),
],
module: {
rules: [
{
test: /\.js$/,
exclude: path.join(__dirname, 'node_modules'),
loader: 'babel-loader',
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: 'css-loader',
}),
},
{
test: /\.styl$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: [
{
loader: 'css-loader',
query: {
modules: true,
importLoaders: 2,
},
},
{ loader: 'postcss-loader' },
{ loader: 'stylus-loader' },
],
}),
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [
{
loader: 'url-loader',
options: { limit: 10000, mimetype: 'mimetype=application/font-woff' },
},
],
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader',
},
{
test: /\.(png|jpg|gif|ico)$/,
use: [
{ loader: 'file-loader', options: { name: '[name].[ext]' } },
],
},
],
},
};