2018-08-21 05:02:21 +08:00
|
|
|
import path from 'path'
|
|
|
|
import webpack from 'webpack'
|
|
|
|
import { VueLoaderPlugin } from 'vue-loader'
|
|
|
|
import SvgStore from 'webpack-svgstore-plugin'
|
|
|
|
import CopyWebpackPlugin from 'copy-webpack-plugin'
|
|
|
|
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
|
|
|
import ManifestPlugin from 'webpack-manifest-plugin'
|
|
|
|
import ImageminWebpackPlugin from 'imagemin-webpack-plugin'
|
|
|
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
|
|
|
|
import OptimizeCssAssetsPlugin from 'optimize-css-assets-webpack-plugin'
|
|
|
|
import { ifDev, ifProd, removeEmpty } from './utilities'
|
2018-08-21 05:24:43 +08:00
|
|
|
import { rootPath, srcPath, examplesSrcPath, examplesBuildPath, buildPath } from './paths'
|
2018-08-21 05:02:21 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
|
|
mode: ifDev('development', 'production'),
|
|
|
|
|
|
|
|
entry: {
|
2018-08-21 05:24:43 +08:00
|
|
|
examples: removeEmpty([
|
2018-08-21 05:02:21 +08:00
|
|
|
ifDev('webpack-hot-middleware/client?reload=true'),
|
2018-08-21 05:24:43 +08:00
|
|
|
`${examplesSrcPath}/assets/sass/main.scss`,
|
|
|
|
`${examplesSrcPath}/main.js`,
|
2018-08-21 05:02:21 +08:00
|
|
|
]),
|
|
|
|
},
|
|
|
|
|
|
|
|
output: {
|
2018-08-21 05:24:43 +08:00
|
|
|
path: `${examplesBuildPath}/`,
|
2018-08-21 05:02:21 +08:00
|
|
|
filename: `assets/js/[name]${ifProd('.[hash]', '')}.js`,
|
|
|
|
chunkFilename: `assets/js/[name]${ifProd('.[chunkhash]', '')}.js`,
|
|
|
|
publicPath: '/',
|
|
|
|
},
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.js', '.scss', '.vue'],
|
|
|
|
alias: {
|
|
|
|
vue$: 'vue/dist/vue.esm.js',
|
|
|
|
modernizr: path.resolve(rootPath, '../.modernizr'),
|
|
|
|
modules: path.resolve(rootPath, '../node_modules'),
|
2018-08-21 05:24:43 +08:00
|
|
|
images: `${examplesSrcPath}/assets/images`,
|
|
|
|
fonts: `${examplesSrcPath}/assets/fonts`,
|
|
|
|
variables: `${examplesSrcPath}/assets/sass/variables`,
|
|
|
|
settings: `${examplesSrcPath}/assets/sass/1-settings/index`,
|
|
|
|
utilityFunctions: `${examplesSrcPath}/assets/sass/2-utility-functions/index`,
|
|
|
|
tiptap: path.resolve(rootPath, '../src'),
|
2018-08-21 05:02:21 +08:00
|
|
|
},
|
|
|
|
modules: [
|
2018-08-21 05:24:43 +08:00
|
|
|
examplesSrcPath,
|
2018-08-21 05:02:21 +08:00
|
|
|
path.resolve(rootPath, '../node_modules'),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
devtool: ifDev('eval-source-map', 'source-map'),
|
|
|
|
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.modernizr$/,
|
|
|
|
loader: 'modernizr-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
|
|
|
loader: 'vue-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
loader: ifDev('babel-loader?cacheDirectory=true', 'babel-loader'),
|
|
|
|
exclude: /node_modules(?!\/quill)/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(graphql|gql)$/,
|
|
|
|
loader: 'graphql-tag/loader',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: removeEmpty([
|
|
|
|
ifDev('vue-style-loader', MiniCssExtractPlugin.loader),
|
|
|
|
'css-loader',
|
|
|
|
'postcss-loader',
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
|
|
|
use: removeEmpty([
|
|
|
|
ifDev('vue-style-loader', MiniCssExtractPlugin.loader),
|
|
|
|
'css-loader',
|
|
|
|
'postcss-loader',
|
|
|
|
'sass-loader',
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif|svg|ico)(\?.*)?$/,
|
|
|
|
use: {
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: `assets/images/[name]${ifProd('.[hash]', '')}.[ext]`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
|
|
|
use: {
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: `assets/fonts/[name]${ifProd('.[hash]', '')}.[ext]`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
// splitting out the vendor
|
|
|
|
optimization: {
|
|
|
|
namedModules: true,
|
|
|
|
splitChunks: {
|
|
|
|
name: 'vendor',
|
|
|
|
minChunks: 2,
|
|
|
|
},
|
|
|
|
noEmitOnErrors: true,
|
|
|
|
// concatenateModules: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: removeEmpty([
|
|
|
|
|
|
|
|
// create manifest file for server-side asset manipulation
|
|
|
|
new ManifestPlugin({
|
|
|
|
fileName: 'assets/manifest.json',
|
|
|
|
writeToFileEmit: true,
|
|
|
|
}),
|
|
|
|
|
|
|
|
// define env
|
2018-08-21 05:24:43 +08:00
|
|
|
// new webpack.DefinePlugin({
|
|
|
|
// 'process.env': {},
|
|
|
|
// }),
|
2018-08-21 05:02:21 +08:00
|
|
|
|
|
|
|
// copy static files
|
|
|
|
new CopyWebpackPlugin([
|
|
|
|
{
|
2018-08-21 05:24:43 +08:00
|
|
|
context: `${examplesSrcPath}/assets/static`,
|
2018-08-21 05:02:21 +08:00
|
|
|
from: { glob: '**/*', dot: false },
|
2018-08-21 05:24:43 +08:00
|
|
|
to: `${examplesBuildPath}/assets`,
|
2018-08-21 05:02:21 +08:00
|
|
|
},
|
|
|
|
]),
|
|
|
|
|
|
|
|
// enable hot reloading
|
|
|
|
ifDev(new webpack.HotModuleReplacementPlugin()),
|
|
|
|
|
|
|
|
// make some packages available everywhere
|
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
// $: 'jquery',
|
|
|
|
// jQuery: 'jquery',
|
|
|
|
// 'window.jQuery': 'jquery',
|
|
|
|
collect: 'collect.js',
|
|
|
|
}),
|
|
|
|
|
|
|
|
// html
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
filename: 'index.html',
|
2018-08-21 05:24:43 +08:00
|
|
|
template: `${examplesSrcPath}/index.html`,
|
2018-08-21 05:02:21 +08:00
|
|
|
inject: true,
|
|
|
|
minify: ifProd({
|
|
|
|
removeComments: true,
|
|
|
|
collapseWhitespace: true,
|
|
|
|
removeAttributeQuotes: true,
|
|
|
|
}),
|
|
|
|
buildVersion: new Date().valueOf(),
|
|
|
|
chunksSortMode: 'none',
|
|
|
|
}),
|
|
|
|
|
|
|
|
new VueLoaderPlugin(),
|
|
|
|
|
|
|
|
// create css files
|
|
|
|
ifProd(new MiniCssExtractPlugin({
|
|
|
|
filename: `assets/css/[name]${ifProd('.[hash]', '')}.css`,
|
|
|
|
chunkFilename: `assets/css/[name]${ifProd('.[hash]', '')}.css`,
|
|
|
|
})),
|
|
|
|
|
|
|
|
// minify css files
|
|
|
|
ifProd(new OptimizeCssAssetsPlugin({
|
|
|
|
cssProcessorOptions: {
|
|
|
|
reduceIdents: false,
|
|
|
|
autoprefixer: false,
|
|
|
|
zindex: false,
|
|
|
|
discardComments: {
|
|
|
|
removeAll: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})),
|
|
|
|
|
|
|
|
// svg icons
|
|
|
|
new SvgStore({
|
|
|
|
prefix: 'icon--',
|
|
|
|
svgoOptions: {
|
|
|
|
plugins: [
|
|
|
|
{ cleanupIDs: false },
|
|
|
|
{ collapseGroups: false },
|
|
|
|
{ removeTitle: true },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
|
|
|
// image optimization
|
|
|
|
new ImageminWebpackPlugin({
|
|
|
|
optipng: ifDev(null, {
|
|
|
|
optimizationLevel: 3,
|
|
|
|
}),
|
|
|
|
jpegtran: ifDev(null, {
|
|
|
|
progressive: true,
|
|
|
|
quality: 80,
|
|
|
|
}),
|
|
|
|
svgo: ifDev(null, {
|
|
|
|
plugins: [
|
|
|
|
{ cleanupIDs: false },
|
|
|
|
{ removeViewBox: false },
|
|
|
|
{ removeUselessStrokeAndFill: false },
|
|
|
|
{ removeEmptyAttrs: false },
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
]),
|
|
|
|
|
|
|
|
node: {
|
|
|
|
fs: 'empty',
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|