Created
March 22, 2016 23:37
-
-
Save icfantv/27e70134bf6cb51e87e1 to your computer and use it in GitHub Desktop.
Webpack FTW
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
import 'bootstrap/dist/css/bootstrap.css'; | |
import 'bootstrap/dist/css/bootstrap-theme.css'; | |
import 'font-awesome/css/font-awesome.css'; | |
import 'angular-ui-tree/dist/angular-ui-tree.css'; | |
import './main.css'; | |
import angular from 'angular'; | |
import ngAnimate from 'angular-animate'; | |
import ngSanitize from 'angular-sanitize'; | |
import ngRoute from 'angular-route'; | |
import ngMessages from 'angular-messages'; | |
import uiBootstrap from 'angular-ui-bootstrap'; | |
import uiTree from 'angular-ui-tree'; | |
// find all the HTML templates in the app and put them in the $templateCache | |
var templates = require.context('.', true, /^(?!\.\/index\.html).+\.html$/); | |
templates.keys().forEach(function(key) { | |
templates(key); | |
}); | |
import app from './core'; | |
import dashboard from './dashboard'; | |
import users from './users'; | |
angular.module('app', [ | |
ngAnimate, | |
ngSanitize, | |
ngRoute, | |
ngMessages, | |
uiBootstrap, | |
uiTree, | |
app, | |
dashboard, | |
users | |
]); | |
// bootstrap the angular application | |
angular.element(document).ready(function() { | |
angular.bootstrap(document.body, ['app'], { //eslint-disable-line angular/document-service | |
strictDi: true | |
}); | |
}); |
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
'use strict'; | |
const path = require('path'); | |
const CopyWebpackPlugin = require('copy-webpack-plugin'); | |
const ExtractTextPlugin = require("extract-text-webpack-plugin"); | |
const ENV = process.env.npm_lifecycle_event; | |
console.log(); | |
const isTestBuild = ENV === 'test'; | |
const isDevBuild = ENV === 'dev-build'; | |
const isProdBuild = ENV === 'build'; | |
const config = { | |
module: { | |
preloaders: [], | |
loaders: [{ | |
test: /\.js$/, | |
loader: 'babel', | |
exclude: /node_modules/ | |
}] | |
} | |
}; | |
if (isTestBuild) { | |
config.devtool = 'inline-source-map'; | |
config.entry = {}; | |
config.output = {}; | |
// code coverage config | |
config.module.preloaders.push({ | |
test: /\.js$/, | |
exclude: [ | |
/node_modules/, | |
/\.html\.js$/, | |
/\.spec\.js$/ | |
], | |
loader: 'isparta-instrumenter' | |
}); | |
} | |
if (isDevBuild || isProdBuild) { | |
config.devtool = isDevBuild ? 'eval-source-map' : 'source-map'; | |
config.entry = ['./src/app.js']; | |
config.output = { | |
path: path.join(__dirname, '/dist'), | |
filename: 'bundle.js' | |
}; | |
config.plugins = [ | |
new CopyWebpackPlugin([ | |
{ | |
from: 'src/index.html' | |
}, | |
{ | |
from: 'src/images' | |
} | |
]), | |
new ExtractTextPlugin("styles.css") | |
]; | |
config.eslint = { | |
configFile: './.eslintrc' | |
}; | |
config.module.loaders = [ | |
{ | |
test: /\.js$/, | |
loader: 'babel?presets[]=es2015', | |
exclude: /node_modules/ | |
}, | |
{ | |
test: /\.html$/, | |
loader: path.join('ngtemplate?relativeTo=', path.resolve(__dirname, './src'), '/!html') | |
}, | |
{ | |
test: /\.css$/, | |
loader: ExtractTextPlugin.extract("style-loader", "css-loader") | |
}, | |
{ | |
test: /\.png$/, | |
loader: 'url-loader?limit=100000' | |
}, | |
{ | |
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, | |
loader: 'url-loader?limit=10000&mimetype=application/font-woff' | |
}, | |
{ | |
test: /\.(ttf|otf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?|(jpg|gif)$/, | |
loader: 'file-loader' | |
} | |
]; | |
} | |
if (isDevBuild) { | |
console.log('**********************************************************************'); | |
console.log('* DEVELOPMENT BUILD *'); | |
console.log('**********************************************************************'); | |
} | |
if (isTestBuild) { | |
console.log('**********************************************************************'); | |
console.log('* TEST BUILD *'); | |
console.log('**********************************************************************'); | |
} | |
if (isProdBuild) { | |
console.log('**********************************************************************'); | |
console.log('* PRODUCTION BUILD *'); | |
console.log('**********************************************************************'); | |
// only do linting for production | |
// builds so we can do log debugging and other stuff | |
config.module.preLoaders.push({ | |
test: /\.js$/, | |
loader: 'eslint-loader', | |
include: path.join(__dirname, '/src'), | |
exclude: /node_modules/ | |
}); | |
} | |
module.exports = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment