-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
152 lines (134 loc) · 4.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Copyright 2017 Palantir Technologies, Inc. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const path = require("path");
const webpack = require("webpack");
// webpack plugins
const { CheckerPlugin } = require("awesome-typescript-loader");
// const CircularDependencyPlugin = require("circular-dependency-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const WebpackNotifierPlugin = require("webpack-notifier");
// globals
const IS_PRODUCTION = process.env.NODE_ENV === "production";
const DEV_PORT = process.env.PORT || 3000;
const PACKAGE_NAME = '@presslabs/icons';
/**
* Configure plugins loaded based on environment.
*/
const plugins = [
// Used for async error reporting
// Can remove after https://github.com/webpack/webpack/issues/3460 resolved
new CheckerPlugin(),
// CSS extraction is only enabled in production (see scssLoaders below).
new MiniCssExtractPlugin({ filename: "[name].css" }),
// TODO: enable this
// Zero tolereance for circular depenendencies
// new CircularDependencyPlugin({
// exclude: /.js|node_modules/,
// failOnError: true,
// }),
];
if (!IS_PRODUCTION) {
plugins.push(
// Trigger an OS notification when the build succeeds in dev mode.
new WebpackNotifierPlugin({ title: PACKAGE_NAME })
);
}
// Module loaders for .scss files, used in reverse order:
// compile Sass, apply PostCSS, interpret CSS as modules.
const scssLoaders = [
// Only extract CSS to separate file in production mode.
IS_PRODUCTION ? MiniCssExtractPlugin.loader : require.resolve("style-loader"),
{
loader: require.resolve("css-loader"),
options: {
// necessary to minify @import-ed files using cssnano
importLoaders: 1,
},
},
{
loader: require.resolve("postcss-loader"),
options: {
plugins: [
require("autoprefixer"),
require("cssnano")({ preset: "default" }),
],
},
},
require.resolve("sass-loader"),
];
module.exports = {
entry: {
icons: [
"./src/index.ts"
],
},
devtool: IS_PRODUCTION ? false : "inline-source-map",
devServer: {
contentBase: "./src",
disableHostCheck: true,
historyApiFallback: true,
https: false,
// TODO: enable HMR
// hot: true,
index: path.resolve(__dirname, "src/index.html"),
inline: true,
stats: "errors-only",
open: false,
overlay: {
warnings: true,
errors: true,
},
port: DEV_PORT,
},
mode: IS_PRODUCTION ? "production" : "development",
module: {
rules: [
{
test: /\.tsx?$/,
loader: require.resolve("awesome-typescript-loader"),
options: {
configFileName: "./src/tsconfig.json",
},
},
{
test: /\.scss$/,
use: scssLoaders,
},
{
test: /\.(eot|ttf|woff|woff2|svg|png|gif|jpe?g)$/,
loader: require.resolve("file-loader"),
options: {
name: "[name].[ext]?[hash]",
outputPath: "assets/",
},
},
],
},
plugins,
resolve: {
extensions: [ ".js", ".jsx", ".ts", ".tsx", ".scss" ],
},
// externals: COMMON_EXTERNALS,
output: {
filename: "[name].bundle.js",
library: ["Blueprint", "Icons"],
libraryTarget: "umd",
path: path.resolve(__dirname, "./dist")
},
performance: {
maxAssetSize: 500000,
maxEntrypointSize: 500000,
},
};