SHARE
TWEET

Untitled

a guest Sep 15th, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var path = require('path');
  2. var glob = require('glob-all');
  3. var webpack = require('webpack');
  4. var inProduction = true;
  5. var BrowserSyncPlugin = require('browser-sync-webpack-plugin');
  6. var ExtractTextPlugin = require('extract-text-webpack-plugin');
  7. var PurifyCSSPlugin = require('purifycss-webpack');
  8. var CleanWebpackPlugin = require('clean-webpack-plugin');
  9. var extractSass = new ExtractTextPlugin({filename: '[name].[contenthash].css'});
  10.  
  11. module.exports = {
  12.   entry: './app/Resources/assets/js/vue/bootstrap.js',
  13.   output: {
  14.     filename: 'bundle.[hash].js',
  15.     path: path.resolve(__dirname, './web/build'),
  16.   },
  17.   node: {
  18.     fs: 'empty',
  19.   },
  20.   module: {
  21.     rules: [
  22.       {
  23.         test: /\.js$/,
  24.         exclude: /(node_modules|bower_components)/,
  25.         use: {
  26.           loader: 'babel-loader',
  27.         },
  28.       },
  29.       {
  30.         test: /\.css$/,
  31.         use: ['style-loader', 'css-loader'],
  32.         use: extractSass.extract({
  33.           use: [
  34.             {
  35.               loader: 'css-loader',
  36.               options: {
  37.                 url: true,
  38.               },
  39.             },
  40.             {
  41.               loader: 'postcss-loader',
  42.               options: {
  43.                 plugins: function() {
  44.                   return [
  45.                     require('precss'),
  46.                     require('autoprefixer'),
  47.                   ];
  48.                 },
  49.               },
  50.             },
  51.           ],
  52.           fallback: 'style-loader',
  53.         }),
  54.       },
  55.       {
  56.         test: /\.scss$/,
  57.         use: extractSass.extract({
  58.           use: [
  59.             {
  60.               loader: 'css-loader',
  61.               options: {
  62.                 url: true,
  63.               },
  64.             },
  65.             {
  66.               loader: 'postcss-loader?sourceMap',
  67.             },
  68.             {
  69.               loader: 'sass-loader',
  70.             }],
  71.           fallback: 'style-loader',
  72.         }),
  73.       },
  74.       {
  75.         test: /\.(png|jpg|gif)$/,
  76.         loader: [
  77.           {
  78.             loader: 'url-loader?limit=1000',
  79.             options: {
  80.               limit: 8192,
  81.             },
  82.           },
  83.         ],
  84.       },
  85.     ],
  86.   },
  87.   plugins: [
  88.     new BrowserSyncPlugin({
  89.       host: 'localhost',
  90.       port: 3000,
  91.       proxy: 'orange.dev',
  92.     }),
  93.     new CleanWebpackPlugin([
  94.       path.join(__dirname, 'web/build'),
  95.     ], {
  96.       exclude: [],
  97.       verbose: true,
  98.     }),
  99.     new webpack.LoaderOptionsPlugin({
  100.       minimize: inProduction,
  101.     }),
  102.     function() {
  103.       this.plugin('done', stats => {
  104.             require('fs').writeFileSync(
  105.                 path.join(__dirname, 'app/Resources/assets/manifest.json'),
  106.                 JSON.stringify(
  107.                     {
  108.                       jsBundle: stats.toJson().assetsByChunkName.main[0],
  109.                       cssBundle: stats.toJson().assetsByChunkName.main[1],
  110.                     },
  111.                 ),
  112.             );
  113.           },
  114.       );
  115.     },
  116.     extractSass,
  117.     new PurifyCSSPlugin({
  118.       paths: glob.sync([
  119.         path.join(__dirname, 'app/Resources/views/*/*/*.html.twig'),
  120.         path.join(__dirname, 'app/Resources/views/*/*.html.twig'),
  121.         path.join(__dirname, 'app/Resources/views/*.html.twig'),
  122.         path.join(__dirname, 'src/ShopBundle/Resources/views/*.html.twig'),
  123.         path.join(__dirname, 'src/ShopBundle/Resources/views/*/*.html.twig'),
  124.         path.join(__dirname, 'src/ShopBundle/Resources/views/*/*/*.html.twig'),
  125.       ]),
  126.       minimize: inProduction,
  127.       purifyOptions: {
  128.         whitelist: [
  129.           '.default-dropdown',
  130.           '.active',
  131.           '.selection',
  132.           '.dropdown',
  133.           '.menu',
  134.           '.focus',
  135.           '.no-pic'
  136.         ],
  137.       },
  138.     }),
  139.     new webpack.DefinePlugin({
  140.       'process.env': {
  141.         NODE_ENV: (inProduction)
  142.             ? JSON.stringify('production')
  143.             : JSON.stringify('development'),
  144.       },
  145.     }),
  146.   ],
  147. };
  148.  
  149. if (inProduction) {
  150.   module.exports.plugins.push(
  151.       new webpack.optimize.UglifyJsPlugin(),
  152.   );
  153. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top