Use webpack-dev-server

This commit is contained in:
Henri Bergius 2018-12-09 21:58:18 +01:00
parent 177dffc681
commit 9896aaf034
2 changed files with 18 additions and 11 deletions

View file

@ -6,7 +6,7 @@
"scripts": { "scripts": {
"build": "webpack", "build": "webpack",
"pretest": "eslint index.js lib/*.js elements/*.js infodisplay/*.js events/*.js", "pretest": "eslint index.js lib/*.js elements/*.js infodisplay/*.js events/*.js",
"start": "http-server dist/ -p 3000 -s -c-1", "start": "webpack-dev-server",
"test": "npm run build" "test": "npm run build"
}, },
"author": "Henri Bergius <henri.bergius@iki.fi>", "author": "Henri Bergius <henri.bergius@iki.fi>",
@ -30,9 +30,9 @@
"eslint": "^4.12.0", "eslint": "^4.12.0",
"eslint-config-airbnb-base": "^12.1.0", "eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.8.0", "eslint-plugin-import": "^2.8.0",
"http-server": "^0.11.0",
"msgflo-nodejs": "^0.11.1", "msgflo-nodejs": "^0.11.1",
"webpack": "^4.0.0", "webpack": "^4.0.0",
"webpack-cli": "^3.0.0" "webpack-cli": "^3.0.0",
"webpack-dev-server": "^3.1.10"
} }
} }

View file

@ -1,3 +1,4 @@
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = { module.exports = {
@ -7,11 +8,12 @@ module.exports = {
calendar: './events/calendar.js', calendar: './events/calendar.js',
}, },
output: { output: {
path: __dirname, path: path.resolve(__dirname, 'dist'),
filename: 'dist/lib/[name].js', filename: 'lib/[name].js',
library: '[name]', library: '[name]',
libraryTarget: 'umd', libraryTarget: 'umd',
}, },
mode: 'production',
module: { module: {
rules: [ rules: [
{ {
@ -31,27 +33,27 @@ module.exports = {
new CopyWebpackPlugin([ new CopyWebpackPlugin([
{ {
from: '**/index.html', from: '**/index.html',
to: 'dist/', to: './',
}, },
{ {
from: '**/*.svg', from: '**/*.svg',
to: 'dist/', to: './',
}, },
{ {
from: 'theme/*', from: 'theme/*',
to: 'dist/', to: './',
}, },
{ {
from: 'node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js', from: 'node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js',
to: 'dist/vendor/webcomponentsjs/webcomponents-lite.js', to: './vendor/webcomponentsjs/webcomponents-lite.js',
}, },
{ {
from: 'node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js', from: 'node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js',
to: 'dist/vendor/webcomponentsjs/custom-elements-es5-adapter.js', to: './vendor/webcomponentsjs/custom-elements-es5-adapter.js',
}, },
{ {
from: 'node_modules/plotly.js/dist/plotly.min.js', from: 'node_modules/plotly.js/dist/plotly.min.js',
to: 'dist/vendor/plotly.js/plotly.min.js', to: './vendor/plotly.js/plotly.min.js',
}, },
]), ]),
], ],
@ -64,4 +66,9 @@ module.exports = {
node: { node: {
fs: 'empty', fs: 'empty',
}, },
devServer: {
host: process.env.HOST || 'localhost',
port: 3000,
inline: true,
},
}; };