2018-01-26 05:32:53 +00:00
|
|
|
const path = require('path')
|
|
|
|
const fs = require('fs-extra')
|
|
|
|
const webpack = require('webpack')
|
|
|
|
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
2018-01-28 02:40:51 +00:00
|
|
|
const NameAllModulesPlugin = require('name-all-modules-plugin')
|
2018-02-03 21:48:25 +00:00
|
|
|
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
|
2018-01-26 05:32:53 +00:00
|
|
|
|
|
|
|
const babelConfig = fs.readJsonSync(path.join(process.cwd(), '.babelrc'))
|
2018-01-27 01:22:31 +00:00
|
|
|
const postCSSConfig = {
|
|
|
|
config: {
|
2018-02-03 21:48:25 +00:00
|
|
|
path: path.join(process.cwd(), 'dev/config/postcss.config.js')
|
2018-01-27 01:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-03 21:48:25 +00:00
|
|
|
const cacheDir = '.webpack-cache/cache'
|
|
|
|
const babelDir = path.join(process.cwd(), '.webpack-cache/babel')
|
|
|
|
|
|
|
|
process.noDeprecation = true
|
2018-01-26 05:32:53 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2018-01-27 01:22:31 +00:00
|
|
|
entry: {
|
|
|
|
client: './client/index.js'
|
|
|
|
},
|
2018-01-26 05:32:53 +00:00
|
|
|
output: {
|
|
|
|
path: path.join(process.cwd(), 'assets'),
|
|
|
|
filename: 'js/[name].js',
|
2018-01-27 05:20:49 +00:00
|
|
|
chunkFilename: 'js/[name].chunk.js'
|
2018-01-26 05:32:53 +00:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'cache-loader',
|
|
|
|
options: {
|
2018-02-03 21:48:25 +00:00
|
|
|
cacheDirectory: cacheDir
|
2018-01-26 05:32:53 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
...babelConfig,
|
2018-02-03 21:48:25 +00:00
|
|
|
cacheDirectory: babelDir
|
2018-01-26 05:32:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'style-loader'
|
|
|
|
},
|
|
|
|
{
|
2018-01-27 01:22:31 +00:00
|
|
|
loader: 'css-loader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: postCSSConfig
|
2018-01-26 05:32:53 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
|
fallback: 'style-loader',
|
|
|
|
use: [
|
2018-02-03 21:48:25 +00:00
|
|
|
{
|
|
|
|
loader: 'cache-loader',
|
|
|
|
options: {
|
|
|
|
cacheDirectory: cacheDir
|
|
|
|
}
|
|
|
|
},
|
2018-01-26 05:32:53 +00:00
|
|
|
{
|
2018-01-27 01:22:31 +00:00
|
|
|
loader: 'css-loader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: postCSSConfig
|
2018-01-26 05:32:53 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
},
|
2018-02-11 23:36:20 +00:00
|
|
|
{
|
|
|
|
test: /\.styl$/,
|
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
|
fallback: 'style-loader',
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'cache-loader',
|
|
|
|
options: {
|
|
|
|
cacheDirectory: cacheDir
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'css-loader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'stylus-loader'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
},
|
2018-01-26 05:32:53 +00:00
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
|
|
|
loader: 'vue-loader',
|
|
|
|
options: {
|
2018-01-27 22:39:55 +00:00
|
|
|
extractCSS: ExtractTextPlugin,
|
2018-01-27 05:20:49 +00:00
|
|
|
postcss: postCSSConfig,
|
2018-01-26 05:32:53 +00:00
|
|
|
loaders: {
|
|
|
|
css: [
|
|
|
|
{
|
|
|
|
loader: 'vue-style-loader'
|
|
|
|
},
|
|
|
|
{
|
2018-01-27 01:22:31 +00:00
|
|
|
loader: 'css-loader'
|
2018-01-26 05:32:53 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
scss: [
|
|
|
|
{
|
|
|
|
loader: 'vue-style-loader'
|
|
|
|
},
|
|
|
|
{
|
2018-01-27 01:22:31 +00:00
|
|
|
loader: 'css-loader'
|
|
|
|
},
|
2018-01-26 05:32:53 +00:00
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-resources-loader',
|
|
|
|
options: {
|
|
|
|
resources: path.join(process.cwd(), '/client/scss/global.scss')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2018-01-27 01:22:31 +00:00
|
|
|
js: [
|
|
|
|
{
|
|
|
|
loader: 'cache-loader',
|
|
|
|
options: {
|
2018-02-03 21:48:25 +00:00
|
|
|
cacheDirectory: cacheDir
|
2018-01-27 01:22:31 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
babelrc: path.join(process.cwd(), '.babelrc'),
|
2018-02-03 21:48:25 +00:00
|
|
|
cacheDirectory: babelDir
|
2018-01-27 01:22:31 +00:00
|
|
|
}
|
2018-01-26 05:32:53 +00:00
|
|
|
}
|
2018-01-27 01:22:31 +00:00
|
|
|
]
|
2018-01-26 05:32:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpg|gif)$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
limit: 8192
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.svg$/,
|
|
|
|
exclude: [
|
|
|
|
path.join(process.cwd(), 'client/svg')
|
|
|
|
],
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[ext]',
|
|
|
|
outputPath: 'svg/'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.svg$/,
|
|
|
|
include: [
|
|
|
|
path.join(process.cwd(), 'client/svg')
|
|
|
|
],
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'raw-loader'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.BannerPlugin('Wiki.js - wiki.js.org - Licensed under AGPL'),
|
|
|
|
new CopyWebpackPlugin([
|
|
|
|
{ from: 'client/static' }
|
|
|
|
], {
|
|
|
|
|
2018-01-28 02:40:51 +00:00
|
|
|
}),
|
2018-02-03 21:48:25 +00:00
|
|
|
new LodashModuleReplacementPlugin(),
|
2018-01-28 02:40:51 +00:00
|
|
|
new webpack.NamedModulesPlugin(),
|
|
|
|
new webpack.NamedChunksPlugin((chunk) => {
|
|
|
|
if (chunk.name) {
|
|
|
|
return chunk.name
|
|
|
|
}
|
|
|
|
return chunk.modules.map(m => path.relative(m.context, m.request)).join('_')
|
2018-01-26 05:32:53 +00:00
|
|
|
}),
|
2018-01-27 01:22:31 +00:00
|
|
|
new webpack.optimize.CommonsChunkPlugin({
|
|
|
|
name: 'vendor',
|
|
|
|
minChunks(module) {
|
|
|
|
return module.context && module.context.includes('node_modules')
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
new webpack.optimize.CommonsChunkPlugin({
|
2018-01-28 02:40:51 +00:00
|
|
|
name: 'runtime',
|
2018-01-27 01:22:31 +00:00
|
|
|
minChunks: Infinity
|
2018-01-28 02:40:51 +00:00
|
|
|
}),
|
|
|
|
new NameAllModulesPlugin()
|
2018-01-26 05:32:53 +00:00
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
symlinks: true,
|
|
|
|
alias: {
|
|
|
|
'@': path.join(process.cwd(), 'client'),
|
2018-02-11 23:36:20 +00:00
|
|
|
'vue$': 'vue/dist/vue.esm.js',
|
2018-03-03 06:32:58 +00:00
|
|
|
'mdi': path.resolve(process.cwd(), 'node_modules/vue-material-design-icons'),
|
2018-02-03 21:48:25 +00:00
|
|
|
// Duplicates fixes:
|
|
|
|
'apollo-link': path.join(process.cwd(), 'node_modules/apollo-link'),
|
|
|
|
'apollo-utilities': path.join(process.cwd(), 'node_modules/apollo-utilities')
|
2018-01-26 05:32:53 +00:00
|
|
|
},
|
|
|
|
extensions: [
|
|
|
|
'.js',
|
|
|
|
'.json',
|
|
|
|
'.vue'
|
|
|
|
],
|
|
|
|
modules: [
|
|
|
|
'node_modules'
|
|
|
|
]
|
|
|
|
},
|
2018-02-25 17:59:59 +00:00
|
|
|
node: {
|
|
|
|
fs: 'empty'
|
|
|
|
},
|
2018-01-26 05:32:53 +00:00
|
|
|
target: 'web'
|
|
|
|
}
|