2017-06-12 20:32:34 +00:00
|
|
|
import ExtractTextPlugin from 'extract-text-webpack-plugin'
|
2017-08-14 14:03:07 +00:00
|
|
|
import { cloneDeep } from 'lodash'
|
2017-06-15 22:28:08 +00:00
|
|
|
import { join, resolve } from 'path'
|
2017-06-15 22:19:53 +00:00
|
|
|
import webpack from 'webpack'
|
2017-06-16 12:42:45 +00:00
|
|
|
import { isUrl, urlJoin } from 'utils'
|
2017-11-07 10:47:55 +00:00
|
|
|
import TimeFixPlugin from './timefix-plugin'
|
2016-11-07 01:34:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Webpack Shared Config
|
|
|
|
|
|
2016-11-18 03:02:43 +00:00
|
|
|
| This is the config which is extended by the server and client
|
2016-11-07 01:34:58 +00:00
|
|
|
| webpack config files
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
*/
|
2017-10-30 16:51:11 +00:00
|
|
|
export default function webpackBaseConfig(name) {
|
2016-12-09 17:54:17 +00:00
|
|
|
const nodeModulesDir = join(__dirname, '..', 'node_modules')
|
2017-06-15 22:19:53 +00:00
|
|
|
|
|
|
|
const config = {
|
2017-08-21 11:16:35 +00:00
|
|
|
name,
|
2017-06-19 20:14:13 +00:00
|
|
|
devtool: this.options.dev ? 'cheap-module-source-map' : 'nosources-source-map',
|
2016-11-09 22:59:41 +00:00
|
|
|
entry: {
|
2017-08-20 18:22:01 +00:00
|
|
|
app: null
|
2016-11-09 22:59:41 +00:00
|
|
|
},
|
|
|
|
output: {
|
2017-06-15 22:19:53 +00:00
|
|
|
path: resolve(this.options.buildDir, 'dist'),
|
|
|
|
filename: this.options.build.filenames.app,
|
2017-08-01 15:45:02 +00:00
|
|
|
chunkFilename: this.options.build.filenames.chunk,
|
2017-06-11 14:17:36 +00:00
|
|
|
publicPath: (isUrl(this.options.build.publicPath)
|
|
|
|
? this.options.build.publicPath
|
|
|
|
: urlJoin(this.options.router.base, this.options.build.publicPath))
|
2016-11-09 22:59:41 +00:00
|
|
|
},
|
2016-12-15 17:53:00 +00:00
|
|
|
performance: {
|
2017-06-19 23:04:01 +00:00
|
|
|
maxEntrypointSize: 1000000,
|
2017-03-24 15:12:59 +00:00
|
|
|
maxAssetSize: 300000,
|
2017-06-15 22:19:53 +00:00
|
|
|
hints: this.options.dev ? false : 'warning'
|
2016-12-15 17:53:00 +00:00
|
|
|
},
|
2016-11-09 22:59:41 +00:00
|
|
|
resolve: {
|
2017-05-20 09:36:35 +00:00
|
|
|
extensions: ['.js', '.json', '.vue', '.ts'],
|
2016-11-14 22:59:54 +00:00
|
|
|
alias: {
|
2017-06-11 14:17:36 +00:00
|
|
|
'~': join(this.options.srcDir),
|
2017-07-04 14:21:41 +00:00
|
|
|
'~~': join(this.options.rootDir),
|
|
|
|
'@': join(this.options.srcDir),
|
|
|
|
'@@': join(this.options.rootDir),
|
2017-08-04 08:59:42 +00:00
|
|
|
// Used by vue-loader so we can use in templates
|
2017-10-28 09:01:41 +00:00
|
|
|
// with <img src="~/assets/nuxt.png"/>
|
2017-08-01 10:39:23 +00:00
|
|
|
'assets': join(this.options.srcDir, 'assets'),
|
2017-08-04 08:59:42 +00:00
|
|
|
'static': join(this.options.srcDir, 'static')
|
2016-11-14 22:59:54 +00:00
|
|
|
},
|
2016-11-09 22:59:41 +00:00
|
|
|
modules: [
|
2017-07-31 22:24:10 +00:00
|
|
|
this.options.modulesDir,
|
2017-05-20 09:36:35 +00:00
|
|
|
nodeModulesDir
|
2016-11-09 22:59:41 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
resolveLoader: {
|
|
|
|
modules: [
|
2017-07-31 22:24:10 +00:00
|
|
|
this.options.modulesDir,
|
2017-05-20 09:36:35 +00:00
|
|
|
nodeModulesDir
|
2016-11-09 22:59:41 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
module: {
|
2017-08-14 14:03:07 +00:00
|
|
|
noParse: /es6-promise\.js$/, // Avoid webpack shimming process
|
2016-11-09 22:59:41 +00:00
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
2016-11-14 22:59:54 +00:00
|
|
|
loader: 'vue-loader',
|
2017-08-21 11:16:35 +00:00
|
|
|
options: this.vueLoader()
|
2016-11-09 22:59:41 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
2016-11-14 22:59:54 +00:00
|
|
|
loader: 'babel-loader',
|
2016-11-09 22:59:41 +00:00
|
|
|
exclude: /node_modules/,
|
2017-08-14 14:03:07 +00:00
|
|
|
options: Object.assign({}, this.babelOptions)
|
2017-03-24 00:28:04 +00:00
|
|
|
},
|
2017-08-14 14:03:07 +00:00
|
|
|
{ test: /\.css$/, use: this.styleLoader('css') },
|
|
|
|
{ test: /\.less$/, use: this.styleLoader('less', 'less-loader') },
|
2017-08-21 20:08:39 +00:00
|
|
|
{ test: /\.sass$/, use: this.styleLoader('sass', {loader: 'sass-loader', options: { indentedSyntax: true }}) },
|
2017-08-14 14:03:07 +00:00
|
|
|
{ test: /\.scss$/, use: this.styleLoader('scss', 'sass-loader') },
|
|
|
|
{ test: /\.styl(us)?$/, use: this.styleLoader('stylus', 'stylus-loader') },
|
2017-06-11 19:04:59 +00:00
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif|svg)$/,
|
|
|
|
loader: 'url-loader',
|
2017-08-14 14:03:07 +00:00
|
|
|
options: {
|
2017-06-11 19:04:59 +00:00
|
|
|
limit: 1000, // 1KO
|
|
|
|
name: 'img/[name].[hash:7].[ext]'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
|
|
|
loader: 'url-loader',
|
2017-08-14 14:03:07 +00:00
|
|
|
options: {
|
2017-06-11 19:04:59 +00:00
|
|
|
limit: 1000, // 1 KO
|
|
|
|
name: 'fonts/[name].[hash:7].[ext]'
|
|
|
|
}
|
2017-07-31 08:41:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(webm|mp4)$/,
|
2017-08-14 14:03:07 +00:00
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
2017-08-01 15:40:31 +00:00
|
|
|
name: 'videos/[name].[hash:7].[ext]'
|
|
|
|
}
|
2017-06-11 19:04:59 +00:00
|
|
|
}
|
2016-11-09 22:59:41 +00:00
|
|
|
]
|
2016-11-17 21:12:21 +00:00
|
|
|
},
|
|
|
|
plugins: this.options.build.plugins
|
2016-11-07 01:34:58 +00:00
|
|
|
}
|
2017-06-15 22:19:53 +00:00
|
|
|
|
2017-11-07 10:47:55 +00:00
|
|
|
// Add timefix-plugin before others plugins
|
|
|
|
config.plugins.unshift(new TimeFixPlugin())
|
|
|
|
|
2017-04-30 11:58:25 +00:00
|
|
|
// CSS extraction
|
2017-11-11 12:52:45 +00:00
|
|
|
const extractCSS = this.options.build.extractCSS
|
|
|
|
if (extractCSS) {
|
|
|
|
const extractOptions = Object.assign(
|
|
|
|
{ filename: this.options.build.filenames.css },
|
|
|
|
typeof extractCSS === 'object' ? extractCSS : {}
|
|
|
|
)
|
|
|
|
config.plugins.push(new ExtractTextPlugin(extractOptions))
|
2017-04-30 11:58:25 +00:00
|
|
|
}
|
2017-06-15 22:19:53 +00:00
|
|
|
|
2017-07-27 17:46:11 +00:00
|
|
|
// Workaround for hiding Warnings about plugins without a default export (#1179)
|
|
|
|
config.plugins.push({
|
2017-10-30 16:51:11 +00:00
|
|
|
apply(compiler) {
|
2017-07-27 17:46:11 +00:00
|
|
|
compiler.plugin('done', stats => {
|
|
|
|
stats.compilation.warnings = stats.compilation.warnings.filter(warn => {
|
|
|
|
if (warn.name === 'ModuleDependencyWarning' && warn.message.includes(`export 'default'`) && warn.message.includes('plugin')) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-06-15 22:19:53 +00:00
|
|
|
// --------------------------------------
|
|
|
|
// Dev specific config
|
|
|
|
// --------------------------------------
|
|
|
|
if (this.options.dev) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------
|
|
|
|
// Production specific config
|
|
|
|
// --------------------------------------
|
|
|
|
if (!this.options.dev) {
|
|
|
|
// This is needed in webpack 2 for minify CSS
|
|
|
|
config.plugins.push(
|
|
|
|
new webpack.LoaderOptionsPlugin({
|
|
|
|
minimize: true
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clone deep avoid leaking config between Client and Server
|
|
|
|
return cloneDeep(config)
|
2016-11-07 01:34:58 +00:00
|
|
|
}
|