123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- /**
- * React Static Boilerplate
- * https://github.com/koistya/react-static-boilerplate
- *
- * Copyright © 2015-2016 Konstantin Tarkus (@koistya)
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE.txt file in the root directory of this source tree.
- */
- const path = require('path');
- const webpack = require('webpack');
- const extend = require('extend');
- const pkg = require('../package.json');
- const isDebug = !(process.argv.includes('--release') || process.argv.includes('-r'));
- const isVerbose = process.argv.includes('--verbose') || process.argv.includes('-v');
- /**
- * Webpack configuration (core/main.js => build/bundle.js)
- * http://webpack.github.io/docs/configuration.html
- */
- const config = {
- // The base directory
- context: path.resolve(__dirname, '../'),
- // The entry point for the bundle
- entry: ['./core/app.js'],
- // Options affecting the output of the compilation
- output: {
- path: path.resolve(__dirname, '../build'),
- publicPath: '/',
- file: 'build/[name].js',
- sourcePrefix: ' ',
- },
- // Switch loaders to debug or release mode
- debug: isDebug,
- // Developer tool to enhance debugging, source maps
- // http://webpack.github.io/docs/configuration.html#devtool
- devtool: isDebug ? 'source-map' : false,
- // What information should be printed to the console
- stats: {
- colors: true,
- reasons: isDebug,
- hash: isVerbose,
- version: isVerbose,
- timings: true,
- chunks: isVerbose,
- chunkModules: isVerbose,
- cached: isVerbose,
- cachedAssets: isVerbose,
- },
- // The list of plugins for Webpack compiler
- plugins: [
- new webpack.optimize.OccurenceOrderPlugin(),
- new webpack.DefinePlugin({
- 'process.env.NODE_ENV': isDebug ? '"development"' : '"production"',
- __DEV__: isDebug,
- }),
- ],
- // Options affecting the normal modules
- module: {
- loaders: [
- {
- test: /\.jsx?$/,
- include: [
- path.resolve(__dirname, '../components'),
- path.resolve(__dirname, '../core'),
- path.resolve(__dirname, '../routes'),
- ],
- loader: 'babel-loader',
- query: extend({}, pkg.babel, { babelrc: false }),
- },
- {
- test: /\.css/,
- loaders: [
- 'style-loader',
- `css-loader?${JSON.stringify({
- sourceMap: isDebug,
- // CSS Modules https://github.com/css-modules/css-modules
- modules: true,
- localIdentName: isDebug ? '[name]_[local]_[hash:base64:3]' : '[hash:base64:4]',
- // CSS Nano http://cssnano.co/options/
- minimize: !isDebug,
- })}`,
- 'postcss-loader',
- ],
- },
- {
- test: /\.json$/,
- loader: 'json-loader',
- },
- {
- test: /\.md$/,
- loader: path.resolve(__dirname, './webpack.markdown-loader.js'),
- },
- {
- test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
- loader: 'url-loader?limit=10000',
- },
- {
- test: /\.(eot|ttf|wav|mp3)$/,
- loader: 'file-loader',
- },
- ],
- },
- // The list of plugins for PostCSS
- // https://github.com/postcss/postcss
- postcss(bundler) {
- return [
- require('postcss-import')({ addDependencyTo: bundler }),
- require('postcss-custom-properties')(),
- require('postcss-calc')(),
- require('postcss-color-function')(),
- require('pleeease-filters')(),
- require('pixrem')(),
- require('postcss-pseudoelements')(),
- require('postcss-selector-not')(),
- require('autoprefixer')(),
- ];
- },
- };
- // Optimize the bundle in release (production) mode
- if (!isDebug) {
- config.plugins.push(new webpack.optimize.DedupePlugin());
- config.plugins.push(new webpack.optimize.UglifyJsPlugin({ compress: { warnings: isVerbose } }));
- config.plugins.push(new webpack.optimize.AggressiveMergingPlugin());
- }
- module.exports = config;
|