-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
80 lines (76 loc) · 3.24 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const fs = require("fs");
const path = require("path");
const webpack = require("webpack");
const { AureliaPlugin, ModuleDependenciesPlugin, GlobDependenciesPlugin } = require("aurelia-webpack-plugin");
const bundleOutputDir = "./dist";
const WebpackDeletePlugin = require("webpack-delete-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const HtmlWebpackHarddiskPlugin = require("html-webpack-harddisk-plugin");
function copyToRawRecursive(dir) {
fs.readdirSync(dir).forEach(it => {
const itsPath = path.resolve(dir, it);
const itsStat = fs.statSync(itsPath);
if (itsStat.isDirectory()) {
copyToRawRecursive(itsPath);
} else if (dir !== "src/samples") {
if ((itsPath.endsWith(".html") || itsPath.endsWith(".ts") || itsPath.endsWith(".css") || itsPath.endsWith(".md")) && !itsPath.endsWith("index.ts")) {
fs.copyFileSync(itsPath, itsPath + ".raw");
}
}
})
}
console.log("Creating raw files for code examples...");
copyToRawRecursive("src/samples");
module.exports = (env, argv) => {
const isDevBuild = argv.mode !== "production";
console.log(isDevBuild);
const cssLoader = { loader: "css-loader" };
return [{
entry: { "app": ["es6-promise/auto", "aurelia-bootstrapper"] },
resolve: {
extensions: [".ts", ".js"],
modules: ["src", "node_modules"]
},
output: {
path: path.resolve(bundleOutputDir),
publicPath: "dist/",
filename: "[name].[hash].js",
chunkFilename: "[name].[chunkhash].js"
},
module: {
rules: [{ test: /\.(png|woff|woff2|eot|ttf|svg|jpg)(\?|$)/, loader: "url-loader?limit=1" },
{ test: /\.ts$/i, include: [/src/], use: "awesome-typescript-loader" },
{
test: /\.html$/i,
use: { loader: "html-loader", options: { attrs: [ /* do not process images */ ] } }
},
{ test: /\.json$/i, use: "json-loader" },
{ test: /\.md$/i, use: "null-loader" },
{ test: /\.raw$/i, use: "raw-loader" },
{ test: /\.css$/i, issuer: /\.html|empty-entry\.js$/i, use: cssLoader },
{ test: /\.css$/i, issuer: [{ not: [{ test: /\.html$/i }] }], use: ["style-loader", cssLoader] }
]
},
optimization: {
concatenateModules: false,
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: "vendor",
chunks: "all"
}
}
}
},
devtool: isDevBuild ? "source-map" : false,
plugins: [
new webpack.DefinePlugin({ IS_DEV_BUILD: JSON.stringify(isDevBuild) }),
new AureliaPlugin({ aureliaApp: "main" }),
new GlobDependenciesPlugin({ "app": ["src/**/*.{ts,html,raw}"] }),
new HtmlWebpackPlugin({ template: 'index.ejs', filename: "../index.html", metadata: {}, alwaysWriteToDisk: true }),
new HtmlWebpackHarddiskPlugin(),
new WebpackDeletePlugin(["./src/**/*.raw"])
]
}];
};