Tone.js/webpack.config.js

84 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-05-18 16:10:52 +00:00
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
2019-09-16 18:03:52 +00:00
// /////////////////////////////////////
2018-05-18 16:10:52 +00:00
// Defaults
2019-09-16 18:03:52 +00:00
// /////////////////////////////////////
2018-05-18 16:10:52 +00:00
const defaults = {
2019-09-16 18:03:52 +00:00
mode: "development",
context: __dirname,
entry: {
Tone: "./Tone/index.ts",
2018-05-18 16:10:52 +00:00
},
2019-09-16 18:03:52 +00:00
output: {
path: path.resolve(__dirname, "build"),
filename: "[name].js",
library: "Tone",
2019-09-16 18:03:52 +00:00
libraryTarget: "umd"
2018-05-18 16:10:52 +00:00
},
2019-09-16 18:03:52 +00:00
resolve: {
extensions: [".ts", ".js"]
2019-07-11 04:21:20 +00:00
},
2019-09-16 18:03:52 +00:00
module: {
rules: [
2019-07-11 04:21:20 +00:00
{
test: /\.ts$/,
2019-09-16 18:03:52 +00:00
use: "ts-loader",
2019-07-11 04:21:20 +00:00
exclude: /(node_modules)/,
}
]
2018-05-18 16:10:52 +00:00
},
2019-09-16 18:03:52 +00:00
devtool: "cheap-source-map",
2018-05-18 16:10:52 +00:00
};
2019-09-16 18:03:52 +00:00
// /////////////////////////////////////
2018-05-18 16:10:52 +00:00
// Scratch
2019-09-16 18:03:52 +00:00
// /////////////////////////////////////
2018-05-18 16:10:52 +00:00
const scratch = Object.assign({}, defaults, {
2019-09-16 18:03:52 +00:00
entry: {
scratch: "./examples/scratch.ts",
2018-05-18 16:10:52 +00:00
},
2019-09-16 18:03:52 +00:00
plugins: [
new HtmlWebpackPlugin({
2019-09-16 18:03:52 +00:00
template: "./examples/scratch.html"
})
2018-05-18 16:10:52 +00:00
],
});
2019-09-16 18:03:52 +00:00
// /////////////////////////////////////
2018-05-18 16:10:52 +00:00
// Tests
2019-09-16 18:03:52 +00:00
// /////////////////////////////////////
2018-05-18 16:10:52 +00:00
const test = Object.assign({}, defaults, {
2019-09-16 18:03:52 +00:00
entry: {
test: "./test/test.js",
2018-05-18 16:10:52 +00:00
},
2019-09-16 18:03:52 +00:00
plugins: [
2018-05-18 16:10:52 +00:00
new HtmlWebpackPlugin({
2019-09-16 18:03:52 +00:00
filename: "test.html",
template: "./test/index.html",
2018-05-18 16:10:52 +00:00
})
],
});
2019-09-16 18:03:52 +00:00
// /////////////////////////////////////
2018-05-18 16:10:52 +00:00
// Production
2019-09-16 18:03:52 +00:00
// /////////////////////////////////////
2018-05-18 16:10:52 +00:00
const production = Object.assign({}, defaults, {
2019-09-16 18:03:52 +00:00
mode: "production",
devtool: "source-map",
2018-05-18 16:10:52 +00:00
});
module.exports = env => {
2019-09-16 18:03:52 +00:00
if (env.test) {
2018-05-18 16:10:52 +00:00
return test;
2019-09-16 18:03:52 +00:00
} else if (env.production) {
2018-05-18 16:10:52 +00:00
return production;
} else {
return scratch;
}
};