2017-06-12 20:32:34 +00:00
|
|
|
import ExtractTextPlugin from 'extract-text-webpack-plugin'
|
2017-06-15 22:28:08 +00:00
|
|
|
import { defaults, cloneDeep } from 'lodash'
|
|
|
|
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-06-18 09:35:00 +00:00
|
|
|
import autoprefixer from 'autoprefixer'
|
2017-06-12 20:32:34 +00:00
|
|
|
import vueLoaderConfig from './vue-loader.config'
|
2017-04-30 11:58:25 +00:00
|
|
|
import { styleLoader, extractStyles } from './helpers'
|
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-06-11 14:17:36 +00:00
|
|
|
export default function webpackBaseConfig ({ isClient, isServer }) {
|
2016-12-09 17:54:17 +00:00
|
|
|
const nodeModulesDir = join(__dirname, '..', 'node_modules')
|
2017-06-15 22:19:53 +00:00
|
|
|
|
2017-06-16 14:00:03 +00:00
|
|
|
if (!Array.isArray(this.options.build.postcss)) {
|
|
|
|
this.options.build.postcss = [
|
2017-06-18 09:35:00 +00:00
|
|
|
autoprefixer({
|
2017-06-16 14:00:03 +00:00
|
|
|
browsers: ['last 3 versions']
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2017-06-15 22:19:53 +00:00
|
|
|
const config = {
|
|
|
|
devtool: this.options.dev ? 'cheap-module-source-map' : false,
|
2016-11-09 22:59:41 +00:00
|
|
|
entry: {
|
2017-01-11 21:18:47 +00:00
|
|
|
vendor: ['vue', 'vue-router', 'vue-meta']
|
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-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-03-24 15:12:59 +00:00
|
|
|
maxEntrypointSize: 300000,
|
|
|
|
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-16 16:55:15 +00:00
|
|
|
// Disable for now
|
2016-11-14 22:59:54 +00:00
|
|
|
alias: {
|
2017-06-11 14:17:36 +00:00
|
|
|
'~': join(this.options.srcDir),
|
|
|
|
'static': join(this.options.srcDir, 'static'), // use in template with <img src="~static/nuxt.png" />
|
|
|
|
'~static': join(this.options.srcDir, 'static'),
|
|
|
|
'assets': join(this.options.srcDir, 'assets'), // use in template with <img src="~assets/nuxt.png" />
|
|
|
|
'~assets': join(this.options.srcDir, 'assets'),
|
|
|
|
'~plugins': join(this.options.srcDir, 'plugins'),
|
|
|
|
'~store': join(this.options.buildDir, 'store'),
|
|
|
|
'~router': join(this.options.buildDir, 'router'),
|
|
|
|
'~pages': join(this.options.srcDir, 'pages'),
|
|
|
|
'~components': join(this.options.srcDir, 'components')
|
2016-11-14 22:59:54 +00:00
|
|
|
},
|
2016-11-09 22:59:41 +00:00
|
|
|
modules: [
|
2017-06-11 14:17:36 +00:00
|
|
|
join(this.options.rootDir, 'node_modules'),
|
2017-05-20 09:36:35 +00:00
|
|
|
nodeModulesDir
|
2016-11-09 22:59:41 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
resolveLoader: {
|
|
|
|
modules: [
|
2017-06-11 14:17:36 +00:00
|
|
|
join(this.options.rootDir, 'node_modules'),
|
2017-05-20 09:36:35 +00:00
|
|
|
nodeModulesDir
|
2016-11-09 22:59:41 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
module: {
|
2017-06-15 22:19:53 +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-01-09 14:10:22 +00:00
|
|
|
query: vueLoaderConfig.call(this, { isClient, isServer })
|
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/,
|
2016-11-18 09:38:47 +00:00
|
|
|
query: defaults(this.options.build.babel, {
|
2017-02-17 15:13:51 +00:00
|
|
|
presets: ['vue-app'],
|
2017-04-17 13:27:32 +00:00
|
|
|
babelrc: false,
|
2017-06-11 14:17:36 +00:00
|
|
|
cacheDirectory: !!this.options.dev
|
2016-11-18 09:38:47 +00:00
|
|
|
})
|
2017-03-24 00:28:04 +00:00
|
|
|
},
|
2017-04-30 11:58:25 +00:00
|
|
|
{ test: /\.css$/, use: styleLoader.call(this, 'css') },
|
|
|
|
{ test: /\.less$/, use: styleLoader.call(this, 'less', 'less-loader') },
|
2017-05-20 09:36:35 +00:00
|
|
|
{ test: /\.sass$/, use: styleLoader.call(this, 'sass', 'sass-loader?indentedSyntax&sourceMap') },
|
|
|
|
{ test: /\.scss$/, use: styleLoader.call(this, 'sass', 'sass-loader?sourceMap') },
|
2017-06-11 19:04:59 +00:00
|
|
|
{ test: /\.styl(us)?$/, use: styleLoader.call(this, 'stylus', 'stylus-loader') },
|
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif|svg)$/,
|
|
|
|
loader: 'url-loader',
|
|
|
|
query: {
|
|
|
|
limit: 1000, // 1KO
|
|
|
|
name: 'img/[name].[hash:7].[ext]'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
|
|
|
loader: 'url-loader',
|
|
|
|
query: {
|
|
|
|
limit: 1000, // 1 KO
|
|
|
|
name: 'fonts/[name].[hash:7].[ext]'
|
|
|
|
}
|
|
|
|
}
|
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-04-30 11:58:25 +00:00
|
|
|
// CSS extraction
|
|
|
|
if (extractStyles.call(this)) {
|
|
|
|
config.plugins.push(
|
2017-06-11 14:17:36 +00:00
|
|
|
new ExtractTextPlugin({ filename: this.options.build.filenames.css })
|
2017-04-30 11:58:25 +00:00
|
|
|
)
|
|
|
|
}
|
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
|
|
|
}
|