Skip to content

Commit

Permalink
Merge pull request #1 from egoist/master
Browse files Browse the repository at this point in the history
update poi master version
  • Loading branch information
throrin19 authored Jan 3, 2019
2 parents b9aab0b + 9b024f0 commit 191cf6d
Show file tree
Hide file tree
Showing 35 changed files with 522 additions and 438 deletions.
10 changes: 10 additions & 0 deletions core/dev-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [12.0.3](https://github.com/egoist/poi/compare/@poi/[email protected]...@poi/[email protected]) (2018-12-21)

### Bug Fixes

- **cli:** only open browser on the first successful build ([13b1ac8](https://github.com/egoist/poi/commit/13b1ac8))
2 changes: 1 addition & 1 deletion core/dev-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poi/dev-utils",
"version": "12.0.2",
"version": "12.0.3",
"publishConfig": {
"access": "public"
},
Expand Down
4 changes: 2 additions & 2 deletions core/dev-utils/printServeMessage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const chalk = require('chalk')
const address = require('address')

module.exports = ({ host, port, open }) => {
module.exports = ({ host, port, open, isFirstBuild }) => {
const ip = address.ip()

const isUnspecifiedHost = host === '0.0.0.0' || host === '::'
Expand All @@ -12,7 +12,7 @@ module.exports = ({ host, port, open }) => {
console.log(`On Your Network: http://${ip}:${chalk.bold(port)}`)
console.log()

if (open) {
if (open && isFirstBuild) {
require('./openBrowser')(`http://${prettyHost}:${port}`)
}
}
77 changes: 77 additions & 0 deletions core/poi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,83 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [12.2.13](https://github.com/egoist/poi/compare/[email protected]@12.2.13) (2019-01-02)

### Features

- allow config file to export a function ([8e82f66](https://github.com/egoist/poi/commit/8e82f66))

## [12.2.12](https://github.com/egoist/poi/compare/[email protected]@12.2.12) (2018-12-31)

**Note:** Version bump only for package poi

## [12.2.11](https://github.com/egoist/poi/compare/[email protected]@12.2.11) (2018-12-31)

### Bug Fixes

- use recommended bucklescript workflow ([2231c5c](https://github.com/egoist/poi/commit/2231c5c))

## [12.2.10](https://github.com/egoist/poi/compare/[email protected]@12.2.10) (2018-12-31)

### Bug Fixes

- let webpack watch all reason files ([e5c7a05](https://github.com/egoist/poi/commit/e5c7a05))

## [12.2.9](https://github.com/egoist/poi/compare/[email protected]@12.2.9) (2018-12-30)

### Bug Fixes

- cache support for vue templates ([aa0a430](https://github.com/egoist/poi/commit/aa0a430))

## [12.2.8](https://github.com/egoist/poi/compare/[email protected]@12.2.8) (2018-12-28)

### Features

- use source field from package.json as default app entry ([af61639](https://github.com/egoist/poi/commit/af61639))

## [12.2.7](https://github.com/egoist/poi/compare/[email protected]@12.2.7) (2018-12-25)

### Bug Fixes

- **cli:** help message ([648727e](https://github.com/egoist/poi/commit/648727e))

### Features

- add a hook to allow modifing devServer config ([df939e6](https://github.com/egoist/poi/commit/df939e6))

## [12.2.6](https://github.com/egoist/poi/compare/[email protected]@12.2.6) (2018-12-23)

### Bug Fixes

- **cli:** cache is enabled by default ([b2171d5](https://github.com/egoist/poi/commit/b2171d5))
- properly handle --no-config flag ([bb94787](https://github.com/egoist/poi/commit/bb94787))

## [12.2.5](https://github.com/egoist/poi/compare/[email protected]@12.2.5) (2018-12-22)

### Bug Fixes

- only change devtoolModuleFilenameTemplate under --serve flag ([fe5b708](https://github.com/egoist/poi/commit/fe5b708))
- resolve modules in local development ([369a352](https://github.com/egoist/poi/commit/369a352))

### Features

- add a new plugin option `when` ([17ff228](https://github.com/egoist/poi/commit/17ff228))
- support all webpack targets ([0d51120](https://github.com/egoist/poi/commit/0d51120))

## [12.2.4](https://github.com/egoist/poi/compare/[email protected]@12.2.4) (2018-12-21)

### Bug Fixes

- react-error-overlay doesn't work with eval source map ([ddc8213](https://github.com/egoist/poi/commit/ddc8213))
- use original file path in sourcemap in dev mode ([a2dfc5f](https://github.com/egoist/poi/commit/a2dfc5f))

## [12.2.3](https://github.com/egoist/poi/compare/[email protected]@12.2.3) (2018-12-21)

### Bug Fixes

- better naming for server hooks ([b9aab0b](https://github.com/egoist/poi/commit/b9aab0b))
- **cli:** only open browser on the first successful build ([13b1ac8](https://github.com/egoist/poi/commit/13b1ac8))

## [12.2.2](https://github.com/egoist/poi/compare/[email protected]@12.2.2) (2018-12-19)

### Bug Fixes
Expand Down
45 changes: 34 additions & 11 deletions core/poi/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ module.exports = class PoiCore {
this.webpackUtils = new WebpackUtils(this)

// Try to load config file
if (externalConfig || this.parsedArgs.has('no-config')) {
if (externalConfig || this.parsedArgs.get('config') === false) {
logger.debug('Poi config file was disabled')
this.config = externalConfig
this.config = externalConfig || {}
} else {
const configFiles = this.parsedArgs.has('config')
? [this.parsedArgs.get('config')]
: defaultConfigFiles
const { path: configPath, data: config } = this.configLoader.load({
const configFiles =
typeof this.parsedArgs.get('config') === 'string'
? [this.parsedArgs.get('config')]
: defaultConfigFiles
const { path: configPath, data: configFn } = this.configLoader.load({
files: configFiles,
packageKey: 'poi'
})
Expand All @@ -95,7 +96,11 @@ module.exports = class PoiCore {
logger.debug(`Not using any Poi config file`)
}
this.configPath = configPath
this.config = config || {}
this.config =
typeof configFn === 'function'
? configFn(this.parsedArgs.options)
: configFn
this.config = this.config || {}
}

this.pkg = this.configLoader.load({
Expand Down Expand Up @@ -148,9 +153,9 @@ module.exports = class PoiCore {
const body = section.body.split('\n')
body.shift()
body.unshift(
` $ ${cli.bin} --help`,
` $ ${cli.bin} --serve --help`,
` $ ${cli.bin} --prod --help`
` $ ${cli.name} --help`,
` $ ${cli.name} --serve --help`,
` $ ${cli.name} --prod --help`
)
section.body = body.join('\n')
}
Expand Down Expand Up @@ -188,6 +193,7 @@ module.exports = class PoiCore {
{ resolve: require.resolve('./plugins/config-html') },
{ resolve: require.resolve('./plugins/config-electron') },
{ resolve: require.resolve('./plugins/config-misc-loaders') },
{ resolve: require.resolve('./plugins/config-reason') },
{ resolve: require.resolve('./plugins/watch') },
{ resolve: require.resolve('./plugins/serve') },
{ resolve: require.resolve('./plugins/eject-html') }
Expand All @@ -200,6 +206,9 @@ module.exports = class PoiCore {
}
return plugin
})
.filter(plugin => {
return plugin.resolve.when ? plugin.resolve.when(this) : true
})

// Run plugin's `filterPlugins` method
for (const plugin of this.plugins) {
Expand Down Expand Up @@ -394,7 +403,21 @@ module.exports = class PoiCore {
}

createWebpackCompiler(config) {
return require('webpack')(config)
const compiler = require('webpack')(config)

// Override the .watch method so we can handle error here instead of letting WDM handle it
// And in fact we disabled WDM logger so errors will never show displayed there
const originalWatch = compiler.watch.bind(compiler)
compiler.watch = (options, cb) => {
return originalWatch(options, (err, stats) => {
if (err) {
throw err
}
cb(null, stats)
})
}

return compiler
}

getCacheConfig(dir, keys, files) {
Expand Down
4 changes: 2 additions & 2 deletions core/poi/lib/plugins/command-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports.apply = api => {

command.option('--parallel', 'Enable multicore compilation (experimental)')

command.option('--cache', 'Enable compilation caching')
command.option('--no-cache', 'Disable compilation caching')

command.option('--public-url <url>', 'Set the public URL to serve on', {
default: '/'
Expand All @@ -26,7 +26,7 @@ exports.apply = api => {
})
command.option('--no-public-folder', 'Disable public folder')
command.option('--target <target>', 'Target environment', {
default: 'browser'
default: 'web'
})
command.option('--format <format>', 'Output format', { default: 'iife' })
command.option('--module-name <name>', 'Module name for "umd" format')
Expand Down
7 changes: 0 additions & 7 deletions core/poi/lib/plugins/config-misc-loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,5 @@ exports.apply = api => {
.test([/\.pug$/, /\.jade$/])
.use('pug-loader')
.loader('pug-loader')

// ReasonML / BuckleScript support
config.module
.rule('bs')
.test(/\.(re|ml)$/)
.use('bs-loader')
.loader('@poi/bs-loader')
})
}
16 changes: 16 additions & 0 deletions core/poi/lib/plugins/config-reason.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
exports.name = 'builtin:config-reason'

exports.when = api => api.hasDependency('bs-platform')

exports.apply = api => {
api.hook('createWebpackChain', config => {
config.module
.rule('reason')
.test(/\.(re|ml)$/)
.use('reason-loader')
.loader(require.resolve('../webpack/reason-loader'))
.options({
watch: api.cli.options.serve || api.cli.options.watch
})
})
}
20 changes: 14 additions & 6 deletions core/poi/lib/plugins/config-vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports.apply = api => {
api.hook('createWebpackChain', config => {
const rule = config.module.rule('vue').test(/\.vue$/)

api.webpackUtils.addCacheSupport(rule, () => {
const getCacheOptions = () => {
const vueLoaderPath = path.dirname(require.resolve('vue-loader'))
const compilerPkg = require(resolveFrom(
vueLoaderPath,
Expand All @@ -22,15 +22,23 @@ exports.apply = api => {
? api.localRequire('vue-template-compiler/package').version
: null
})
})
}

api.webpackUtils.addCacheSupport(rule, getCacheOptions)

rule
.use('vue-loader')
.loader('vue-loader')
.options({
// TODO: error with thread-loader
compiler: api.localRequire('vue-template-compiler')
})
.options(
Object.assign(
{
// TODO: error with thread-loader
compiler: api.localRequire('vue-template-compiler')
},
// For Vue templates
api.config.cache && getCacheOptions()
)
)

config.plugin('vue').use(require('vue-loader/lib/plugin'))
})
Expand Down
28 changes: 19 additions & 9 deletions core/poi/lib/plugins/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,27 @@ exports.apply = api => {
if (api.mode !== 'test') {
webpackConfig.plugins.push({
apply(compiler) {
let isFirstBuild = true
// TODO: figure out why using .tap() can't catch error
compiler.hooks.done.tap('print-serve-urls', stats => {
if (stats.hasErrors() || stats.hasWarnings()) return

require('@poi/dev-utils/printServeMessage')({
host,
port,
open
open,
isFirstBuild
})

isFirstBuild = false
})
}
})
}

const compiler = api.createWebpackCompiler(webpackConfig)

const devServerOptions = Object.assign(
const devServerConfig = Object.assign(
{
quiet: true,
historyApiFallback: true,
Expand All @@ -69,8 +73,8 @@ exports.apply = api => {
}
)

const existingBefore = devServerOptions.before
devServerOptions.before = server => {
const existingBefore = devServerConfig.before
devServerConfig.before = server => {
api.hooks.invoke('beforeDevMiddlewares', server)

server.use(
Expand All @@ -86,16 +90,18 @@ exports.apply = api => {
existingBefore && existingBefore(server)
}

const exitingAfter = devServerOptions.after
devServerOptions.after = server => {
const exitingAfter = devServerConfig.after
devServerConfig.after = server => {
exitingAfter && exitingAfter(server)
api.hooks.invoke('onCreateServer', server) // TODO: remove this in the future

api.hooks.invoke('afterDevMiddlewares', server)
}

api.hooks.invoke('createDevServerConfig', devServerConfig)

const WebpackDevServer = require('webpack-dev-server')
const server = new WebpackDevServer(compiler, devServerOptions)
const server = new WebpackDevServer(compiler, devServerConfig)

server.listen(port, host)
})
Expand All @@ -104,8 +110,6 @@ exports.apply = api => {
api.hook('createWebpackChain', config => {
if (!api.cli.options.serve) return

config.devtool('cheap-module-eval-source-map')

const { hotEntries, hot } = api.config.devServer

if (hot) {
Expand All @@ -121,6 +125,12 @@ exports.apply = api => {
config.plugin('hot').use(HotModuleReplacementPlugin)
}

// Point sourcemap entries to original disk location (format as URL on Windows)
// Useful for react-error-overlay
config.output.devtoolModuleFilenameTemplate(info =>
info.absoluteResourcePath.replace(/\\/g, '/')
)

// Don't show bundled files in --serve
if (config.plugins.has('print-status')) {
config.plugin('print-status').tap(([options]) => [
Expand Down
4 changes: 3 additions & 1 deletion core/poi/lib/utils/parseArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module.exports = _args => {

has(name) {
return this.get(name) !== undefined
}
},

options
}
}
Loading

0 comments on commit 191cf6d

Please sign in to comment.