Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require('path');
- const webpack = require('webpack');
- //plugin for analyzing js bundle file. helps to make file size under control by identifying large libraries
- const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
- const ExtractTextPlugin = require("extract-text-webpack-plugin");
- const env = require('node-env-file');
- env(path.resolve(`.env`));
- const analyzeBundles = new BundleAnalyzerPlugin({
- analyzerMode: 'static',
- reportFilename: 'report.html', //look into /dist folder
- openAnalyzer: false,
- generateStatsFile: false,
- });
- const definePlugin = new webpack.DefinePlugin({
- 'process.env': {
- 'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
- 'FACEBOOK_APP_ID': JSON.stringify(process.env.FACEBOOK_APP_ID),
- 'RECAPTCHA_SITE_KEY': JSON.stringify(process.env.RECAPTCHA_SITE_KEY),
- 'GOOGLE_OAUTH_CLIEN_ID': JSON.stringify(process.env.GOOGLE_OAUTH_CLIEN_ID),
- 'GOOGLE_MAPS_API_KEY': JSON.stringify(process.env.GOOGLE_MAPS_API_KEY),
- 'DRAUGIEM_APP_ID': JSON.stringify(process.env.DRAUGIEM_APP_ID),
- 'DRAUGIEM_API_KEY': JSON.stringify(process.env.DRAUGIEM_API_KEY),
- }
- });
- const uglifyPlugin = new webpack.optimize.UglifyJsPlugin({
- compress:{
- warnings: true
- }
- });
- const mergePlugin = new webpack.optimize.AggressiveMergingPlugin();
- const sourceMapPlugin = new webpack.SourceMapDevToolPlugin();
- const extractTextPlugin = new ExtractTextPlugin('[name].css');
- const ignorePlugin = new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/);
- const isDevelopment = process.env.NODE_ENV !== 'production';
- const config = {
- watch: isDevelopment,
- watchOptions: {
- poll: 1000
- },
- devtool: isDevelopment ? 'eval' : false,
- entry: {
- bundle: path.join(`${__dirname}/web/js/entry.js`),
- },
- output: {
- path: path.join(`${__dirname}/web/dist`), //distribution directory
- filename: "[name].js" //bundle file name
- },
- module: {
- loaders: [
- {
- test: /\.js$/,
- exclude: /node_modules/,
- loaders: ['babel-loader', 'eslint-loader'],
- },
- {
- test: /\.css$/,
- loader: ExtractTextPlugin.extract({
- use: ['css-loader', 'postcss-loader']
- }),
- },
- ],
- },
- plugins: isDevelopment ? [
- ignorePlugin,
- definePlugin,
- extractTextPlugin,
- analyzeBundles,
- sourceMapPlugin,
- ] : [
- ignorePlugin,
- definePlugin,
- extractTextPlugin,
- uglifyPlugin,
- mergePlugin,
- analyzeBundles
- ],
- devServer: {
- contentBase: path.resolve(__dirname, 'web/build'),
- watchContentBase: true,
- overlay: true
- }
- };
- module.exports = config;
Advertisement
Add Comment
Please, Sign In to add comment