Skip to content

Commit b4f50c5

Browse files
committed
Update npm modules; tweak webpack.config.js a little
1 parent 97a2bc9 commit b4f50c5

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"babel-loader": "^6.2.4",
2525
"babel-plugin-transform-runtime": "^6.9.0",
2626
"babel-preset-es2015": "^6.9.0",
27-
"babel-preset-react": "^6.11.0",
27+
"babel-preset-react": "^6.11.1",
2828
"babel-preset-stage-1": "^6.5.0",
2929
"babel-register": "^6.9.0",
3030
"babel-runtime": "^6.9.2",
@@ -41,7 +41,7 @@
4141
"extend": "^3.0.0",
4242
"file-loader": "^0.9.0",
4343
"front-matter": "^2.1.0",
44-
"highlight.js": "^9.4.0",
44+
"highlight.js": "^9.5.0",
4545
"json-loader": "^0.5.4",
4646
"markdown-it": "^7.0.0",
4747
"mkdirp": "^0.5.1",
@@ -67,7 +67,7 @@
6767
"stylelint": "^6.7.1",
6868
"stylelint-config-standard": "^9.0.0",
6969
"url-loader": "^0.5.7",
70-
"webpack": "^2.1.0-beta.14",
70+
"webpack": "^2.1.0-beta.15",
7171
"webpack-dev-middleware": "^1.6.1",
7272
"webpack-hot-middleware": "^2.11.0"
7373
},

run.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const del = require('del');
1414
const cpy = require('cpy');
1515
const mkdirp = require('mkdirp');
1616
const webpack = require('webpack');
17+
const cp = require('child_process');
1718
const browserSync = require('browser-sync');
1819
const webpackDevMiddleware = require('webpack-dev-middleware');
1920
const webpackHotMiddleware = require('webpack-hot-middleware');
@@ -22,24 +23,31 @@ const tasks = new Map();
2223
const config = require('./webpack.config');
2324
const routes = require('./routes.json');
2425

25-
// Execute a task
26+
/* eslint-disable no-console, global-require */
27+
2628
function run(task) {
2729
const start = new Date();
28-
console.log(`Starting '${task}'...`); // eslint-disable-line no-console
30+
console.log(`Starting '${task}'...`);
2931
return Promise.resolve().then(() => tasks.get(task)()).then(() => {
3032
const end = new Date();
3133
const time = end.getTime() - start.getTime();
32-
console.log(`Finished '${task}' after ${time}ms`); // eslint-disable-line no-console
33-
}, err => console.error(err.stack)); // eslint-disable-line no-console
34+
console.log(`Finished '${task}' after ${time}ms`);
35+
}, err => console.error(err.stack));
3436
}
3537

38+
//
3639
// Clean up the output directory
40+
// -----------------------------------------------------------------------------
3741
tasks.set('clean', () => del(['build/*', '!build/.git'], { dot: true }));
3842

43+
//
3944
// Copy static files into the output directory
45+
// -----------------------------------------------------------------------------
4046
tasks.set('copy', () => cpy(['static/**/*.*'], 'build'));
4147

48+
//
4249
// Generate static HTML pages based on routes.json
50+
// -----------------------------------------------------------------------------
4351
tasks.set('pages', () => {
4452
const assets = JSON.parse(fs.readFileSync('./build/assets.json', 'utf8'));
4553
const html = fs.readFileSync('./static/index.html', 'utf8')
@@ -63,34 +71,39 @@ tasks.set('bundle', () =>
6371
if (err) {
6472
reject(err);
6573
} else {
66-
console.log(stats.toString(config.stats)); // eslint-disable-line no-console
74+
console.log(stats.toString(config.stats));
6775
resolve();
6876
}
6977
});
7078
})
7179
);
7280

81+
//
7382
// Build website into a distributable format
83+
// -----------------------------------------------------------------------------
7484
tasks.set('build', () => Promise.resolve()
7585
.then(() => run('clean'))
7686
.then(() => run('copy'))
7787
.then(() => run('bundle'))
7888
.then(() => run('pages'))
7989
);
8090

91+
//
8192
// Build and publish the website
93+
// -----------------------------------------------------------------------------
8294
tasks.set('publish', () => run('publish:gh'));
8395

96+
//
8497
// Build and publish the website to GitHub Pages
98+
// -----------------------------------------------------------------------------
8599
tasks.set('publish:gh', () => {
86100
const remote = {
87101
url: 'https://github.com/<owner>/<repo>.git', // TODO: Update deployment URL
88102
branch: 'gh-pages',
89103
};
90-
const { spawn } = require('child_process'); // eslint-disable-line global-require
91104
const opts = { cwd: path.resolve(__dirname, './build'), stdio: ['ignore', 'inherit', 'inherit'] };
92105
const git = (...args) => new Promise((resolve, reject) => {
93-
spawn('git', args, opts).on('close', code => {
106+
cp.spawn('git', args, opts).on('close', code => {
94107
if (code === 0) {
95108
resolve();
96109
} else {
@@ -121,9 +134,11 @@ tasks.set('publish:gh', () => {
121134
.then(() => git('push', 'origin', `HEAD:${remote.branch}`, '--force', '--set-upstream'));
122135
});
123136

137+
//
124138
// Build and publish the website to Amazon S3
139+
// -----------------------------------------------------------------------------
125140
tasks.set('publish:s3', () => {
126-
const s3 = require('s3'); // eslint-disable-line global-require
141+
const s3 = require('s3');
127142
return run('build').then(() => new Promise((resolve, reject) => {
128143
const client = s3.createClient({
129144
s3Options: {
@@ -141,7 +156,9 @@ tasks.set('publish:s3', () => {
141156
}));
142157
});
143158

159+
//
144160
// Build website and launch it in a browser for testing (default)
161+
// -----------------------------------------------------------------------------
145162
tasks.set('start', () =>
146163
new Promise(resolve => {
147164
// Hot Module Replacement (HMR) + React Hot Reload

webpack.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ const pkg = require('./package.json');
1919
const isDebug = !(process.argv.includes('--release') || process.argv.includes('-r'));
2020
const isVerbose = process.argv.includes('--verbose') || process.argv.includes('-v');
2121

22-
// Webpack configuration (core/main.js => build/bundle.js)
22+
// Webpack configuration (main.js => build/main.{hash}.js)
2323
// http://webpack.github.io/docs/configuration.html
2424
const config = {
2525

26+
// The base directory for resolving the entry option
27+
context: __dirname,
28+
2629
// The entry point for the bundle
2730
entry: [
2831
'./main.js',
@@ -33,7 +36,7 @@ const config = {
3336
path: path.resolve(__dirname, './build'),
3437
publicPath: '/',
3538
filename: isDebug ? '[name].js?[hash]' : '[name].[hash].js',
36-
chunkFilename: isDebug ? '[id].js?[hash]' : '[id].[hash].js',
39+
chunkFilename: isDebug ? '[id].js?[chunkhash]' : '[id].[chunkhash].js',
3740
sourcePrefix: ' ',
3841
},
3942

0 commit comments

Comments
 (0)