Skip to content

Commit

Permalink
fix: devtool and sourceMap, dev: eval
Browse files Browse the repository at this point in the history
  • Loading branch information
hubcarl committed Nov 22, 2018
1 parent 34a5b4a commit 446bdbb
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 141 deletions.
14 changes: 7 additions & 7 deletions lib/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,17 @@ class Config {
// devtool 只在 dev 模式开启,build 模式需要 通过 easy build 显示制定 --devtool
setDevTool(devtool, force) {
// cli mode force devtool, not use default config
const cliDevtool = this.config.cliDevtool;
const cli = this.config.cli || {};
/* istanbul ignore next */
if (this.utils.isString(cliDevtool)) {
this.webpackConfig.devtool = cliDevtool;
} else if (cliDevtool === true) {
if (this.utils.isString(cli.devtool)) {
this.webpackConfig.devtool = cli.devtool;
} else if (cli.devtool === true) {
this.webpackConfig.devtool = 'source-map';
} else if (devtool) { /* istanbul ignore next */
if (this.dev) {
} else if (this.dev) { /* istanbul ignore next */
if (devtool) {
this.webpackConfig.devtool = devtool;
} else {
this.webpackConfig.devtool = false;
this.webpackConfig.devtool = 'eval';
}
} else {
this.webpackConfig.devtool = false;
Expand Down
1 change: 1 addition & 0 deletions lib/target/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class WebpackBaseBuilder extends Config {
constructor(config = {}) {
super(config);
this.setStyleLoader(STYLE_LOADER);
this.setDevTool(config.devtool);
}

getDLLChunk() {
Expand Down
3 changes: 1 addition & 2 deletions lib/target/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class WebpackClientBuilder extends WebpackBaseBuilder {
constructor(config) {
super(config);
this.type = WebpackClientBuilder.TYPE;
this.setDevTool(config.devtool);
this.setPack(config.packs);
this.setTarget(WebpackClientBuilder.TARGET);
// this.setCommonsChunkLib();
Expand All @@ -21,7 +20,7 @@ class WebpackClientBuilder extends WebpackBaseBuilder {
prepareLoaderOption(loaders, loaderOptions) {
super.prepareLoaderOption(loaders, loaderOptions);
// 自动设置sourceMap
const options = this.config.devtool ? { sourceMap: true } : {};
const options = this.webpackConfig.devtool ? { sourceMap: true } : {};
const cssLoaderOptions = this.getCssLoaderOptions();
Object.keys(loaders).forEach(name => {
const itemLoader = loaders[name];
Expand Down
1 change: 0 additions & 1 deletion lib/target/dll.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class WebpackDllBuilder extends WebpackBaseBuilder {
this.setTarget(WebpackDllBuilder.TARGET);
this.mergeConfig(dll);
this.setBuildPath(this.utils.getDllCompileFileDir(this.env), true);
this.setDevTool(config.devtool);
this.setLibrary('[name]');
this.setStartCreateQueue(this.setBabelENV);
this.setCreateQueue(this.createDllPlugin);
Expand Down
13 changes: 9 additions & 4 deletions test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,13 @@ describe('client.test.js', () => {
const webpackConfig = builder.create();
expect(webpackConfig.devtool).to.equal('source-map');
});
it('should test eval devtool test', () => {
const builder = createBuilder({ env: 'test', devtool: 'eval'});
const webpackConfig = builder.create();
expect(webpackConfig.devtool).to.be.false;
});
it('should prod devtool test', () => {
const builder = createBuilder({ env: 'prod', cliDevtool: 'source-map'});
const builder = createBuilder({ env: 'prod', cli: { devtool: 'source-map' }});
const webpackConfig = builder.create();
expect(webpackConfig.devtool).to.equal('source-map');
});
Expand All @@ -365,17 +370,17 @@ describe('client.test.js', () => {
expect(webpackConfig.devtool).to.equal('eval');
});
it('should prod eval devtool test', () => {
const builder = createBuilder({ env: 'prod', cliDevtool: 'eval'});
const builder = createBuilder({ env: 'prod', cli: { devtool: 'eval' }});
const webpackConfig = builder.create();
expect(webpackConfig.devtool).to.equal('eval');
});
it('should dev cli eval devtool test', () => {
const builder = createBuilder({ env: 'prod', devtool: 'eval', cliDevtool: true});
const builder = createBuilder({ env: 'prod', devtool: 'eval', cli: { devtool: true }});
const webpackConfig = builder.create();
expect(webpackConfig.devtool).to.equal('source-map');
});
it('should prod cli eval devtool test', () => {
const builder = createBuilder({ env: 'prod', devtool: 'eval', cliDevtool: true });
const builder = createBuilder({ env: 'prod', devtool: 'eval', cli: { devtool: true } });
const webpackConfig = builder.create();
expect(webpackConfig.devtool).to.equal('source-map');
});
Expand Down
4 changes: 2 additions & 2 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,13 @@ describe('loader.test.js', () => {

describe('#webpack feature loader test', () => {
it('should postcss-loader default config', () => {
const builder = createBuilder();
const builder = createBuilder({ env: 'dev' });
const webpackConfig = builder.create();
const cssLoader = helper.getLoaderByName('css', webpackConfig.module.rules);
const postcssLoader = cssLoader.use.find(loader => {
return loader.loader === 'postcss-loader';
});
expect(postcssLoader.options.sourceMap).to.be.undefined;
expect(postcssLoader.options.sourceMap).to.be.true;
});

it('should postcss-loader devtool config', () => {
Expand Down
250 changes: 125 additions & 125 deletions test/typescript.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,138 +25,138 @@ describe('typescript.test.js', () => {
expect(webpackConfig.resolve.extensions).to.include.members(['.ts']);
});

// it('should webpack typescript babel test', () => {
// const builder = helper.createClientBuilder({ framework: 'react', loaders: { typescript: true }});
// const webpackConfig = builder.create();
// const loaders = helper.getLoaderByName('ts', webpackConfig.module.rules);
// expect(webpackConfig.resolve.extensions).to.include.members(['.ts']);
// expect(loaders.use.length).to.equal(4);
// expect(loaders.use[0].loader).to.equal('babel-loader');
// });
it('should webpack typescript babel test', () => {
const builder = helper.createClientBuilder({ framework: 'react', loaders: { typescript: true }});
const webpackConfig = builder.create();
const loaders = helper.getLoaderByName('ts', webpackConfig.module.rules);
expect(webpackConfig.resolve.extensions).to.include.members(['.ts']);
expect(loaders.use.length).to.equal(4);
expect(loaders.use[0].loader).to.equal('babel-loader');
});

// it('should default typescript enable test', () => {
// const builder = helper.createBuilder();
// const webpackConfig = builder.create();
// const tsLoader = helper.getLoaderByName('ts', webpackConfig.module.rules);
// const tslint = helper.getLoaderByName('tslint', webpackConfig.module.rules);
// expect(tsLoader).to.be.undefined;
// expect(tslint).to.be.undefined;
// });
it('should default typescript enable test', () => {
const builder = helper.createBuilder();
const webpackConfig = builder.create();
const tsLoader = helper.getLoaderByName('ts', webpackConfig.module.rules);
const tslint = helper.getLoaderByName('tslint', webpackConfig.module.rules);
expect(tsLoader).to.be.undefined;
expect(tslint).to.be.undefined;
});

// it('should typescript cache enable test', () => {
// const builder = helper.createBuilder({
// loaders:{
// eslint: true,
// tslint: true,
// typescript: true
// },
// compile:{
// thread: false
// }
// });
// const webpackConfig = builder.create();
// const tsLoader = helper.getLoaderByName('ts', webpackConfig.module.rules);
// const eslint = helper.getLoaderByName('eslint', webpackConfig.module.rules);
// const tslint = helper.getLoaderByName('tslint', webpackConfig.module.rules);
// expect(tsLoader.use[0].loader).to.equal('cache-loader');
// expect(tsLoader.use[1].loader).to.equal('ts-loader');
// expect(eslint.use[0].loader).to.equal('eslint-loader');
// expect(tslint.use[0].loader).to.equal('tslint-loader');
// expect(webpackConfig.resolve.extensions).to.include.members(['.ts', '.js']);
// });
it('should typescript cache enable test', () => {
const builder = helper.createBuilder({
loaders:{
eslint: true,
tslint: true,
typescript: true
},
compile:{
thread: false
}
});
const webpackConfig = builder.create();
const tsLoader = helper.getLoaderByName('ts', webpackConfig.module.rules);
const eslint = helper.getLoaderByName('eslint', webpackConfig.module.rules);
const tslint = helper.getLoaderByName('tslint', webpackConfig.module.rules);
expect(tsLoader.use[0].loader).to.equal('cache-loader');
expect(tsLoader.use[1].loader).to.equal('ts-loader');
expect(eslint.use[0].loader).to.equal('eslint-loader');
expect(tslint.use[0].loader).to.equal('tslint-loader');
expect(webpackConfig.resolve.extensions).to.include.members(['.ts', '.js']);
});

// it('should typescript cache and thread enable test', () => {
// const builder = helper.createBuilder({
// loaders:{
// eslint: true,
// tslint: true,
// typescript: true
// }
// });
// const webpackConfig = builder.create();
// const tsLoader = helper.getLoaderByName('ts', webpackConfig.module.rules);
// const eslint = helper.getLoaderByName('eslint', webpackConfig.module.rules);
// const tslint = helper.getLoaderByName('tslint', webpackConfig.module.rules);
// expect(tsLoader.use[0].loader).to.equal('cache-loader');
// expect(tsLoader.use[1].loader).to.equal('thread-loader');
// expect(tsLoader.use[2].loader).to.equal('ts-loader');
// expect(eslint.use[0].loader).to.equal('eslint-loader');
// expect(tslint.use[0].loader).to.equal('tslint-loader');
// expect(webpackConfig.resolve.extensions).to.include.members(['.ts', '.js']);
// });
it('should typescript cache and thread enable test', () => {
const builder = helper.createBuilder({
loaders:{
eslint: true,
tslint: true,
typescript: true
}
});
const webpackConfig = builder.create();
const tsLoader = helper.getLoaderByName('ts', webpackConfig.module.rules);
const eslint = helper.getLoaderByName('eslint', webpackConfig.module.rules);
const tslint = helper.getLoaderByName('tslint', webpackConfig.module.rules);
expect(tsLoader.use[0].loader).to.equal('cache-loader');
expect(tsLoader.use[1].loader).to.equal('thread-loader');
expect(tsLoader.use[2].loader).to.equal('ts-loader');
expect(eslint.use[0].loader).to.equal('eslint-loader');
expect(tslint.use[0].loader).to.equal('tslint-loader');
expect(webpackConfig.resolve.extensions).to.include.members(['.ts', '.js']);
});

// it('should typescript cache config test', () => {
// const configFile = path.resolve(__dirname, './app/web/tsconfig.json');
// const builder = helper.createBuilder({
// loaders:{
// typescript: {
// options:{
// configFile,
// }
// }
// },
// compile:{
// thread: false
// }
// });
// const webpackConfig = builder.create();
// const tsLoader = helper.getLoaderByName('ts', webpackConfig.module.rules);
// const eslint = helper.getLoaderByName('eslint', webpackConfig.module.rules);
// const tslint = helper.getLoaderByName('tslint', webpackConfig.module.rules);
// expect(eslint).to.be.undefined;
// expect(tslint).to.be.undefined;
// expect(tsLoader.use[0].loader).to.equal('cache-loader');
// expect(tsLoader.use[1].loader).to.equal('ts-loader');
// expect(tsLoader.use[1].options.configFile).to.equal(configFile);
// });
it('should typescript cache config test', () => {
const configFile = path.resolve(__dirname, './app/web/tsconfig.json');
const builder = helper.createBuilder({
loaders:{
typescript: {
options:{
configFile,
}
}
},
compile:{
thread: false
}
});
const webpackConfig = builder.create();
const tsLoader = helper.getLoaderByName('ts', webpackConfig.module.rules);
const eslint = helper.getLoaderByName('eslint', webpackConfig.module.rules);
const tslint = helper.getLoaderByName('tslint', webpackConfig.module.rules);
expect(eslint).to.be.undefined;
expect(tslint).to.be.undefined;
expect(tsLoader.use[0].loader).to.equal('cache-loader');
expect(tsLoader.use[1].loader).to.equal('ts-loader');
expect(tsLoader.use[1].options.configFile).to.equal(configFile);
});

// it('should typescript cache config test', () => {
// const configFile = path.resolve(__dirname, './app/web/tsconfig.json');
// const builder = helper.createBuilder({
// loaders:{
// typescript: {
// options:{
// configFile,
// }
// }
// },
// compile:{
// thread: false
// }
// });
// const webpackConfig = builder.create();
// const tsLoader = helper.getLoaderByName('ts', webpackConfig.module.rules);
// const eslint = helper.getLoaderByName('eslint', webpackConfig.module.rules);
// const tslint = helper.getLoaderByName('tslint', webpackConfig.module.rules);
// expect(eslint).to.be.undefined;
// expect(tslint).to.be.undefined;
// expect(tsLoader.use[0].loader).to.equal('cache-loader');
// expect(tsLoader.use[1].loader).to.equal('ts-loader');
// expect(tsLoader.use[1].options.configFile).to.equal(configFile);
// });
it('should typescript cache config test', () => {
const configFile = path.resolve(__dirname, './app/web/tsconfig.json');
const builder = helper.createBuilder({
loaders:{
typescript: {
options:{
configFile,
}
}
},
compile:{
thread: false
}
});
const webpackConfig = builder.create();
const tsLoader = helper.getLoaderByName('ts', webpackConfig.module.rules);
const eslint = helper.getLoaderByName('eslint', webpackConfig.module.rules);
const tslint = helper.getLoaderByName('tslint', webpackConfig.module.rules);
expect(eslint).to.be.undefined;
expect(tslint).to.be.undefined;
expect(tsLoader.use[0].loader).to.equal('cache-loader');
expect(tsLoader.use[1].loader).to.equal('ts-loader');
expect(tsLoader.use[1].options.configFile).to.equal(configFile);
});

// it('should tslint enable test', () => {
// const builder = helper.createBuilder({
// loaders:{
// tslint: true
// }
// });
// const webpackConfig = builder.create();
// const tsLoader = helper.getLoaderByName('tslint', webpackConfig.module.rules);
// expect(tsLoader.use[0].loader).to.equal('tslint-loader');
// });
it('should tslint enable test', () => {
const builder = helper.createBuilder({
loaders:{
tslint: true
}
});
const webpackConfig = builder.create();
const tsLoader = helper.getLoaderByName('tslint', webpackConfig.module.rules);
expect(tsLoader.use[0].loader).to.equal('tslint-loader');
});

// it('should typescript egg configFile auto set test', () => {
// const builder = helper.createBuilder({
// egg: true,
// loaders:{
// typescript: true
// }
// });
// const webpackConfig = builder.create();
// const tsLoader = helper.getLoaderByName('ts', webpackConfig.module.rules);
// expect(tsLoader.use[2].loader).to.equal('ts-loader');
// });
it('should typescript egg configFile auto set test', () => {
const builder = helper.createBuilder({
egg: true,
loaders:{
typescript: true
}
});
const webpackConfig = builder.create();
const tsLoader = helper.getLoaderByName('ts', webpackConfig.module.rules);
expect(tsLoader.use[2].loader).to.equal('ts-loader');
});

});
});

0 comments on commit 446bdbb

Please sign in to comment.