build: Update webpack config
Make building more convenient, add linting and distribute html files.
This commit is contained in:
parent
811e3eebe0
commit
3f7ac60374
3 changed files with 111 additions and 10 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,4 +1,4 @@
|
|||
*~
|
||||
*.retry
|
||||
node_modules/
|
||||
build/
|
||||
dist/
|
||||
|
|
|
|||
|
|
@ -14,6 +14,12 @@
|
|||
"babel-loader": "^7.0.0",
|
||||
"babel-plugin-transform-react-jsx": "^6.24.1",
|
||||
"babel-preset-env": "^1.5.2",
|
||||
"copy-webpack-plugin": "~3.0.1",
|
||||
"eslint": "^3.0.0",
|
||||
"eslint-loader": "~1.6.1",
|
||||
"eslint-plugin-react": "~6.9.0",
|
||||
"jshint": "~2.9.1",
|
||||
"jshint-loader": "~0.8.3",
|
||||
"webpack": "^2.6.1"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -1,18 +1,113 @@
|
|||
const path = require("path");
|
||||
const copy = require("copy-webpack-plugin");
|
||||
const fs = require("fs");
|
||||
|
||||
/* These can be overridden, typically from the Makefile.am */
|
||||
const srcdir = (process.env.SRCDIR || __dirname) + path.sep + "src";
|
||||
const builddir = (process.env.SRCDIR || __dirname);
|
||||
const distdir = builddir + path.sep + "dist";
|
||||
const section = process.env.ONLYDIR || null;
|
||||
|
||||
var info = {
|
||||
entries: {
|
||||
"index": [
|
||||
"./index.js"
|
||||
]
|
||||
},
|
||||
files: [
|
||||
"index.html"
|
||||
]
|
||||
};
|
||||
|
||||
var output = {
|
||||
path: distdir,
|
||||
filename: "[name].js",
|
||||
sourceMapFilename: "[file].map",
|
||||
};
|
||||
|
||||
/*
|
||||
* Note that we're avoiding the use of path.join as webpack and nodejs
|
||||
* want relative paths that start with ./ explicitly.
|
||||
*
|
||||
* In addition we mimic the VPATH style functionality of GNU Makefile
|
||||
* where we first check builddir, and then srcdir.
|
||||
*/
|
||||
|
||||
function vpath(/* ... */) {
|
||||
var filename = Array.prototype.join.call(arguments, path.sep);
|
||||
var expanded = builddir + path.sep + filename;
|
||||
if (fs.existsSync(expanded))
|
||||
return expanded;
|
||||
expanded = srcdir + path.sep + filename;
|
||||
return expanded;
|
||||
}
|
||||
|
||||
/* Qualify all the paths in entries */
|
||||
Object.keys(info.entries).forEach(function(key) {
|
||||
if (section && key.indexOf(section) !== 0) {
|
||||
delete info.entries[key];
|
||||
return;
|
||||
}
|
||||
|
||||
info.entries[key] = info.entries[key].map(function(value) {
|
||||
if (value.indexOf("/") === -1)
|
||||
return value;
|
||||
else
|
||||
return vpath(value);
|
||||
});
|
||||
});
|
||||
|
||||
/* Qualify all the paths in files listed */
|
||||
var files = [];
|
||||
info.files.forEach(function(value) {
|
||||
if (!section || value.indexOf(section) === 0)
|
||||
files.push({ from: vpath("src", value), to: value });
|
||||
});
|
||||
info.files = files;
|
||||
|
||||
var plugins = [
|
||||
new copy(info.files)
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
entry: ["./src/index.js"],
|
||||
output: {
|
||||
filename: "bundle.js",
|
||||
path: path.resolve(__dirname, "build")
|
||||
},
|
||||
entry: info.entries,
|
||||
output: output,
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
enforce: 'pre',
|
||||
exclude: /node_modules/,
|
||||
loader: 'jshint-loader',
|
||||
test: /\.js$/
|
||||
},
|
||||
{
|
||||
enforce: 'pre',
|
||||
exclude: /node_modules/,
|
||||
loader: 'eslint-loader',
|
||||
test: /\.jsx$/
|
||||
},
|
||||
{
|
||||
enforce: 'pre',
|
||||
exclude: /node_modules/,
|
||||
loader: 'jshint-loader?esversion=6',
|
||||
test: /\.es6$/
|
||||
},
|
||||
{
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel-loader',
|
||||
test: /\.js$/
|
||||
},
|
||||
{
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel-loader',
|
||||
test: /\.jsx$/
|
||||
},
|
||||
{
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel-loader',
|
||||
test: /\.es6$/
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
plugins: plugins
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue