Skip to content
This repository has been archived by the owner on Nov 20, 2019. It is now read-only.

Commit

Permalink
[webpack] Makes sure it's working with v2
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Dec 30, 2016
1 parent ce02b7f commit 8e7dc76
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 194 deletions.
2 changes: 1 addition & 1 deletion docs/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import Main from './Main';
import './normalize.scss';
import './stylesheet.scss';

render(<Main />, document.getElementById('main'));
render(<Main />, document.querySelector('#main'));
103 changes: 0 additions & 103 deletions docs/webpack.config.js

This file was deleted.

85 changes: 0 additions & 85 deletions docs/webpack.js

This file was deleted.

63 changes: 63 additions & 0 deletions docs/webpack/baseConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// @flow weak

import path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import ServiceWorkerWebpackPlugin from '../../src/index';

export default {
entry: [
'./docs/src/app.js',
],
output: {
pathinfo: false,
path: path.join(__dirname, '../dist'), // No used by webpack dev server
publicPath: '',
filename: 'app.js',
},
target: 'web',
resolve: {
extensions: ['.js'],
alias: {
'serviceworker-webpack-plugin/lib': path.resolve(__dirname, '../../src'),
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.scss$/,
loaders: [
'style-loader',
'css-loader',
'postcss-loader',
'sass-loader',
],
},
],
},
performance: {
maxAssetSize: 4e6,
maxEntrypointSize: 6e6,
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, '../src/index.html'),
minify: {
removeComments: true,
collapseWhitespace: true,
},
}),
new ServiceWorkerWebpackPlugin({
entry: path.join(__dirname, '../src/sw.js'),
excludes: [
'**/.*',
'**/*.map',
'*.html',
],
}),
],
};
71 changes: 71 additions & 0 deletions docs/webpack/developmentConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// @flow weak

import webpack from 'webpack';
import ForceCaseSensitivityPlugin from 'force-case-sensitivity-webpack-plugin';
import baseConfig from './baseConfig';

const PORT = 8002;

export default {
...baseConfig,
output: {
...baseConfig.output,
// * filename */ comments to generated require()s in the output.
pathinfo: true,
publicPath: '/',
},
// webpack-dev-server options.
devServer: {
// activate hot reloading.
hot: true,
historyApiFallback: true,
port: PORT,

// webpack-dev-middleware options.
stats: {
// Remove built modules information.
modules: false,
// Remove built modules information to chunk information.
chunkModules: false,
colors: true,
},
},
module: {
rules: [
...baseConfig.module.rules.map((rule) => {
if (rule.use === 'babel-loader') {
return {
...rule,
options: {
presets: [
['es2015', {
modules: false,
}],
],
plugins: [
'react-hot-loader/babel',
],
},
};
}

return rule;
}),
],
},
devtool: 'eval', // no SourceMap, but named modules. Fastest at the expense of detail.
plugins: [
...baseConfig.plugins,
// Prevent naming issues.
new ForceCaseSensitivityPlugin(),
// Activates HMR.
new webpack.HotModuleReplacementPlugin(),
// Prints more readable module names in the browser console on HMR updates.
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('development'),
},
}),
],
};
45 changes: 45 additions & 0 deletions docs/webpack/productionConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// @flow weak

import webpack from 'webpack';
import baseConfig from './baseConfig';

export default {
...baseConfig,
module: {
rules: [
...baseConfig.module.rules.map((rule) => {
if (rule.use === 'babel-loader') {
return {
...rule,
options: {
presets: [
['es2015', {
modules: false,
}],
],
},
};
}

return rule;
}),
],
},
plugins: [
...baseConfig.plugins,
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true,
},
output: {
comments: false,
},
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
],
};
Loading

0 comments on commit 8e7dc76

Please sign in to comment.