2018-03-16 19:52:17 +00:00
|
|
|
import path from 'path'
|
2018-08-22 21:54:08 +00:00
|
|
|
import consola from 'consola'
|
2018-03-16 16:12:06 +00:00
|
|
|
import TimeFixPlugin from 'time-fix-plugin'
|
2018-10-18 15:43:44 +00:00
|
|
|
import clone from 'lodash/clone'
|
|
|
|
import cloneDeep from 'lodash/cloneDeep'
|
2018-11-15 22:02:55 +00:00
|
|
|
import escapeRegExp from 'lodash/escapeRegExp'
|
2018-03-22 09:11:16 +00:00
|
|
|
import VueLoader from 'vue-loader'
|
2018-12-09 10:28:08 +00:00
|
|
|
import ExtractCssChunks from 'extract-css-chunks-webpack-plugin'
|
2018-12-01 10:13:28 +00:00
|
|
|
import TerserWebpackPlugin from 'terser-webpack-plugin'
|
2018-03-24 13:02:04 +00:00
|
|
|
import WebpackBar from 'webpackbar'
|
2018-11-08 09:15:56 +00:00
|
|
|
import env from 'std-env'
|
2018-03-22 10:31:23 +00:00
|
|
|
|
2018-10-17 21:28:25 +00:00
|
|
|
import { isUrl, urlJoin } from '@nuxt/common'
|
|
|
|
|
2018-12-01 10:13:28 +00:00
|
|
|
import PerfLoader from '../utils/perf-loader'
|
|
|
|
import StyleLoader from '../utils/style-loader'
|
|
|
|
import WarnFixPlugin from '../plugins/warnfix'
|
2016-11-07 01:34:58 +00:00
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
export default class WebpackBaseConfig {
|
|
|
|
constructor(builder, options) {
|
|
|
|
this.name = options.name
|
|
|
|
this.isServer = options.isServer
|
2018-10-31 15:52:35 +00:00
|
|
|
this.isModern = options.isModern
|
2018-03-22 14:06:54 +00:00
|
|
|
this.builder = builder
|
2018-10-24 16:55:18 +00:00
|
|
|
this.nuxt = builder.context.nuxt
|
|
|
|
this.isStatic = builder.context.isStatic
|
|
|
|
this.options = builder.context.options
|
2018-03-22 14:06:54 +00:00
|
|
|
this.spinner = builder.spinner
|
2018-09-10 08:27:01 +00:00
|
|
|
this.loaders = this.options.build.loaders
|
2018-11-14 12:00:12 +00:00
|
|
|
this.buildMode = this.options.dev ? 'development' : 'production'
|
2018-11-15 22:02:55 +00:00
|
|
|
this.modulesToTranspile = this.normalizeTranspile()
|
2018-03-22 14:06:54 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 15:52:35 +00:00
|
|
|
get colors() {
|
|
|
|
return {
|
|
|
|
client: 'green',
|
|
|
|
server: 'orange',
|
|
|
|
modern: 'blue'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-22 21:54:08 +00:00
|
|
|
get nuxtEnv() {
|
|
|
|
return {
|
|
|
|
isDev: this.options.dev,
|
|
|
|
isServer: this.isServer,
|
2018-10-31 15:52:35 +00:00
|
|
|
isClient: !this.isServer,
|
|
|
|
isModern: !!this.isModern
|
2018-08-22 21:54:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 22:02:55 +00:00
|
|
|
normalizeTranspile() {
|
|
|
|
// include SFCs in node_modules
|
|
|
|
const items = [/\.vue\.js/]
|
|
|
|
for (const pattern of this.options.build.transpile) {
|
|
|
|
if (pattern instanceof RegExp) {
|
|
|
|
items.push(pattern)
|
|
|
|
} else {
|
|
|
|
const posixModule = pattern.replace(/\\/g, '/')
|
|
|
|
items.push(new RegExp(escapeRegExp(path.normalize(posixModule))))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return items
|
|
|
|
}
|
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
getBabelOptions() {
|
2018-10-18 15:43:44 +00:00
|
|
|
const options = clone(this.options.build.babel)
|
2018-03-22 14:06:54 +00:00
|
|
|
|
|
|
|
if (typeof options.presets === 'function') {
|
|
|
|
options.presets = options.presets({ isServer: this.isServer })
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options.babelrc && !options.presets) {
|
|
|
|
options.presets = [
|
|
|
|
[
|
2018-10-26 17:58:21 +00:00
|
|
|
require.resolve('@nuxt/babel-preset-app'),
|
2018-03-22 14:06:54 +00:00
|
|
|
{
|
2018-08-10 13:45:58 +00:00
|
|
|
buildTarget: this.isServer ? 'server' : 'client'
|
2018-03-22 14:06:54 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
return options
|
|
|
|
}
|
|
|
|
|
2018-08-22 21:54:08 +00:00
|
|
|
getFileName(key) {
|
|
|
|
let fileName = this.options.build.filenames[key]
|
2018-08-22 15:08:51 +00:00
|
|
|
if (typeof fileName === 'function') {
|
2018-08-22 21:54:08 +00:00
|
|
|
fileName = fileName(this.nuxtEnv)
|
2018-08-22 15:08:51 +00:00
|
|
|
}
|
2018-03-22 14:06:54 +00:00
|
|
|
if (this.options.dev) {
|
2018-08-22 21:54:08 +00:00
|
|
|
const hash = /\[(chunkhash|contenthash|hash)(?::(\d+))?\]/.exec(fileName)
|
|
|
|
if (hash) {
|
|
|
|
consola.warn(`Notice: Please do not use ${hash[1]} in dev mode to prevent memory leak`)
|
|
|
|
}
|
2018-03-23 08:22:05 +00:00
|
|
|
}
|
2018-03-22 14:06:54 +00:00
|
|
|
return fileName
|
|
|
|
}
|
|
|
|
|
2018-12-01 10:13:28 +00:00
|
|
|
get devtool() {
|
2018-08-22 14:24:47 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
env() {
|
|
|
|
const env = {
|
2018-11-14 12:00:12 +00:00
|
|
|
'process.env.NODE_ENV': JSON.stringify(this.buildMode),
|
2018-03-22 14:06:54 +00:00
|
|
|
'process.mode': JSON.stringify(this.options.mode),
|
|
|
|
'process.static': this.isStatic
|
|
|
|
}
|
2018-10-12 22:31:19 +00:00
|
|
|
Object.entries(this.options.env).forEach(([key, value]) => {
|
2018-03-22 14:06:54 +00:00
|
|
|
env['process.env.' + key] =
|
2018-10-12 22:31:19 +00:00
|
|
|
['boolean', 'number'].includes(typeof value)
|
2018-03-22 14:06:54 +00:00
|
|
|
? value
|
|
|
|
: JSON.stringify(value)
|
|
|
|
})
|
|
|
|
return env
|
|
|
|
}
|
|
|
|
|
|
|
|
output() {
|
|
|
|
return {
|
2018-08-20 16:04:55 +00:00
|
|
|
path: path.resolve(this.options.buildDir, 'dist', this.isServer ? 'server' : 'client'),
|
2017-12-11 20:07:11 +00:00
|
|
|
filename: this.getFileName('app'),
|
|
|
|
chunkFilename: this.getFileName('chunk'),
|
2018-01-11 18:32:47 +00:00
|
|
|
publicPath: isUrl(this.options.build.publicPath)
|
2017-06-11 14:17:36 +00:00
|
|
|
? this.options.build.publicPath
|
2018-01-11 18:32:47 +00:00
|
|
|
: urlJoin(this.options.router.base, this.options.build.publicPath)
|
2018-03-22 14:06:54 +00:00
|
|
|
}
|
2016-11-07 01:34:58 +00:00
|
|
|
}
|
2017-06-15 22:19:53 +00:00
|
|
|
|
2018-08-22 14:24:47 +00:00
|
|
|
optimization() {
|
2018-12-01 10:13:28 +00:00
|
|
|
const optimization = cloneDeep(this.options.build.optimization)
|
|
|
|
|
|
|
|
if (optimization.minimize && optimization.minimizer === undefined) {
|
|
|
|
optimization.minimizer = this.minimizer()
|
|
|
|
}
|
|
|
|
|
|
|
|
return optimization
|
|
|
|
}
|
|
|
|
|
|
|
|
minimizer() {
|
|
|
|
const minimizer = []
|
|
|
|
|
|
|
|
// https://github.com/webpack-contrib/terser-webpack-plugin
|
|
|
|
if (this.options.build.terser) {
|
|
|
|
minimizer.push(
|
|
|
|
new TerserWebpackPlugin(Object.assign({
|
|
|
|
parallel: true,
|
|
|
|
cache: this.options.build.cache,
|
|
|
|
sourceMap: this.devtool && /source-?map/.test(this.devtool),
|
|
|
|
extractComments: {
|
|
|
|
filename: 'LICENSES'
|
|
|
|
},
|
|
|
|
terserOptions: {
|
|
|
|
compress: {
|
|
|
|
ecma: this.isModern ? 6 : undefined
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
comments: /^\**!|@preserve|@license|@cc_on/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, this.options.build.terser))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return minimizer
|
2018-08-22 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
alias() {
|
2018-09-19 08:46:21 +00:00
|
|
|
const { srcDir, rootDir, dir: { assets: assetsDir, static: staticDir } } = this.options
|
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
return {
|
2018-09-19 08:46:21 +00:00
|
|
|
'~': path.join(srcDir),
|
|
|
|
'~~': path.join(rootDir),
|
|
|
|
'@': path.join(srcDir),
|
|
|
|
'@@': path.join(rootDir),
|
|
|
|
[assetsDir]: path.join(srcDir, assetsDir),
|
|
|
|
[staticDir]: path.join(srcDir, staticDir)
|
2018-03-22 14:06:54 +00:00
|
|
|
}
|
2018-03-22 10:31:23 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
rules() {
|
2018-11-08 22:26:52 +00:00
|
|
|
const perfLoader = new PerfLoader(this)
|
2018-03-23 04:09:03 +00:00
|
|
|
const styleLoader = new StyleLoader(
|
|
|
|
this.options,
|
2018-10-24 16:55:18 +00:00
|
|
|
this.nuxt,
|
2018-11-08 22:26:52 +00:00
|
|
|
{ isServer: this.isServer, perfLoader }
|
2018-03-23 04:09:03 +00:00
|
|
|
)
|
2018-03-22 21:21:17 +00:00
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
|
|
|
loader: 'vue-loader',
|
2018-09-10 08:27:01 +00:00
|
|
|
options: this.loaders.vue
|
2018-03-22 14:06:54 +00:00
|
|
|
},
|
2018-04-21 07:27:48 +00:00
|
|
|
{
|
|
|
|
test: /\.pug$/,
|
|
|
|
oneOf: [
|
|
|
|
{
|
|
|
|
resourceQuery: /^\?vue/,
|
2018-09-10 08:27:01 +00:00
|
|
|
use: [{
|
|
|
|
loader: 'pug-plain-loader',
|
|
|
|
options: this.loaders.pugPlain
|
|
|
|
}]
|
2018-04-21 07:27:48 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-10 08:27:01 +00:00
|
|
|
use: [
|
|
|
|
'raw-loader',
|
|
|
|
{
|
|
|
|
loader: 'pug-plain-loader',
|
|
|
|
options: this.loaders.pugPlain
|
|
|
|
}
|
|
|
|
]
|
2018-04-21 07:27:48 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2018-03-22 14:06:54 +00:00
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
2018-08-06 00:12:44 +00:00
|
|
|
exclude: (file) => {
|
2018-05-06 18:46:02 +00:00
|
|
|
// not exclude files outside node_modules
|
2018-10-12 22:31:19 +00:00
|
|
|
if (!/node_modules/.test(file)) {
|
|
|
|
return false
|
2018-05-06 18:46:02 +00:00
|
|
|
}
|
2018-10-12 22:31:19 +00:00
|
|
|
|
|
|
|
// item in transpile can be string or regex object
|
2018-11-15 22:02:55 +00:00
|
|
|
return !this.modulesToTranspile.some(module => module.test(file))
|
2018-05-06 18:46:02 +00:00
|
|
|
},
|
2018-11-08 22:26:52 +00:00
|
|
|
use: perfLoader.js().concat({
|
2018-10-22 21:48:06 +00:00
|
|
|
loader: require.resolve('babel-loader'),
|
2018-03-22 21:21:17 +00:00
|
|
|
options: this.getBabelOptions()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
2018-11-08 22:26:52 +00:00
|
|
|
oneOf: styleLoader.apply('css')
|
2018-03-22 21:21:17 +00:00
|
|
|
},
|
2018-11-30 15:23:44 +00:00
|
|
|
{
|
|
|
|
test: /\.postcss$/,
|
|
|
|
oneOf: styleLoader.apply('postcss')
|
|
|
|
},
|
2018-03-22 21:21:17 +00:00
|
|
|
{
|
|
|
|
test: /\.less$/,
|
2018-11-08 22:26:52 +00:00
|
|
|
oneOf: styleLoader.apply('less', {
|
2018-09-10 08:27:01 +00:00
|
|
|
loader: 'less-loader',
|
|
|
|
options: this.loaders.less
|
2018-11-08 22:26:52 +00:00
|
|
|
})
|
2018-03-22 14:06:54 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.sass$/,
|
2018-11-08 22:26:52 +00:00
|
|
|
oneOf: styleLoader.apply('sass', {
|
2018-03-22 14:06:54 +00:00
|
|
|
loader: 'sass-loader',
|
2018-09-10 08:27:01 +00:00
|
|
|
options: this.loaders.sass
|
2018-11-08 22:26:52 +00:00
|
|
|
})
|
2018-03-22 14:06:54 +00:00
|
|
|
},
|
2018-03-22 21:21:17 +00:00
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
2018-11-08 22:26:52 +00:00
|
|
|
oneOf: styleLoader.apply('scss', {
|
2018-09-10 08:27:01 +00:00
|
|
|
loader: 'sass-loader',
|
|
|
|
options: this.loaders.scss
|
2018-11-08 22:26:52 +00:00
|
|
|
})
|
2018-03-22 21:21:17 +00:00
|
|
|
},
|
2018-03-22 14:06:54 +00:00
|
|
|
{
|
|
|
|
test: /\.styl(us)?$/,
|
2018-11-08 22:26:52 +00:00
|
|
|
oneOf: styleLoader.apply('stylus', {
|
2018-09-10 08:27:01 +00:00
|
|
|
loader: 'stylus-loader',
|
|
|
|
options: this.loaders.stylus
|
2018-11-08 22:26:52 +00:00
|
|
|
})
|
2018-03-22 14:06:54 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-01 04:26:10 +00:00
|
|
|
test: /\.(png|jpe?g|gif|svg|webp)$/,
|
2018-11-08 22:26:52 +00:00
|
|
|
use: perfLoader.asset().concat({
|
2018-03-23 07:34:55 +00:00
|
|
|
loader: 'url-loader',
|
2018-09-10 08:27:01 +00:00
|
|
|
options: Object.assign(
|
|
|
|
this.loaders.imgUrl,
|
|
|
|
{ name: this.getFileName('img') }
|
|
|
|
)
|
2018-03-23 07:34:55 +00:00
|
|
|
})
|
2018-03-22 14:06:54 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
2018-11-08 22:26:52 +00:00
|
|
|
use: perfLoader.asset().concat({
|
2018-03-23 07:34:55 +00:00
|
|
|
loader: 'url-loader',
|
2018-09-10 08:27:01 +00:00
|
|
|
options: Object.assign(
|
|
|
|
this.loaders.fontUrl,
|
|
|
|
{ name: this.getFileName('font') }
|
|
|
|
)
|
2018-03-23 07:34:55 +00:00
|
|
|
})
|
2018-03-22 14:06:54 +00:00
|
|
|
},
|
|
|
|
{
|
2018-08-01 16:07:18 +00:00
|
|
|
test: /\.(webm|mp4|ogv)$/,
|
2018-11-08 22:26:52 +00:00
|
|
|
use: perfLoader.asset().concat({
|
2018-03-23 07:34:55 +00:00
|
|
|
loader: 'file-loader',
|
2018-09-10 08:27:01 +00:00
|
|
|
options: Object.assign(
|
|
|
|
this.loaders.file,
|
|
|
|
{ name: this.getFileName('video') }
|
|
|
|
)
|
2018-03-23 07:34:55 +00:00
|
|
|
})
|
2018-03-20 22:11:30 +00:00
|
|
|
}
|
2018-03-22 14:06:54 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
plugins() {
|
2018-10-18 15:43:44 +00:00
|
|
|
const plugins = [new VueLoader.VueLoaderPlugin()]
|
2018-03-22 14:06:54 +00:00
|
|
|
|
|
|
|
Array.prototype.push.apply(plugins, this.options.build.plugins || [])
|
|
|
|
|
|
|
|
// Add timefix-plugin before others plugins
|
|
|
|
if (this.options.dev) {
|
|
|
|
plugins.unshift(new TimeFixPlugin())
|
2018-03-18 08:51:56 +00:00
|
|
|
}
|
2018-03-11 21:28:56 +00:00
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
// Hide warnings about plugins without a default export (#1179)
|
|
|
|
plugins.push(new WarnFixPlugin())
|
|
|
|
|
2018-03-22 16:22:41 +00:00
|
|
|
// Build progress indicator
|
2018-03-31 16:22:14 +00:00
|
|
|
plugins.push(new WebpackBar({
|
2018-10-31 15:52:35 +00:00
|
|
|
name: this.name,
|
|
|
|
color: this.colors[this.name],
|
2018-11-08 09:15:56 +00:00
|
|
|
reporters: [
|
|
|
|
'basic',
|
|
|
|
'fancy',
|
|
|
|
'profile',
|
|
|
|
'stats'
|
|
|
|
],
|
2018-11-08 21:54:10 +00:00
|
|
|
basic: !this.options.build.quiet && env.minimalCLI,
|
2018-11-08 22:13:39 +00:00
|
|
|
fancy: !this.options.build.quiet && !env.minimalCLI,
|
2018-11-08 09:15:56 +00:00
|
|
|
profile: !this.options.build.quiet && this.options.build.profile,
|
|
|
|
stats: !this.options.build.quiet && !this.options.dev && this.options.build.stats,
|
|
|
|
reporter: {
|
|
|
|
change: (_, { shortPath }) => {
|
|
|
|
if (!this.isServer) {
|
|
|
|
this.nuxt.callHook('bundler:change', shortPath)
|
|
|
|
}
|
|
|
|
},
|
2018-11-08 11:16:07 +00:00
|
|
|
done: (context) => {
|
|
|
|
if (context.hasErrors) {
|
2018-11-08 09:15:56 +00:00
|
|
|
this.nuxt.callHook('bundler:error')
|
2018-04-01 19:30:39 +00:00
|
|
|
}
|
2018-11-08 11:16:07 +00:00
|
|
|
},
|
|
|
|
allDone: () => {
|
|
|
|
this.nuxt.callHook('bundler:done')
|
2018-03-28 22:05:27 +00:00
|
|
|
}
|
2018-03-31 16:22:14 +00:00
|
|
|
}
|
|
|
|
}))
|
2018-03-22 14:06:54 +00:00
|
|
|
|
2018-12-09 10:28:08 +00:00
|
|
|
// CSS extraction)
|
|
|
|
if (this.options.build.extractCSS) {
|
|
|
|
plugins.push(new ExtractCssChunks(Object.assign({
|
2018-03-28 18:55:36 +00:00
|
|
|
filename: this.getFileName('css'),
|
2018-12-09 10:28:08 +00:00
|
|
|
chunkFilename: this.getFileName('css'),
|
|
|
|
// TODO: https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/issues/132
|
|
|
|
reloadAll: true
|
2018-03-23 16:28:35 +00:00
|
|
|
}, this.options.build.extractCSS)))
|
|
|
|
}
|
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
return plugins
|
2018-03-22 10:31:23 +00:00
|
|
|
}
|
2018-03-18 23:15:07 +00:00
|
|
|
|
2018-09-10 08:27:01 +00:00
|
|
|
extendConfig(config) {
|
2018-08-16 17:14:26 +00:00
|
|
|
if (typeof this.options.build.extend === 'function') {
|
2018-09-10 08:27:01 +00:00
|
|
|
const extendedConfig = this.options.build.extend.call(
|
|
|
|
this.builder, config, { loaders: this.loaders, ...this.nuxtEnv }
|
|
|
|
)
|
2018-08-16 17:14:26 +00:00
|
|
|
// Only overwrite config when something is returned for backwards compatibility
|
|
|
|
if (extendedConfig !== undefined) {
|
|
|
|
return extendedConfig
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
config() {
|
|
|
|
// Prioritize nested node_modules in webpack search path (#2558)
|
|
|
|
const webpackModulesDir = ['node_modules'].concat(this.options.modulesDir)
|
2018-12-01 10:13:28 +00:00
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
const config = {
|
|
|
|
name: this.name,
|
2018-11-14 12:00:12 +00:00
|
|
|
mode: this.buildMode,
|
2018-12-01 10:13:28 +00:00
|
|
|
devtool: this.devtool,
|
2018-08-22 14:24:47 +00:00
|
|
|
optimization: this.optimization(),
|
2018-03-22 14:06:54 +00:00
|
|
|
output: this.output(),
|
|
|
|
performance: {
|
|
|
|
maxEntrypointSize: 1000 * 1024,
|
|
|
|
hints: this.options.dev ? false : 'warning'
|
|
|
|
},
|
|
|
|
resolve: {
|
2018-04-24 06:58:01 +00:00
|
|
|
extensions: ['.wasm', '.mjs', '.js', '.json', '.vue', '.jsx'],
|
2018-03-22 14:06:54 +00:00
|
|
|
alias: this.alias(),
|
|
|
|
modules: webpackModulesDir
|
|
|
|
},
|
|
|
|
resolveLoader: {
|
|
|
|
modules: webpackModulesDir
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: this.rules()
|
|
|
|
},
|
|
|
|
plugins: this.plugins()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clone deep avoid leaking config between Client and Server
|
2018-12-10 21:34:41 +00:00
|
|
|
const extendedConfig = this.extendConfig(cloneDeep(config))
|
|
|
|
const { optimization } = extendedConfig
|
|
|
|
// Todo remove in nuxt 3 in favor of devtool config property or https://webpack.js.org/plugins/source-map-dev-tool-plugin
|
|
|
|
if (optimization && optimization.minimizer && extendedConfig.devtool) {
|
|
|
|
const terser = optimization.minimizer.find(p => p instanceof TerserWebpackPlugin)
|
|
|
|
if (terser) {
|
|
|
|
terser.options.sourceMap = extendedConfig.devtool && /source-?map/.test(extendedConfig.devtool)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return extendedConfig
|
2018-03-22 14:06:54 +00:00
|
|
|
}
|
2016-11-07 01:34:58 +00:00
|
|
|
}
|