Skip to content

Commit

Permalink
chore - Port to webpack 2
Browse files Browse the repository at this point in the history
  • Loading branch information
bebraw committed May 27, 2017
1 parent be2c69a commit 0ce9fc0
Show file tree
Hide file tree
Showing 12 changed files with 2,515 additions and 2,218 deletions.
4 changes: 2 additions & 2 deletions bootstrap.js → antwar.bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const antwar = require('antwar');

const environment = process.env.npm_lifecycle_event || 'build';
const environment = process.argv[2];

// Patch Babel env to make HMR switch work
process.env.BABEL_ENV = environment;
Expand All @@ -9,7 +9,7 @@ antwar[environment]({
environment,
antwar: require('./antwar.config'),
webpack: require('./webpack.config')
}).catch(function (err) {
}).catch((err) => {
console.error(err);

process.exit(1);
Expand Down
304 changes: 82 additions & 222 deletions antwar.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
var _ = require('lodash');
var path = require('path');
var prevnextPlugin = require('antwar-prevnext-plugin');
var markdown = require('./utilities/markdown');
var highlight = require('./utilities/highlight');
const path = require('path');
const _ = require('lodash');
const prevnextPlugin = require('antwar-prevnext-plugin');

module.exports = {
maximumWorkers: process.env.TRAVIS && 1, // Faster on Travis
template: {
title: 'webpack',
description: 'webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.',
Expand All @@ -13,6 +12,8 @@ module.exports = {
output: 'build',
title: 'webpack',
keywords: ['webpack', 'javascript', 'web development', 'programming'],

// XXXXX: restore
pageTitle: function(config, pageTitle) {
var siteName = config.name;

Expand All @@ -29,238 +30,97 @@ module.exports = {
return require('./components/site/site.jsx').default
},
paths: {
'/': root(
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content',
false,
/^\.\/.*\.md$/
);
}
),

'get-started': {
redirects: {
'': '/guides/get-started',
'install-webpack': '/guides/installation',
'why-webpack': '/guides/why-webpack',
}
},

concepts: section(
'Concepts',
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content/concepts',
false,
/^\.\/.*\.md$/
);
}
),

guides: section(
'Guides',
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content/guides',
true,
/^\.\/.*\.md$/
);
}, {
'code-splitting-import': '/guides/code-splitting-async',
'code-splitting-require': '/guides/code-splitting-async/#require-ensure-',
'why-webpack': '/guides/comparison'
}
),

development: section(
'Development',
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content/development',
'/': {
content: () => (
require.context(
'./loaders/page-loader!./content',
true,
/^\.\/.*\.md$/
);
}
),

configuration: section(
'Configuration',
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content/configuration',
false,
/^\.\/.*\.md$/
);
}, {
'external-configs': 'javascript-alternatives'
}
),

api: section(
'API',
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content/api',
false,
/^\.\/.*\.md$/
);
}, {
'passing-a-config': 'configuration-types'
}
),

'api/plugins': section(
'API',
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content/api/plugins',
false,
/^\.\/.*\.md$/
);
}
),

pluginsapi: {
redirects: {
'': '/api/plugins',
'compiler': '/api/plugins/compiler',
'template': '/api/plugins/template'
)
),
index: () => require('./components/splash/splash.jsx').default,
layout: () => require('./components/page/page.jsx').default,
paths: {
'get-started': {
redirects: {
'': '/guides/get-started',
'install-webpack': '/guides/installation',
'why-webpack': '/guides/why-webpack',
}
},
guides: {
redirects: {
'code-splitting-import': '/guides/code-splitting-async',
'code-splitting-require': '/guides/code-splitting-async/#require-ensure-',
'why-webpack': '/guides/comparison'
}
},
configuration: {
redirects: {
'external-configs': 'javascript-alternatives'
}
},
api: {
redirects: {
'passing-a-config': 'configuration-types'
}
},
pluginsapi: {
redirects: {
'': '/api/plugins',
'compiler': '/api/plugins/compiler',
'template': '/api/plugins/template'
}
},
loaders: {
content: () => {
const content = require.context(
'./loaders/page-loader!./content/loaders',
false,
/^\.\/.*\.md$/
);
const generated = require.context(
'./loaders/page-loader!./generated/loaders',
false,
/^\.\/.*\.md$/
);

return combineContexts(content, generated);
}
},
loaders: {
content: () => {
const content = require.context(
'./loaders/page-loader!./content/plugins',
false,
/^\.\/.*\.md$/
);
const generated = require.context(
'./loaders/page-loader!./generated/plugins',
false,
/^\.\/.*\.md$/
);

return combineContexts(content, generated);
}
}
}
},

loaders: section(
'Loaders',
function() {
const content = require.context(
'json-loader!yaml-frontmatter-loader!./content/loaders',
false,
/^\.\/.*\.md$/
);
const generated = require.context(
'json-loader!yaml-frontmatter-loader!./generated/loaders',
false,
/^\.\/.*\.md$/
);
return combineContexts(content, generated);
}
),

plugins: section(
'Plugins',
function() {
const content = require.context(
'json-loader!yaml-frontmatter-loader!./content/plugins',
false,
/^\.\/.*\.md$/
);
const generated = require.context(
'json-loader!yaml-frontmatter-loader!./generated/plugins',
false,
/^\.\/.*\.md$/
);
return combineContexts(content, generated);
}
),

support: section(
'Support',
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content/support',
false,
/^\.\/.*\.md$/
);
}
),

vote: {
path() {
return require('./components/vote/list.jsx').default
}
index: () => require('./components/vote/list.jsx').default
},

'vote/feedback': {
path() {
return require('./components/vote/list.jsx').default
}
index: () => require('./components/vote/list.jsx').default
},

'vote/moneyDistribution': {
path() {
return require('./components/vote/list.jsx').default
}
index: () => require('./components/vote/list.jsx').default
},

organization: {
path() {
return require('./components/organization/organization.jsx').default
}
index: () => require('./components/organization/organization.jsx').default
}
}
};

function root(contentCb) {
return {
title: 'webpack',
path: function() { // Load path content
return contentCb();
},
processPage: processPage(), // Process individual page (url, content)
layouts: { // Layouts (page/section)
index: function() {
return require('./components/splash/splash.jsx').default
},
page: function() {
return require('./components/page/page.jsx').default
}
},
redirects: {} // Redirects <from>: <to>
};
}

function section(title, contentCb, redirects = {}) {
return {
title: title,
path: function() {
return contentCb();
},
sort(pages) {
return _.sortBy(pages, (page) => page.file.sort)
},
processPage: processPage(),
layouts: {
index: function() {
return require('./components/page/page.jsx').default
},
page: function() {
return require('./components/page/page.jsx').default
}
},
redirects: redirects // <from>: <to>
};
}

function processPage() {
return {
url: function(o) {
return o.sectionName + '/' + o.fileName.split('.')[0]
},
content: function(o) {
return markdown().process(o.file.__content, highlight);
},
anchors: function(o) {
return markdown().getAnchors(o.file.__content);
},
contributors: function(o) {
return Array.isArray(o.file.contributors) && o.file.contributors.length && o.file.contributors.slice().sort();
},
related: function(o) {
return Array.isArray(o.file.related) ? o.file.related : []
}
};
}

function combineContexts(context1, context2) {
function webpackContext(req) {
try {
Expand Down
4 changes: 2 additions & 2 deletions components/site/site.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default props => {
url
}))
}));

// Rename the root section ("webpack" => "Other") and push it to the end
let rootIndex = sections.findIndex(section => section.title === 'webpack');
let rootSection = sections.splice(rootIndex, 1)[0];
Expand All @@ -42,7 +42,7 @@ export default props => {
<Interactive
id="components/notification-bar/notification-bar.jsx"
component={ NotificationBar } />

<Interactive
id="components/navigation/navigation.jsx"
component={ Navigation }
Expand Down
2 changes: 1 addition & 1 deletion content/index.md → components/splash/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ Then run `webpack` on the command-line to create `bundle.js`.

## It's that simple

## [Get Started](/guides/get-started)
## [Get Started](/guides/get-started/)
Loading

0 comments on commit 0ce9fc0

Please sign in to comment.