Created
July 25, 2017 04:16
-
-
Save astrotim/d701c82f5f477758d4ac85d372df1bfb to your computer and use it in GitHub Desktop.
Builds site as client side app and runs with Webpack dev server
This file contains 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 webpack = require('webpack'); | |
const CopyWebpackPlugin = require('copy-webpack-plugin'); | |
module.exports = { | |
entry: { | |
bundle: path.resolve(__dirname, 'src', 'client.js'), | |
scripts: path.resolve(__dirname, 'src', 'scripts.js') | |
}, | |
output: { | |
path: path.resolve(__dirname, 'dist'), | |
filename: '[name].js', | |
libraryTarget: 'umd' | |
}, | |
plugins: [ | |
new CopyWebpackPlugin([ | |
{ | |
from: path.resolve(__dirname, 'src', 'index.html'), | |
to: path.resolve(__dirname, 'dist') | |
}, | |
{ | |
from: path.resolve(__dirname, 'fonts'), | |
to: path.resolve(__dirname, 'dist') | |
} | |
]) | |
], | |
devServer: { | |
contentBase: path.resolve(__dirname, 'dist'), | |
port: 3000, | |
historyApiFallback: true | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
include: [path.resolve(__dirname, 'src')], | |
use: { | |
loader: 'babel-loader', | |
options: { | |
presets: ['react', 'es2015'] | |
} | |
} | |
}, | |
{ | |
test: /\.(css|scss)$/, | |
use: [ | |
{ | |
loader: 'style-loader' | |
}, | |
{ | |
loader: 'css-loader', | |
options: { | |
modules: true, | |
camelCase: true, | |
localIdentName: '[name]__[local]--[hash:base64:5]' | |
} | |
}, | |
{ | |
loader: 'postcss-loader', | |
options: { | |
plugins: [require('autoprefixer')] | |
} | |
}, | |
{ | |
loader: 'sass-loader' | |
} | |
] | |
}, | |
{ | |
test: /\.(woff|woff2)$/, | |
use: { | |
loader: 'file-loader?name=fonts/[name].[ext]' | |
} | |
} | |
] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment