This repository has been archived by the owner on Oct 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
150 lines (137 loc) · 3.54 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
const path = require('path');
const fs = require('fs');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const IS_TEST = process.env.NODE_ENV === 'test';
const src = path.resolve(__dirname, 'src');
const static = path.resolve(__dirname, 'calchart', 'static');
/**** LOADER OPTIONS ****/
const babelLoaderOptions = {
minified: true,
comments: false,
cacheDirectory: true, // faster compilation
presets: [
// general transpiler for general browser compatability
['env', {
targets: {
browsers: ['last 2 versions'],
},
}],
],
plugins: [
// allow spread operator
'transform-object-rest-spread',
],
};
const cssLoader = {
loader: 'css-loader',
options: {
url: false,
},
};
let resourcesDir = path.resolve(src, 'scss')
let resources = fs.readdirSync(resourcesDir)
.filter(s => s.startsWith('_') && s.endsWith('.scss'));
const sassResourcesLoaderOptions = {
resources: resources.map(s => path.resolve(resourcesDir, s)),
};
// https://vue-loader.vuejs.org/en/configurations/advanced.html
const vueLoaderOptions = {
loaders: {
js: [
{
loader: 'babel-loader',
options: babelLoaderOptions,
},
],
scss: ExtractTextPlugin.extract([
cssLoader,
'sass-loader',
{
loader: 'sass-resources-loader',
options: sassResourcesLoaderOptions,
},
]),
'context-menu': require.resolve('vue-ctxmenu/loader'),
},
preserveWhitespace: false,
};
/**** WEBPACK CONFIG ****/
const aliases = {};
if (IS_TEST) {
aliases['vue$'] = 'vue/dist/vue.esm.js';
}
webpackConfig = {
context: src,
entry: {
calchart: path.resolve(src, 'calchart.js'),
},
output: {
path: static,
filename: '[name].js',
},
resolve: {
extensions: ['.js', '.vue'],
alias: aliases,
modules: [
src,
path.resolve(__dirname, 'node_modules'),
],
},
module: {
rules: [
{
test: /\.vue$/,
use: {
loader: 'vue-loader',
options: vueLoaderOptions
},
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: babelLoaderOptions
},
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract([
cssLoader,
]),
},
],
},
plugins: [
new CopyWebpackPlugin([
'static',
], {
ignore: [
'.DS_Store',
],
}),
new ExtractTextPlugin({
filename: '[name].css',
allChunks: true,
}),
],
devtool: 'source-map',
stats: 'normal',
devServer: {
host: '0.0.0.0',
port: 4200,
headers: {
'Access-Control-Allow-Origin': '*',
},
},
};
if (IS_TEST) {
webpackConfig.externals = [nodeExternals({
whitelist: [/\.css/],
})];
webpackConfig.devtool = 'inline-cheap-module-source-map';
webpackConfig.resolve.modules.push(path.resolve(__dirname));
}
module.exports = webpackConfig;