-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwebpack.common.js
101 lines (95 loc) · 2.96 KB
/
webpack.common.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var path = require("path");
var webpack = require("webpack");
var node_modules = path.resolve(__dirname, "node_modules");
var globule = require("globule");
const CopyPlugin = require("copy-webpack-plugin");
var outputDir = "dist";
// From Bloom's webpack, it seems this is needed
// if ever our output directory does not have the same parent as our node_modules. We then
// need to resolve the babel related presets (and plugins). This mapping function was
// suggested at https://github.com/babel/babel-loader/issues/166.
// Since our node_modules DOES have the same parent, maybe we could do without it?
function localResolve(preset) {
return Array.isArray(preset)
? [require.resolve(preset[0]), preset[1]]
: require.resolve(preset);
}
module.exports = {
// mode must be set to either "production" or "development" in webpack 4.
// Webpack-common is intended to be 'required' by something that provides that.
context: __dirname,
entry: {
index: "./src/index.ts"
},
output: {
path: path.join(__dirname, outputDir),
filename: "[name].js",
library: "ComicalJS",
// Exporting the library in umd format allows its various classes to
// be imported in typescript using import (rather than only by
// using require on the whole library) in a way that is consistent
// with the d.ts files we are generating. Using various other formats
// we found that a client could import the classes apparently successfully,
// but they were undefined at runtime.
// UMD is also a good universal library format that supports both AMD and commonjs.
libraryTarget: "umd"
},
resolve: {
modules: [".", node_modules],
extensions: [".js", ".jsx", ".ts", ".tsx"]
},
optimization: {
minimize: false,
namedModules: true,
splitChunks: {
cacheGroups: {
default: false
}
}
},
module: {
rules: [
{
test: /\.ts(x?)$/,
use: [{ loader: "ts-loader" }]
},
{
test: /\.less$/i,
use: [
{
loader: "style-loader" // creates style nodes from JS strings
},
{
loader: "css-loader" // translates CSS into CommonJS
},
{
loader: "less-loader" // compiles Less to CSS
}
]
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
// WOFF Font--needed?
{
test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
use: {
loader: "url-loader",
options: {
limit: 10000,
mimetype: "application/font-woff"
}
}
},
{
// this allows things like background-image: url("myComponentsButton.svg") and have the resulting path look for the svg in the stylesheet's folder
// the last few seem to be needed for (at least) slick-carousel to build.
test: /\.(svg|jpg|png|ttf|eot|gif)$/,
use: {
loader: "file-loader"
}
}
]
}
};