Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Commit

Permalink
* Load .babelrc if one is found and merge with reactpack babel settings.
Browse files Browse the repository at this point in the history
* Use absolute path with dev server.
* Add option to not inject bundles `--no-inject`.
* Add option to inject bundles with absolute path `--absolute-path`.

close #18, close #19
  • Loading branch information
Ola Holmström committed Jun 19, 2016
1 parent 16f7cd6 commit 8848892
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 2016-06-20 (0.6.0)

* Load .babelrc if one is found and merge with reactpack babel settings.
* Use absolute path with dev server.
* Add option to not inject bundles `--no-inject`.
* Add option to inject bundles with absolute path `--absolute-path`.

# 2016-06-13 (0.5.1)

* Force `process.env.NODE_ENV` to equal `production` when optimizing.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ for generating html. The default `index.ejs` looks like:
-p, --port <port> port for dev server (default is 8000)
--standard force standard linting (do not look for eslint config)
--clean delete everything in bundle path before building
--absolute-path use absolute path for assets
--no-source-map don't output source maps for css and js
--no-postcss don't use postcss (autoprefixer and precss)
--no-html don't output an index.html
--no-extract don't extract css into separate bundle
--no-lint turn off linting
--no-env don't try and load .env.js file
--no-inject don't inject bundles into index.html
```

## Tested on
Expand Down
6 changes: 5 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ program
.option('-p, --port <port>', 'port for dev server (default is 8000)', parseInt)
.option('--standard', 'force standard linting (do not look for eslint config)')
.option('--clean', 'delete everything in bundle path before building')
.option('--absolute-path', 'use absolute path for assets')
.option('--no-source-map', 'don\'t output source maps for css and js')
.option('--no-postcss', 'don\'t use postcss (autoprefixer and precss)')
.option('--no-html', 'don\'t output an index.html')
.option('--no-extract', 'don\'t extract css into separate bundle')
.option('--no-lint', 'turn off linting')
.option('--no-env', 'don\'t try and load .env.js file')
.option('--no-inject', 'don\'t inject bundles into index.html')
.arguments('<entry> [path/to/bundle]')

program.parse(process.argv)
Expand Down Expand Up @@ -67,7 +69,9 @@ var webpackConfig = config({
clean: program.clean,
standard: program.standard,
extract: program.extract,
env: program.env
env: program.env,
inject: program.inject,
absolutePath: program.absolutePath
})

if (!program.quiet) {
Expand Down
48 changes: 36 additions & 12 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ var HtmlWebpackPlugin = require('html-webpack-plugin')
var WebpackCleanupPlugin = require('webpack-cleanup-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var eslintrcUp = require('eslintrc-up')
var findUp = require('find-up')
var merge = require('lodash.merge')

module.exports = function (options) {
options = options || {}
Expand All @@ -21,6 +23,7 @@ module.exports = function (options) {
var bundleName = bundleBasename.split('.').slice(0, -1).join('.')

var eslintConf = eslintrcUp.sync({cwd: process.cwd()})
var babelRc = findUp.sync('.babelrc', {cwd: process.cwd()})

var config = {
entry: entry,
Expand All @@ -39,6 +42,10 @@ module.exports = function (options) {
config.devtool = 'source-map'
}

if (options.dev || options.absolutePath) {
config.output.publicPath = '/'
}

config._msgs = []

var preLoaders = []
Expand Down Expand Up @@ -73,17 +80,37 @@ module.exports = function (options) {
}
}

var babelLoaderQuery = {
presets: [
'babel-preset-es2015',
'babel-preset-react',
'babel-preset-stage-0'
].map(require.resolve)
}

if (babelRc) {
try {
var babelRcData = fs.readFileSync(babelRc, 'utf8')
var babelRcQuery = JSON.parse(babelRcData)
config._msgs.push(util.format(
'Using babel config (%s)',
path.relative(process.cwd(), babelRc)
))
babelLoaderQuery = merge(babelLoaderQuery, babelRcQuery)
} catch (e) {
config._msgs.push(util.format(
'Error loading babel config (%s): %s',
path.relative(process.cwd(), babelRc),
e.message
))
}
}

loaders.push({
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: [
'babel-preset-es2015',
'babel-preset-react',
'babel-preset-stage-0'
].map(require.resolve)
}
query: babelLoaderQuery
})

loaders.push({
Expand Down Expand Up @@ -141,10 +168,6 @@ module.exports = function (options) {
path.relative(process.cwd(), envfile)
))
} catch (e) {
config._msgs.push(util.format(
'No custom environments found in root of entrypoint (%s).',
path.relative(process.cwd(), envfile)
))
}
}

Expand Down Expand Up @@ -187,7 +210,8 @@ module.exports = function (options) {
title: 'Reactpack App',
dev: options.dev,
port: options.port,
template: template
template: template,
inject: options.inject
}))
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reactpack",
"version": "0.5.1",
"version": "0.6.0",
"description": "One command to build your React frontend.",
"bin": "cli.js",
"main": "index.js",
Expand Down Expand Up @@ -41,8 +41,10 @@
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.8.5",
"filesize": "^3.3.0",
"find-up": "^1.1.2",
"html-webpack-plugin": "^2.18.0",
"json-loader": "^0.5.4",
"lodash.merge": "^4.4.0",
"lodash.padleft": "^3.1.3",
"lodash.padright": "^3.1.3",
"log-update": "^1.0.2",
Expand Down

0 comments on commit 8848892

Please sign in to comment.