-
-
Save slopeofhope81/844ed6ec99452c32c951e7ffeac0288b to your computer and use it in GitHub Desktop.
webpack config
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
//require("babel-register"); | |
//module.exports = require("./webpack.config.babel"); | |
import webpack from "webpack"; | |
import path from 'path'; | |
import CleanWebpackPlugin from 'clean-webpack-plugin'; | |
import HtmlWebpackPlugin from "html-webpack-plugin"; | |
const PATHS = { | |
src: path.join(__dirname, 'src'), | |
build: path.join(__dirname, 'static/build'), | |
font: path.join(__dirname, 'font') | |
}; | |
export default { | |
context: PATHS.src, | |
debug: true, | |
devtool: 'inline-source-map', | |
noInfo: false, | |
entry: [ | |
path.resolve(__dirname, 'src/index') | |
], | |
target: 'web', | |
output: { | |
path: path.resolve(__dirname, 'src'), | |
publicPath: '/', //static/build/ | |
filename: 'bundle.js' | |
}, | |
plugins: [ | |
// environmental variables to pass to client, e.g. process.env.API_URL | |
new webpack.DefinePlugin({ | |
'process.env': { | |
'NODE_ENV': JSON.stringify(process.env.NODE_ENV), | |
} | |
}), | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: "vendors" | |
}), | |
new CleanWebpackPlugin([PATHS.build], { | |
root: process.cwd() | |
}), | |
new HtmlWebpackPlugin({ | |
inject: true, | |
chunks: ["static_bundle", "vendors", "unsupported-browser"], | |
template: "views/static.html", | |
filename: "static_built.html" | |
}), | |
], | |
module: { | |
module: { | |
// noParse: /node_modules\/json-schema\/lib\/validate\.js/, | |
rules: [ | |
// js and jsx | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
use: ['babel-loader'] | |
}, | |
// scss | |
{ | |
test: /\.scss|.css$/, | |
use: [ | |
'style-loader', | |
'css-loader', | |
'sass-loader' | |
] | |
}, | |
// images; inline small images as DATAUrls | |
{ | |
test: /\.(jpg|jpeg|png|gif)$/, | |
use: [ | |
// { | |
// loader: 'url-loader', | |
// | |
// options: { | |
// limit: 8000 | |
// } | |
// }, | |
{ | |
loader: 'file-loader', | |
options: { | |
name: '[path][name]-[hash:8].[ext]' | |
}, | |
}, | |
] | |
}, | |
// fonts | |
{ | |
test: /\.(eot|svg|ttf|otf|woff|woff2)$/, | |
include: PATHS.font, | |
use: ['file-loader'] | |
} | |
] | |
}, | |
resolve: { | |
modules: [ | |
__dirname, | |
"node_modules" | |
], | |
// these make the path readable and easy to modify | |
alias: { | |
Actions: 'src/_actions', | |
Components: 'src/_components', | |
Config: 'src/_config/', | |
Images: 'src/_images/', | |
Styles: 'src/_styles', | |
Utils: 'src/_utils' | |
} | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment