@vcmap/plugin-cli 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -25
- package/assets/index.html +81 -0
- package/cli.js +21 -16
- package/index.js +5 -12
- package/package.json +21 -19
- package/src/build.js +113 -27
- package/src/context.js +9 -12
- package/src/create.js +82 -29
- package/src/defaultCommand.js +26 -8
- package/src/hostingHelpers.js +226 -0
- package/src/licenses.js +128 -0
- package/src/pack.js +28 -52
- package/src/packageJsonHelpers.js +10 -14
- package/src/preview.js +94 -0
- package/src/serve.js +67 -189
- package/src/getWebpackConfig.js +0 -290
- package/src/webpack.config.js +0 -29
package/src/getWebpackConfig.js
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const webpack = require('webpack');
|
|
3
|
-
const VueLoaderPlugin = require('vue-loader/lib/plugin');
|
|
4
|
-
const TerserPlugin = require('terser-webpack-plugin');
|
|
5
|
-
const autoprefixer = require('autoprefixer');
|
|
6
|
-
const { getPluginEntry } = require('./packageJsonHelpers');
|
|
7
|
-
const { resolveContext, getContext } = require('./context');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @enum {string}
|
|
11
|
-
*/
|
|
12
|
-
const buildMode = {
|
|
13
|
-
DEVELOPMENT: 'development',
|
|
14
|
-
PRODUCTION: 'production',
|
|
15
|
-
TESTING: 'testing',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @typedef {GetWebpackOptions} DevOptions
|
|
20
|
-
* @property {string|undefined} vcm - the vcm directory
|
|
21
|
-
* @property {number} port - the port number of the dev server // XXX take these options apart
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @typedef {GetWebpackOptions} ProdOptions
|
|
26
|
-
* @property {string} pluginName - the name of the plugin being built
|
|
27
|
-
* @property {boolean|undefined} modern - build for modern browsers
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @typedef {Object} GetWebpackOptions
|
|
32
|
-
* @property {string|Object|undefined} entry - an alternative entry point, defaults to 'src/index'
|
|
33
|
-
* @property {string|undefined} mode - 'development', 'production' or 'test'.
|
|
34
|
-
* @property {boolean|undefined} condenseWhitespace - pass whitespace: 'condense' to vue loader
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param {GetWebpackOptions} options
|
|
39
|
-
* @returns {webpack.Configuration}
|
|
40
|
-
*/
|
|
41
|
-
function getBaseConfig(options) {
|
|
42
|
-
return {
|
|
43
|
-
experiments: {
|
|
44
|
-
outputModule: true,
|
|
45
|
-
},
|
|
46
|
-
externals: {
|
|
47
|
-
'@vcmap/core': 'import @vcmap-core.js',
|
|
48
|
-
},
|
|
49
|
-
entry: options.entry,
|
|
50
|
-
context: getContext(),
|
|
51
|
-
resolve: {
|
|
52
|
-
extensions: ['.js', '.vue', '.json'],
|
|
53
|
-
alias: {
|
|
54
|
-
'@': resolveContext('src'),
|
|
55
|
-
},
|
|
56
|
-
modules: [
|
|
57
|
-
path.join(__dirname, '..', 'node_modules'),
|
|
58
|
-
'node_modules',
|
|
59
|
-
resolveContext('node_modules'),
|
|
60
|
-
],
|
|
61
|
-
},
|
|
62
|
-
resolveLoader: {
|
|
63
|
-
modules: [
|
|
64
|
-
path.join(__dirname, '..', 'node_modules'),
|
|
65
|
-
'node_modules',
|
|
66
|
-
resolveContext('node_modules'),
|
|
67
|
-
],
|
|
68
|
-
},
|
|
69
|
-
module: {
|
|
70
|
-
rules: [
|
|
71
|
-
{
|
|
72
|
-
test: /\.vue$/,
|
|
73
|
-
loader: 'vue-loader',
|
|
74
|
-
options: {
|
|
75
|
-
compilerOptions: {
|
|
76
|
-
whitespace: options.condenseWhitespace ? 'condense' : 'preserve',
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
test: /\.js$/,
|
|
82
|
-
loader: 'babel-loader',
|
|
83
|
-
include: [resolveContext('src')],
|
|
84
|
-
options: {
|
|
85
|
-
presets: [
|
|
86
|
-
require.resolve('@vue/babel-preset-app'),
|
|
87
|
-
],
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
test: /\.(png|jpe?g|gif)(\?.*)?$/,
|
|
92
|
-
use: [
|
|
93
|
-
{
|
|
94
|
-
loader: 'url-loader',
|
|
95
|
-
options: {
|
|
96
|
-
limit: 10000,
|
|
97
|
-
name: 'img/[name].[hash:8].[ext]',
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
test: /\.(svg)(\?.*)?$/,
|
|
104
|
-
use: [
|
|
105
|
-
{
|
|
106
|
-
loader: 'file-loader',
|
|
107
|
-
options: {
|
|
108
|
-
name: 'img/[name].[hash:8].[ext]',
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
|
|
115
|
-
use: [
|
|
116
|
-
{
|
|
117
|
-
loader: 'url-loader',
|
|
118
|
-
options: {
|
|
119
|
-
limit: 10000,
|
|
120
|
-
name: 'media/[name].[hash:8].[ext]',
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
],
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
|
|
127
|
-
use: [
|
|
128
|
-
{
|
|
129
|
-
loader: 'url-loader',
|
|
130
|
-
options: {
|
|
131
|
-
limit: 10000,
|
|
132
|
-
name: 'fonts/[name].[hash:8].[ext]',
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
],
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
test: /\.css$/,
|
|
139
|
-
use: [
|
|
140
|
-
{
|
|
141
|
-
loader: 'vue-style-loader',
|
|
142
|
-
options: {
|
|
143
|
-
base: 1020,
|
|
144
|
-
shadowMode: false,
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
loader: 'css-loader',
|
|
149
|
-
options: {
|
|
150
|
-
sourceMap: false,
|
|
151
|
-
importLoaders: 2,
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
loader: 'postcss-loader',
|
|
156
|
-
options: {
|
|
157
|
-
sourceMap: false,
|
|
158
|
-
plugins: [
|
|
159
|
-
autoprefixer,
|
|
160
|
-
],
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
],
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
test: /\.p(ost)?css$/,
|
|
167
|
-
use: [
|
|
168
|
-
{
|
|
169
|
-
loader: 'vue-style-loader',
|
|
170
|
-
options: {
|
|
171
|
-
base: 1020,
|
|
172
|
-
shadowMode: false,
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
loader: 'css-loader',
|
|
177
|
-
options: {
|
|
178
|
-
sourceMap: false,
|
|
179
|
-
importLoaders: 2,
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
loader: 'postcss-loader',
|
|
184
|
-
options: {
|
|
185
|
-
sourceMap: false,
|
|
186
|
-
plugins: [
|
|
187
|
-
autoprefixer,
|
|
188
|
-
],
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
],
|
|
192
|
-
},
|
|
193
|
-
],
|
|
194
|
-
},
|
|
195
|
-
plugins: [
|
|
196
|
-
new VueLoaderPlugin(),
|
|
197
|
-
new webpack.DefinePlugin({
|
|
198
|
-
'process.env': { NODE_ENV: `"${options.mode}"`, BASE_URL: '""' },
|
|
199
|
-
}),
|
|
200
|
-
],
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* @param {ProdOptions} options
|
|
206
|
-
* @returns {Promise<webpack.Configuration>}
|
|
207
|
-
*/
|
|
208
|
-
async function getProdWebpackConfig(options) {
|
|
209
|
-
options.entry = options.entry || { plugin: await getPluginEntry() || './src/index' };
|
|
210
|
-
options.mode = options.mode || buildMode.PRODUCTION;
|
|
211
|
-
process.env.VUE_CLI_MODERN_BUILD = true;
|
|
212
|
-
|
|
213
|
-
if (typeof options.entry === 'string') {
|
|
214
|
-
options.entry = { plugin: options.entry };
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const config = getBaseConfig(options);
|
|
218
|
-
config.output = {
|
|
219
|
-
path: resolveContext('dist'),
|
|
220
|
-
filename: `${options.pluginName}.js`,
|
|
221
|
-
library: {
|
|
222
|
-
type: 'module',
|
|
223
|
-
},
|
|
224
|
-
publicPath: './',
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
config.mode = options.mode;
|
|
228
|
-
if (options.mode !== 'development') {
|
|
229
|
-
config.devtool = false;
|
|
230
|
-
config.optimization = {
|
|
231
|
-
minimize: true,
|
|
232
|
-
minimizer: [
|
|
233
|
-
new TerserPlugin({
|
|
234
|
-
extractComments: false,
|
|
235
|
-
}),
|
|
236
|
-
],
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return config;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* @param {DevOptions} options
|
|
245
|
-
* @returns {Promise<webpack.Configuration>}
|
|
246
|
-
*/
|
|
247
|
-
async function getDevWebpackConfig(options) {
|
|
248
|
-
options.entry = options.entry || {
|
|
249
|
-
plugin: [
|
|
250
|
-
`webpack-dev-server/client?http://0.0.0.0:${options.port}/`,
|
|
251
|
-
'webpack/hot/only-dev-server',
|
|
252
|
-
await getPluginEntry() || './src/index.js',
|
|
253
|
-
],
|
|
254
|
-
};
|
|
255
|
-
options.mode = options.mode || buildMode.DEVELOPMENT;
|
|
256
|
-
if (typeof options.entry === 'string') {
|
|
257
|
-
options.entry = {
|
|
258
|
-
plugin: [
|
|
259
|
-
`webpack-dev-server/client?http://0.0.0.0:${options.port}/`,
|
|
260
|
-
'webpack/hot/only-dev-server',
|
|
261
|
-
options.entry,
|
|
262
|
-
],
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
const config = getBaseConfig(options);
|
|
266
|
-
|
|
267
|
-
config.output = {
|
|
268
|
-
globalObject: '(typeof self !== \'undefined\' ? self : this)',
|
|
269
|
-
path: resolveContext('_dist'),
|
|
270
|
-
library: {
|
|
271
|
-
type: 'module',
|
|
272
|
-
},
|
|
273
|
-
filename: '[name].js',
|
|
274
|
-
publicPath: '/_dist',
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
config.plugins.push(
|
|
278
|
-
new webpack.HotModuleReplacementPlugin(),
|
|
279
|
-
// new webpack.NoEmitOnErrorsPlugin(),
|
|
280
|
-
);
|
|
281
|
-
config.mode = options.mode;
|
|
282
|
-
config.devtool = 'eval-cheap-module-source-map';
|
|
283
|
-
return config;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
module.exports = {
|
|
287
|
-
getBaseConfig,
|
|
288
|
-
getProdWebpackConfig,
|
|
289
|
-
getDevWebpackConfig,
|
|
290
|
-
};
|
package/src/webpack.config.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const { getBaseConfig } = require('./getWebpackConfig');
|
|
2
|
-
const { getPluginEntry } = require('./packageJsonHelpers');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Use this file to point your ID eslint settings to a webpack resolver. Do to a bug in `eslint-import-resolver-webpack`
|
|
6
|
-
* you must provide the ENTRY env for use with eslint, see example.
|
|
7
|
-
* @example
|
|
8
|
-
* 'import/resolver': {
|
|
9
|
-
* webpack: {
|
|
10
|
-
* config: 'node_modules/vcmplugin-cli/src/webpack.config.js'
|
|
11
|
-
* env: {
|
|
12
|
-
* ENTRY: './index.js'
|
|
13
|
-
* }
|
|
14
|
-
* }
|
|
15
|
-
* }
|
|
16
|
-
* @param {Object=} env
|
|
17
|
-
* @returns {webpack.Configuration|Promise<webpack.Configuration>}
|
|
18
|
-
*/
|
|
19
|
-
function getConfig(env) {
|
|
20
|
-
if (env && env.ENTRY) {
|
|
21
|
-
return getBaseConfig({ entry: env.ENTRY, mode: 'development' });
|
|
22
|
-
}
|
|
23
|
-
return getPluginEntry()
|
|
24
|
-
.then((entry) => {
|
|
25
|
-
return getBaseConfig({ entry, mode: 'development' });
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = getConfig;
|