Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84c979d

Browse files
mikeericksonFoxandxss
authored andcommitted
065 update to webpack 2 (preboot#66)
1 parent da4ce19 commit 84c979d

File tree

5 files changed

+50
-28
lines changed

5 files changed

+50
-28
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015-2016 Preboot team
3+
Copyright (c) 2015-2017 Preboot team
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
A complete, yet simple, starter for Angular using Webpack.
66

7-
This workflow serves as a starting point for building Angular 1.x applications using Webpack. Should be noted that apart from the pre-installed angular package, this workflow is pretty much generic.
7+
This workflow serves as a starting point for building Angular 1.x applications using Webpack 2.x. Should be noted that apart from the pre-installed angular package, this workflow is pretty much generic.
88

99
* Heavily commented webpack configuration with reasonable defaults.
1010
* ES6, and ES7 support with babel.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-webpack-workflow",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "A workflow for Angular made with Webpack",
55
"scripts": {
66
"build": "rimraf dist && webpack --bail --progress --profile",
@@ -28,9 +28,9 @@
2828
"babel-core": "^6.2.1",
2929
"babel-loader": "^6.2.0",
3030
"babel-preset-es2015": "^6.1.18",
31-
"copy-webpack-plugin": "^4.0.1",
32-
"css-loader": "^0.23.0",
33-
"extract-text-webpack-plugin": "^1.0.1",
31+
"copy-webpack-plugin": "4.0.1",
32+
"css-loader": "0.26.1",
33+
"extract-text-webpack-plugin": "2.0.0-beta.5",
3434
"file-loader": "^0.9.0",
3535
"html-webpack-plugin": "^2.7.1",
3636
"istanbul-instrumenter-loader": "^1.0.0",
@@ -41,15 +41,15 @@
4141
"karma-phantomjs-launcher": "^1.0.0",
4242
"karma-sourcemap-loader": "^0.3.7",
4343
"karma-spec-reporter": "0.0.26",
44-
"karma-webpack": "^1.7.0",
45-
"node-libs-browser": "^2.0.0",
44+
"karma-webpack": "2.0.1",
45+
"node-libs-browser": "2.0.0",
4646
"null-loader": "^0.1.1",
4747
"phantomjs-prebuilt": "^2.1.4",
48-
"postcss-loader": "^1.1.1",
48+
"postcss-loader": "1.2.2",
4949
"raw-loader": "^0.5.1",
5050
"rimraf": "^2.5.1",
5151
"style-loader": "^0.13.0",
52-
"webpack": "^1.12.13",
53-
"webpack-dev-server": "^1.14.1"
52+
"webpack": "2.2.0",
53+
"webpack-dev-server": "2.2.0"
5454
}
5555
}

postcss.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
plugins: {
3+
autoprefixer: {
4+
browsers: ['last 2 versions']
5+
},
6+
},
7+
};

webpack.config.js

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var ENV = process.env.npm_lifecycle_event;
1515
var isTest = ENV === 'test' || ENV === 'test-watch';
1616
var isProd = ENV === 'build';
1717

18-
module.exports = function makeWebpackConfig () {
18+
module.exports = function makeWebpackConfig() {
1919
/**
2020
* Config
2121
* Reference: http://webpack.github.io/docs/configuration.html
@@ -63,9 +63,11 @@ module.exports = function makeWebpackConfig () {
6363
*/
6464
if (isTest) {
6565
config.devtool = 'inline-source-map';
66-
} else if (isProd) {
66+
}
67+
else if (isProd) {
6768
config.devtool = 'source-map';
68-
} else {
69+
}
70+
else {
6971
config.devtool = 'eval-source-map';
7072
}
7173

@@ -78,14 +80,13 @@ module.exports = function makeWebpackConfig () {
7880

7981
// Initialize module
8082
config.module = {
81-
preLoaders: [],
82-
loaders: [{
83+
rules: [{
8384
// JS LOADER
8485
// Reference: https://github.com/babel/babel-loader
8586
// Transpile .js files using babel-loader
8687
// Compiles ES6 and ES7 into ES5 code
8788
test: /\.js$/,
88-
loader: 'babel',
89+
loader: 'babel-loader',
8990
exclude: /node_modules/
9091
}, {
9192
// CSS LOADER
@@ -100,7 +101,14 @@ module.exports = function makeWebpackConfig () {
100101
//
101102
// Reference: https://github.com/webpack/style-loader
102103
// Use style-loader in development.
103-
loader: isTest ? 'null' : ExtractTextPlugin.extract('style-loader', 'css-loader?sourceMap!postcss-loader')
104+
105+
loader: isTest ? 'null' : ExtractTextPlugin.extract({
106+
fallbackLoader: 'style-loader',
107+
loader: [
108+
{loader: 'css-loader', query: {sourceMap: true}},
109+
{loader: 'postcss-loader'}
110+
],
111+
})
104112
}, {
105113
// ASSET LOADER
106114
// Reference: https://github.com/webpack/file-loader
@@ -109,13 +117,13 @@ module.exports = function makeWebpackConfig () {
109117
// Pass along the updated reference to your code
110118
// You can add here any file extension you want to get copied to your output
111119
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/,
112-
loader: 'file'
120+
loader: 'file-loader'
113121
}, {
114122
// HTML LOADER
115123
// Reference: https://github.com/webpack/raw-loader
116124
// Allow loading html through js
117125
test: /\.html$/,
118-
loader: 'raw'
126+
loader: 'raw-loader'
119127
}]
120128
};
121129

@@ -124,7 +132,8 @@ module.exports = function makeWebpackConfig () {
124132
// Instrument JS files with istanbul-lib-instrument for subsequent code coverage reporting
125133
// Skips node_modules and files that end with .test
126134
if (isTest) {
127-
config.module.preLoaders.push({
135+
config.module.rules.push({
136+
enforce: 'pre',
128137
test: /\.js$/,
129138
exclude: [
130139
/node_modules/,
@@ -142,18 +151,24 @@ module.exports = function makeWebpackConfig () {
142151
* Reference: https://github.com/postcss/autoprefixer-core
143152
* Add vendor prefixes to your css
144153
*/
145-
config.postcss = [
146-
autoprefixer({
147-
browsers: ['last 2 version']
148-
})
149-
];
154+
// NOTE: This is now handled in the `postcss.config.js`
155+
// webpack2 has some issues, making the config file necessary
150156

151157
/**
152158
* Plugins
153159
* Reference: http://webpack.github.io/docs/configuration.html#plugins
154160
* List: http://webpack.github.io/docs/list-of-plugins.html
155161
*/
156-
config.plugins = [];
162+
config.plugins = [
163+
new webpack.LoaderOptionsPlugin({
164+
test: /\.scss$/i,
165+
options: {
166+
postcss: {
167+
plugins: [autoprefixer]
168+
}
169+
}
170+
})
171+
];
157172

158173
// Skip rendering index.html in test mode
159174
if (!isTest) {
@@ -168,7 +183,7 @@ module.exports = function makeWebpackConfig () {
168183
// Reference: https://github.com/webpack/extract-text-webpack-plugin
169184
// Extract css files
170185
// Disabled when in test mode or not in build mode
171-
new ExtractTextPlugin('[name].[hash].css', {disable: !isProd})
186+
new ExtractTextPlugin({filename: 'css/[name].css', disable: !isProd, allChunks: true})
172187
)
173188
}
174189

0 commit comments

Comments
 (0)