dist
4 years ago
src
4 weeks ago
Makefile
4 years ago
loader.php
4 weeks ago
webpack.config.js
4 years ago
webpack.config.js
105 lines
| 1 | const path = require('path'); |
| 2 | const ExtractTextPlugin = require('extract-text-webpack-plugin'); |
| 3 | const WebpackAssetsManifest = require('webpack-assets-manifest'); |
| 4 | const CleanWebpackPlugin = require('clean-webpack-plugin'); |
| 5 | |
| 6 | /** |
| 7 | * @typedef LibrariesHash |
| 8 | * @property {object} [entryChunkName: string] A unique entry ID |
| 9 | * @property {array} entryChunkName.entry - A list of entries to bundle with the library |
| 10 | * @property {string} [entryChunkName.filename] - The target file name (if omitted, the entry entryChunkName will be used |
| 11 | * @property {string} [entryChunkName.var] - The name of the global variable to which the library will be assigned |
| 12 | * |
| 13 | * @type LibrariesHash |
| 14 | */ |
| 15 | const libraries = { |
| 16 | 'otgsSwitcher': { |
| 17 | entry: ['./src/js/otgsSwitcher.js'], |
| 18 | }, |
| 19 | 'otgsPopoverTooltip': { |
| 20 | entry: ['./src/js/otgsPopoverTooltip.js'], |
| 21 | }, |
| 22 | 'otgsTableStickyHeader': { |
| 23 | entry: ['./src/js/otgsTableStickyHeader.js'], |
| 24 | }, |
| 25 | }; |
| 26 | |
| 27 | const getEntries = () => { |
| 28 | const entries = {}; |
| 29 | Object.keys(libraries).map(key => entries[key] = libraries[key].entry); |
| 30 | |
| 31 | return entries; |
| 32 | }; |
| 33 | |
| 34 | const getEntryFileName = (chunk) => { |
| 35 | if (libraries.hasOwnProperty(chunk.id) && libraries[chunk.id].hasOwnProperty('filename') && libraries[chunk.id].filename) { |
| 36 | return libraries[chunk.id].filename; |
| 37 | } |
| 38 | return path.join(chunk.name); |
| 39 | }; |
| 40 | |
| 41 | module.exports = env => { |
| 42 | const isProduction = env === 'production'; |
| 43 | |
| 44 | console.log('getEntries()', getEntries()); |
| 45 | // console.log('getVars()',getVars()); |
| 46 | |
| 47 | return { |
| 48 | entry: getEntries, |
| 49 | output: { |
| 50 | path: path.join(__dirname, 'dist'), |
| 51 | filename: chunkData => path.join('js', getEntryFileName(chunkData.chunk) + '.js?ver=' + chunkData.chunk.hash), |
| 52 | chunkFilename: '[id].[name].js?ver=[chunkhash]', |
| 53 | library: ["OTGSUI", "[name]"], |
| 54 | libraryTarget: 'var' |
| 55 | }, |
| 56 | module: { |
| 57 | rules: [ |
| 58 | { |
| 59 | loader: 'babel-loader', |
| 60 | test: /\.js$/, |
| 61 | exclude: /node_modules/, |
| 62 | query: { |
| 63 | presets: ['es2015'], |
| 64 | }, |
| 65 | }, |
| 66 | { |
| 67 | test: /\.s?css$/, |
| 68 | use: ExtractTextPlugin.extract({ |
| 69 | fallback: 'style-loader', |
| 70 | use: [ |
| 71 | { |
| 72 | loader: 'css-loader', |
| 73 | options: { |
| 74 | sourceMap: !isProduction, |
| 75 | minimize: isProduction, |
| 76 | }, |
| 77 | }, |
| 78 | { |
| 79 | loader: 'sass-loader', |
| 80 | options: { |
| 81 | sourceMap: !isProduction, |
| 82 | }, |
| 83 | }, |
| 84 | { |
| 85 | loader: 'postcss-loader', |
| 86 | }, |
| 87 | ], |
| 88 | }), |
| 89 | }, |
| 90 | ], |
| 91 | }, |
| 92 | plugins: [ |
| 93 | new CleanWebpackPlugin(['dist']), |
| 94 | new ExtractTextPlugin({ |
| 95 | filename: path.join('css', '[name].css?ver=[chunkhash]'), |
| 96 | }), |
| 97 | new WebpackAssetsManifest({ |
| 98 | output: path.join(__dirname, 'dist', 'assets.json'), |
| 99 | entrypoints: true, |
| 100 | }), |
| 101 | ], |
| 102 | devtool: isProduction ? '' : 'inline-source-map' |
| 103 | }; |
| 104 | }; |
| 105 |