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

232 lines
5.4 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-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'))
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'),
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: /\.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'
},
{
loader: 'css-loader'
2018-01-26 05:32:53 +00:00
}
],
scss: [
{
loader: 'vue-style-loader'
},
{
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')
}
}
],
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'
}
]
}
]
},
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
}),
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'),
2018-02-03 21:48:25 +00:00
'vue$': 'vue/dist/vue.common.js',
// 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'
]
},
target: 'web'
}