Skip to content

Commit a88cdb8

Browse files
committed
fix test-watch
1 parent 4507284 commit a88cdb8

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

webpack.config.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var CopyWebpackPlugin = require('copy-webpack-plugin');
1212
* Get npm lifecycle event to identify the environment
1313
*/
1414
var ENV = process.env.npm_lifecycle_event;
15+
var isTest = ENV === 'test' || ENV === 'test-watch';
16+
var isProd = ENV === 'build';
1517

1618
module.exports = function makeWebpackConfig () {
1719
/**
@@ -27,7 +29,7 @@ module.exports = function makeWebpackConfig () {
2729
* Should be an empty object if it's generating a test build
2830
* Karma will set this when it's a test build
2931
*/
30-
config.entry = ENV === 'test' ? {} : {
32+
config.entry = isTest ? {} : {
3133
app: './src/app/app.js'
3234
};
3335

@@ -37,31 +39,31 @@ module.exports = function makeWebpackConfig () {
3739
* Should be an empty object if it's generating a test build
3840
* Karma will handle setting it up for you when it's a test build
3941
*/
40-
config.output = ENV === 'test' ? {} : {
42+
config.output = isTest ? {} : {
4143
// Absolute output directory
4244
path: __dirname + '/dist',
4345

4446
// Output path from the view of the page
4547
// Uses webpack-dev-server in development
46-
publicPath: ENV === 'build' ? '/' : 'http://localhost:8080/',
48+
publicPath: isProd ? '/' : 'http://localhost:8080/',
4749

4850
// Filename for entry points
4951
// Only adds hash in build mode
50-
filename: ENV === 'build' ? '[name].[hash].js' : '[name].bundle.js',
52+
filename: isProd ? '[name].[hash].js' : '[name].bundle.js',
5153

5254
// Filename for non-entry points
5355
// Only adds hash in build mode
54-
chunkFilename: ENV === 'build' ? '[name].[hash].js' : '[name].bundle.js'
56+
chunkFilename: isProd ? '[name].[hash].js' : '[name].bundle.js'
5557
};
5658

5759
/**
5860
* Devtool
5961
* Reference: http://webpack.github.io/docs/configuration.html#devtool
6062
* Type of sourcemap to use per build type
6163
*/
62-
if (ENV === 'test') {
64+
if (isTest) {
6365
config.devtool = 'inline-source-map';
64-
} else if (ENV === 'build') {
66+
} else if (isProd) {
6567
config.devtool = 'source-map';
6668
} else {
6769
config.devtool = 'eval-source-map';
@@ -98,7 +100,7 @@ module.exports = function makeWebpackConfig () {
98100
//
99101
// Reference: https://github.com/webpack/style-loader
100102
// Use style-loader in development.
101-
loader: ENV === 'test' ? 'null' : ExtractTextPlugin.extract('style', 'css?sourceMap!postcss')
103+
loader: isTest ? 'null' : ExtractTextPlugin.extract('style', 'css?sourceMap!postcss')
102104
}, {
103105
// ASSET LOADER
104106
// Reference: https://github.com/webpack/file-loader
@@ -121,7 +123,7 @@ module.exports = function makeWebpackConfig () {
121123
// Reference: https://github.com/ColCh/isparta-instrumenter-loader
122124
// Instrument JS files with Isparta for subsequent code coverage reporting
123125
// Skips node_modules and files that end with .test.js
124-
if (ENV === 'test') {
126+
if (isTest) {
125127
config.module.preLoaders.push({
126128
test: /\.js$/,
127129
exclude: [
@@ -151,7 +153,7 @@ module.exports = function makeWebpackConfig () {
151153
config.plugins = [];
152154

153155
// Skip rendering index.html in test mode
154-
if (ENV !== 'test') {
156+
if (!isTest) {
155157
// Reference: https://github.com/ampedandwired/html-webpack-plugin
156158
// Render index.html
157159
config.plugins.push(
@@ -163,12 +165,12 @@ module.exports = function makeWebpackConfig () {
163165
// Reference: https://github.com/webpack/extract-text-webpack-plugin
164166
// Extract css files
165167
// Disabled when in test mode or not in build mode
166-
new ExtractTextPlugin('[name].[hash].css', {disable: ENV !== 'build'})
168+
new ExtractTextPlugin('[name].[hash].css', {disable: !isProd})
167169
)
168170
}
169171

170172
// Add build specific plugins
171-
if (ENV === 'build') {
173+
if (isProd) {
172174
config.plugins.push(
173175
// Reference: http://webpack.github.io/docs/list-of-plugins.html#noerrorsplugin
174176
// Only emit files when there are no errors

0 commit comments

Comments
 (0)