Adjust output file paths.
parent
816d77c44b
commit
d365ede8c2
|
@ -40,6 +40,8 @@ const {
|
||||||
ModuleConcatenationPlugin,
|
ModuleConcatenationPlugin,
|
||||||
} = optimize;
|
} = optimize;
|
||||||
|
|
||||||
|
const dj = 'icedream';
|
||||||
|
|
||||||
export default (options, { mode }) => {
|
export default (options, { mode }) => {
|
||||||
const environment = new Environment({
|
const environment = new Environment({
|
||||||
// @HACK
|
// @HACK
|
||||||
|
@ -59,39 +61,62 @@ export default (options, { mode }) => {
|
||||||
docker,
|
docker,
|
||||||
} = environment;
|
} = environment;
|
||||||
|
|
||||||
const baseOutputFilename = development
|
const baseOutputFilepath = 'static/theme/[type]/[filename]';
|
||||||
? 'assets/dev/[name].dev.[ext]'
|
const filenames = {
|
||||||
// Always use a hash (in production) to prevent files with the same name causing issues
|
css: '[name].[ext]',
|
||||||
: 'assets/prod/[chunkhash:2]/[name].[chunkhash:8].[ext]';
|
default: development
|
||||||
|
? '[name].dev.[ext]'
|
||||||
|
// Always use a hash (in production) to prevent files with the same name causing issues
|
||||||
|
: '[name].[chunkhash:8].[ext]',
|
||||||
|
};
|
||||||
|
|
||||||
const webpackChunkFilename = baseOutputFilename
|
function replaceField(string, name, value) {
|
||||||
.replace(/\[ext(.*?)\]/g, 'js');
|
const retval = string.replace(new RegExp(`\\[${name}(.*?)\\]`), value);
|
||||||
const webpackOutputFilename = webpackChunkFilename;
|
debug('replaceField:', { args: { string, name, value } }, string, '=>', retval);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
const assetOutputFilename = baseOutputFilename
|
function getOutputFilename(type) {
|
||||||
.replace(/\[chunkhash(.*?)\]/g, '[hash$1]');
|
let filename = baseOutputFilepath;
|
||||||
|
switch (type) {
|
||||||
|
case 'css':
|
||||||
|
filename = replaceField(filename, 'type', type);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
filename = replaceField(filename, 'type', `${type}/${dj}`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
filename = replaceField(filename, 'filename', filenames[type] || filenames.default);
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
const cssOutputFileName = baseOutputFilename
|
function getAssetOutputFilename(type) {
|
||||||
|
let filename = getOutputFilename(type);
|
||||||
|
filename = replaceField(filename, 'chunkhash', '[hash$1]');
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cssOutputFileName = getOutputFilename('css')
|
||||||
.replace(/\[ext(.*?)\]/g, 'css');
|
.replace(/\[ext(.*?)\]/g, 'css');
|
||||||
// .replace(/\[chunkhash(.*?)\]/g, '[contenthash$1]');
|
// .replace(/\[chunkhash(.*?)\]/g, '[contenthash$1]');
|
||||||
const cssChunkOutputFileName = baseOutputFilename
|
const cssChunkOutputFileName = getOutputFilename('css')
|
||||||
.replace(/\[chunkhash(.*?)\]/g, '[id$1]')
|
.replace(/\[chunkhash(.*?)\]/g, '[id$1]')
|
||||||
.replace(/\[ext(.*?)\]/g, 'css');
|
.replace(/\[ext(.*?)\]/g, 'css');
|
||||||
// const cssOutputRebasePath = `${slash(path.relative(path.dirname(cssOutputFileName), ''))}/`;
|
// const cssOutputRebasePath = `${slash(path.relative(path.dirname(cssOutputFileName), ''))}/`;
|
||||||
const cssOutputRebasePath = '/';
|
const cssOutputRebasePath = '/';
|
||||||
|
|
||||||
// Default options for file-loader
|
// Default options for file-loader
|
||||||
const fileLoaderOptions = {
|
const getFileLoaderOptions = type => ({
|
||||||
name: assetOutputFilename,
|
name: getAssetOutputFilename(type),
|
||||||
publicPath: cssOutputRebasePath,
|
publicPath: cssOutputRebasePath,
|
||||||
};
|
});
|
||||||
|
|
||||||
// Default options for url-loader
|
// Default options for url-loader
|
||||||
const urlLoaderOptions = {
|
const getUrlLoaderOptions = type => ({
|
||||||
...fileLoaderOptions,
|
...getFileLoaderOptions(type),
|
||||||
// limit: 1, // Don't inline anything (but empty files) by default
|
// limit: 1, // Don't inline anything (but empty files) by default
|
||||||
limit: 4 * 1024,
|
limit: 4 * 1024,
|
||||||
};
|
});
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
name: 'frontend',
|
name: 'frontend',
|
||||||
|
@ -168,22 +193,34 @@ export default (options, { mode }) => {
|
||||||
/\.jpe?g$/i, // jpeg
|
/\.jpe?g$/i, // jpeg
|
||||||
].map(test => ({
|
].map(test => ({
|
||||||
test,
|
test,
|
||||||
loader: 'url-loader',
|
use: [
|
||||||
options: {
|
{
|
||||||
...urlLoaderOptions,
|
loader: 'url-loader',
|
||||||
// fallback: 'responsive-loader',
|
options: {
|
||||||
},
|
...getUrlLoaderOptions('img'),
|
||||||
|
// fallback: 'responsive-loader',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
})),
|
})),
|
||||||
|
|
||||||
...[
|
...[
|
||||||
/\.(mp4|ogg|webm)$/i, // video
|
/\.(mp4|ogg|webm)$/i, // video
|
||||||
/\.(eot|otf|ttf|woff|woff2)$/i, // fonts
|
|
||||||
/\.(wav|mp3|m4a|aac|oga)$/i, // audio
|
/\.(wav|mp3|m4a|aac|oga)$/i, // audio
|
||||||
].map(test => ({
|
].map(test => ({
|
||||||
test,
|
test,
|
||||||
loader: 'url-loader',
|
loader: 'url-loader',
|
||||||
options: urlLoaderOptions,
|
options: getUrlLoaderOptions('media'),
|
||||||
})),
|
})),
|
||||||
|
|
||||||
|
...[
|
||||||
|
/\.(eot|otf|ttf|woff|woff2)$/i, // fonts
|
||||||
|
].map(test => ({
|
||||||
|
test,
|
||||||
|
loader: 'url-loader',
|
||||||
|
options: getUrlLoaderOptions('font'),
|
||||||
|
})),
|
||||||
|
|
||||||
{
|
{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
use: environment.styleLoaders(),
|
use: environment.styleLoaders(),
|
||||||
|
@ -205,8 +242,8 @@ export default (options, { mode }) => {
|
||||||
},
|
},
|
||||||
|
|
||||||
output: {
|
output: {
|
||||||
filename: webpackOutputFilename,
|
filename: replaceField(getOutputFilename('js'), 'ext', 'js'),
|
||||||
chunkFilename: webpackChunkFilename,
|
chunkFilename: replaceField(getOutputFilename('js'), 'ext', 'js'),
|
||||||
path: path.join(__dirname, 'dist'),
|
path: path.join(__dirname, 'dist'),
|
||||||
publicPath: '',
|
publicPath: '',
|
||||||
globalObject: 'this', // https://github.com/webpack-contrib/worker-loader/issues/142#issuecomment-385764803
|
globalObject: 'this', // https://github.com/webpack-contrib/worker-loader/issues/142#issuecomment-385764803
|
||||||
|
@ -337,7 +374,7 @@ export default (options, { mode }) => {
|
||||||
},
|
},
|
||||||
devtool: server ? 'cheap-module-source-map' : 'source-map',
|
devtool: server ? 'cheap-module-source-map' : 'source-map',
|
||||||
entry: {
|
entry: {
|
||||||
app: [
|
[dj]: [
|
||||||
path.join(__dirname, 'src'),
|
path.join(__dirname, 'src'),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue