-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.js
155 lines (141 loc) · 3.29 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
153
154
155
var path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
// Github Pages only reads from a top-level folder named `docs/`
var DEMO_BUILD_DIR = path.resolve(__dirname, 'docs');
var DEMO_SRC_DIR = path.resolve(__dirname, 'demo');
var DIST_DIR = path.resolve(__dirname, 'dist');
var SRC_DIR = path.resolve(__dirname, 'src');
var config = {
mode: process.env.NODE_ENV,
resolve: {
extensions: ['.js', '.sass', '.scss', '.css'],
modules: [
SRC_DIR,
'node_modules'
]
},
resolveLoader: {
modules: ['node_modules']
},
module: {
strictExportPresence: true,
rules: [
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: { hmr: process.env.NODE_ENV == 'development' },
},
'css-loader',
],
},
{
test: /\.(sass|scss)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: { hmr: process.env.NODE_ENV == 'development' },
},
'css-loader',
'sass-loader'
],
},
{
test: /\.(js)$/,
exclude: /node_modules/,
use: [
'babel-loader'
]
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: ['svg-inline-loader'],
}
]
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
};
// We build 2 outputs -
//
// 1. A compiled demo for Github Pages. Also serves
// as a convenient preview for local development
// Input: DEMO_SRC_DIR
// Output: DEMO_BUILD_DIR
//
// 2. A distribution for production / npm package
// Input: SRC_DIR
// Output: DIST_DIR
//
//
// DEMO (AND DEVELOPMENT PREVIEW)
//
var demoConfig = Object.assign({}, config, {
entry: DEMO_SRC_DIR + '/index.js',
output: {
path: DEMO_BUILD_DIR,
filename: 'index.js'
},
plugins: [
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({
hash: true,
filename: 'index.html',
template: DEMO_SRC_DIR + '/template.html'
})
]
});
if (config.mode == 'development') {
demoConfig.devServer = {
contentBase: DEMO_SRC_DIR + '/index',
disableHostCheck: true,
headers: {
'Access-Control-Allow-Origin': '*'
},
host: 'localhost',
hot: true,
overlay: true,
port: 3035,
quiet: false,
stats: {
errorDetails: true
},
useLocalIp: false,
watchOptions: {
ignored: '/node_modules/'
}
}
demoConfig.output.publicPath = '/';
}
//
// PRODUCTION DISTRIBUTION
//
var distConfig = Object.assign({}, config, {
entry: SRC_DIR + '/components/VanillaTreeViewer/VanillaTreeViewer.js',
output: {
path: DIST_DIR,
filename: 'index.js',
library: 'VanillaTreeViewer',
libraryTarget: 'var',
libraryExport: 'default'
},
externals: {},
plugins: [
new MiniCssExtractPlugin()
],
devtool: 'source-map'
});
module.exports = [
// Order matters! From the docs:
//
// > When exporting multiple configurations only the `devServer`
// > options for the first configuration will be taken into
// > account and used for all the configurations in the array.
//
demoConfig,
distConfig
];