Skip to content

Commit

Permalink
Merge pull request #18 from brocessing/dev
Browse files Browse the repository at this point in the history
0.7.0
  • Loading branch information
pqml authored Oct 15, 2017
2 parents a51da47 + d8cc2db commit 5e83784
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 101 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<div align="center">
<!-- Version -->
<a href="https://github.com/brocessing/kirby-webpack/releases"><img src="https://img.shields.io/badge/version-0.6.2-green.svg?style=flat-square" alt="Version"/></a>
<a href="https://github.com/brocessing/kirby-webpack/releases"><img src="https://img.shields.io/badge/version-0.7.0-green.svg?style=flat-square" alt="Version"/></a>
<!-- License -->
<a href="https://raw.githubusercontent.com/brocessing/kirby-webpack/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="License" /></a>
</div>
Expand Down
57 changes: 25 additions & 32 deletions main.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ const path = require('path')
* BUNDLE ENTRY FILES
* All file will be passed to your webpack config.
* Formatted as { input: output }
* input path are relative to paths.src
* output path are relative to paths.build
* paths are relative to your project root (__dirname)
*/
const entries = {
'index.js': 'assets/bundle.js',
'index.less': 'assets/bundle.css'
'src/index.js': 'www/assets/bundle.js',
'src/index.less': 'www/assets/bundle.css'
}

/**
Expand Down Expand Up @@ -51,37 +50,31 @@ const devServer = {
* All paths used in kirby-webpack.
* change them if you want to customize the folder architecture.
*/
const paths = {
// source folder for js / css
src: path.join(__dirname, 'src'),
const paths = {}

// folder where webpack bundle files
build: path.join(__dirname, 'www'),
// public folder to deploy to your server
// if you use a proxy, this is often the document root of the server used
paths.www = path.join(__dirname, 'www')

// public folder to deploy to your server
// if you use a proxy, this is often the document root of the server used
www: path.join(__dirname, 'www'),

// public baseUrl of your site, generally '/'.
// it often change depending on your environment,
// the correct one will be chosen from the value of appEnv.
basepaths: {
development: '/',
preprod: '/',
production: '/'
},
// public baseUrl of your site, generally '/'.
// it often change depending on your environment,
// the correct one will be chosen from the value of appEnv.
paths.basepaths = {
development: '/',
preprod: '/',
production: '/'
}

// all kirby paths
kirby: {
core: path.join(__dirname, 'www', 'kirby'),
panel: path.join(__dirname, 'www', 'panel'),
assets: path.join(__dirname, 'www', 'assets'),
cache: path.join(__dirname, 'www', 'site', 'cache'),
fields: path.join(__dirname, 'www', 'site', 'fields'),
tags: path.join(__dirname, 'www', 'site', 'tags'),
plugins: path.join(__dirname, 'www', 'site', 'plugins'),
widgets: path.join(__dirname, 'www', 'site', 'widgets')
}
// all kirby paths
paths.kirby = {
core: path.join(paths.www, 'kirby'),
panel: path.join(paths.www, 'panel'),
assets: path.join(paths.www, 'assets'),
cache: path.join(paths.www, 'site', 'cache'),
fields: path.join(paths.www, 'site', 'fields'),
tags: path.join(paths.www, 'site', 'tags'),
plugins: path.join(paths.www, 'site', 'plugins'),
widgets: path.join(paths.www, 'site', 'widgets')
}

// the appEnv variable can be used to create environment-specific behaviours
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kirby-webpack",
"version": "0.6.2",
"version": "0.7.0",
"description": "A kirby starter-kit with modern frontend tools",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -38,11 +38,11 @@
"browser-sync": "^2.18.13",
"cross-env": "^5.0.5",
"css-loader": "^0.28.7",
"eslint": "^4.8.0",
"eslint": "^4.9.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-standard": "^3.0.1",
"extract-text-webpack-plugin": "^3.0.1",
"file-loader": "^1.1.5",
Expand All @@ -51,7 +51,7 @@
"kool-shell": "^1.5.0",
"less": "^3.0.0-alpha.3",
"less-loader": "^4.0.5",
"postcss-loader": "^2.0.7",
"postcss-loader": "^2.0.8",
"progress-bar-webpack-plugin": "^1.10.0",
"resolve-url-loader": "^2.1.1",
"style-loader": "^0.19.0",
Expand Down
21 changes: 19 additions & 2 deletions scripts/utils/format-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const path = require('path')
const sh = require('kool-shell')()
.use(require('kool-shell/plugins/log'))

const PREPROC_LOADER = {
less: 'less-loader',
Expand All @@ -19,9 +21,24 @@ function formatConfig (config) {

// format entries for webpack
const nEntries = {}
const projectRoot = path.join(__dirname, '..', '..')
for (let k in config.entries) {
const src = path.join(config.paths.src, k)
const dist = config.entries[k]
const relativeWww = path.relative(projectRoot, config.paths.www)
const src = path.join(projectRoot, k)
const dist = path.relative(relativeWww, config.entries[k])
if (
dist.length >= 2 &&
dist.substr(0, 2) === '..' &&
config.appEnv === 'development'
) {
sh.log()
sh.warn(
'\n' + k + ' will not be bundled in development.\n' +
'Its destination is outside the public folder.'
)
continue
}

if (!nEntries[dist]) {
nEntries[dist] = (config.appEnv === 'development')
? [src, 'webpack-hot-middleware/client?reload=true']
Expand Down
12 changes: 8 additions & 4 deletions scripts/webpack-serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,20 @@ function ready () {
}

function logPhpError () {
fs.ensureFile(LOGPATH)
Promise.resolve()
.then(() => fs.remove(LOGPATH))
.then(() => fs.ensureFile(LOGPATH))
.then(() => {
const tail = new Tail(LOGPATH, {
useWatchFile: true,
fsWatchOptions: { interval: 300 }
})
tail.on('line', (data) => {
data = data.toString('utf8').split(']')
const date = sh.colors.gray(data.shift() + ']')
data = date + data.join(']')
if (/^\[[a-zA-Z0-9: -]+\] .+/g.test(data)) {
data = data.toString('utf8').split(']')
const date = sh.colors.gray(data.shift() + ']')
data = date + data.join(']')
}
sh.log(sh.colors.red('[PHP]') + data)
})
tail.on('error', err => sh.error(err))
Expand Down
6 changes: 4 additions & 2 deletions webpack.config.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ if (user.css.preprocessorLoader) {
const webpack = {
output: {
publicPath: user.paths.basepath,
path: user.paths.build,
// we bundle from the www folder to avoid messing with the webpack dev middleware
// all entries src/dest path are converted through scripts/utils/format-config.js
path: user.paths.www,
filename: '[name]',
chunkFilename: '[name].[id].chunk.js'
},
Expand All @@ -43,7 +45,7 @@ const webpack = {
{
test: /\.(js)$/,
loader: 'babel-loader',
include: user.paths.src
exclude: /(node_modules|bower_components)/
}
]
},
Expand Down
Loading

0 comments on commit 5e83784

Please sign in to comment.