Skip to content
Prev Previous commit
Next Next commit
feat: add --no-cache option for both serve and build
  • Loading branch information
jeneser committed Apr 11, 2021
commit e4bf01ea82313d6571271ef7de8ed4ae462299f6
28 changes: 15 additions & 13 deletions packages/@vue/cli-service/lib/commands/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const defaults = {
clean: true,
target: 'app',
formats: 'commonjs,umd,umd-min',
'unsafe-inline': true
'unsafe-inline': true,
cache: true
}

const buildModes = {
Expand Down Expand Up @@ -38,7 +39,8 @@ module.exports = (api, options) => {
'--report-json': 'generate report.json to help analyze bundle content',
'--skip-plugins': `comma-separated list of plugin names to skip for this run`,
'--watch': `watch for changes`,
'--stdin': `close when stdin ends`
'--stdin': `close when stdin ends`,
'--no-cache': `disable webpack persistent caching`
}
}, async (args, rawArgs) => {
for (const key in defaults) {
Expand Down Expand Up @@ -196,17 +198,17 @@ async function build (args, api, options) {
await fs.emptyDir(targetDir)
}

modifyConfig(webpackConfig, config => {
config.cache.name = `${
config.mode
}-${
args.target
}-${
Object.keys(config.entry).join('-')
}${
args.modern ? (args.modernBuild ? '-modern' : '-legacy') : ''
}`
})
if (args.cache) {
modifyConfig(webpackConfig, config => {
config.cache.name = `${config.mode}-${args.target}-${Object.keys(config.entry).join('-')}${
args.modern ? (args.modernBuild ? '-modern' : '-legacy') : ''
}`
})
} else {
modifyConfig(webpackConfig, config => {
config.cache = false
})
}

return new Promise((resolve, reject) => {
webpack(webpackConfig, (err, stats) => {
Expand Down
13 changes: 10 additions & 3 deletions packages/@vue/cli-service/lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const {
const defaults = {
host: '0.0.0.0',
port: 8080,
https: false
https: false,
cache: true
}

module.exports = (api, options) => {
Expand All @@ -26,7 +27,8 @@ module.exports = (api, options) => {
'--port': `specify port (default: ${defaults.port})`,
'--https': `use https (default: ${defaults.https})`,
'--public': `specify the public network URL for the HMR client`,
'--skip-plugins': `comma-separated list of plugin names to skip for this run`
'--skip-plugins': `comma-separated list of plugin names to skip for this run`,
'--no-cache': `disable webpack persistent caching`
}
}, async function serve (args) {
info('Starting development server...')
Expand Down Expand Up @@ -160,7 +162,12 @@ module.exports = (api, options) => {
addDevClientToEntry(webpackConfig, devClients)
}

webpackConfig.cache.name = `${webpackConfig.mode}-${Object.keys(webpackConfig.entry).join('-')}`
args.cache = args.cache == null ? defaults.cache : args.cache
if (args.cache) {
webpackConfig.cache.name = `${webpackConfig.mode}-${Object.keys(webpackConfig.entry).join('-')}`
} else {
webpackConfig.cache = false
}

// create compiler
const compiler = webpack(webpackConfig)
Expand Down