diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 98b707f3..00000000 --- a/.babelrc +++ /dev/null @@ -1,14 +0,0 @@ -{ - "presets": ["es2015", "stage-0", "react"], - "env": { - "development": { - "presets": ["react-hmre"] - }, - "production": { - "presets": [] - }, - "test": { - "presets": [] - } - } -} diff --git a/karma.conf.js b/karma.conf.js deleted file mode 100644 index b863edeb..00000000 --- a/karma.conf.js +++ /dev/null @@ -1,40 +0,0 @@ -var argv = require('yargs').argv; -var path = require('path'); - -var webpackConfig = require('./webpack.config'); - -module.exports = function(config) { - config.set({ - basePath: '', - frameworks: ['mocha', 'chai'], - files: [ - 'tests.webpack.js' - ], - - preprocessors: { - // add webpack as preprocessor - 'tests.webpack.js': ['webpack', 'sourcemap'], - }, - - webpack: webpackConfig, - webpackServer: { - noInfo: true - }, - - plugins: [ - 'karma-mocha', - 'karma-chai', - 'karma-webpack', - 'karma-phantomjs-launcher', - 'karma-spec-reporter', - 'karma-sourcemap-loader' - ], - - reporters: ['spec'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - browsers: ['PhantomJS'], - singleRun: !argv.watch - }) -}; diff --git a/nwb.config.js b/nwb.config.js new file mode 100644 index 00000000..dda4d828 --- /dev/null +++ b/nwb.config.js @@ -0,0 +1,63 @@ +var path = require('path') + +var isDev = process.env.NODE_ENV === 'development' +var isTest = process.env.NODE_ENV === 'test' + +var config = { + type: 'react-app', + babel: { + stage: 0, + loose: 'all' + }, + webpack: { + define: { + __GAPI_KEY__: JSON.stringify('YOURAPIKEY') + }, + html: { + mountId: 'root', + title: 'yelp-clone from fullstackreact.com (with nwb)' + }, + loaders: { + css: { + modules: true, + localIdentName: (isDev ? '[path][name]__[local]__' : '') + '[hash:base64:5]' + } + }, + postcss: [ + require('precss'), + require('autoprefixer'), + require('cssnano') + ], + extra: { + resolve: { + alias: { + containers: path.resolve('src/containers'), + components: path.resolve('src/components'), + utils: path.resolve('src/utils'), + styles: path.resolve('src/styles') + } + } + } + } +} + +if (isTest) { + // Enable webpack compatibility tweaks + config.webpack.compat = { + enzyme: true, + sinon: true + } + + // Tweak Karma config + config.karma = { + tests: 'tests.webpack.js', + plugins: [ + require('karma-chai'), + require('karma-spec-reporter') + ], + frameworks: ['mocha', 'chai'], + reporters: ['spec'] + } +} + +module.exports = config diff --git a/package.json b/package.json index 52cd0037..ba538edb 100644 --- a/package.json +++ b/package.json @@ -3,61 +3,32 @@ "version": "1.0.0", "description": "", "scripts": { - "start": "cross-env NODE_ENV=development hjs-dev-server", - "clean": "rimraf dist", - "build": "npm run clean && cross-env NODE_ENV=production webpack", + "start": "nwb serve src/app.js", + "clean": "nwb clean-app", + "build": "nwb build src/app.js", "publish_pages": "gh-pages -d dist", "ghpages": "npm run build && npm run publish_pages", - "test": "cross-env NODE_ENV=test karma start karma.conf.js", - "test:watch": "npm run test -- --watch" + "test": "nwb test", + "test:watch": "nwb test --server" }, "author": "Ari Lerner (http://willcodeforfoo.com)", "license": "ISC", "devDependencies": { "autoprefixer": "^6.3.6", - "babel-core": "^6.7.7", - "babel-loader": "^6.2.4", - "babel-plugin-transform-es2015-modules-umd": "^6.8.0", - "babel-polyfill": "^6.7.4", - "babel-preset-es2015": "^6.6.0", - "babel-preset-react": "^6.5.0", - "babel-preset-react-hmre": "^1.1.1", - "babel-preset-stage-0": "^6.5.0", - "babel-register": "^6.7.2", "chai": "^3.5.0", "chai-enzyme": "^0.4.2", "cheerio": "^0.20.0", - "cross-env": "^1.0.8", - "css-loader": "^0.23.1", "cssnano": "^3.5.2", "dotenv": "^2.0.0", "enzyme": "^2.2.0", - "expect": "^1.18.0", - "file-loader": "^0.8.5", "gh-pages": "^0.11.0", - "hjs-webpack": "^8.1.0", - "jasmine-core": "^2.4.1", - "json-loader": "^0.5.4", - "karma": "^0.13.22", "karma-chai": "^0.1.0", - "karma-jasmine": "^0.3.8", - "karma-mocha": "^1.0.1", - "karma-phantomjs-launcher": "^1.0.0", - "karma-sourcemap-loader": "^0.3.7", "karma-spec-reporter": "0.0.26", - "karma-webpack": "^1.7.0", - "mocha": "^2.4.5", - "phantomjs-polyfill": "0.0.2", - "phantomjs-prebuilt": "^2.1.7", + "nwb": "0.11.0", "postcss-loader": "^0.9.1", "precss": "^1.4.0", - "prettyjson": "^1.1.3", "react-addons-test-utils": "^15.0.2", - "sinon": "^1.17.4", - "style-loader": "^0.13.1", - "url-loader": "^0.5.7", - "webpack": "^1.13.0", - "yargs": "^4.7.1" + "sinon": "^1.17.4" }, "dependencies": { "classnames": "^2.2.5", diff --git a/scripts/prepublish.sh b/scripts/prepublish.sh index 9defa4ec..45140adc 100755 --- a/scripts/prepublish.sh +++ b/scripts/prepublish.sh @@ -3,6 +3,6 @@ echo "=> Compiling..." echo "" rm -rf ./dist -NODE_ENV=production ./node_modules/.bin/webpack +./node_modules/.bin/nwb build echo "" echo "=> Complete" diff --git a/tests.webpack.js b/tests.webpack.js index 8babb0c8..897dcd3c 100644 --- a/tests.webpack.js +++ b/tests.webpack.js @@ -1,6 +1,3 @@ -require('babel-polyfill'); -// some setup first - var chai = require('chai'); var chaiEnzyme = require('chai-enzyme'); diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 1124c3dd..00000000 --- a/webpack.config.js +++ /dev/null @@ -1,136 +0,0 @@ -const NODE_ENV = process.env.NODE_ENV; -const dotenv = require('dotenv'); - -const webpack = require('webpack'); -const fs = require('fs'); -const path = require('path'), - join = path.join, - resolve = path.resolve; - -const getConfig = require('hjs-webpack'); - -const isDev = NODE_ENV === 'development'; -const isTest = NODE_ENV === 'test'; - -const root = resolve(__dirname); -const src = join(root, 'src'); -const modules = join(root, 'node_modules'); -const dest = join(root, 'dist'); - -var config = getConfig({ - isDev: isDev, - in: join(src, 'app.js'), - out: dest, - html: function (context) { - return { - 'index.html': context.defaultTemplate({ - title: 'yelp-clone from fullstackreact.com', - publicPath: isDev ? 'http://localhost:3000/' : '', - meta: { - 'name': 'fullstackreact yelp clone', - 'description': 'A minimal yelp clone from the team behind the fullstackreact.com book' - } - }) - } - } -}); - -// ENV variables -const dotEnvVars = dotenv.config(); -const environmentEnv = dotenv.config({ - path: join(root, 'config', `${NODE_ENV}.config.js`), - silent: true, -}); -const envVariables = - Object.assign({}, dotEnvVars, environmentEnv); - -const defines = - Object.keys(envVariables) - .reduce((memo, key) => { - const val = JSON.stringify(envVariables[key]); - memo[`__${key.toUpperCase()}__`] = val; - return memo; - }, { - __NODE_ENV__: JSON.stringify(NODE_ENV) - }); - -config.plugins = [ - new webpack.DefinePlugin(defines) -].concat(config.plugins); -// END ENV variables - -// CSS modules -const cssModulesNames = `${isDev ? '[path][name]__[local]__' : ''}[hash:base64:5]`; - -const matchCssLoaders = /(^|!)(css-loader)($|!)/; - -const findLoader = (loaders, match) => { - const found = loaders.filter(l => l && l.loader && l.loader.match(match)) - return found ? found[0] : null; -} -// existing css loader -const cssloader = - findLoader(config.module.loaders, matchCssLoaders); - -const newloader = Object.assign({}, cssloader, { - test: /\.module\.css$/, - include: [src], - loader: cssloader.loader.replace(matchCssLoaders, `$1$2?modules&localIdentName=${cssModulesNames}$3`) -}) -config.module.loaders.push(newloader); -cssloader.test = new RegExp(`[^module]${cssloader.test.source}`) -cssloader.loader = newloader.loader - -config.module.loaders.push({ - test: /\.css$/, - include: [modules], - loader: 'style!css' -}) -// CSS modules - -// postcss -config.postcss = [].concat([ - require('precss')({}), - require('autoprefixer')({}), - require('cssnano')({}) -]) -// END postcss - -// Roots -config.resolve.root = [src, modules] -config.resolve.alias = { - 'css': join(src, 'styles'), - 'containers': join(src, 'containers'), - 'components': join(src, 'components'), - 'utils': join(src, 'utils'), - - 'styles': join(src, 'styles') -} -// end Roots - -// console.log(require('prettyjson').render(config)); - -// Testing -if (isTest) { - config.externals = { - 'react/addons': true, - 'react/lib/ReactContext': true, - 'react/lib/ExecutionEnvironment': true, - } - config.module.noParse = /[/\\]sinon\.js/; - config.resolve.alias['sinon'] = 'sinon/pkg/sinon'; - - config.plugins = config.plugins.filter(p => { - const name = p.constructor.toString(); - const fnName = name.match(/^function (.*)\((.*\))/) - - const idx = [ - 'DedupePlugin', - 'UglifyJsPlugin' - ].indexOf(fnName[1]); - return idx < 0; - }) -} -// End Testing - -module.exports = config;