1 | import { ServicePlugin } from '@vue/cli-service'
|
2 |
|
3 | const servicePlugin: ServicePlugin = (api, options) => {
|
4 | const version = api.version
|
5 | api.assertVersion(4)
|
6 | api.assertVersion('^100')
|
7 | api.getCwd()
|
8 | api.resolve('src/main.js')
|
9 | api.hasPlugin('eslint')
|
10 | api.registerCommand(
|
11 | 'lint',
|
12 | {
|
13 | description: 'lint and fix source files',
|
14 | usage: 'vue-cli-service lint [options] [...files]',
|
15 | options: {
|
16 | '--format [formatter]': 'specify formatter (default: stylish)'
|
17 | },
|
18 | details: 'For more options, see https://eslint.org/docs/user-guide/command-line-interface#options'
|
19 | },
|
20 | async args => {
|
21 | await require('./lint')(args, api)
|
22 | }
|
23 | )
|
24 | api.registerCommand('lint', args => {})
|
25 |
|
26 | api.chainWebpack(webpackConfig => {
|
27 | if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
|
28 | webpackConfig.devtool('eval-cheap-module-source-map')
|
29 |
|
30 | webpackConfig.plugin('hmr').use(require('webpack/lib/HotModuleReplacementPlugin'))
|
31 |
|
32 | webpackConfig.output.globalObject(`(typeof self !== 'undefined' ? self : this)`)
|
33 | }
|
34 | })
|
35 |
|
36 | api.configureWebpack(config => {
|
37 | config.output = {
|
38 | path: 'test-dist-2'
|
39 | }
|
40 | })
|
41 |
|
42 | api.configureWebpack(config => {
|
43 | return {
|
44 | devtool: config.devtool || 'source-map'
|
45 | }
|
46 | })
|
47 |
|
48 | api.resolveWebpackConfig()
|
49 |
|
50 | api.resolveWebpackConfig(api.resolveChainableWebpackConfig())
|
51 |
|
52 | const { cacheIdentifier, cacheDirectory } = api.genCacheConfig(
|
53 | 'babel-loader',
|
54 | {
|
55 | '@babel/core': require('@babel/core/package.json').version,
|
56 | '@vue/babel-preset-app': require('@vue/babel-preset-app/package.json').version,
|
57 | 'babel-loader': require('babel-loader/package.json').version,
|
58 | modern: !!process.env.VUE_CLI_MODERN_BUILD,
|
59 | browserslist: api.service.pkg.browserslist
|
60 | },
|
61 | ['babel.config.js', '.browserslistrc']
|
62 | )
|
63 | }
|
64 | export = servicePlugin
|