Completed
Pull Request — devel (#145)
by Litera
05:12
created

webpack.config.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
const webpack = require('webpack')
2
const path = require('path')
3
// const glob = require('glob-all')
4
const ExtractTextPlugin = require('extract-text-webpack-plugin')
5
// const PurifyCSSPlugin = require('purifycss-webpack')
6
const CleanWebpackPlugin = require('clean-webpack-plugin')
7
const ManifestPlugin = require('webpack-manifest-plugin')
8
9
const ExtractTextPluginConfig = (minify) => ({
10
  fallback: 'style-loader',
11
  use: [{
12
    loader: 'css-loader',
13
    options: {
14
      minimize: minify,
15
      sourceMap: true
16
    }
17
  }, {
18
    loader: 'sass-loader',
19
    options: {
20
      sourceMap: true
21
    }
22
  }]
23
})
24
25
module.exports = ({minify = false, production = false} = {}) => {
26
  const extractStylesheet = new ExtractTextPlugin('css/[name].[contenthash].css')
27
  const plugins = [
28
    new webpack.ProvidePlugin({
29
      $: 'jquery',
30
      jQuery: 'jquery',
31
      moment: 'moment'
32
    }),
33
    extractStylesheet,
34
    /* new webpack.LoaderOptionsPlugin({
35
       minimize: inProduction
36
    }), */
37
    new webpack.optimize.CommonsChunkPlugin({
38
      name: 'vendor',
39
      minChunks: Infinity
40
    }),
41
    /* new PurifyCSSPlugin({
42
      paths: glob.sync([
43
        path.join(__dirname, 'app/templates/!*.latte'),
44
        path.join(__dirname, 'app/templates/!**!/!*.latte')
45
      ]),
46
      minimize: minify
47
    }), */
48
    new CleanWebpackPlugin(['www/*/main.*', 'www/*/vendor.*'], {
49
      root: __dirname,
50
      verbose: true,
51
      dry: false
52
    }),
53
    new ManifestPlugin()
54
  ]
55
56
  if (production) {
57
    plugins.push(new webpack.optimize.UglifyJsPlugin({
58
      compress: {
59
        warnings: false
60
      }
61
    }))
62
  }
63
64
  return {
65
    entry: {
66
      main: [
67
        './app/assets/js/main.js',
68
        './app/assets/styles/main.scss'
69
      ],
70
      vendor: [
71
        'jquery',
72
        './www/js/jquery/jquery.tinytips.js',
73
        'bootstrap',
74
        './node_modules/bootstrap-ui/dist/js/bootstrap-ui.js',
75
        'moment',
76
        'eonasdan-bootstrap-datetimepicker'
77
      ]
78
    },
79
    output: {
80
      path: path.resolve(__dirname, 'www'),
81
      publicPath: '/srazvs/www/',
82
      filename: 'js/[name].[chunkhash].js'
83
    },
84
    watchOptions: {
85
      poll: true
86
    },
87
    module: {
88
      rules: [
89
        {
90
          test: /\.s[ac]ss$/,
91
          use: extractStylesheet.extract(ExtractTextPluginConfig(minify))
92
        }, {
93
          test: /\.(svg|eot|ttf|woff|woff2)$/,
94
          loaders: [
95
            {
96
              loader: 'file-loader',
97
              options: {
98
                name: 'fonts/[name].[ext]'
99
              }
100
            }
101
          ]
102
        }, {
103
          test: /\.(png|jpe?g|gif)$/,
104
          loaders: [
105
            {
106
              loader: 'file-loader',
107
              options: {
108
                name: 'images/[name].[hash].[ext]'
109
              }
110
            },
111
            'img-loader'
112
          ]
113
        }, {
114
          test: /\.css$/,
115
          use: [
116
            'style-loader',
117
            'css-loader'
118
          ]
119
        }, {
120
          test: /\.js$/,
121
          exclude: /node_modules/,
122
          loader: 'babel-loader'
123
        }
124
      ]
125
    },
126
    plugins,
127
    devtool: 'source-map',
128
    resolve: {
129
      alias: [
130
        {
131
          alias: 'recharts',
132
          name: 'recharts/es6'
133
        }, {
134
          // Force all modules to use the same jquery version.
135
          alias: 'jquery',
136
          name: path.join(__dirname, 'node_modules/jquery/src/jquery')
137
        }
138
      ]
139
    }
140
  }
141
}
142