Migrate build pipeline to Webpack 2

This commit is contained in:
squidfunk
2017-02-11 16:00:45 +01:00
committed by Martin Donath
parent 7c36b5c4ef
commit 80fe7e010d
8 changed files with 219 additions and 281 deletions

View File

@@ -2,9 +2,6 @@
"presets": ["es2015"], "presets": ["es2015"],
"plugins": [ "plugins": [
"add-module-exports", "add-module-exports",
"babel-root-import", "babel-root-import"
["transform-react-jsx", {
"pragma": "JSX.createElement"
}]
] ]
} }

View File

@@ -50,12 +50,13 @@ export default (gulp, config, args) => {
], ],
output: { output: {
filename: "application.js", filename: "application.js",
library: "Application" library: "app",
libraryTarget: "window"
}, },
module: { module: {
/* Transpile ES6 to ES5 with Babel */ /* Transpile ES6 to ES5 with Babel */
loaders: [ rules: [
{ {
loader: "babel-loader", loader: "babel-loader",
test: /\.jsx?$/ test: /\.jsx?$/
@@ -65,7 +66,7 @@ export default (gulp, config, args) => {
plugins: [ plugins: [
/* Don't emit assets that include errors */ /* Don't emit assets that include errors */
new webpack.NoErrorsPlugin(), new webpack.NoEmitOnErrorsPlugin(),
/* Provide JSX helper */ /* Provide JSX helper */
new webpack.ProvidePlugin({ new webpack.ProvidePlugin({
@@ -77,19 +78,30 @@ export default (gulp, config, args) => {
args.optimize ? [ args.optimize ? [
new webpack.optimize.UglifyJsPlugin({ new webpack.optimize.UglifyJsPlugin({
compress: { compress: {
warnings: false warnings: false,
screw_ie8: true, // eslint-disable-line camelcase
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true, // eslint-disable-line camelcase
evaluate: true,
if_return: true, // eslint-disable-line camelcase
join_vars: true // eslint-disable-line camelcase
},
output: {
comments: false
} }
}) })
] : []), ] : []),
/* Module resolver */ /* Module resolver */
resolve: { resolve: {
modulesDirectories: [ modules: [
"src/assets/javascripts", "src/assets/javascripts",
"node_modules" "node_modules"
], ],
extensions: [ extensions: [
"",
".js", ".js",
".jsx" ".jsx"
] ]
@@ -102,7 +114,7 @@ export default (gulp, config, args) => {
/* Sourcemap support */ /* Sourcemap support */
devtool: args.sourcemaps ? "inline-source-map" : "" devtool: args.sourcemaps ? "inline-source-map" : ""
})) }, webpack))
/* Revisioning */ /* Revisioning */
.pipe(gulpif(args.revision, rev())) .pipe(gulpif(args.revision, rev()))

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -124,8 +124,8 @@
{% endblock %} {% endblock %}
</div> </div>
{% block scripts %} {% block scripts %}
<script src="{{ base_url }}/assets/javascripts/application-7f35cda7dd.js"></script> <script src="{{ base_url }}/assets/javascripts/application-39a173f6f5.js"></script>
<script>var config={url:{base:"{{ base_url }}"}},app=new Application(config);app.initialize()</script> <script>app.initialize({url:{base:"{{ base_url }}"}})</script>
{% for path in extra_javascript %} {% for path in extra_javascript %}
<script src="{{ path }}"></script> <script src="{{ path }}"></script>
{% endfor %} {% endfor %}

10
src/.babelrc Normal file
View File

@@ -0,0 +1,10 @@
{
"presets": [
["es2015", { "modules": false }]
],
"plugins": [
["transform-react-jsx", {
"pragma": "JSX.createElement"
}]
]
}

View File

@@ -27,22 +27,7 @@ import Material from "./components/Material"
* Application * Application
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
export default class Application { export const initialize = config => {
/**
* Create the application
*
* @constructor
* @param {object} config Configuration object
*/
constructor(config) {
this.config_ = config
}
/**
* Initialize all components and listeners
*/
initialize() {
/* Initialize Modernizr and FastClick */ /* Initialize Modernizr and FastClick */
new Material.Event.Listener(document, "DOMContentLoaded", () => { new Material.Event.Listener(document, "DOMContentLoaded", () => {
@@ -57,7 +42,7 @@ export default class Application {
return !!navigator.standalone return !!navigator.standalone
}) })
/* Attack FastClick to mitigate 300ms delay on touch devices */ /* Attach FastClick to mitigate 300ms delay on touch devices */
FastClick.attach(document.body) FastClick.attach(document.body)
/* Wrap all data tables for better overflow scrolling */ /* Wrap all data tables for better overflow scrolling */
@@ -141,12 +126,12 @@ export default class Application {
new Material.Event.Listener(document.forms.search.query, [ new Material.Event.Listener(document.forms.search.query, [
"focus", "keyup" "focus", "keyup"
], new Material.Search.Result("[data-md-component=result]", () => { ], new Material.Search.Result("[data-md-component=result]", () => {
return fetch(`${this.config_.url.base}/mkdocs/search_index.json`, { return fetch(`${config.url.base}/mkdocs/search_index.json`, {
credentials: "same-origin" credentials: "same-origin"
}).then(response => response.json()) }).then(response => response.json())
.then(data => { .then(data => {
return data.docs.map(doc => { return data.docs.map(doc => {
doc.location = this.config_.url.base + doc.location doc.location = config.url.base + doc.location
return doc return doc
}) })
}) })
@@ -237,5 +222,4 @@ export default class Application {
.initialize(facts) .initialize(facts)
}) })
}) })
}
} }

View File

@@ -245,17 +245,7 @@
{% block scripts %} {% block scripts %}
<script src="{{ base_url }}/assets/javascripts/application.js"></script> <script src="{{ base_url }}/assets/javascripts/application.js"></script>
<script> <script>
app.initialize({ url: { base: "{{ base_url }}", } });
/* Configuration for application */
var config = {
url: {
base: "{{ base_url }}",
}
};
/* Initialize application */
var app = new Application(config);
app.initialize();
</script> </script>
{% for path in extra_javascript %} {% for path in extra_javascript %}
<script src="{{ path }}"></script> <script src="{{ path }}"></script>