|
| 1 | +const path = require('path'); |
| 2 | +const HtmlWebpackPlugin = require('html-webpack-plugin'); |
| 3 | +const { BaseHrefWebpackPlugin } = require('base-href-webpack-plugin'); |
| 4 | +const ExtWebpackPlugin = require('@sencha/ext-webpack-plugin'); |
| 5 | +const portfinder = require('portfinder'); |
| 6 | + |
| 7 | +module.exports = async function (env) { |
| 8 | + function get(it, val) {if(env == undefined) {return val} else if(env[it] == undefined) {return val} else {return env[it]}} |
| 9 | + |
| 10 | + //******* */ |
| 11 | + var framework = get('framework', 'extjs') |
| 12 | + var contextFolder = get('contextFolder', './') |
| 13 | + var entryFile = get('entryFile', './index.js') |
| 14 | + var outputFolder = get('outputFolder', './') |
| 15 | + const rules =[ |
| 16 | + //{ test: /.(js|jsx)$/, exclude: /node_modules/ } |
| 17 | + { test: /.(js)$/, use: ['babel-loader'] } |
| 18 | + ] |
| 19 | + const resolve = { |
| 20 | + } |
| 21 | + //******* */ |
| 22 | + |
| 23 | + var toolkit = get('toolkit', 'modern') |
| 24 | + var theme = get('theme', 'theme-material') |
| 25 | + var packages = get('packages', ['treegrid']) |
| 26 | + var script = get('script', '') |
| 27 | + var emit = get('emit', 'yes') |
| 28 | + var profile = get('profile', '') |
| 29 | + var environment = get('environment', 'development') |
| 30 | + var treeshake = get('treeshake', 'no') |
| 31 | + var browser = get('browser', 'yes') |
| 32 | + var watch = get('watch', 'yes') |
| 33 | + var verbose = get('verbose', 'no') |
| 34 | + var basehref = get('basehref', '/') |
| 35 | + |
| 36 | + const isProd = environment === 'production' |
| 37 | + portfinder.basePort = (env && env.port) || 1962 |
| 38 | + return portfinder.getPortPromise().then(port => { |
| 39 | + const plugins = [ |
| 40 | + new HtmlWebpackPlugin({ template: "index.html", hash: true, inject: "body" }), |
| 41 | + new BaseHrefWebpackPlugin({ baseHref: basehref }), |
| 42 | + new ExtWebpackPlugin({ |
| 43 | + framework: framework, |
| 44 | + toolkit: toolkit, |
| 45 | + theme: theme, |
| 46 | + packages: packages, |
| 47 | + script: script, |
| 48 | + emit: emit, |
| 49 | + port: port, |
| 50 | + profile: profile, |
| 51 | + environment: environment, |
| 52 | + treeshake: treeshake, |
| 53 | + browser: browser, |
| 54 | + watch: watch, |
| 55 | + verbose: verbose |
| 56 | + }) |
| 57 | + ] |
| 58 | + |
| 59 | + return { |
| 60 | + mode: environment, |
| 61 | + devtool: (environment === 'development') ? 'inline-source-map' : false, |
| 62 | + context: path.join(__dirname, contextFolder), |
| 63 | + entry: entryFile, |
| 64 | + output: { |
| 65 | + path: path.join(__dirname, outputFolder), |
| 66 | + filename: "[name].js" |
| 67 | + }, |
| 68 | + plugins: plugins, |
| 69 | + module: { |
| 70 | + rules: rules |
| 71 | + }, |
| 72 | + resolve: resolve, |
| 73 | + performance: { hints: false }, |
| 74 | + stats: 'none', |
| 75 | + optimization: { noEmitOnErrors: true }, |
| 76 | + node: false, |
| 77 | + devServer: { |
| 78 | + contentBase: outputFolder, |
| 79 | + hot: !isProd, |
| 80 | + historyApiFallback: true, |
| 81 | + host: '0.0.0.0', |
| 82 | + port: port, |
| 83 | + disableHostCheck: false, |
| 84 | + compress: isProd, |
| 85 | + inline:!isProd, |
| 86 | + stats: 'none' |
| 87 | + } |
| 88 | + } |
| 89 | + }) |
| 90 | +} |
0 commit comments