Last active
December 28, 2017 09:39
-
-
Save YonatanKra/2a5deb5acf20f94c2bcd7acffca59fa7 to your computer and use it in GitHub Desktop.
webpack basic configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require('path'); | |
| const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
| const webpack = require('webpack'); | |
| const CleanWebpackPlugin = require('clean-webpack-plugin'); | |
| const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); | |
| module.exports = { | |
| entry: './src/app.js', // this is our app | |
| output: { | |
| filename: '[name].bundle.js', // the file name would be my entry's name with a ".bundle.js" suffix | |
| path: path.resolve(__dirname, 'dist') // put all of the build in a dist folder | |
| }, | |
| plugins: [ | |
| new UglifyJsPlugin({ | |
| sourceMap: true | |
| }), | |
| new CleanWebpackPlugin(['dist']), // use the clean plugin to delete the dist folder before a build | |
| // This plugin creates our index.html that would load the app for us in the browser | |
| new HtmlWebpackPlugin({ | |
| title: 'Your Phrase Fireworks!' | |
| }) | |
| ], | |
| module: { | |
| rules: [ | |
| // use the html loader | |
| { | |
| test: /\.html$/, | |
| exclude: /node_modules/, | |
| use: {loader: 'html-loader'} | |
| }, | |
| // use the css loaders (first load the css, then inject the style) | |
| { | |
| test: /\.css$/, | |
| use: [ | |
| 'style-loader', | |
| 'css-loader' | |
| ] | |
| }, | |
| // use babel to be able to use es6 and es7 in older browsers | |
| { | |
| test: /\.js$/, | |
| exclude: /(node_modules|bower_components)/, | |
| use: { | |
| loader: 'babel-loader', | |
| options: { | |
| presets: ['@babel/preset-env'] | |
| } | |
| } | |
| } | |
| ] | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment