Created
June 13, 2016 19:18
-
-
Save mitchell-garcia/ad0aeaa168e7bfee57f92792289b229e to your computer and use it in GitHub Desktop.
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
// most literally copied from https://github.com/preboot/angular-webpack/blob/master/webpack.config.js - view for reference | |
var webpack = require('webpack'); | |
var autoprefixer = require('autoprefixer'); | |
var HtmlWebpackPlugin = require('html-webpack-plugin'); | |
var ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
var CopyWebpackPlugin = require('copy-webpack-plugin'); | |
/** | |
* Env | |
* Get npm lifecycle event to identify the environment | |
*/ | |
var ENV = process.env.npm_lifecycle_event; | |
var isTest = ENV === 'test' || ENV === 'test-watch'; | |
var isProd = ENV === 'build'; | |
/** | |
* Plugin that copies HTML file into the dist folder during webpack build. | |
*/ | |
var HtmlWebpackPlugin = require('html-webpack-plugin'); | |
var HtmlWebpackPluginConfig = { | |
title: 'Consumption Trackr', | |
template: __dirname + '/client/index.ejs' | |
}; | |
/** | |
* NEEDS TO | |
* - Minify and Build | |
* - ngConstant | |
* - ng-annotate | |
* - unit tests | |
* - dom-munger | |
* - ng-templates | |
* - css | |
* - cleans tmp/cache | |
* - serve & watch | |
*/ | |
/** | |
* Bourbon and Bourbon Neat node packages export an array | |
* of file paths to inlude in project. Use with Webpack | |
* sass loader to have all bourbon + neat mixins included globally. | |
*/ | |
var bourbonPaths = require('bourbon').includePaths; | |
var neatPaths = require('bourbon-neat').includePaths; | |
module.exports = function makeWebpackConfig () { | |
/** | |
* Config | |
* Reference: http://webpack.github.io/docs/configuration.html | |
* This is the object where all configuration gets set | |
*/ | |
var config = {}; | |
config.entry = [ | |
'webpack-dev-server/client?http://localhost:8080', // WebpackDevServer host and port | |
__dirname + '/client/app/app.js' // Your appʼs entry point | |
]; | |
/** | |
* Devtool | |
* Reference: http://webpack.github.io/docs/configuration.html#devtool | |
* Type of sourcemap to use per build type | |
*/ | |
if (isTest) { | |
config.devtool = 'inline-source-map'; | |
} else if (isProd) { | |
config.devtool = 'source-map'; | |
} | |
config.resolve = { | |
'modulesDirectories' : ['node_modules', 'client', 'assets'] | |
}; | |
config.output = { | |
path: __dirname + "/dist", | |
filename: "bundle.js", | |
publicPath: "/" | |
}; | |
/** | |
* Dev server configuration | |
* Reference: http://webpack.github.io/docs/configuration.html#devserver | |
* Reference: http://webpack.github.io/docs/webpack-dev-server.html | |
*/ | |
config.devServer = { | |
contentBase: './dist', | |
stats: 'minimal' | |
}; | |
config.module = { | |
preLoaders: [], | |
loaders: [{ | |
// JS LOADER | |
// Reference: https://github.com/babel/babel-loader | |
// Transpile .js files using babel-loader | |
// Compiles ES6 and ES7 into ES5 code | |
test: /\.js$/, | |
loader: 'babel', | |
exclude: /node_modules/, | |
query: { | |
presets: ['es2015'] | |
} | |
}, { | |
// CSS LOADER | |
// Reference: https://github.com/webpack/css-loader | |
// Allow loading css through js | |
// | |
// Reference: https://github.com/postcss/postcss-loader | |
// Postprocess your css with PostCSS plugins | |
test: /\.css$/, | |
// Reference: https://github.com/webpack/extract-text-webpack-plugin | |
// Extract css files in production builds | |
// | |
// Reference: https://github.com/webpack/style-loader | |
// Use style-loader in development. | |
loader: isTest ? 'null' : ExtractTextPlugin.extract('style', 'css?sourceMap!postcss') | |
}, { | |
// ASSET LOADER | |
// Reference: https://github.com/webpack/file-loader | |
// Copy png, jpg, jpeg, gif, svg, woff, woff2, ttf, eot files to output | |
// Rename the file using the asset hash | |
// Pass along the updated reference to your code | |
// You can add here any file extension you want to get copied to your output | |
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/, | |
loader: 'file' | |
}, { | |
// HTML LOADER | |
// Reference: https://github.com/webpack/raw-loader | |
// Allow loading html through js | |
test: /\.html$/, | |
loader: 'raw' | |
}] | |
}; | |
// ISPARTA LOADER | |
// Reference: https://github.com/ColCh/isparta-instrumenter-loader | |
// Instrument JS files with Isparta for subsequent code coverage reporting | |
// Skips node_modules and files that end with .test.js | |
if (isTest) { | |
config.module.preLoaders.push({ | |
test: /\.js$/, | |
exclude: [ | |
/node_modules/, | |
/\.spec\.js$/ | |
], | |
loader: 'isparta-instrumenter' | |
}) | |
} | |
/** | |
* PostCSS | |
* Reference: https://github.com/postcss/autoprefixer-core | |
* Add vendor prefixes to your css | |
*/ | |
config.postcss = [ | |
autoprefixer({ | |
browsers: ['last 2 version'] | |
}) | |
]; | |
config.plugins = [new HtmlWebpackPlugin(HtmlWebpackPluginConfig)]; | |
return config; | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment