mirror of
https://github.com/tomru/pdfer.git
synced 2026-03-03 06:27:19 +01:00
add preact with webpack
This commit is contained in:
8
config/babel.js
Normal file
8
config/babel.js
Normal file
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
['es2015', {modules: false}]
|
||||
],
|
||||
plugins: [
|
||||
['transform-react-jsx', {pragma: 'h'}]
|
||||
]
|
||||
};
|
||||
47
config/setup.js
Normal file
47
config/setup.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const { join } = require('path');
|
||||
const webpack = require('webpack');
|
||||
const Dashboard = require('webpack-dashboard/plugin');
|
||||
const Clean = require('clean-webpack-plugin');
|
||||
const Copy = require('copy-webpack-plugin');
|
||||
const HTML = require('html-webpack-plugin');
|
||||
|
||||
const uglify = require('./uglify');
|
||||
const babel = require('./babel');
|
||||
|
||||
const root = join(__dirname, '..');
|
||||
|
||||
module.exports = isProd => {
|
||||
// base plugins array
|
||||
const plugins = [
|
||||
new Clean(['dist'], { root }),
|
||||
new Copy([{ context: 'webapp/static/', from: '**/*.*' }]),
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development')
|
||||
}),
|
||||
new HTML({ template: 'webapp/index.html' }),
|
||||
new webpack.LoaderOptionsPlugin({
|
||||
options: {
|
||||
babel
|
||||
}
|
||||
})
|
||||
];
|
||||
|
||||
if (isProd) {
|
||||
plugins.push(
|
||||
new webpack.LoaderOptionsPlugin({ minimize: true, debug: false }),
|
||||
new webpack.optimize.UglifyJsPlugin(uglify)
|
||||
);
|
||||
} else {
|
||||
// dev only
|
||||
plugins.push(
|
||||
new webpack.HotModuleReplacementPlugin(),
|
||||
new webpack.NamedModulesPlugin(),
|
||||
new webpack.DefinePlugin({
|
||||
__DEVELOPMENT__: !isProd
|
||||
}),
|
||||
new Dashboard()
|
||||
);
|
||||
}
|
||||
|
||||
return plugins;
|
||||
};
|
||||
16
config/uglify.js
Normal file
16
config/uglify.js
Normal file
@@ -0,0 +1,16 @@
|
||||
module.exports = {
|
||||
output: {
|
||||
comments: 0
|
||||
},
|
||||
compress: {
|
||||
unused: 1,
|
||||
warnings: 0,
|
||||
comparisons: 1,
|
||||
conditionals: 1,
|
||||
negate_iife: 0, // <- for `LazyParseWebpackPlugin()`
|
||||
dead_code: 1,
|
||||
if_return: 1,
|
||||
join_vars: 1,
|
||||
evaluate: 1
|
||||
}
|
||||
};
|
||||
46
config/webpack.js
Normal file
46
config/webpack.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const { join } = require('path');
|
||||
const setup = require('./setup');
|
||||
|
||||
const dist = join(__dirname, '../dist');
|
||||
const exclude = /node_modules/;
|
||||
|
||||
module.exports = env => {
|
||||
const isProd = env && env.production;
|
||||
|
||||
return {
|
||||
entry: {
|
||||
app: './webapp/index.js',
|
||||
vendor: [
|
||||
'preact'
|
||||
]
|
||||
},
|
||||
output: {
|
||||
path: dist,
|
||||
filename: '[name].[hash].js',
|
||||
publicPath: '/'
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'react': 'preact/aliases',
|
||||
'react-dom': 'preact/aliases'
|
||||
}
|
||||
},
|
||||
module: {
|
||||
rules: [{
|
||||
test: /\.jsx?$/,
|
||||
exclude: exclude,
|
||||
loader: 'babel-loader'
|
||||
}]
|
||||
},
|
||||
plugins: setup(isProd),
|
||||
devtool: !isProd && 'source-map',
|
||||
devServer: {
|
||||
contentBase: dist,
|
||||
port: process.env.PORT || 5050,
|
||||
historyApiFallback: true,
|
||||
compress: isProd,
|
||||
inline: !isProd,
|
||||
hot: !isProd
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user