Skip to content

Add support for webpack 2 (beta.27) #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"redux-devtools": "3.3.1",
"redux-devtools-dock-monitor": "1.1.1",
"redux-devtools-log-monitor": "1.1.1",
"webpack-dev-server": "1.16.2",
"webpack-dev-server": "2.1.0-beta.11",
"webpack-sources": "0.1.2"
},
"dependencies": {
Expand Down Expand Up @@ -71,7 +71,7 @@
"css-modules-require-hook": "4.0.5",
"expose-loader": "0.7.1",
"express": "4.14.0",
"extract-text-webpack-plugin": "1.0.1",
"extract-text-webpack-plugin": "2.0.0-beta.4",
"file-loader": "0.9.0",
"font-awesome": "4.7.0",
"history": "4.4.0",
Expand All @@ -95,7 +95,7 @@
"serve-static": "1.11.1",
"style-loader": "0.13.1",
"url-loader": "0.5.7",
"webpack": "1.13.3",
"webpack": "2.1.0-beta.27",
"webpack-isomorphic-tools": "2.6.4"
}
}
5 changes: 5 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const autoprefixer = require('autoprefixer');

module.exports = {
plugins: [autoprefixer]
};
2 changes: 1 addition & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ app.listen(port, (error) => {
if (error) {
console.error(error);
} else {
console.info(`🌎 Application server listening on port ${port}.`);
console.info(`Application server mounted locally on port ${port}.`);
}
});
28 changes: 16 additions & 12 deletions webpack/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import mapValues from 'lodash/mapValues';
import autoprefixer from 'autoprefixer';
import isomorphicConfig from './isomorphic';
import IsomorphicPlugin from 'webpack-isomorphic-tools/plugin';
import { OUTPUT_PATH, ASSET_HOST, RESOLVE_PATHS } from './config';
import { OUTPUT_PATH, ASSET_HOST, RESOLVE_PATHS } from './constants';

const isDev = process.env.NODE_ENV === 'development';
const isomorphicPlugin = new IsomorphicPlugin(isomorphicConfig).development(isDev);
Expand Down Expand Up @@ -36,36 +36,40 @@ export default {
publicPath: ASSET_HOST
},
resolve: {
extensions: ['', '.js', '.jsx', '.scss'],
extensions: ['.js', '.jsx', '.scss'],
alias: mapValues(RESOLVE_PATHS, (str) => (
path.join(process.cwd(), ...str.split('/'))
))
},
module: {
preLoaders: [
rules: [
{
enforce: 'pre',
test: /\.jsx$|\.js$/,
loader: 'eslint-loader',
exclude: /node_modules/
}
],
loaders: [
exclude: /node_modules/,
use: [
{
loader: 'eslint-loader',
options: {
configFile: './.eslintrc',
}
}
]
},
{
test: /\.json$/,
loader: 'json'
loader: 'json-loader'
},
{
test: isomorphicPlugin.regular_expression('images'),
loader: 'url-loader?limit=10240'
},
{
// test: /\.(woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]*)?$/,
test: /\.(ttf|eot|svg|jpe?g|png|gif|ico|woff2?)$/,
loader: 'file'
loader: 'file-loader'
}
]
},
postcss: [autoprefixer],
plugins: [
isomorphicPlugin,
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en|es/),
Expand Down
File renamed without changes.
51 changes: 32 additions & 19 deletions webpack/development.hot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
import { DEV_SERVER_PORT, DEV_SERVER_HOSTNAME, DEV_SERVER_HOST_URL } from './config';
import { DEV_SERVER_PORT, DEV_SERVER_HOSTNAME, DEV_SERVER_HOST_URL } from './constants';
import WebpackDevServer from 'webpack-dev-server';
import webpack from 'webpack';
import baseConfig from './base';
Expand All @@ -13,33 +13,47 @@ const entry = [

// Additional plugins
const plugins = [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
new webpack.NoErrorsPlugin(),
new webpack.NamedModulesPlugin()
];

// Additional loaders
const loaders = [
{
test: /\.css$/,
loaders: [
'style',
`css?modules&importLoaders=3&localIdentName=${packageJson.config.css}`,
'postcss',
],
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 3,
localIdentName: packageJson.config.css
}
},
'postcss-loader'
]
},
{
test: /\.scss$/,
loaders: [
'style',
`css?modules&importLoaders=3&localIdentName=${packageJson.config.css}`,
'postcss',
'sass'
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 3,
localIdentName: packageJson.config.css
}
},
'postcss-loader',
'sass-loader'
]
},
{
test: /\.jsx$|\.js$/,
loader: 'babel',
loader: 'babel-loader',
exclude: /node_modules/,
// use react-transform to hot reload modules when hot is specified
query: {
Expand All @@ -60,8 +74,6 @@ const loaders = [
];

const config = Object.assign({}, baseConfig, {
eslint: { configFile: './.eslintrc' },
devServerPort: DEV_SERVER_PORT,
devtool: 'eval',
entry: Object.assign({}, baseConfig.entry, {
app: [
Expand All @@ -74,8 +86,8 @@ const config = Object.assign({}, baseConfig, {
...plugins
],
module: Object.assign({}, baseConfig.module, {
loaders: [
...baseConfig.module.loaders,
rules: [
...baseConfig.module.rules,
...loaders
]
})
Expand All @@ -84,6 +96,7 @@ const config = Object.assign({}, baseConfig, {
console.info('Firing up Webpack dev server...');

new WebpackDevServer(webpack(config), {
port: DEV_SERVER_PORT,
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
Expand All @@ -101,6 +114,6 @@ new WebpackDevServer(webpack(config), {
if (err) {
console.error(err);
} else {
console.info('🚧 Webpack client dev-server listening on ' + DEV_SERVER_HOST_URL + ' with publicPath:' + config.output.publicPath);
console.info(`Webpack dev server mounted at ${DEV_SERVER_HOST_URL}. Asset path: ${config.output.publicPath}`);
}
});
37 changes: 19 additions & 18 deletions webpack/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,36 @@ const loaders = [
exclude: /node_modules/
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract(
'style',
`css?minimize&modules&importLoaders=1&localIdentName=${packageJson.config.css}` +
'!postcss'
)
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract(
'style',
`css?minimize&modules&importLoaders=1&localIdentName=${packageJson.config.css}` +
'!postcss' +
'!sass'
)
test: /\.(css|scss)$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: [
{
loader: 'css-loader',
options: {
modules: true,
minimize: false,
importLoaders: 1,
localIdentName: packageJson.config.css
}
},
{ loader: 'postcss-loader' },
{ loader: 'sass-loader' }
]
})
}
];

export default {
...baseConfig,
eslint: { configFile: './.eslintrc' },
devtool: 'source-map',
plugins: [
...baseConfig.plugins,
...plugins
],
module: Object.assign({}, baseConfig.module, {
loaders: [
...baseConfig.module.loaders,
rules: [
...baseConfig.module.rules,
...loaders
]
})
Expand Down
31 changes: 21 additions & 10 deletions webpack/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,25 @@ const plugins = [
})
];

const loaders = [{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('css!sass')
}, {
test: /\.js$/,
loaders: ['babel'],
exclude: /node_modules/
}];
const loaders = [
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: [
{ loader: 'css-loader' },
{ loader: 'postcss-loader' },
{ loader: 'sass-loader' }
]
})
},
{
test: /\.js$/,
loader: 'babel-loader',
rules: ['babel'],
exclude: /node_modules/
}
];

export default {
...baseConfig,
Expand All @@ -41,8 +52,8 @@ export default {
...plugins
],
module: Object.assign({}, baseConfig.module, {
loaders: [
...baseConfig.module.loaders,
rules: [
...baseConfig.module.rules,
...loaders
]
})
Expand Down
Loading