improve webpack config

This commit is contained in:
Philipp Kühn 2018-08-21 22:40:55 +02:00
parent ab6c4aeabf
commit 0e75610fcd
8 changed files with 106 additions and 34 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
.DS_Store
node_modules
/dist
/docs
# local env files
.env.local

View File

@ -3,10 +3,19 @@
"version": "0.1.0",
"description": "A rich-text editor for Vue.js",
"license": "MIT",
"main": "dist/index.js",
"main": "dist/tiptap.min.js",
"files": [
"src",
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/heyscrumpy/tiptap.git"
},
"scripts": {
"start": "babel-node webpack/server.js --env=development",
"build": "babel-node webpack/build.js --env=production"
"build:package": "babel-node webpack/build.package.js --env=production",
"build:examples": "babel-node webpack/build.examples.js --env=production"
},
"babel": {
"presets": [
@ -53,7 +62,6 @@
"imagemin-webpack-plugin": "^2.1.5",
"mini-css-extract-plugin": "^0.4.1",
"minimist": "^1.2.0",
"modernizr-loader": "1.0.1",
"node-sass": "^4.9.1",
"optimize-css-assets-webpack-plugin": "^5.0.0",
"ora": "^3.0.0",
@ -62,6 +70,7 @@
"postcss-scss": "^2.0.0",
"sass-loader": "^7.0.3",
"style-loader": "^0.22.1",
"vue": "^2.5.17",
"vue-loader": "^15.2.4",
"vue-style-loader": "^4.1.0",
"vue-template-compiler": "^2.5.13",
@ -85,7 +94,6 @@
"prosemirror-state": "^1.2.1",
"prosemirror-tables": "^0.7.6",
"prosemirror-utils": "^0.6.5",
"prosemirror-view": "^1.4.3",
"vue": "^2.5.17"
"prosemirror-view": "^1.4.3"
}
}

24
webpack/build.examples.js Normal file
View File

@ -0,0 +1,24 @@
import ora from 'ora'
import webpack from 'webpack'
import config from './webpack.examples.config'
const spinner = ora('Building …')
export default new Promise((resolve, reject) => {
spinner.start()
webpack(config, (error, stats) => {
if (error) {
return reject(error)
}
if (stats.hasErrors()) {
process.stdout.write(stats.toString() + "\n");
return reject(new Error('Build failed with errors.'))
}
return resolve('Build complete.')
})
})
.then(success => spinner.succeed(success))
.catch(error => spinner.fail(error))

View File

@ -1,6 +1,6 @@
import ora from 'ora'
import webpack from 'webpack'
import config from './webpack.config'
import config from './webpack.package.config'
const spinner = ora('Building …')

View File

@ -4,21 +4,13 @@ import webpack from 'webpack'
import httpProxyMiddleware from 'http-proxy-middleware'
import webpackDevMiddleware from 'webpack-dev-middleware'
import webpackHotMiddleware from 'webpack-hot-middleware'
import config from './webpack.config'
import config from './webpack.examples.config'
import { sassImport } from './utilities'
import { srcPath, sassImportPath } from './paths'
const bundler = webpack(config)
const middlewares = []
middlewares.push(httpProxyMiddleware('/api', {
target: 'http://local.app.scrumpy.io/api',
changeOrigin: true,
pathRewrite: {
'^/api': '',
},
}))
// add webpack stuff
middlewares.push(webpackDevMiddleware(bundler, {
publicPath: config.output.publicPath,
@ -32,7 +24,7 @@ middlewares.push(webpackDevMiddleware(bundler, {
middlewares.push(webpackHotMiddleware(bundler))
// start browsersync
const url = 'http://local.app.scrumpy.io'
const url = 'http://localhost'
const bs = browserSync.create()
const server = bs.init({
server: {

View File

@ -9,7 +9,7 @@ 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'
import { rootPath, srcPath, examplesSrcPath, examplesBuildPath, buildPath } from './paths'
import { rootPath, examplesSrcPath, examplesBuildPath } from './paths'
export default {
@ -27,7 +27,7 @@ export default {
path: `${examplesBuildPath}/`,
filename: `assets/js/[name]${ifProd('.[hash]', '')}.js`,
chunkFilename: `assets/js/[name]${ifProd('.[chunkhash]', '')}.js`,
publicPath: '',
publicPath: '/',
},
resolve: {
@ -53,10 +53,6 @@ export default {
module: {
rules: [
{
test: /\.modernizr$/,
loader: 'modernizr-loader',
},
{
test: /\.vue$/,
loader: 'vue-loader',
@ -145,14 +141,6 @@ export default {
// 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',

View File

@ -0,0 +1,63 @@
import path from 'path'
import { VueLoaderPlugin } from 'vue-loader'
import { ifDev, removeEmpty } from './utilities'
import { rootPath, srcPath, buildPath } from './paths'
export default {
mode: ifDev('development', 'production'),
entry: {
tiptap: removeEmpty([
ifDev('webpack-hot-middleware/client?reload=true'),
`${srcPath}/index.js`,
]),
},
output: {
path: `${buildPath}/`,
filename: '[name].min.js',
publicPath: '/',
},
resolve: {
extensions: ['.js', '.scss', '.vue'],
alias: {
vue$: 'vue/dist/vue.esm.js',
tiptap: path.resolve(rootPath, '../src'),
},
modules: [
srcPath,
path.resolve(rootPath, '../node_modules'),
],
},
devtool: ifDev('eval-source-map', 'source-map'),
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.js$/,
loader: ifDev('babel-loader?cacheDirectory=true', 'babel-loader'),
exclude: /node_modules/,
},
],
},
externals: {
vue: 'vue',
},
plugins: removeEmpty([
new VueLoaderPlugin(),
]),
node: {
fs: 'empty',
},
}

View File

@ -5411,10 +5411,6 @@ mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkd
dependencies:
minimist "0.0.8"
modernizr-loader@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/modernizr-loader/-/modernizr-loader-1.0.1.tgz#e52a6f9a12578b944abbd6cbd65c863ea4a83f49"
move-concurrently@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"