-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
141 lines (121 loc) · 3.89 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
/*
For a clean reinstall:
delete 'package-lock.json', empty 'package.json'`s dev/Dependencies, and run:
npm i -D \
webpack webpack-dev-server webpack-cli \
style-loader css-loader null-loader \
html-webpack-plugin text-transform-loader \
babel-loader @babel/core @babel/preset-env \
vue vue-loader vue-template-compiler @vue/test-utils \
document-register-element vue-custom-element \
mocha mocha-webpack@^2.0.0-beta.0 sinon webpack-node-externals \
jsdom jsdom-global chai \
eslint eslint-loader eslint-plugin-vue \
stylelint stylelint-webpack-plugin \
stylelint-config-standard stylelint-config-recess-order \
opn-cli npm-run-all \
vsm-dictionary-local vsm-dictionary-cacher ;\
npm i -P \
string-style-html
*/
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const StylelintPlugin = require('stylelint-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const nodeExternals = require('webpack-node-externals');
const src = path.resolve(__dirname, './src');
module.exports = (env = {}) => {
var DEV = env.NODE_ENV == 'development';
var TEST = env.NODE_ENV == 'testing';
return Object.assign(
{ mode: DEV ? 'development' : TEST ? 'production' : 'none' },
DEV ? {
devServer: {
port: 3000,
open: true,
contentBase: src,
watchContentBase: true
},
entry: src + '/index-dev.js'
} : {},
{
devtool: DEV ? 'inline-source-map' :
TEST ? 'inline-cheap-module-source-map' : false,
module: {
rules: [
{
test: /\.(js|vue)$/,
exclude: /node_modules/,
enforce: 'pre',
loader: 'eslint-loader',
options: { // These override '.estlintrc' options.
emitWarning: true // Make errors not abort the build.
}
},
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.js$/,
include: src,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: { presets: ['@babel/preset-env'] }
},
{
loader: 'text-transform-loader',
options: {
transformText: s =>
// Exclude this VsmDictionary dependency, for use in browser:
s.replace(/require\('xmlhttprequest'\)/g, '{}')
}
}
]
},
Object.assign( { test: /\.css$/ },
TEST ? { loader: 'null-loader'} :
{ use: ['style-loader', 'css-loader'] }
)
]
},
resolve: {
extensions: ['.js', '.vue'],
alias: DEV ? { // Do not use the default 'vue.runtime.js' during dev:
'vue$': 'vue/dist/vue.js' // -> this enables informative warning msgs.
} : {}
},
node: {
fs: 'empty',
child_process: 'empty'
},
externals: TEST ? [nodeExternals()] : {},
plugins:
[ new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env.NODE_ENV)
}),
new VueLoaderPlugin()
]
.concat( DEV ?
[ new HtmlWebpackPlugin({
template: src + '/index-dev.html',
inject: 'body'
}),
new StylelintPlugin({ files: ['src/**/*.vue'] })
] : []
),
output: Object.assign(
!TEST ? {
filename: 'vsm-autocomplete.js',
} : {},
TEST ? { // As recommended on https://vue-test-utils.vuejs.org
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]'
} : {}
)
}
);
}