Skip to content

Commit

Permalink
refactor(build): use node 6 compat (no babel-node)
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Jul 1, 2016
1 parent 71d93f7 commit 0e5593f
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 74 deletions.
31 changes: 13 additions & 18 deletions build/karma.conf.babel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { argv } from 'yargs'

import config from '../config'
import webpackConfig from './webpack.config'
const { argv } = require('yargs')
const config = require('../config')
const webpackConfig = require('./webpack.config')

const { paths } = config

Expand Down Expand Up @@ -42,23 +41,19 @@ module.exports = (karmaConfig) => {
},
webpack: {
devtool: 'cheap-module-source-map',
module: {
...webpackConfig.module,
module: Object.assign({}, webpackConfig.module, {
loaders: [
{
test: /sinon\.js$/,
loader: 'imports?define=>false,require=>false',
},
...webpackConfig.module.loaders,
],
},
plugins: [
...webpackConfig.plugins,
],
resolve: {
...webpackConfig.resolve,
alias: {
...webpackConfig.resolve.alias,
].concat(
webpackConfig.module.loaders
),
}),
plugins: webpackConfig.plugins,
resolve: Object.assign({}, webpackConfig.resolve, {
alias: Object.assign({}, webpackConfig.resolve.alias, {
jquery: `${paths.test('mocks')}/SemanticjQuery-mock.js`,
sinon: 'sinon/pkg/sinon',
// These are internal deps specific to React 0.13 required() by enzyme
Expand All @@ -69,8 +64,8 @@ module.exports = (karmaConfig) => {
// this is a React 0.13 dep required by enzyme
// ignore it since we don't have it
'react/addons': 'empty/object',
},
},
}),
}),
},
webpackServer: {
progress: false,
Expand Down
44 changes: 19 additions & 25 deletions build/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import config from '../config'
import webpack from 'webpack'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import _ from 'lodash'
import yargs from 'yargs'
const config = require('../config')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const _ = require('lodash')
const yargs = require('yargs')
const { argv } = yargs

const { paths } = config
Expand All @@ -27,7 +27,7 @@ const webpackConfig = {

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

export const webpackHotMiddlewareEntry = `webpack-hot-middleware/client?${_.map({
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.
Expand All @@ -36,19 +36,18 @@ export const webpackHotMiddlewareEntry = `webpack-hot-middleware/client?${_.map(
quiet: false, // Set to true to disable all console logging.
}, (val, key) => `&${key}=${val}`).join('')}`

const APP_ENTRY = [
paths.docsSrc('index.js'),
]
const APP_ENTRY = paths.docsSrc('index.js')

webpackConfig.entry = __DEV__ ? {
app: [
webpackHotMiddlewareEntry,
...APP_ENTRY,
APP_ENTRY,
],
vendor: [
webpackHotMiddlewareEntry,
...config.compiler_vendor,
],
].concat(
config.compiler_vendor
),
} : {
app: APP_ENTRY,
vendor: config.compiler_vendor,
Expand Down Expand Up @@ -100,7 +99,7 @@ webpackConfig.plugins = [
if (__DEV__) {
webpackConfig.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.NoErrorsPlugin()
)
} else if (!__TEST__) {
webpackConfig.plugins.push(
Expand Down Expand Up @@ -164,8 +163,7 @@ webpackConfig.module.loaders = [{
// For faster builds in dev, rely on prebuilt libraries
// Local modules can still be enabled (ie for offline development)
if (argv.localModules) {
webpackConfig.module.loaders = [
...webpackConfig.module.loaders,
webpackConfig.module.loaders = webpackConfig.module.loaders.concat([
{
//
// SASS
Expand All @@ -179,27 +177,23 @@ if (argv.localModules) {
test: /\.(eot|ttf|woff|woff2|svg|png)$/,
loader: 'file',
},
]
])
} else {
webpackConfig.module.noParse = [
...webpackConfig.module.noParse,
webpackConfig.module.noParse = webpackConfig.module.noParse.concat([
/jquery/,
/semantic-ui-css\/semantic\.js/,
/semantic-ui-css\/semantic\.css/,
]

webpackConfig.resolve.alias = {
...webpackConfig.resolve.alias,
])
webpackConfig.resolve.alias = Object.assign({}, webpackConfig.resolve.alias, {
'semantic-ui-css/semantic.js': 'empty',
'semantic-ui-css/semantic.css': 'empty',
'highlight.js/styles/github.css': 'empty',
}

})
webpackConfig.externals = {
jquery: 'jQuery',
faker: 'faker',
lodash: '_',
}
}

export default webpackConfig
module.exports = webpackConfig
11 changes: 5 additions & 6 deletions build/webpack.dll.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import webpack from 'webpack'
const webpack = require('webpack')

import config from '../config'
const config = require('../config')
const webpackDllConfig = { module: {} }

const { paths } = config
Expand All @@ -15,12 +15,11 @@ webpackDllConfig.entry = {
// ------------------------------------
// Bundle Output
// ------------------------------------
webpackDllConfig.output = {
...webpackDllConfig.output,
webpackDllConfig.output = Object.assign({}, webpackDllConfig.output, {
path: 'dll',
filename: `dll.[name].[${config.compiler_hash_type}].js`,
library: '[name]_[hash]',
}
})

// ------------------------------------
// Plugins
Expand Down Expand Up @@ -60,4 +59,4 @@ webpackDllConfig.module.loaders = [{
loader: 'file',
}]

export default webpackDllConfig
module.exports = webpackDllConfig
13 changes: 7 additions & 6 deletions config/_default.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import path from 'path'
import { argv } from 'yargs'
const path = require('path')
const yargs = require('yargs')

const { argv } = yargs

const env = process.env.NODE_ENV || 'development'
const __DEV__ = env === 'development'
Expand Down Expand Up @@ -38,8 +40,7 @@ const paths = {
docsSrc: base.bind(null, config.dir_docs_src),
}

config = {
...config,
config = Object.assign({}, config, {
paths,

// ----------------------------------
Expand Down Expand Up @@ -115,6 +116,6 @@ config = {
dir: 'coverage',
},
],
}
})

export default config
module.exports = config
7 changes: 3 additions & 4 deletions config/development.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
export default (config) => {
module.exports = (config) => {
// We use an explicit public path in development to resolve this issue:
// http://stackoverflow.com/questions/34133808/webpack-ots-parsing-error-loading-fonts/34133809#34133809
const __BASE__ = `http://${config.server_host}:${config.server_port}/`

return {
compiler_devtool: 'eval-cheap-module-source-map',
compiler_public_path: __BASE__,
compiler_globals: {
...config.compiler_globals,
compiler_globals: Object.assign({}, config.compiler_globals, {
__BASE__: JSON.stringify(__BASE__),
},
}),
}
}
7 changes: 4 additions & 3 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base from './_default'
const base = require('./_default')

const envConfig = require(`./${base.env}`).default(base)
const envConfig = require(`./${base.env}`)(base)

export default { ...base, ...envConfig }

module.exports = Object.assign({}, base, envConfig)
7 changes: 3 additions & 4 deletions config/production.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const __BASE__ = '/stardust/'

export default (config) => ({
module.exports = (config) => ({
compiler_fail_on_warning: true,
compiler_hash_type: 'chunkhash',
compiler_devtool: false,
compiler_public_path: __BASE__,
compiler_globals: {
...config.compiler_globals,
compiler_globals: Object.assign({}, config.compiler_globals, {
__BASE__: JSON.stringify(__BASE__),
},
}),
})
4 changes: 2 additions & 2 deletions config/staging.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from './production'
const config = require('./production')

// Enable source-maps in staging
config.compiler_devtool = 'source-map'

export default config
module.exports = config
4 changes: 2 additions & 2 deletions config/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Just use the production configuration
import production from './production'
const production = require('./production')

export default production
module.exports = production
2 changes: 1 addition & 1 deletion gulp/tasks/dll.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const g = loadPlugins()
const { log, PluginError } = g.util

task('dll', (cb) => {
const webpackDLLConfig = require('../../build/webpack.dll').default
const webpackDLLConfig = require('../../build/webpack.dll')
const compiler = webpack(webpackDLLConfig)

compiler.run((err, stats) => {
Expand Down
2 changes: 1 addition & 1 deletion gulp/tasks/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ task('generate-docs-json', () => {
})

task('webpack-docs', (cb) => {
const webpackConfig = require('../../build/webpack.config').default
const webpackConfig = require('../../build/webpack.config')
const compiler = webpack(webpackConfig)

compiler.run((err, stats) => {
Expand Down
2 changes: 1 addition & 1 deletion gulp/tasks/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const g = loadPlugins()
const { log, colors } = g.util

const serve = (cb) => {
const webpackConfig = require('../../build/webpack.config').default
const webpackConfig = require('../../build/webpack.config')
const app = express()
const compiler = webpack(webpackConfig)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"start": "npm run docs",
"start:local-modules": "npm run docs -- --local-modules",
"pretest": "gulp dll",
"test": "NODE_ENV=test babel-node $(npm bin)/karma start build/karma.conf.babel.js",
"test": "NODE_ENV=test karma start build/karma.conf.babel.js",
"test:watch": "npm run test --silent -- --watch"
},
"repository": {
Expand Down

0 comments on commit 0e5593f

Please sign in to comment.