Skip to content

Commit ffb14a6

Browse files
committed
fix: set prefix support with easywebpack 3
1 parent c8cb1ab commit ffb14a6

4 files changed

Lines changed: 28 additions & 12 deletions

File tree

lib/builder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ exports.getDllWebpackConfig = (config, option = {}) => {
3636
const publicPath = config.publicPath;
3737
const buildPath = config.buildPath;
3838
const install = config.install;
39+
const prefix = config.prefix;
3940
const resolveLoader = config.resolveLoader;
4041
const cdn = config.cdn;
4142
const configPlugins = config.plugins || {};
@@ -50,7 +51,7 @@ exports.getDllWebpackConfig = (config, option = {}) => {
5051
}
5152
}
5253
dllArray.forEach(item => {
53-
const builderConfig = Object.assign({}, dllConfig, { entry: {}, dll: item, publicPath, buildPath, alias, externals, resolveLoader, install, cdn, plugins }, item.webpackConfig);
54+
const builderConfig = Object.assign({}, dllConfig, { prefix, entry: {}, dll: item, publicPath, buildPath, alias, externals, resolveLoader, install, cdn, plugins }, item.webpackConfig);
5455
if (option.onlyView || utils.checkDllUpdate(config, item)) {
5556
dllWebpackConfig.push(new WebpackDllBuilder(builderConfig).create());
5657
}

lib/config.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ class Config {
8282
return this.dev && this.utils.isTrue(config.proxy);
8383
}
8484

85+
get prefix() {
86+
return this.config.prefix || '';
87+
}
88+
8589
get nativeWebpackConfig() {
8690
return this.configList.reduce((result, item) => {
8791
return merge(result, this.analysisWebpackConfig(item));
@@ -249,35 +253,35 @@ class Config {
249253

250254
createFileName(config) {
251255
if ((config.hash && this.utils.isTrue(config.fileHash)) || config.fileHash) {
252-
this.setOutputFileName(`js/[name].[chunkhash:${config.hashLength}].js`);
253-
this.setOutputFileChunkName(`js/chunk/[name].[chunkhash:${config.hashLength}].js`)
256+
this.setOutputFileName(utils.assetsPath(this.prefix, `js/[name].[chunkhash:${config.hashLength}].js`));
257+
this.setOutputFileChunkName(utils.assetsPath(this.prefix, `js/chunk/[name].[chunkhash:${config.hashLength}].js`));
254258
} else {
255-
this.setOutputFileName('js/[name].js');
256-
this.setOutputFileChunkName('js/chunk/[name].js');
259+
this.setOutputFileName(utils.assetsPath(this.prefix, 'js/[name].js'));
260+
this.setOutputFileChunkName(utils.assetsPath(this.prefix, 'js/chunk/[name].js'));
257261
}
258262
}
259263

260264
createImageName(config) {
261265
if ((config.hash && this.utils.isTrue(config.imageHash)) || config.imageHash) {
262-
this.webpackInfo.imageName = `img/[name].[hash:${config.hashLength}].[ext]`;
266+
this.webpackInfo.imageName = utils.assetsPath(this.prefix, `img/[name].[hash:${config.hashLength}].[ext]`);
263267
} else {
264-
this.webpackInfo.imageName = 'img/[name].[ext]';
268+
this.webpackInfo.imageName = utils.assetsPath(this.prefix, 'img/[name].[ext]');
265269
}
266270
}
267271

268272
createCssName(config) {
269273
if ((config.hash && this.utils.isTrue(config.cssHash)) || config.cssHash) {
270-
this.webpackInfo.cssName = `css/[name].[contenthash:${config.hashLength}].css`;
274+
this.webpackInfo.cssName = utils.assetsPath(this.prefix, `css/[name].[contenthash:${config.hashLength}].css`);
271275
} else {
272-
this.webpackInfo.cssName = 'css/[name].css';
276+
this.webpackInfo.cssName = utils.assetsPath(this.prefix, 'css/[name].css');
273277
}
274278
}
275279

276280
createFrontName(config) {
277281
if ((config.hash && this.utils.isTrue(config.fontHash)) || config.fontHash) {
278-
this.webpackInfo.frontName = `font/[name].[hash:${config.hashLength}].[ext]`;
282+
this.webpackInfo.frontName = utils.assetsPath(this.prefix, `font/[name].[hash:${config.hashLength}].[ext]`);
279283
} else {
280-
this.webpackInfo.frontName = 'font/[name].[ext]';
284+
this.webpackInfo.frontName = utils.assetsPath(this.prefix, 'font/[name].[ext]');
281285
}
282286
}
283287

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "easywebpack",
3-
"version": "4.0.3",
3+
"version": "4.0.4",
44
"description": "基于 Webpack 的前端构建工程化解决方案",
55
"keywords": [
66
"webpack",

test/base.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,15 @@ describe('base.test.js', () => {
9696
expect(webpackConfig.resolve.extensions).to.be.an('array').that.includes('.js');
9797
});
9898
});
99+
100+
describe('#webpack create test', () => {
101+
it('should create webpack config', () => {
102+
const builder = createBuilder({
103+
prefix: 'static'
104+
});
105+
const webpackConfig = builder.create();
106+
expect(webpackConfig.output.filename).to.equal('static/js/[name].js');
107+
expect(webpackConfig.output.chunkFilename).to.equal('static/js/chunk/[name].js');
108+
});
109+
});
99110
});

0 commit comments

Comments
 (0)