Skip to content

Commit

Permalink
chore(build): rewrite build system
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Mar 29, 2016
1 parent a5acee5 commit 280d97f
Show file tree
Hide file tree
Showing 37 changed files with 573 additions and 587 deletions.
3 changes: 0 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
"es2015",
"react",
"stage-1"
],
"plugins": [
"add-module-exports"
]
}
34 changes: 0 additions & 34 deletions ENV.js

This file was deleted.

65 changes: 65 additions & 0 deletions build/karma.conf.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { argv } from 'yargs'
import config from '../config'
import webpackConfig from './webpack.config'
const { paths } = config

module.exports = (karmaConfig) => {
karmaConfig.set({
basePath: process.cwd(),
browsers: ['PhantomJS'],
singleRun: !argv.watch,
reporters: ['mocha'],
files: [
'./node_modules/babel-polyfill/dist/polyfill.js',
'./node_modules/phantomjs-polyfill/bind-polyfill.js',
'./test/tests.bundle.js',
],
frameworks: ['mocha'],
preprocessors: {
'**/*.bundle.js': ['webpack', 'sourcemap'],
},
client: {
mocha: {
reporter: 'html', // change Karma's debug.html to mocha web reporter
ui: 'bdd',
},
},
webpack: {
devtool: 'inline-source-map',
module: {
...webpackConfig.module,
loaders: [
{
test: /sinon\.js$/,
loader: 'imports?define=>false,require=>false',
},
{
test: /\.js$/,
loaders: ['babel', 'eslint'],
exclude: paths.base('node_modules'),
},
{
test: /\.json$/,
loaders: ['json'],
exclude: paths.base('node_modules'),
},
],
},
resolve: {
...webpackConfig.resolve,
alias: {
...webpackConfig.resolve.alias,
jquery: `${paths.test('mocks')}/SemanticjQuery-mock.js`,
sinon: 'sinon/pkg/sinon',
},
},
},
webpackServer: {
progress: false,
stats: config.compiler_stats,
debug: true,
noInfo: false,
quiet: false,
},
})
}
168 changes: 168 additions & 0 deletions build/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import config from '../config'
import webpack from 'webpack'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import _ from 'lodash'

const { paths } = config
const { __DEV__, __TEST__ } = config.compiler_globals

const webpackConfig = {
name: 'client',
target: 'web',
devtool: config.compiler_devtool,
resolve: {
root: paths.base(),
alias: {
stardust: paths.src('index.js'),
},
},
externals: {
bluebird: 'Promise',
faker: 'faker',
jquery: 'jQuery',
lodash: '_',
},
module: {},
}

// ------------------------------------
// Entry Points
// ------------------------------------

const webpackHotPath = `${config.compiler_public_path}__webpack_hmr`

const webpackHotMiddlewareEntry = 'webpack-hot-middleware/client?' + _.map({
path: webpackHotPath, // The path which the middleware is serving the event stream on
timeout: 2000, // The time to wait after a disconnection before attempting to reconnect
overlay: true, // Set to false to disable the DOM-based client-side overlay.
reload: true, // Set to true to auto-reload the page when webpack gets stuck.
noInfo: false, // Set to true to disable informational console logging.
quiet: false, // Set to true to disable all console logging.
}, (val, key) => `&${key}=${val}`).join('')

const APP_ENTRY = paths.docsSrc('DocsApp.js')

webpackConfig.entry = {
app: __DEV__
? [webpackHotMiddlewareEntry, APP_ENTRY]
: [APP_ENTRY],
vendor: [
webpackHotMiddlewareEntry,
'babel-polyfill',
...config.compiler_vendor,
],
}

// ------------------------------------
// Bundle Output
// ------------------------------------
webpackConfig.output = {
filename: `[name].[${config.compiler_hash_type}].js`,
path: config.compiler_output_path,
publicPath: config.compiler_public_path,
pathinfo: true,
}

// ------------------------------------
// Plugins
// ------------------------------------
webpackConfig.plugins = [
new webpack.DefinePlugin(config.compiler_globals),
new HtmlWebpackPlugin({
template: paths.docsSrc('index.html'),
hash: false,
filename: 'index.html',
inject: 'body',
minify: {
collapseWhitespace: true,
},
}),
]

if (__DEV__) {
webpackConfig.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
)
} else if (!__TEST__) {
webpackConfig.plugins.push(
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
unused: true,
dead_code: true,
warnings: false,
},
})
)
}

// Don't split bundles during testing, since we only want import one bundle
if (!__TEST__) {
webpackConfig.plugins.push(new webpack.optimize.CommonsChunkPlugin({
names: ['vendor'],
}))
}

// ------------------------------------
// No Parse
// ------------------------------------
webpackConfig.module.noParse = [
/autoit.js/, // highlight.js dep throws if parsed
]

// ------------------------------------
// Pre-Loaders
// ------------------------------------
webpackConfig.module.preLoaders = [{
test: /\.js$/,
loader: 'eslint',
exclude: /node_modules/,
}]

webpackConfig.eslint = {
configFile: paths.base('.eslintrc'),
emitWarning: __DEV__,
}

// ------------------------------------
// Loaders
// ------------------------------------
webpackConfig.module.loaders = [{
//
// Babel
//
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: {
cacheDirectory: true,
plugins: [],
presets: ['es2015', 'react', 'stage-1'],
env: {
development: {
plugins: [
['react-transform', {
transforms: [{
transform: 'react-transform-hmr',
imports: ['react'],
locals: ['module'],
}, {
transform: 'react-transform-catch-errors',
imports: ['react', 'redbox-react'],
}],
}],
],
},
},
},
}, {
//
// JSON
//
test: /\.json$/,
loader: 'json',
}]

export default webpackConfig
6 changes: 1 addition & 5 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ general:

machine:
node:
version: 4.2.1
version: 5

dependencies:
pre:
- echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- npm install -g npm@3

test:
post:
- nvm install 5 && npm test

deployment:
development:
branch: /^(?!master).*$/
Expand Down
Loading

0 comments on commit 280d97f

Please sign in to comment.