/* Libraries */ const path = require('path'); const webpack = require('webpack'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const WebpackNotifierPlugin = require('webpack-notifier'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const plugins = require('./postcss.config'); let extractHtml = new ExtractTextPlugin('[name].html') const SpriteLoaderPlugin = require('svg-sprite-loader/plugin'); const vesion = require('./src/config/version.js'); /* Configuration */ module.exports = env => { return { context: path.resolve(__dirname, './src'), entry: { app: './app.js' }, output: { path: path.resolve(__dirname, './dist'), publicPath: '/', filename: 'assets/js/[name].bundle.js?v=' + '[hash:7]' }, devServer: { contentBase: path.resolve(__dirname, './src'), // hot: true, }, resolve: { extensions: ['.js'], alias: { source: path.resolve(__dirname, './src'), // Relative path of src images: path.resolve(__dirname, './src/assets/images'), // Relative path of images 'debug.addIndicators': path.resolve('node_modules', 'scrollmagic/scrollmagic/uncompressed/plugins/debug.addIndicators.js') } }, /* Loaders with their configurations */ module: { rules: [ { test: /\.js$/, exclude: [/node_modules/], use: [ { loader: 'babel-loader', options: { presets: ['es2015'] } } ] }, { test: /\.css$/, use: ExtractTextPlugin.extract({ fallback: 'style-loader', use: [ { loader: 'css-loader', options: { importLoaders: 1, sourceMap: true, minimize: true, colormin: false } }, ] }) }, { use: 'css-loader!sass-loader?sourceMap', test: /\.(sass|scss)$/, use: ExtractTextPlugin.extract({ fallback: 'style-loader', use: [ { loader: 'css-loader', options: { importLoaders: 1, sourceMap: true, minimize: true, colormin: false } }, { loader: 'postcss-loader', options: { sourceMap: true, minimize: true, colormin: false } }, 'sass-loader?sourceMap' ] }) }, { test: /\.pug$/, use: [ { loader: 'pug-loader' } ] }, { test: /\.(png|jpe?g|gif|svg|ico)(\?.*)?$/, loader: 'url-loader', options: { limit: 512, name: 'assets/images/[name].[ext]?v=' + '[hash:7]', } }, { test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, loader: 'url-loader', options: { limit: 512, name: 'assets/fonts/[name].[ext]?v=' + '[hash:7]', } }, { test: /\.(mp4)(\?.*)?$/, loader: 'url-loader', options: { limit: 512, name: 'assets/videos/[name].[ext]?v=' + '[hash:7]', } }, { test: /\.svg$/, use: [ 'svg-sprite-loader', 'svgo-loader' ] // use: [ // { loader: 'svg-sprite-loader', // options: { // extract: true, // spriteFilename: svgPath => `assets/images/sprite${svgPath.substr(-4)}` // } // }, // 'svgo-loader' // ], // } ] }, plugins: [ new CopyWebpackPlugin([ { from: '../manifest.json', to: 'manifest.json' }, { from: '../browserconfig.xml', to: 'browserconfig.xml' }, { from: 'assets/images/favicons/android-chrome-192x192.png', to: 'assets/images/android-chrome-192x192.png' }, { from: 'assets/images/favicons/android-chrome-256x256.png', to: 'assets/images/android-chrome-256x256.png' }, { from: 'assets/images/favicons/mstile-150x150.png', to: 'assets/images/mstile-150x150.png' }, { from: 'assets/images/animation/animation.json', to: 'assets/images/animation/animation.json' } ]), new ExtractTextPlugin({ filename: 'assets/css/[name].bundle.css?v=' + '[hash:7]', allChunks: true }), new webpack.optimize.CommonsChunkPlugin({ name: 'vendor' }), /* Pages */ // Landing page new HtmlWebpackPlugin({ filename: 'index.html', template: 'views/index.pug', inject: true }), new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', 'window.$': 'jquery', 'window.jQuery': 'jquery' }), new SpriteLoaderPlugin(), ] } };