0
0
Fork 0

Upgrade Webpacker to version 2.0 (#3729)

This commit is contained in:
Yamagishi Kazutoshi 2017-06-18 09:57:09 +09:00 committed by Eugen Rochko
parent 94d0e012de
commit 53e42bf91e
17 changed files with 241 additions and 128 deletions

View file

@ -7,21 +7,22 @@ const { sync } = require('glob');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const extname = require('path-complete-extname');
const { env, paths, publicPath, loadersDir } = require('./configuration.js');
const { env, settings, output, loadersDir } = require('./configuration.js');
const localePackPaths = require('./generateLocalePacks');
const extensionGlob = `**/*{${paths.extensions.join(',')}}*`;
const packPaths = sync(join(paths.source, paths.entry, extensionGlob));
const entryPacks = [].concat(packPaths).concat(localePackPaths).filter(path => path !== join(paths.source, paths.entry, 'custom.js'));
const extensionGlob = `**/*{${settings.extensions.join(',')}}*`;
const entryPath = join(settings.source_path, settings.source_entry_path);
const packPaths = sync(join(entryPath, extensionGlob));
const entryPacks = [...packPaths, ...localePackPaths].filter(path => path !== join(entryPath, 'custom.js'));
const customApplicationStyle = resolve(join(paths.source, 'styles/custom.scss'));
const originalApplicationStyle = resolve(join(paths.source, 'styles/application.scss'));
const customApplicationStyle = resolve(join(settings.source_path, 'styles/custom.scss'));
const originalApplicationStyle = resolve(join(settings.source_path, 'styles/application.scss'));
module.exports = {
entry: entryPacks.reduce(
(map, entry) => {
const localMap = map;
let namespace = relative(join(paths.source, paths.entry), dirname(entry));
let namespace = relative(join(entryPath), dirname(entry));
if (namespace === join('..', '..', '..', 'tmp', 'packs')) {
namespace = ''; // generated by generateLocalePacks.js
}
@ -33,8 +34,8 @@ module.exports = {
output: {
filename: '[name].js',
chunkFilename: '[name]-[chunkhash].js',
path: resolve(paths.output, paths.entry),
publicPath,
path: output.path,
publicPath: output.publicPath,
},
module: {
@ -44,7 +45,10 @@ module.exports = {
plugins: [
new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css'),
new ManifestPlugin({ fileName: paths.manifest, publicPath, writeToFileEmit: true }),
new ManifestPlugin({
publicPath: output.publicPath,
writeToFileEmit: true,
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
minChunks: (module, count) => {
@ -67,15 +71,15 @@ module.exports = {
'mastodon-application-style': existsSync(customApplicationStyle) ?
customApplicationStyle : originalApplicationStyle,
},
extensions: paths.extensions,
extensions: settings.extensions,
modules: [
resolve(paths.source),
resolve(paths.node_modules),
resolve(settings.source_path),
'node_modules',
],
},
resolveLoader: {
modules: [paths.node_modules],
modules: ['node_modules'],
},
node: {