mirror of
https://github.com/trambarhq/relaks-wordpress-example.git
synced 2025-09-03 05:02:34 +02:00
Initial check in.
This commit is contained in:
134
webpack.config.js
Normal file
134
webpack.config.js
Normal file
@@ -0,0 +1,134 @@
|
||||
var FS = require('fs');
|
||||
var Path = require('path');
|
||||
var Webpack = require('webpack');
|
||||
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
var DefinePlugin = Webpack.DefinePlugin;
|
||||
var NamedChunksPlugin = Webpack.NamedChunksPlugin;
|
||||
var NamedModulesPlugin = Webpack.NamedModulesPlugin;
|
||||
var UglifyJSPlugin = require('uglifyjs-webpack-plugin');
|
||||
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
||||
var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
||||
|
||||
var event = process.env.npm_lifecycle_event;
|
||||
|
||||
var clientConfig = {
|
||||
context: Path.resolve('./src'),
|
||||
entry: './main',
|
||||
output: {
|
||||
path: Path.resolve('./server/www'),
|
||||
filename: 'app.js',
|
||||
},
|
||||
resolve: {
|
||||
extensions: [ '.js', '.jsx' ],
|
||||
modules: [ Path.resolve('./src'), Path.resolve('./node_modules') ],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.jsx?$/,
|
||||
loader: 'babel-loader',
|
||||
exclude: /node_modules/,
|
||||
query: {
|
||||
presets: [
|
||||
'env',
|
||||
'react',
|
||||
'stage-0',
|
||||
],
|
||||
plugins: [
|
||||
'syntax-async-functions',
|
||||
'syntax-class-properties',
|
||||
'transform-regenerator',
|
||||
'transform-runtime',
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: ExtractTextPlugin.extract({
|
||||
use: 'css-loader!sass-loader',
|
||||
})
|
||||
},
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new NamedChunksPlugin,
|
||||
new NamedModulesPlugin,
|
||||
new BundleAnalyzerPlugin({
|
||||
analyzerMode: (event === 'build') ? 'static' : 'disabled',
|
||||
reportFilename: `report.html`,
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
template: Path.resolve(`./src/index.html`),
|
||||
filename: Path.resolve(`./server/www/index.html`),
|
||||
}),
|
||||
new ExtractTextPlugin("styles.css"),
|
||||
],
|
||||
devtool: (event === 'build') ? false : 'inline-source-map',
|
||||
devServer: {
|
||||
inline: true,
|
||||
historyApiFallback: {
|
||||
rewrites: [
|
||||
{
|
||||
from: /.*/,
|
||||
to: function(context) {
|
||||
return context.parsedUrl.pathname.replace(/.*\/(.*)$/, '/$1');
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var serverConfig = {
|
||||
context: clientConfig.context,
|
||||
entry: clientConfig.entry,
|
||||
target: 'node',
|
||||
output: {
|
||||
path: Path.resolve('./server/client'),
|
||||
filename: 'app.js',
|
||||
libraryTarget: 'commonjs2',
|
||||
},
|
||||
resolve: clientConfig.resolve,
|
||||
module: clientConfig.module,
|
||||
plugins: [
|
||||
new NamedChunksPlugin,
|
||||
new NamedModulesPlugin,
|
||||
new HtmlWebpackPlugin({
|
||||
template: Path.resolve(`./src/index.html`),
|
||||
filename: Path.resolve(`./server/client/index.html`),
|
||||
}),
|
||||
new ExtractTextPlugin('styles.css'),
|
||||
],
|
||||
devtool: clientConfig.devtool,
|
||||
};
|
||||
|
||||
var configs = module.exports = clientConfig; //[ clientConfig, serverConfig ];
|
||||
|
||||
var constants = {};
|
||||
if (event === 'build') {
|
||||
console.log('Optimizing JS code');
|
||||
|
||||
configs.forEach((config) => {
|
||||
// set NODE_ENV to production
|
||||
var plugins = config.plugins;
|
||||
var constants = {
|
||||
'process.env.NODE_ENV': '"production"',
|
||||
};
|
||||
plugins.unshift(new DefinePlugin(constants));
|
||||
|
||||
// use Uglify to remove dead-code
|
||||
plugins.unshift(new UglifyJSPlugin({
|
||||
uglifyOptions: {
|
||||
compress: {
|
||||
drop_console: true,
|
||||
}
|
||||
}
|
||||
}));
|
||||
})
|
||||
}
|
||||
|
||||
// copy webpack.resolve.js into webpack.debug.js to resolve Babel presets
|
||||
// and plugins to absolute paths, required when linked modules are used
|
||||
if (FS.existsSync('./webpack.debug.js')) {
|
||||
configs.map(require('./webpack.debug.js'));
|
||||
}
|
Reference in New Issue
Block a user