/ webpack.config.js
webpack.config.js
1 var webpack = require('webpack'); 2 3 var path = require('path'); 4 5 var HtmlWebpackPlugin = require('html-webpack-plugin'); 6 var CleanWebpackPlugin = require('clean-webpack-plugin'); 7 var BrowserSyncPlugin = require('browser-sync-webpack-plugin'); 8 var CopyWebpackPlugin = require('copy-webpack-plugin'); 9 var ExtractTextPlugin = require("extract-text-webpack-plugin"); 10 11 var inProduction = (process.env.NODE_ENV === 'production'); 12 13 module.exports = { 14 15 context: path.resolve('./src'), 16 17 entry: { 18 19 app: [ 20 21 './js/main.js' 22 23 ] 24 }, 25 26 output: { 27 28 path: path.resolve(__dirname,'./dist'), 29 30 filename: 'js/bundle.js', 31 32 publicPath: '/' 33 34 }, 35 36 module: { 37 loaders: [{ 38 test: /\.js$/, 39 loader: 'babel-loader', 40 exclude: /node_modules/, 41 query: { 42 presets: ['es2015'] 43 } 44 },{ 45 test: /\.html$/, 46 loader: 'html-loader' 47 },{ 48 test: /\.scss$/, 49 use: ExtractTextPlugin.extract({ 50 use: ["css-loader", "sass-loader"], 51 fallback: "style-loader" 52 }) 53 },{ 54 test: /\.css$/, 55 use: ExtractTextPlugin.extract({ 56 use: ["css-loader"], 57 fallback: "style-loader" 58 }) 59 },{ 60 test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, 61 loader: "url-loader?limit=10000&mimetype=application/font-woff&name=./fonts/[name].[ext]" 62 },{ 63 test: /\.(ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/, 64 loader: "file-loader?name=./fonts/[name].[ext]" 65 },{ 66 test: /\.(jpe?g|png|gif|svg)$/i, 67 loaders: [ 68 69 { 70 loader:'file-loader', 71 options: { 72 name: 'img/[name].[ext]' 73 } 74 75 }, 76 77 'img-loader' 78 79 ] 80 81 }] 82 }, 83 84 plugins: [ 85 new CleanWebpackPlugin(['dist']), 86 new HtmlWebpackPlugin({ 87 template: './index.html' 88 }), 89 new webpack.ProvidePlugin({ 90 $: 'jquery', 91 jQuery: 'jquery', 92 Tether: 'tether', 93 Popper: ['popper.js', 'default'] 94 }), 95 new BrowserSyncPlugin({ 96 server: { 97 baseDir: ['dist'] 98 }, 99 port: 3000, 100 host: 'localhost', 101 open: false 102 }), 103 new CopyWebpackPlugin([{ 104 from: './robots.txt' 105 },{ 106 from: './favicon.ico' 107 },{ 108 from: './*.png' 109 },{ 110 from: './*.xml' 111 },{ 112 from: './manifest.json' 113 },{ 114 from: './img/**/*', 115 to: './' 116 }]), 117 new ExtractTextPlugin("css/[name].css"), 118 new webpack.LoaderOptionsPlugin({ 119 minimize : inProduction 120 }) 121 ] 122 123 }; 124 125 126 if (process.env.NODE_ENV === 'production'){ 127 128 module.exports.plugins.push( 129 130 new webpack.optimize.UglifyJsPlugin() 131 132 ); 133 134 135 // module.exports.output.publicPath = "/ETHPrize/"; //To deploy to github pages - uncomment this 136 137 module.exports.output.filename = "js/bundle.[chunkhash].js"; 138 139 }