-
Notifications
You must be signed in to change notification settings - Fork 233
/
webpack.prod.js
63 lines (54 loc) · 1.73 KB
/
webpack.prod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const glob = require('glob');
const resolve = require('path').resolve;
const CopyPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const I18nPlugin = require('i18n-webpack-plugin');
const BUILD_DIR = resolve(__dirname, 'dist');
const copyAssets = new CopyPlugin([{ from: './assets', to: 'assets', ignore: '*.svg' }]);
const copySite = new CopyPlugin([{ from: './example', to: './' }]);
const extractSass = new ExtractTextPlugin({ filename: 'leaflet-measure.css' });
const jsLoader = {
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader?optional=runtime',
options: { presets: ['babel-preset-env'] }
}
};
const htmlLoader = {
test: /\.html$/,
use: { loader: 'html-loader?interpolate' }
};
const scssLoader = {
test: /\.scss$/,
use: extractSass.extract({
use: [{ loader: 'css-loader', options: { url: false } }, { loader: 'sass-loader' }],
fallback: 'style-loader'
})
};
// Build for all languages in the in `./languages` using I18nPlugin
const languages = glob.sync('./languages/*.json').reduce(
(dict, filePath) => {
const match = /\/languages\/(.+).json/.exec(filePath);
dict[match[1]] = require(filePath);
return dict;
},
{
default: require(`./languages/en.json`)
}
);
module.exports = Object.keys(languages).map(language => {
const langPrefix = language === 'default' ? '' : `.${language}`;
return {
entry: ['./src/leaflet-measure.js'],
output: {
filename: `leaflet-measure${langPrefix}.js`,
path: BUILD_DIR,
publicPath: '/dist/'
},
module: {
rules: [jsLoader, htmlLoader, scssLoader]
},
plugins: [copySite, copyAssets, extractSass, new I18nPlugin(languages[language])]
};
});