|
1 |
| -'use strict' |
2 |
| - |
3 |
| -// const ExtractTextPlugin = require('extract-text-webpack-plugin') |
4 |
| -// const HtmlWebpackPlugin = require('html-webpack-plugin') |
5 | 1 | const path = require('path')
|
6 | 2 | const webpack = require('webpack')
|
7 | 3 | const pkg = require('../package.json')
|
8 | 4 |
|
| 5 | +// paths |
9 | 6 | const buildPath = 'dist'
|
10 | 7 | const publicPath = 'assets'
|
11 |
| -const port = process.env.PORT || 3000 |
12 |
| -const webpackPort = process.env.WEBPACK_PORT || 3001 |
13 | 8 |
|
14 |
| -function createWebpackConfig (options) { |
| 9 | +// create configuration |
| 10 | +module.exports = function (options) { |
15 | 11 | if (!options) { options = {} }
|
16 |
| - // Sourcemaps |
17 |
| - const devtool = options.dev ? 'eval-source-map' : 'sourcemap' |
18 |
| - |
19 |
| - const entry = path.join(__dirname, '..', 'src/index') |
20 |
| - |
21 |
| - // Webpack dev-server |
22 |
| - // if (options.dev) { |
23 |
| - // entry = entry.concat( |
24 |
| - // 'webpack/hot/only-dev-server', |
25 |
| - // 'webpack-dev-server/client?http://localhost:' + webpackPort |
26 |
| - // ) |
27 |
| - // } |
28 |
| - |
29 |
| - const output = { |
30 |
| - path: path.resolve(__dirname, '..', buildPath), |
31 |
| - library: 'Pano', |
32 |
| - libraryTarget: 'umd', |
33 |
| - publicPath: '/dist/' |
34 |
| - } |
35 | 12 |
|
36 |
| - var plugins = [ |
37 |
| - new webpack.BannerPlugin('pano.js v' + pkg.version + ' | (c) Sinan Bolel & Prescott Prue', { |
38 |
| - raw: false, entryOnly: true |
| 13 | + const plugins = [ |
| 14 | + new webpack.BannerPlugin({ |
| 15 | + banner: `pano.js v${pkg.version} | (c) Sinan Bolel & Prescott Prue`, |
| 16 | + entryOnly: true, raw: false |
39 | 17 | }),
|
40 |
| - new webpack.NoErrorsPlugin(), |
41 |
| - // new ExtractTextPlugin('style.css', {allChunks: true}), //put all imported css into one bundled css file |
42 |
| - // |
43 |
| - // function () { |
44 |
| - // this.plugin('done', function (stats) { |
45 |
| - // fs.writeFileSync( |
46 |
| - // path.resolve(__dirname, '..', 'stats.json'), |
47 |
| - // JSON.stringify(stats.toJson()) |
48 |
| - // ) |
49 |
| - // }) |
50 |
| - // } |
| 18 | + new webpack.NoEmitOnErrorsPlugin() |
51 | 19 | ]
|
52 | 20 |
|
53 | 21 | if (!options.dev) {
|
54 |
| - plugins = plugins.concat( |
55 |
| - [ |
56 |
| - new webpack.optimize.UglifyJsPlugin({ |
57 |
| - compress: { |
58 |
| - warnings: false |
59 |
| - }, |
60 |
| - compressor: { |
61 |
| - screw_ie8: true, |
62 |
| - warnings: false |
63 |
| - } |
64 |
| - }) |
65 |
| - ] |
66 |
| - ) |
67 |
| - } |
68 |
| - // Place the tags into an html file |
69 |
| - if (options.includeHtml) { |
70 |
| - plugins = plugins.concat( |
71 |
| - // new HtmlWebpackPlugin({ |
72 |
| - // template: path.resolve(__dirname, '..', 'index.html'), |
73 |
| - // filename: 'index.html' |
74 |
| - // }) |
| 22 | + plugins.push( |
| 23 | + new webpack.optimize.UglifyJsPlugin({ |
| 24 | + compress: { |
| 25 | + warnings: false |
| 26 | + }, |
| 27 | + compressor: { |
| 28 | + screw_ie8: true, |
| 29 | + warnings: false |
| 30 | + } |
| 31 | + }) |
75 | 32 | )
|
76 | 33 | }
|
77 | 34 |
|
78 |
| - const resolve = { |
79 |
| - alias: { |
80 |
| - assets: path.resolve(__dirname, '..', 'assets') |
81 |
| - }, |
82 |
| - extensions: ['', '.js'] |
83 |
| - } |
84 |
| - |
85 |
| - const cssLoaders = [ |
86 |
| - 'css?root=..', |
87 |
| - 'sass?outputStyle=expanded&' |
88 |
| - ].join('!') |
89 |
| - |
90 |
| - const loaders = [ |
91 |
| - { |
92 |
| - exclude: /node_modules/, |
93 |
| - test: /\.js$/, |
94 |
| - loaders: ['babel'] |
95 |
| - }, |
96 |
| - // npm i --save-dev style-loader css-loader scss-loader |
97 |
| - // { |
98 |
| - // test: /\.(scss|css)$/, |
99 |
| - // loader: options.dev |
100 |
| - // ? 'style!' + cssLoaders |
101 |
| - // : ExtractTextPlugin.extract(cssLoaders) |
102 |
| - // }, |
103 |
| - // npm i --save-dev url-loader file-loader |
104 |
| - // { |
105 |
| - // exclude: /node_modules/, |
106 |
| - // test: /\.(jpg|png|svg)$/, |
107 |
| - // loader: 'url?limit=8192' |
108 |
| - // }, |
109 |
| - // npm i --save-dev url-loader file-loader |
110 |
| - // { |
111 |
| - // test: /\.json$/, |
112 |
| - // loader: 'json' |
113 |
| - // }, |
114 |
| - // npm i --save-dev url-loader file-loader |
115 |
| - // { |
116 |
| - // test: /\.(otf|eot|svg|ttf|woff|woff2).*$/, |
117 |
| - // loader: 'url?limit=8192' |
118 |
| - // } |
119 |
| - ] |
120 | 35 | return {
|
121 | 36 | bail: !options.dev,
|
122 |
| - devtool: devtool, |
123 |
| - entry: entry, |
124 |
| - output: output, |
| 37 | + devtool: options.dev ? 'eval-source-map' : 'sourcemap', |
| 38 | + entry: path.join(__dirname, '..', 'src/index'), |
| 39 | + module: { |
| 40 | + loaders: [{ |
| 41 | + exclude: /node_modules/, |
| 42 | + loaders: ['babel-loader'], |
| 43 | + test: /\.js$/ |
| 44 | + }] |
| 45 | + }, |
| 46 | + output: { |
| 47 | + library: 'Pano', |
| 48 | + libraryTarget: 'umd', |
| 49 | + path: path.resolve(__dirname, '..', buildPath), |
| 50 | + publicPath: '/dist/' |
| 51 | + }, |
125 | 52 | plugins: plugins,
|
126 |
| - resolve: resolve, |
127 |
| - module: { loaders: loaders }, |
128 |
| - target: options.target, |
129 |
| - |
130 |
| - port: port, |
131 |
| - webpackPort: webpackPort, |
132 |
| - buildPath: buildPath, |
133 |
| - publicPath: publicPath |
| 53 | + resolve: { |
| 54 | + alias: { assets: path.resolve(__dirname, '..', 'assets') }, |
| 55 | + extensions: ['.js'] |
| 56 | + }, |
| 57 | + target: options.target |
134 | 58 | }
|
135 | 59 | }
|
136 |
| -module.exports = createWebpackConfig |
0 commit comments