diff --git a/README.md b/README.md index 1418817..5be821b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@
- Version + Version License
diff --git a/main.config.js b/main.config.js index aa39589..db3f3f1 100644 --- a/main.config.js +++ b/main.config.js @@ -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' } /** @@ -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 diff --git a/package.json b/package.json index be143d9..b979062 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", @@ -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", diff --git a/scripts/utils/format-config.js b/scripts/utils/format-config.js index bb34f4e..6a4a4b5 100644 --- a/scripts/utils/format-config.js +++ b/scripts/utils/format-config.js @@ -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', @@ -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'] diff --git a/scripts/webpack-serve.js b/scripts/webpack-serve.js index e7d0f62..ae0a733 100644 --- a/scripts/webpack-serve.js +++ b/scripts/webpack-serve.js @@ -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)) diff --git a/webpack.config.common.js b/webpack.config.common.js index c2eff49..e7abf31 100644 --- a/webpack.config.common.js +++ b/webpack.config.common.js @@ -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' }, @@ -43,7 +45,7 @@ const webpack = { { test: /\.(js)$/, loader: 'babel-loader', - include: user.paths.src + exclude: /(node_modules|bower_components)/ } ] }, diff --git a/yarn.lock b/yarn.lock index 9ea6fc0..c857398 100644 --- a/yarn.lock +++ b/yarn.lock @@ -256,15 +256,15 @@ autoprefixer@^6.3.1: postcss "^5.2.16" postcss-value-parser "^3.2.3" -autoprefixer@^7.1.4: - version "7.1.4" - resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-7.1.4.tgz#960847dbaa4016bc8e8e52ec891cbf8f1257a748" +autoprefixer@^7.1.5: + version "7.1.5" + resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-7.1.5.tgz#d65d14b83c7cd1dd7bc801daa00557addf5a06b2" dependencies: - browserslist "^2.4.0" - caniuse-lite "^1.0.30000726" + browserslist "^2.5.0" + caniuse-lite "^1.0.30000744" normalize-range "^0.1.2" num2fraction "^1.2.2" - postcss "^6.0.11" + postcss "^6.0.13" postcss-value-parser "^3.2.3" aws-sign2@~0.6.0: @@ -900,8 +900,8 @@ browser-sync@^2.18.13: yargs "6.4.0" browserify-aes@^1.0.0, browserify-aes@^1.0.4: - version "1.0.8" - resolved "https://registry.yarnpkg.com/browserify-aes/-/browserify-aes-1.0.8.tgz#c8fa3b1b7585bb7ba77c5560b60996ddec6d5309" + version "1.1.0" + resolved "https://registry.yarnpkg.com/browserify-aes/-/browserify-aes-1.1.0.tgz#1d2ad62a8b479f23f0ab631c1be86a82dbccbe48" dependencies: buffer-xor "^1.0.3" cipher-base "^1.0.0" @@ -958,12 +958,12 @@ browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6: caniuse-db "^1.0.30000639" electron-to-chromium "^1.2.7" -browserslist@^2.1.2, browserslist@^2.4.0: - version "2.4.0" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-2.4.0.tgz#693ee93d01e66468a6348da5498e011f578f87f8" +browserslist@^2.1.2, browserslist@^2.5.0: + version "2.5.1" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-2.5.1.tgz#68e4bc536bbcc6086d62843a2ffccea8396821c6" dependencies: - caniuse-lite "^1.0.30000718" - electron-to-chromium "^1.3.18" + caniuse-lite "^1.0.30000744" + electron-to-chromium "^1.3.24" bs-recipes@1.3.4: version "1.3.4" @@ -1025,12 +1025,12 @@ caniuse-api@^1.5.2: lodash.uniq "^4.5.0" caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634, caniuse-db@^1.0.30000639: - version "1.0.30000744" - resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000744.tgz#00758ff7dd5f7138d34a15608dccf71a59656ffe" + version "1.0.30000746" + resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000746.tgz#501098c66f5fbbf634c02f25508b05e8809910f4" -caniuse-lite@^1.0.30000718, caniuse-lite@^1.0.30000726: - version "1.0.30000744" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000744.tgz#860fa5c83ba34fe619397d607f30bb474821671b" +caniuse-lite@^1.0.30000744: + version "1.0.30000746" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000746.tgz#c64f95a3925cfd30207a308ed76c1ae96ea09ea0" caseless@~0.12.0: version "0.12.0" @@ -1220,8 +1220,8 @@ concat-stream@^1.6.0: typedarray "^0.0.6" connect-history-api-fallback@^1.1.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/connect-history-api-fallback/-/connect-history-api-fallback-1.3.0.tgz#e51d17f8f0ef0db90a64fdb47de3051556e9f169" + version "1.4.0" + resolved "https://registry.yarnpkg.com/connect-history-api-fallback/-/connect-history-api-fallback-1.4.0.tgz#3db24f973f4b923b0e82f619ce0df02411ca623d" connect@1.x: version "1.9.2" @@ -1615,9 +1615,9 @@ ee-first@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" -electron-to-chromium@^1.2.7, electron-to-chromium@^1.3.18: - version "1.3.24" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.24.tgz#9b7b88bb05ceb9fa016a177833cc2dde388f21b6" +electron-to-chromium@^1.2.7, electron-to-chromium@^1.3.24: + version "1.3.26" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.26.tgz#996427294861a74d9c7c82b9260ea301e8c02d66" elliptic@^6.0.0: version "6.4.0" @@ -1704,13 +1704,13 @@ error-ex@^1.2.0: is-arrayish "^0.2.1" es5-ext@^0.10.14, es5-ext@^0.10.9, es5-ext@~0.10.14: - version "0.10.30" - resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.30.tgz#7141a16836697dbabfaaaeee41495ce29f52c939" + version "0.10.35" + resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.35.tgz#18ee858ce6a3c45c7d79e91c15fcca9ec568494f" dependencies: - es6-iterator "2" - es6-symbol "~3.1" + es6-iterator "~2.0.1" + es6-symbol "~3.1.1" -es6-iterator@2, es6-iterator@^2.0.1, es6-iterator@~2.0.1: +es6-iterator@^2.0.1, es6-iterator@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.1.tgz#8e319c9f0453bf575d374940a655920e59ca5512" dependencies: @@ -1739,7 +1739,7 @@ es6-set@~0.1.5: es6-symbol "3.1.1" event-emitter "~0.3.5" -es6-symbol@3.1.1, es6-symbol@^3.1, es6-symbol@^3.1.1, es6-symbol@~3.1, es6-symbol@~3.1.1: +es6-symbol@3.1.1, es6-symbol@^3.1, es6-symbol@^3.1.1, es6-symbol@~3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.1.tgz#bf00ef4fdab6ba1b46ecb7b629b4c7ed5715cc77" dependencies: @@ -1814,9 +1814,9 @@ eslint-plugin-node@^5.2.0: resolve "^1.3.3" semver "5.3.0" -eslint-plugin-promise@^3.5.0: - version "3.5.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-3.5.0.tgz#78fbb6ffe047201627569e85a6c5373af2a68fca" +eslint-plugin-promise@^3.6.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-3.6.0.tgz#54b7658c8f454813dc2a870aff8152ec4969ba75" eslint-plugin-standard@^3.0.1: version "3.0.1" @@ -1829,9 +1829,9 @@ eslint-scope@^3.7.1: esrecurse "^4.1.0" estraverse "^4.1.1" -eslint@^4.8.0: - version "4.8.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.8.0.tgz#229ef0e354e0e61d837c7a80fdfba825e199815e" +eslint@^4.9.0: + version "4.9.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.9.0.tgz#76879d274068261b191fe0f2f56c74c2f4208e8b" dependencies: ajv "^5.2.0" babel-code-frame "^6.22.0" @@ -2022,7 +2022,7 @@ file-entry-cache@^2.0.0: flat-cache "^1.2.1" object-assign "^4.0.1" -file-loader@^1.1.4: +file-loader@^1.1.5: version "1.1.5" resolved "https://registry.yarnpkg.com/file-loader/-/file-loader-1.1.5.tgz#91c25b6b6fbe56dae99f10a425fd64933b5c9daa" dependencies: @@ -2853,9 +2853,9 @@ less-loader@^4.0.5: loader-utils "^1.1.0" pify "^2.3.0" -less@^2.7.2: - version "2.7.2" - resolved "https://registry.yarnpkg.com/less/-/less-2.7.2.tgz#368d6cc73e1fb03981183280918743c5dcf9b3df" +less@^3.0.0-alpha.3: + version "3.0.0-pre.4" + resolved "https://registry.yarnpkg.com/less/-/less-3.0.0-pre.4.tgz#67507b12e6dc93746f73d231ae38e3c043f1e380" optionalDependencies: errno "^0.1.1" graceful-fs "^4.1.2" @@ -2863,7 +2863,6 @@ less@^2.7.2: mime "^1.2.11" mkdirp "^0.5.0" promise "^7.1.1" - request "^2.72.0" source-map "^0.5.3" levn@^0.3.0, levn@~0.3.0: @@ -3671,12 +3670,12 @@ postcss-load-plugins@^2.3.0: cosmiconfig "^2.1.1" object-assign "^4.1.0" -postcss-loader@^2.0.6: - version "2.0.6" - resolved "https://registry.yarnpkg.com/postcss-loader/-/postcss-loader-2.0.6.tgz#8c7e0055a3df1889abc6bad52dd45b2f41bbc6fc" +postcss-loader@^2.0.8: + version "2.0.8" + resolved "https://registry.yarnpkg.com/postcss-loader/-/postcss-loader-2.0.8.tgz#8c67ddb029407dfafe684a406cfc16bad2ce0814" dependencies: loader-utils "^1.1.0" - postcss "^6.0.2" + postcss "^6.0.0" postcss-load-config "^1.2.0" schema-utils "^0.3.0" @@ -3857,7 +3856,7 @@ postcss@^5.0.10, postcss@^5.0.11, postcss@^5.0.12, postcss@^5.0.13, postcss@^5.0 source-map "^0.5.6" supports-color "^3.2.3" -postcss@^6.0.1, postcss@^6.0.11, postcss@^6.0.2: +postcss@^6.0.0, postcss@^6.0.1, postcss@^6.0.13: version "6.0.13" resolved "https://registry.yarnpkg.com/postcss/-/postcss-6.0.13.tgz#b9ecab4ee00c89db3ec931145bd9590bbf3f125f" dependencies: @@ -3878,8 +3877,8 @@ preserve@^0.2.0: resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" private@^0.1.6, private@^0.1.7: - version "0.1.7" - resolved "https://registry.yarnpkg.com/private/-/private-0.1.7.tgz#68ce5e8a1ef0a23bb570cc28537b5332aba63ef1" + version "0.1.8" + resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff" process-nextick-args@~1.0.6: version "1.0.7" @@ -3990,8 +3989,8 @@ range-parser@^1.0.3, range-parser@~1.2.0: resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e" rc@^1.1.7: - version "1.2.1" - resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.1.tgz#2e03e8e42ee450b8cb3dce65be1bf8974e1dfd95" + version "1.2.2" + resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.2.tgz#d8ce9cb57e8d64d9c7badd9876c7c34cbe3c7077" dependencies: deep-extend "~0.4.0" ini "~1.3.0" @@ -4160,7 +4159,7 @@ request@2.81.0: tunnel-agent "^0.6.0" uuid "^3.0.0" -request@^2.12.0, request@^2.72.0: +request@^2.12.0: version "2.83.0" resolved "https://registry.yarnpkg.com/request/-/request-2.83.0.tgz#ca0b65da02ed62935887808e6f510381034e3356" dependencies: @@ -4214,9 +4213,9 @@ resolve-from@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226" -resolve-url-loader@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/resolve-url-loader/-/resolve-url-loader-2.1.0.tgz#27c95cc16a4353923fdbdc2dbaf5eef22232c477" +resolve-url-loader@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/resolve-url-loader/-/resolve-url-loader-2.1.1.tgz#5354e87381aae348371e555172c50816708e6c1c" dependencies: adjust-sourcemap-loader "^1.1.0" camelcase "^4.0.0" @@ -4953,9 +4952,9 @@ webpack-sources@^1.0.1: source-list-map "^2.0.0" source-map "~0.5.3" -webpack@^3.6.0: - version "3.6.0" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-3.6.0.tgz#a89a929fbee205d35a4fa2cc487be9cbec8898bc" +webpack@^3.7.1: + version "3.7.1" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-3.7.1.tgz#6046b5c415ff7df7a0dc54c5b6b86098e8b952da" dependencies: acorn "^5.0.0" acorn-dynamic-import "^2.0.0"