|
1 | | -var config = require('./config.js'); |
2 | | -const path = require('path'); |
3 | | -const webpack = require('webpack'); |
4 | | -const MiniCssExtractPlugin = require('mini-css-extract-plugin'); |
| 1 | +var config = require("./config.js"); |
| 2 | +const path = require("path"); |
| 3 | +const webpack = require("webpack"); |
| 4 | +const MiniCssExtractPlugin = require("mini-css-extract-plugin"); |
5 | 5 |
|
6 | 6 | //const TARGET = process.env.npm_lifecycle_event; |
7 | 7 |
|
8 | | -const common = { |
9 | | - devtool: 'eval-source-map', |
10 | | - entry: './vis/entrypoint.js', |
| 8 | +const getSkinExample = (skin) => { |
| 9 | + switch (skin) { |
| 10 | + case "": |
| 11 | + return ["/project_website/base.html"]; |
| 12 | + case "covis": |
| 13 | + return ["/local_covis/"]; |
| 14 | + case "triple": |
| 15 | + return ["/local_triple/map.html"]; |
| 16 | + case "viper": |
| 17 | + return "/local_viper/"; |
| 18 | + default: |
| 19 | + return false; |
| 20 | + } |
| 21 | +}; |
| 22 | + |
| 23 | +module.exports = (env) => { |
| 24 | + const { publicPath, skin } = { ...config, ...env }; |
| 25 | + |
| 26 | + return { |
| 27 | + devtool: "eval-source-map", |
| 28 | + entry: "./vis/entrypoint.js", |
11 | 29 |
|
12 | 30 | output: { |
13 | | - path: path.resolve(__dirname, "dist"), |
14 | | - //dev: specify a full path including protocol, production: specify full path excluding protocol |
15 | | - publicPath: config.publicPath, |
16 | | - filename: 'headstart.js', |
17 | | - libraryTarget: 'var', |
18 | | - library: 'headstart' |
| 31 | + path: path.resolve(__dirname, "dist"), |
| 32 | + //dev: specify a full path including protocol, production: specify full path excluding protocol |
| 33 | + publicPath: publicPath, |
| 34 | + filename: "headstart.js", |
| 35 | + libraryTarget: "var", |
| 36 | + library: "headstart", |
19 | 37 | }, |
20 | 38 |
|
21 | 39 | devServer: { |
22 | | - static: { |
23 | | - directory: path.resolve(__dirname, 'examples/'), |
24 | | - }, |
25 | | - allowedHosts: "all", |
26 | | - host: "0.0.0.0", |
27 | | - devMiddleware: { publicPath: '/dist/' }, |
| 40 | + open: getSkinExample(skin), |
| 41 | + static: { |
| 42 | + directory: path.resolve(__dirname, "examples/"), |
| 43 | + }, |
| 44 | + allowedHosts: "all", |
| 45 | + devMiddleware: { publicPath: "/dist/" }, |
28 | 46 | }, |
29 | 47 |
|
30 | 48 | resolve: { |
31 | | - alias: { |
32 | | - // |
33 | | - 'hypher': 'hypher/dist/jquery.hypher.js', |
34 | | - 'markjs': 'mark.js/dist/jquery.mark.js', |
| 49 | + alias: { |
| 50 | + // |
| 51 | + hypher: "hypher/dist/jquery.hypher.js", |
| 52 | + markjs: "mark.js/dist/jquery.mark.js", |
35 | 53 |
|
36 | | - // paths |
37 | | - 'templates': path.resolve(__dirname, 'vis/templates'), |
38 | | - 'images': path.resolve(__dirname, 'vis/images'), |
39 | | - 'lib': path.resolve(__dirname, 'vis/lib'), |
40 | | - 'styles': path.resolve(__dirname, 'vis/stylesheets'), |
| 54 | + // paths |
| 55 | + templates: path.resolve(__dirname, "vis/templates"), |
| 56 | + images: path.resolve(__dirname, "vis/images"), |
| 57 | + lib: path.resolve(__dirname, "vis/lib"), |
| 58 | + styles: path.resolve(__dirname, "vis/stylesheets"), |
41 | 59 |
|
42 | | - // modules |
43 | | - 'config': path.resolve(__dirname, 'vis/js/default-config.js'), |
44 | | - 'headstart': path.resolve(__dirname, 'vis/js/headstart.js'), |
45 | | - 'mediator': path.resolve(__dirname, 'vis/js/mediator.js'), |
46 | | - 'io' : path.resolve(__dirname, 'vis/js/io.js'), |
| 60 | + // modules |
| 61 | + config: path.resolve(__dirname, "vis/js/default-config.js"), |
| 62 | + headstart: path.resolve(__dirname, "vis/js/headstart.js"), |
| 63 | + mediator: path.resolve(__dirname, "vis/js/mediator.js"), |
| 64 | + io: path.resolve(__dirname, "vis/js/io.js"), |
47 | 65 |
|
48 | | - // building |
49 | | - process: "process/browser", |
50 | | - }, |
| 66 | + // building |
| 67 | + process: "process/browser", |
| 68 | + }, |
51 | 69 | }, |
52 | 70 |
|
53 | 71 | externals: { |
54 | | - 'chart': 'Chart' |
| 72 | + chart: "Chart", |
55 | 73 | }, |
56 | 74 | plugins: [ |
57 | | - new webpack.ProvidePlugin({ |
58 | | - process: 'process/browser', |
59 | | - }), |
60 | | - new MiniCssExtractPlugin({ |
61 | | - // Options similar to the same options in webpackOptions.output |
62 | | - // all options are optional |
63 | | - filename: 'headstart.css', |
64 | | - chunkFilename: '[id].css', |
65 | | - ignoreOrder: false, // Enable to remove warnings about conflicting order |
66 | | - }), |
67 | | - // can be used for simulating env variables |
68 | | - new webpack.EnvironmentPlugin({}) |
| 75 | + new webpack.ProvidePlugin({ |
| 76 | + process: "process/browser", |
| 77 | + }), |
| 78 | + new MiniCssExtractPlugin({ |
| 79 | + // Options similar to the same options in webpackOptions.output |
| 80 | + // all options are optional |
| 81 | + filename: "headstart.css", |
| 82 | + chunkFilename: "[id].css", |
| 83 | + ignoreOrder: false, // Enable to remove warnings about conflicting order |
| 84 | + }), |
| 85 | + // can be used for simulating env variables |
| 86 | + new webpack.EnvironmentPlugin({}), |
69 | 87 | ], |
70 | 88 | module: { |
71 | | - rules: [ |
| 89 | + rules: [ |
| 90 | + { |
| 91 | + test: require.resolve("hypher/dist/jquery.hypher.js"), |
| 92 | + use: [ |
| 93 | + { |
| 94 | + loader: "imports-loader", |
| 95 | + options: { |
| 96 | + imports: ["default jquery $", "default jquery jQuery"], |
| 97 | + }, |
| 98 | + }, |
| 99 | + ], |
| 100 | + }, |
| 101 | + { |
| 102 | + test: /lib\/*.js/, |
| 103 | + use: [ |
| 104 | + { |
| 105 | + loader: "imports-loader", |
| 106 | + options: { |
| 107 | + imports: ["default jquery $", "default jquery jQuery"], |
| 108 | + }, |
| 109 | + }, |
| 110 | + ], |
| 111 | + }, |
| 112 | + { |
| 113 | + test: /.jsx?$/, |
| 114 | + resolve: { extensions: [".js", ".jsx"] }, |
| 115 | + exclude: /node_modules/, |
| 116 | + use: [ |
| 117 | + { |
| 118 | + loader: "babel-loader", |
| 119 | + options: { |
| 120 | + presets: ["@babel/preset-env", "@babel/preset-react"], |
| 121 | + }, |
| 122 | + }, |
| 123 | + ], |
| 124 | + }, |
| 125 | + { |
| 126 | + test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, |
| 127 | + use: [ |
| 128 | + { |
| 129 | + loader: |
| 130 | + "url-loader?limit=10000&minetype=application/font-woff&name=/assets/[name].[ext]", |
| 131 | + }, |
| 132 | + ], |
| 133 | + }, |
| 134 | + { |
| 135 | + test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, |
| 136 | + use: [{ loader: "file-loader?name=/assets/[name].[ext]" }], |
| 137 | + }, |
| 138 | + { |
| 139 | + test: /\.png$/, |
| 140 | + use: [ |
| 141 | + { |
| 142 | + loader: "file-loader?name=img/[name].[ext]", |
| 143 | + options: { exclude: /examples/ }, |
| 144 | + }, |
| 145 | + ], |
| 146 | + }, |
| 147 | + { |
| 148 | + test: /\.(sa|sc|c)ss$/, |
| 149 | + use: [ |
| 150 | + { |
| 151 | + loader: "style-loader", |
| 152 | + }, |
72 | 153 | { |
73 | | - test: require.resolve("hypher/dist/jquery.hypher.js"), |
74 | | - use: [ |
75 | | - { |
76 | | - loader: "imports-loader", |
77 | | - options: { |
78 | | - imports: [ |
79 | | - "default jquery $", |
80 | | - "default jquery jQuery" |
81 | | - ] |
82 | | - } |
83 | | - } |
84 | | - ] |
85 | | - }, { |
86 | | - test: /lib\/*.js/, |
87 | | - use: [ |
88 | | - { |
89 | | - loader: "imports-loader", |
90 | | - options: { |
91 | | - imports: [ |
92 | | - "default jquery $", |
93 | | - "default jquery jQuery" |
94 | | - ] |
95 | | - } |
96 | | - } |
97 | | - ] |
98 | | - }, { |
99 | | - test: /.jsx?$/, |
100 | | - resolve: { extensions: [".js", ".jsx"] }, |
101 | | - exclude: /node_modules/, |
102 | | - use: [ |
103 | | - { |
104 | | - loader: 'babel-loader', |
105 | | - options: { |
106 | | - presets: ['@babel/preset-env', '@babel/preset-react'] |
107 | | - } |
108 | | - } |
109 | | - ] |
110 | | - }, { |
111 | | - test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, |
112 | | - use: [ |
113 | | - { loader: 'url-loader?limit=10000&minetype=application/font-woff&name=/assets/[name].[ext]' } |
114 | | - ] |
115 | | - }, { |
116 | | - test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, |
117 | | - use: [ |
118 | | - { loader: 'file-loader?name=/assets/[name].[ext]' } |
119 | | - ] |
120 | | - }, { |
121 | | - test: /\.png$/, |
122 | | - use: [ |
123 | | - { |
124 | | - loader: 'file-loader?name=img/[name].[ext]', |
125 | | - options: { exclude: /examples/ } |
126 | | - }, |
127 | | - ] |
128 | | - }, { |
129 | | - test: /\.(sa|sc|c)ss$/, |
130 | | - use: [{ |
131 | | - loader: 'style-loader', |
132 | | - }, { |
133 | | - loader: MiniCssExtractPlugin.loader, |
134 | | - options: { esModule: false }, |
135 | | - }, { |
136 | | - loader: 'css-loader', |
137 | | - }, { |
138 | | - loader: 'sass-loader', |
139 | | - options: { |
140 | | - additionalData: ` |
141 | | - $skin: "${config.skin}"; |
| 154 | + loader: MiniCssExtractPlugin.loader, |
| 155 | + options: { esModule: false }, |
| 156 | + }, |
| 157 | + { |
| 158 | + loader: "css-loader", |
| 159 | + }, |
| 160 | + { |
| 161 | + loader: "sass-loader", |
| 162 | + options: { |
| 163 | + additionalData: ` |
| 164 | + $skin: "${skin}"; |
142 | 165 | `, |
143 | | - sassOptions: { |
144 | | - includePaths: ["node_modules"] |
145 | | - } |
146 | | - } |
| 166 | + sassOptions: { |
| 167 | + includePaths: ["node_modules"], |
147 | 168 | }, |
148 | | - ], |
| 169 | + }, |
149 | 170 | }, |
150 | | - { test: /\.csl$/, type: 'asset/source' } |
151 | | - ] |
152 | | - } |
| 171 | + ], |
| 172 | + }, |
| 173 | + { test: /\.csl$/, type: "asset/source" }, |
| 174 | + ], |
| 175 | + }, |
| 176 | + }; |
153 | 177 | }; |
154 | | - |
155 | | -module.exports = common |
|
0 commit comments