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

270 lines
6.3 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')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
2018-01-28 02:40:51 +00:00
const NameAllModulesPlugin = require('name-all-modules-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-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'
},
{
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
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: postCSSConfig
2018-01-26 05:32:53 +00:00
},
{
loader: 'sass-loader',
options: {
sourceMap: false
}
}
]
})
},
{
test: /\.styl$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'cache-loader',
options: {
cacheDirectory: cacheDir
}
},
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: postCSSConfig
},
{
loader: 'stylus-loader'
}
]
})
},
2018-01-26 05:32:53 +00:00
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
css: ExtractTextPlugin.extract({
fallback: 'vue-style-loader',
use: [
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: postCSSConfig
2018-01-26 05:32:53 +00:00
}
]
}),
scss: ExtractTextPlugin.extract({
fallback: 'vue-style-loader',
use: [
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: postCSSConfig
},
{
loader: 'sass-loader',
options: {
sourceMap: false
}
},
{
loader: 'sass-resources-loader',
options: {
resources: path.join(process.cwd(), '/client/scss/global.scss')
}
2018-01-26 05:32:53 +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
}),
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
}),
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',
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'),
'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-01-26 05:32:53 +00:00
target: 'web'
}