wikijs-fork/dev/webpack/webpack.common.js

263 lines
6.0 KiB
JavaScript
Raw Normal View History

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')
2018-03-17 02:51:56 +00:00
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
2018-03-17 06:35:52 +00:00
const HtmlWebpackPugPlugin = require('html-webpack-pug-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
2018-01-26 05:32:53 +00:00
const babelConfig = fs.readJsonSync(path.join(process.cwd(), '.babelrc'))
const postCSSConfig = {
config: {
2018-02-03 21:48:25 +00:00
path: path.join(process.cwd(), 'dev/config/postcss.config.js')
}
}
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 = {
entry: {
client: './client/index.js'
},
2018-01-26 05:32:53 +00:00
output: {
path: path.join(process.cwd(), 'assets'),
publicPath: '/',
2018-01-26 05:32:53 +00:00
filename: 'js/[name].js',
2018-03-17 06:35:52 +00:00
chunkFilename: 'js/[name].js',
2018-03-17 02:51:56 +00:00
globalObject: 'this'
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: [
2018-03-17 02:51:56 +00:00
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: postCSSConfig
2018-01-26 05:32:53 +00:00
}
]
},
{
test: /\.scss$/,
2018-03-17 02:51:56 +00:00
use: [
'style-loader',
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: postCSSConfig
},
{
loader: 'sass-loader',
options: {
sourceMap: false
2018-01-26 05:32:53 +00:00
}
2018-03-17 02:51:56 +00:00
}
]
2018-01-26 05:32:53 +00:00
},
{
test: /\.styl$/,
2018-03-17 02:51:56 +00:00
use: [
'style-loader',
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: postCSSConfig
},
'stylus-loader'
]
},
2018-01-26 05:32:53 +00:00
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
2018-03-17 02:51:56 +00:00
css: [
'vue-style-loader',
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: postCSSConfig
}
],
scss: [
'vue-style-loader',
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: postCSSConfig
},
{
loader: 'sass-loader',
options: {
sourceMap: false
2018-01-26 05:32:53 +00:00
}
2018-03-17 02:51:56 +00:00
},
{
loader: 'sass-resources-loader',
options: {
resources: path.join(process.cwd(), '/client/scss/global.scss')
2018-01-26 05:32:53 +00:00
}
2018-03-17 02:51:56 +00:00
}
],
js: [
{
loader: 'cache-loader',
options: {
2018-02-03 21:48:25 +00:00
cacheDirectory: cacheDir
}
},
{
loader: 'babel-loader',
options: {
babelrc: path.join(process.cwd(), '.babelrc'),
2018-02-03 21:48:25 +00:00
cacheDirectory: babelDir
}
2018-01-26 05:32:53 +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'
}
]
2018-03-17 01:31:28 +00:00
},
{
test: /\.flow$/,
loader: 'ignore-loader'
2018-01-26 05:32:53 +00:00
}
]
},
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-03-17 02:51:56 +00:00
new MiniCssExtractPlugin({
filename: 'css/bundle.css',
2018-03-17 06:35:52 +00:00
chunkFilename: 'css/[name].css'
}),
new HtmlWebpackPlugin({
template: 'dev/templates/master.pug',
filename: '../server/views/master.pug',
hash: true,
inject: 'head'
}),
new HtmlWebpackPugPlugin(),
new ScriptExtHtmlWebpackPlugin({
sync: 'runtime.js',
defaultAttribute: 'async'
2018-03-17 02:51:56 +00:00
})
2018-01-26 05:32:53 +00:00
],
2018-03-17 02:51:56 +00:00
optimization: {
namedModules: true,
2018-03-17 06:35:52 +00:00
namedChunks: true,
2018-03-17 02:51:56 +00:00
splitChunks: {
2018-03-17 06:35:52 +00:00
cacheGroups: {
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
},
vendor: {
test: /[\\/]node_modules[\\/]/,
priority: -10
}
}
2018-03-17 02:51:56 +00:00
},
2018-03-17 06:35:52 +00:00
runtimeChunk: 'single'
2018-03-17 02:51:56 +00:00
},
2018-01-26 05:32:53 +00:00
resolve: {
2018-03-17 02:51:56 +00:00
mainFields: ['browser', 'main', 'module'],
2018-01-26 05:32:53 +00:00
symlinks: true,
alias: {
'@': path.join(process.cwd(), 'client'),
'vue$': 'vue/dist/vue.esm.js',
'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'),
'uc.micro': path.join(process.cwd(), 'node_modules/uc.micro')
2018-01-26 05:32:53 +00:00
},
extensions: [
'.js',
'.json',
'.vue'
],
modules: [
'node_modules'
]
},
node: {
fs: 'empty'
},
2018-03-17 02:51:56 +00:00
stats: {
children: false,
entrypoints: false
},
2018-01-26 05:32:53 +00:00
target: 'web'
}