Optimize build process

This commit is contained in:
uwap 2017-11-06 09:39:55 +01:00
parent 735737f4a2
commit c99cc70bcf
5 changed files with 958 additions and 37 deletions

View file

@ -4,8 +4,9 @@
"author": "uwap <me+spacemap.package.json@uwap.name>", "author": "uwap <me+spacemap.package.json@uwap.name>",
"description": "control devices via mqtt on a beautiful map of your space", "description": "control devices via mqtt on a beautiful map of your space",
"scripts": { "scripts": {
"build": "webpack --bail", "build": "webpack --bail --config webpack.dev.js",
"watch": "webpack --watch" "production-build": "webpack --bail --config webpack.prod.js",
"watch": "webpack-dev-server --open --config webpack.dev.js"
}, },
"dependencies": { "dependencies": {
"babel-preset-env": "^1.6.0", "babel-preset-env": "^1.6.0",
@ -26,6 +27,7 @@
"babel-core": "^6.25.0", "babel-core": "^6.25.0",
"babel-loader": "^7.1.1", "babel-loader": "^7.1.1",
"babel-preset-react": "^6.24.1", "babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^0.1.17",
"css-loader": "^0.28.7", "css-loader": "^0.28.7",
"extract-text-webpack-plugin": "^3.0.2", "extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.5", "file-loader": "^1.1.5",
@ -35,6 +37,8 @@
"html-webpack-plugin": "^2.30.1", "html-webpack-plugin": "^2.30.1",
"style-loader": "^0.19.0", "style-loader": "^0.19.0",
"webpack": "^3.1.0", "webpack": "^3.1.0",
"webpack-dev-server": "^2.9.4",
"webpack-merge": "^4.1.1",
"webpack-shell-plugin": "^0.5.0" "webpack-shell-plugin": "^0.5.0"
}, },
"license": "MIT" "license": "MIT"

View file

@ -1,20 +1,14 @@
// webpack.config.js:
const path = require('path'); const path = require('path');
const webpack = require('webpack'); const webpack = require('webpack');
const WebpackShellPlugin = require('webpack-shell-plugin'); const WebpackShellPlugin = require('webpack-shell-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin"); const ExtractTextPlugin = require("extract-text-webpack-plugin");
const CleanWebpackPlugin = require('clean-webpack-plugin');
const preBuildScripts = process.env.NO_FLOW == undefined ? const preBuildScripts = process.env.NO_FLOW == undefined ?
process.env.FLOW_PATH != undefined ? [process.env.FLOW_PATH] : ['flow'] process.env.FLOW_PATH != undefined ? [process.env.FLOW_PATH] : ['flow']
: []; : [];
const extractTextCSSLoader = ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
});
module.exports = { module.exports = {
resolve: { resolve: {
extensions: ['.js', '.jsx'] extensions: ['.js', '.jsx']
@ -24,23 +18,20 @@ module.exports = {
], ],
output: { output: {
path: path.resolve(__dirname, 'dist'), path: path.resolve(__dirname, 'dist'),
filename: 'main.js', filename: 'main.js'
publicPath: './'
}, },
module: { module: {
loaders: [ loaders: [
{ test: /\.(woff2?|eot|ttf|svg)$/, loader: "file-loader" }, { test: /\.(woff2?|eot|ttf|svg)$/, loader: "file-loader" }
{ test: /\.css$/, use: extractTextCSSLoader },
{ test: /\.js(x)?$/, exclude: /node_modules/, loader: "babel-loader" }
] ]
}, },
plugins: [ plugins: [
new WebpackShellPlugin({onBuildStart:preBuildScripts}), new CleanWebpackPlugin(["dist"]),
// new WebpackShellPlugin({onBuildStart:preBuildScripts}),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
title: 'Space Map', title: 'Space Map',
template: 'index.ejs' template: 'index.ejs'
}), }),
new ExtractTextPlugin("styles.css") new ExtractTextPlugin("styles.css")
], ]
devtool: 'source-map'
}; };

23
webpack.dev.js Normal file
View file

@ -0,0 +1,23 @@
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const extractCSS = ExtractTextPlugin.extract({
fallback: "style-loader",
use: {
loader: "css-loader"
}
});
module.exports = merge(common, {
module: {
loaders: [
{ test: /\.css$/, use: extractCSS },
{ test: /\.js(x)?$/, exclude: /node_modules/, loader: "babel-loader?cacheDirectory=true" }
]
},
devtool: "eval-cheap-module-source-map",
devServer: {
contentBase: './dist'
},
});

33
webpack.prod.js Normal file
View file

@ -0,0 +1,33 @@
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const extractCSS = ExtractTextPlugin.extract({
fallback: "style-loader",
use: {
loader: "css-loader",
options: {
sourceMap: true,
minimize: true
}
}
});
module.exports = merge(common, {
module: {
loaders: [
{ test: /\.css$/, use: extractCSS },
{ test: /\.js(x)?$/, exclude: /node_modules/, loader: "babel-loader" }
]
},
devtool: "source-map",
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
})
]
});

910
yarn.lock

File diff suppressed because it is too large Load diff