Webpack and script for building

This commit is contained in:
Jesper Wrang 2018-01-09 02:15:49 +01:00
parent 904863a8de
commit 5654426230
4 changed files with 83 additions and 1 deletions

View file

@ -4,7 +4,10 @@
"description": "View removed comments from reddit",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"start": "webpack-dev-server --config webpack.dev.js",
"build": "webpack --config webpack.dev.js",
"build-prod": "webpack --config webpack.prod.js",
"gh-pages": "npm run build-prod && node publish.js"
},
"repository": {
"type": "git",

57
webpack.common.js Normal file
View file

@ -0,0 +1,57 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = {
entry: [
'./src/js/index.js'
],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/'
},
resolve: {
modules: [
path.resolve('./src/js'),
path.resolve('./src'),
path.resolve('./node_modules')
]
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ["@babel/preset-react"],
}
},
{
test: /\.html$/,
loader: 'html-loader'
},
]
},
plugins: [
new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
template: 'src/index.html'
}),
new CopyWebpackPlugin([
{
from: 'src/404.html',
to: '404.html'
},
{
from: 'src/images',
to: 'images/'
}
]),
],
stats: {
colors: true
},
}

9
webpack.dev.js Normal file
View file

@ -0,0 +1,9 @@
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common, {
devServer: {
historyApiFallback: true
},
});

13
webpack.prod.js Normal file
View file

@ -0,0 +1,13 @@
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
module.exports = merge(common, {
plugins: [
new UglifyJSPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
});