github.com/jacobsoderblom/buffalo@v0.11.0/generators/assets/webpack/templates/webpack.config.js.tmpl (about)

     1  var webpack = require("webpack");
     2  var glob = require("glob");
     3  var CopyWebpackPlugin = require("copy-webpack-plugin");
     4  var ExtractTextPlugin = require("extract-text-webpack-plugin");
     5  var ManifestPlugin = require("webpack-manifest-plugin");
     6  var PROD = process.env.NODE_ENV || "development";
     7  var CleanWebpackPlugin = require("clean-webpack-plugin");
     8  
     9  var entries = {
    10    application: [
    11      './node_modules/jquery-ujs/src/rails.js',
    12      './assets/css/application.scss',
    13    ],
    14  }
    15  
    16  glob.sync("./assets/*/*.*").reduce((_, entry) => {
    17    let key = entry.replace(/(\.\/assets\/(js|css|go)\/)|\.(js|s[ac]ss|go)/g, '')
    18    if(key.startsWith("_") || (/(js|s[ac]ss|go)$/i).test(entry) == false) {
    19      return
    20    }
    21    
    22    if( entries[key] == null) {
    23      entries[key] = [entry]
    24      return
    25    } 
    26    
    27    entries[key].push(entry)
    28  })
    29  
    30  module.exports = {
    31    entry: entries,
    32    output: {
    33      filename: "[name].[hash].js",
    34      path: `${__dirname}/public/assets`
    35    },
    36    plugins: [
    37      new CleanWebpackPlugin([
    38        "public/assets"
    39      ], {
    40        verbose: false,
    41      }),
    42      new webpack.ProvidePlugin({
    43        $: "jquery",
    44        jQuery: "jquery"
    45      }),
    46      new ExtractTextPlugin("[name].[hash].css"),
    47      new CopyWebpackPlugin(
    48        [{
    49          from: "./assets",
    50          to: ""
    51        }], {
    52          copyUnmodified: true,
    53          ignore: ["css/**", "js/**"]
    54        }
    55      ),
    56      new webpack.LoaderOptionsPlugin({
    57        minimize: true,
    58        debug: false
    59      }),
    60      new ManifestPlugin({
    61        fileName: "manifest.json"
    62      })
    63    ],
    64    module: {
    65      rules: [{
    66        test: /\.jsx?$/,
    67        loader: "babel-loader",
    68        exclude: /node_modules/
    69      },
    70        {
    71          test: /\.s[ac]ss$/,
    72          use: ExtractTextPlugin.extract({
    73            fallback: "style-loader",
    74            use: [{
    75              loader: "css-loader",
    76              options: {
    77                sourceMap: true
    78              }
    79            },
    80              {
    81                loader: "sass-loader",
    82                options: {
    83                  sourceMap: true
    84                }
    85              }
    86            ]
    87          })
    88        },
    89        { test: /\.(woff|woff2|ttf|svg)(\?v=\d+\.\d+\.\d+)?$/,use: "url-loader"},
    90        { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,use: "file-loader" },
    91        {
    92          test: require.resolve("jquery"),
    93          use: "expose-loader?jQuery!expose-loader?$"
    94        },
    95        {
    96          test: /\.go$/,
    97          use: "gopherjs-loader"
    98        }
    99      ]
   100    }
   101  };
   102  
   103  if (PROD != "development") {
   104    module.exports.plugins.push(
   105      new webpack.optimize.UglifyJsPlugin({
   106        beautify: false,
   107        mangle: {
   108          screw_ie8: true,
   109          keep_fnames: true
   110        },
   111        compress: {
   112          screw_ie8: true
   113        },
   114        comments: false
   115      })
   116    );
   117  }