This repository has been archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
124 lines (117 loc) · 2.75 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
const ExtractTextPlugin = require(`extract-text-webpack-plugin`);
const HtmlWebpackPlugin = require(`html-webpack-plugin`);
const path = require(`path`);
const webpack = require(`webpack`);
const {
PROD, // productionized build
PUBLIC_PATH, // file-loader publicPath override
} = process.env;
const BABEL_LOADER = {
loader: `babel-loader`,
options: {
presets: [`env`],
},
};
const CSS_LOADERS = [
{loader: `css-loader`},
{loader: `postcss-loader`},
];
const STYLUS_LOADERS = [
...CSS_LOADERS,
{loader: `stylus-loader`},
];
const fileLoaderOptions = {
name: `[name]-[hash].[ext]`,
outputPath: `images/`,
};
const optionalPlugins = [];
if (PROD) {
fileLoaderOptions.publicPath = `https://mixpanel.github.io/panel-farm/images/`;
optionalPlugins.push(new webpack.optimize.UglifyJsPlugin());
}
if (PUBLIC_PATH) {
fileLoaderOptions.publicPath = PUBLIC_PATH;
}
const webpackConfig = {
entry: {
farm: `./src/index.js`,
polyfills: [
`@webcomponents/custom-elements`,
`@webcomponents/shadydom`,
],
'animal-badge': `./src/panel-farm/animal-badge/index.js`,
'css-reset': './src/reset.css',
},
output: {
path: path.join(__dirname, `build`),
filename: `[name]-[hash].bundle.js`,
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
BABEL_LOADER,
],
},
{
test: /\.jade$/,
exclude: /node_modules/,
use: [
BABEL_LOADER,
{
loader: `virtual-jade-loader`,
options: {
vdom: `snabbdom`,
runtime: `var h = require("panel").h;`,
},
},
],
},
{
test: /\.styl$/,
exclude: /node_modules/,
oneOf: [
{
resourceQuery: /inline/,
loader: STYLUS_LOADERS,
},
{
loader: ExtractTextPlugin.extract({
use: STYLUS_LOADERS,
fallback: `style-loader`,
}),
},
],
},
{
test: /\.css$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract({
use: CSS_LOADERS,
fallback: `style-loader`,
}),
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: `file-loader`,
options: fileLoaderOptions,
}
],
},
],
},
plugins: [
new ExtractTextPlugin(`[name]-[hash].bundle.css`),
new HtmlWebpackPlugin({
template: `index.template.html`,
chunks: [`polyfills`, `css-reset`, `farm`],
chunksSortMode: (a, b) => a.names[0] === `polyfills` ? -1 : 1, // polyfills first
}),
...optionalPlugins,
],
};
module.exports = webpackConfig;